Skip to content

Commit ec2a44a

Browse files
committed
refactor: native deps auto-wire via mkPodmanService, no manual wiring needed
mkPodmanService now accepts appDir in its outer import args and auto-derives native systemd deps from metadata.yaml — same IFD pattern as mkPodmanApp. Apps using mkPodmanService directly (e.g. authentik) declare: mkPodmanService = import .../podman-service.nix { inherit pkgs lib; appDir = ./.; }; Deps from integrations.*.compatible[].app auto-apply to every container created via that import. No extraAfter/extraRequires for native services needed. authentik loses its manual redis.service wiring — now comes from metadata.yaml.
1 parent 5ffa012 commit ec2a44a

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

apps/authentik/module.nix

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ let
55
bloudCfg = config.bloud;
66
traefikCfg = config.bloud.apps.traefik;
77
postgresCfg = config.bloud.apps.postgres;
8-
mkPodmanService = import ../../nixos/lib/podman-service.nix { inherit pkgs lib; };
9-
nativeDeps = import ../../nixos/lib/metadata.nix { inherit pkgs lib; };
10-
nativeIntegrationDeps = nativeDeps ./metadata.yaml;
8+
mkPodmanService = import ../../nixos/lib/podman-service.nix { inherit pkgs lib; appDir = ./.; };
119
# Note: App-specific blueprints are now generated by the host-agent from metadata.yaml SSO config
1210

1311
userHome = "/home/${bloudCfg.user}";
@@ -155,8 +153,8 @@ in
155153
network = "apps-net";
156154
dependsOn = [ "apps-network" ];
157155
userns = "keep-id";
158-
extraAfter = [ "bloud-db-init.service" ] ++ nativeIntegrationDeps;
159-
extraRequires = [ "bloud-db-init.service" ] ++ nativeIntegrationDeps;
156+
extraAfter = [ "bloud-db-init.service" ];
157+
extraRequires = [ "bloud-db-init.service" ];
160158
# Wire up configurator to run after container starts (sets admin password, etc.)
161159
bloudAppName = "authentik";
162160
bloudAgentPath = bloudCfg.agentPath;
@@ -194,8 +192,8 @@ in
194192
network = "apps-net";
195193
dependsOn = [ "apps-network" ];
196194
userns = "keep-id";
197-
extraAfter = [ "bloud-db-init.service" ] ++ nativeIntegrationDeps;
198-
extraRequires = [ "bloud-db-init.service" ] ++ nativeIntegrationDeps;
195+
extraAfter = [ "bloud-db-init.service" ];
196+
extraRequires = [ "bloud-db-init.service" ];
199197
};
200198

201199
# Authentik nginx proxy (adds X-Forwarded-Host header for correct OAuth URLs)

nixos/lib/podman-app.nix

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,11 @@
7070
}:
7171

7272
let
73-
mkPodmanService = import ./podman-service.nix { inherit pkgs lib; };
73+
# Pass appDir so mkPodmanService auto-derives native deps from metadata.yaml.
74+
mkPodmanService = import ./podman-service.nix { inherit pkgs lib; inherit appDir; };
7475
nativeDeps = import ./metadata.nix { inherit pkgs lib; };
7576

76-
# Auto-derive native service deps from metadata.yaml (IFD) when appDir is provided.
77-
# Convention: integrations.*.compatible[].app → "{app}.service" (canonical alias).
78-
# Native apps (postgres, redis) expose real system aliases; container app names are no-ops.
77+
# Used for the db-init service's after list (mkPodmanService handles the main container).
7978
nativeIntegrationDeps = if appDir == null then [] else nativeDeps (appDir + "/metadata.yaml");
8079

8180
# References to other configs
@@ -190,11 +189,9 @@ let
190189
};
191190
};
192191

193-
# Extra systemd dependencies for database init + native integration deps
192+
# Extra systemd dependencies for database init (native deps handled by mkPodmanService)
194193
dbExtraAfter = lib.optionals (database != null) [ "${serviceName}-db-init.service" ];
195194
dbExtraRequires = lib.optionals (database != null) [ "${serviceName}-db-init.service" ];
196-
containerExtraAfter = dbExtraAfter ++ nativeIntegrationDeps;
197-
containerExtraRequires = dbExtraRequires ++ nativeIntegrationDeps;
198195

199196
# Port option (only if port is specified)
200197
portOption = lib.optionalAttrs (port != null) {
@@ -245,8 +242,8 @@ in
245242
volumes = allVolumes;
246243
network = network;
247244
dependsOn = [ "apps-network" ] ++ normalizedDependsOn;
248-
extraAfter = containerExtraAfter;
249-
extraRequires = containerExtraRequires;
245+
extraAfter = dbExtraAfter;
246+
extraRequires = dbExtraRequires;
250247
# Bloud configurator hooks (uses dev path for now, will be packaged later)
251248
bloudAppName = name;
252249
bloudAgentPath = config.bloud.agentPath;

nixos/lib/podman-service.nix

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
{ pkgs, lib, ... }:
2-
3-
# Helper function to create a systemd user service for a podman container
4-
# This abstracts the common patterns for running containers with rootless podman
1+
# Pass appDir = ./. in the import to auto-derive native service deps from metadata.yaml:
2+
# mkPodmanService = import ../../nixos/lib/podman-service.nix { inherit pkgs lib; appDir = ./.; };
53
#
64
# Parameters:
7-
# waitFor - list of {container, command} to health check before starting
8-
# e.g. [{ container = "postgres"; command = "pg_isready -U user"; }]
5+
# waitFor - list of {container, command} to health check before starting
96
# bloudAppName - if set, runs bloud-agent configure prestart/poststart hooks
107
# bloudAgentPath - path to bloud-agent binary (required if bloudAppName is set)
118

9+
{ pkgs, lib, appDir ? null }:
10+
1211
{ name, image, ports ? [], environment ? {}, volumes ? [], network ? null, dependsOn ? [], cmd ? [], userns ? null, waitFor ? [], extraAfter ? [], extraRequires ? [], bloudAppName ? null, bloudAgentPath ? null, envFile ? null, preStartScript ? null }:
1312
let
13+
nativeDeps = import ./metadata.nix { inherit pkgs lib; };
14+
nativeIntegrationDeps = if appDir == null then [] else nativeDeps (appDir + "/metadata.yaml");
1415
# Generate health check script for each waitFor entry
1516
mkHealthCheck = { container, command, timeout ? 60 }: ''
1617
echo "Waiting for ${container} to be ready..."
@@ -41,9 +42,9 @@ let
4142
in
4243
{
4344
description = "Podman container: ${name}";
44-
after = [ "network-online.target" "bloud-init-secrets.service" ] ++ (map (dep: "podman-${dep}.service") dependsOn) ++ extraAfter;
45+
after = [ "network-online.target" "bloud-init-secrets.service" ] ++ (map (dep: "podman-${dep}.service") dependsOn) ++ extraAfter ++ nativeIntegrationDeps;
4546
wants = [ "network-online.target" "bloud-init-secrets.service" ] ++ (map (dep: "podman-${dep}.service") dependsOn);
46-
requires = extraRequires;
47+
requires = extraRequires ++ nativeIntegrationDeps;
4748
wantedBy = [ "bloud-apps.target" ];
4849

4950
# Add /run/wrappers/bin to PATH for newuidmap/newgidmap (rootless podman)

0 commit comments

Comments
 (0)