From a338deb8a1d11ead60c3d20b03f466b745514c38 Mon Sep 17 00:00:00 2001 From: cinereal Date: Sat, 4 Apr 2026 08:23:23 +0200 Subject: [PATCH] lib/services: move portable service infrastructure out of nixos/ Move the portable modular service base from nixos/modules/system/service/portable/ to lib/services/, making it importable by any module system (home-manager, nix-darwin) without reaching into the nixos/ tree. Moved files: service.nix, lib.nix, config-data.nix, config-data-item.nix, test.nix. All external references updated (systemd/system.nix, doc/manual/default.nix, assertions.nix, README.md). No functional changes - only import paths differ. --- .../service/portable => lib/services}/config-data-item.nix | 2 +- .../service/portable => lib/services}/config-data.nix | 2 +- .../system/service/portable => lib/services}/lib.nix | 0 .../system/service/portable => lib/services}/service.nix | 4 ++-- .../system/service/portable => lib/services}/test.nix | 4 ++-- nixos/doc/manual/default.nix | 2 +- nixos/modules/misc/assertions.nix | 2 +- nixos/modules/system/service/README.md | 6 +++--- nixos/modules/system/service/systemd/system.nix | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) rename {nixos/modules/system/service/portable => lib/services}/config-data-item.nix (96%) rename {nixos/modules/system/service/portable => lib/services}/config-data.nix (96%) rename {nixos/modules/system/service/portable => lib/services}/lib.nix (100%) rename {nixos/modules/system/service/portable => lib/services}/service.nix (95%) rename {nixos/modules/system/service/portable => lib/services}/test.nix (97%) diff --git a/nixos/modules/system/service/portable/config-data-item.nix b/lib/services/config-data-item.nix similarity index 96% rename from nixos/modules/system/service/portable/config-data-item.nix rename to lib/services/config-data-item.nix index 90fae10068e7..44671b704d8d 100644 --- a/nixos/modules/system/service/portable/config-data-item.nix +++ b/lib/services/config-data-item.nix @@ -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: { diff --git a/nixos/modules/system/service/portable/config-data.nix b/lib/services/config-data.nix similarity index 96% rename from nixos/modules/system/service/portable/config-data.nix rename to lib/services/config-data.nix index 63f570140b55..953574b8a04d 100644 --- a/nixos/modules/system/service/portable/config-data.nix +++ b/lib/services/config-data.nix @@ -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 }: diff --git a/nixos/modules/system/service/portable/lib.nix b/lib/services/lib.nix similarity index 100% rename from nixos/modules/system/service/portable/lib.nix rename to lib/services/lib.nix diff --git a/nixos/modules/system/service/portable/service.nix b/lib/services/service.nix similarity index 95% rename from nixos/modules/system/service/portable/service.nix rename to lib/services/service.nix index 77befdfb63d6..1bcf0845f0d7 100644 --- a/nixos/modules/system/service/portable/service.nix +++ b/lib/services/service.nix @@ -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 = { diff --git a/nixos/modules/system/service/portable/test.nix b/lib/services/test.nix similarity index 97% rename from nixos/modules/system/service/portable/test.nix rename to lib/services/test.nix index acc07742dfcb..65d05ceb39e9 100644 --- a/nixos/modules/system/service/portable/test.nix +++ b/lib/services/test.nix @@ -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; diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index bdede559d1df..137010637f09 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -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"; }) ]; diff --git a/nixos/modules/misc/assertions.nix b/nixos/modules/misc/assertions.nix index ae8fa710b2b8..e3adc2dcac46 100644 --- a/nixos/modules/misc/assertions.nix +++ b/nixos/modules/misc/assertions.nix @@ -34,5 +34,5 @@ }; # impl of assertions is in # - - # - + # - } diff --git a/nixos/modules/system/service/README.md b/nixos/modules/system/service/README.md index 70c08e706577..d2124cbb1ec6 100644 --- a/nixos/modules/system/service/README.md +++ b/nixos/modules/system/service/README.md @@ -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**: diff --git a/nixos/modules/system/service/systemd/system.nix b/nixos/modules/system/service/systemd/system.nix index 3405072089e1..b1ae25b85118 100644 --- a/nixos/modules/system/service/systemd/system.nix +++ b/nixos/modules/system/service/systemd/system.nix @@ -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: