lib/services: move portable service infrastructure out of nixos/ (#506519)

This commit is contained in:
Robert Hensing
2026-04-05 19:17:30 +00:00
committed by GitHub
10 changed files with 16 additions and 13 deletions
@@ -1,4 +1,4 @@
# Tests in: ../../../../tests/modular-service-etc/test.nix
# Tests in: ../../nixos/tests/modular-service-etc/test.nix
# This file is a function that returns a module.
pkgs:
{
@@ -1,4 +1,4 @@
# Tests in: ../../../../tests/modular-service-etc/test.nix
# Tests in: ../../nixos/tests/modular-service-etc/test.nix
# Non-modular context provided by the modular services integration.
{ pkgs }:
@@ -16,8 +16,8 @@ in
# https://nixos.org/manual/nixos/unstable/#modular-services
_class = "service";
imports = [
../../../../../modules/generic/meta-maintainers.nix
../../../misc/assertions.nix
../../modules/generic/meta-maintainers.nix
../../nixos/modules/misc/assertions.nix
(lib.modules.importApply ./config-data.nix { inherit pkgs; })
];
options = {
@@ -1,7 +1,7 @@
# Run:
# nix-instantiate --eval nixos/modules/system/service/portable/test.nix
# nix-instantiate --eval lib/services/test.nix
let
lib = import ../../../../../lib;
lib = import ../.;
inherit (lib) mkOption types;
+1 -1
View File
@@ -134,7 +134,7 @@ let
inherit
(evalModules {
modules = [
(modules.importApply ../../modules/system/service/portable/service.nix {
(modules.importApply ../../../lib/services/service.nix {
pkgs = throw "nixos docs / portableServiceOptions: Do not reference pkgs in docs";
})
];
+1 -1
View File
@@ -34,5 +34,5 @@
};
# impl of assertions is in
# - <nixpkgs/nixos/modules/system/activation/top-level.nix>
# - <nixpkgs/nixos/modules/system/service/portable/lib.nix>
# - <nixpkgs/lib/services/lib.nix>
}
+4 -1
View File
@@ -116,7 +116,10 @@ let
&& (t == "directory" -> baseNameOf n != "tests")
&& (t == "file" -> hasSuffix ".nix" n)
);
prefixRegex = "^" + lib.strings.escapeRegex (toString pkgs.path) + "($|/(modules|nixos)($|/.*))";
prefixRegex =
"^"
+ lib.strings.escapeRegex (toString pkgs.path)
+ "($|/(modules|nixos|lib/services)($|/.*)|/lib)";
filteredModules = builtins.path {
name = "source";
inherit (pkgs) path;
+3 -3
View File
@@ -43,7 +43,7 @@ Many services implement automatic reloading or reloading on e.g. `SIGUSR1`, but
### Service Manager Integration
- **Portable base**: The `configData` interface is declared in `portable/config-data.nix`, making it available to all service manager implementations.
- **Portable base**: The `configData` interface is declared in `lib/services/config-data.nix`, making it available to all service manager implementations.
- **Systemd integration**: The systemd implementation (`systemd/system.nix`) maps `configData` entries to `environment.etc` entries under `/etc/system-services/`.
@@ -66,11 +66,11 @@ The modular service infrastructure avoids exposing `pkgs` as a module argument t
### Implementation
- **Portable layer**: Service modules in `portable/` do not receive `pkgs` as a module argument. Any required derivations must be provided by the caller.
- **Portable layer**: Service modules in `lib/services/` do not receive `pkgs` as a module argument. Any required derivations must be provided by the caller.
- **Systemd integration**: The `systemd/system.nix` module imports `config-data.nix` as a function, providing `pkgs` in lexical closure:
```nix
(import ../portable/config-data.nix { inherit pkgs; })
(import lib/services/config-data.nix { inherit pkgs; })
```
- **Service modules**:
@@ -15,7 +15,7 @@ let
mapAttrsToList
;
portable-lib = import ../portable/lib.nix { inherit lib; };
portable-lib = import ../../../../../lib/services/lib.nix { inherit lib; };
dash =
before: after: