mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-02 13:00:23 +00:00
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
This commit is contained in:
@@ -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.<path>.text` to a store path.
|
||||
`configData.<path>.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
|
||||
|
||||
Reference in New Issue
Block a user