From e5e85e40ede8dc8c8f94e031fd0c79fe9f73603d Mon Sep 17 00:00:00 2001 From: cinereal Date: Sun, 30 Aug 2026 21:13:21 +0200 Subject: [PATCH] lib/services: allow overriding the base modules of `configure` Consumers that supply their own portable service base -- a pinned `service.nix` from a different nixpkgs, for example -- had no way to replace the module that `configure` loads. Add a `baseModules` parameter for that. It defaults to the portable service base, so callers that only set `serviceManagerPkgs` are unaffected. Assisted-by: Claude:claude-opus-5 Claude-Session: https://claude.ai/code/session_01DPPuohWjgbww5Rq8faiP57 --- lib/services/lib.nix | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/services/lib.nix b/lib/services/lib.nix index 37249512b65b..7c235e066802 100644 --- a/lib/services/lib.nix +++ b/lib/services/lib.nix @@ -52,6 +52,8 @@ rec { let modularServiceConfiguration = lib.services.configure { serviceManagerPkgs = pkgs; + # To load a different portable service base, set `baseModules` instead: + # baseModules = [ (lib.importService { inherit pkgs; }) ]; extraRootModules = [ ./launchd-service.nix # launchd-specific options (plist generation, etc.) ]; @@ -80,18 +82,27 @@ rec { `serviceManagerPkgs` : 1\. A Nixpkgs instance used for built-in logic such as converting - `configData..text` to a store path. + `configData..text` to a store path. Required unless `baseModules` + is set. + + `baseModules` + + : 2\. Modules that replace the portable service base. They are loaded + into the "root" service submodule and must handle propagation to + sub-`services` themselves. Defaults to the portable service base of + this Nixpkgs. Set it to supply a different one, for example a + `service.nix` pinned from another Nixpkgs. `extraRootModules` - : 2\. Modules to be loaded into the "root" service submodule, but not + : 3\. Modules to be loaded into the "root" service submodule, but not into its sub-`services`. That's the modules' own responsibility. Typically contains service-manager-specific option modules (e.g. systemd unit options, launchd plist options). `extraRootSpecialArgs` - : 3\. Fixed module arguments provided alongside `extraRootModules`. + : 4\. Fixed module arguments provided alongside `extraRootModules`. # Output @@ -101,17 +112,15 @@ rec { */ configure = { - serviceManagerPkgs, + serviceManagerPkgs ? throw "lib.services.configure: `serviceManagerPkgs` is required unless `baseModules` is set", + baseModules ? [ (lib.importService { pkgs = serviceManagerPkgs; }) ], extraRootModules ? [ ], extraRootSpecialArgs ? { }, }: let - modules = [ - (lib.modules.importApply ./service.nix { pkgs = serviceManagerPkgs; }) - ]; serviceSubmodule = types.submoduleWith { class = "service"; - modules = modules ++ extraRootModules; + modules = baseModules ++ extraRootModules; specialArgs = extraRootSpecialArgs; }; in