From 1aabcdd4704f2fbe6d9284f368f6cba2ad2e8a4a Mon Sep 17 00:00:00 2001 From: cinereal Date: Tue, 5 May 2026 11:02:25 +0200 Subject: [PATCH] modular-services: simple example using `mpd` Signed-off-by: cinereal --- docs/manual/usage/modular-services.md | 18 +++++------------- tests/modules/services-modular/basic.nix | 8 +++----- tests/modules/services-modular/demo.service | 8 ++++++++ 3 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 tests/modules/services-modular/demo.service diff --git a/docs/manual/usage/modular-services.md b/docs/manual/usage/modular-services.md index 102ca5205..943f26307 100644 --- a/docs/manual/usage/modular-services.md +++ b/docs/manual/usage/modular-services.md @@ -9,26 +9,18 @@ systemd module loaded into it, so service modules shipped with packages (e.g. `pkgs..passthru.services.default`) drop in unchanged -- the same module evaluates on NixOS and on Home Manager. -A minimal example -- run a one-shot user service from a package's -modular service definition: +A minimal example -- run mpd as a user service: ```nix { pkgs, ... }: { - home.services.tunnel = { - imports = [ pkgs.ghostunnel.passthru.services.default ]; - ghostunnel = { - listen = "127.0.0.1:8443"; - target = "127.0.0.1:8080"; - cert = "/run/secrets/cert.pem"; - key = "/run/secrets/key.pem"; - allowAll = true; - }; + home.services.mpd = { + process.argv = [ "${pkgs.mpd}/bin/mpd" "--no-daemon" ]; }; } ``` -This produces `~/.config/systemd/user/tunnel.service` with the expected -`ExecStart`, `LoadCredential`, and `WantedBy=default.target`. +This produces `~/.config/systemd/user/mpd.service` with `ExecStart` set +to the mpd binary and `WantedBy=default.target`. Each service exposes the upstream NixOS-style schema: [`process.argv`], `systemd.lib`, `systemd.mainExecStart`, `systemd.service`, diff --git a/tests/modules/services-modular/basic.nix b/tests/modules/services-modular/basic.nix index b79f7afc0..3f309130a 100644 --- a/tests/modules/services-modular/basic.nix +++ b/tests/modules/services-modular/basic.nix @@ -2,14 +2,12 @@ { home.services.demo = { process.argv = [ - "${pkgs.coreutils}/bin/echo" - "hello" + "${pkgs.mpd}/bin/mpd" + "--no-daemon" ]; }; nmt.script = '' - assertFileExists home-files/.config/systemd/user/demo.service - assertFileContains home-files/.config/systemd/user/demo.service '/bin/echo' - assertFileContains home-files/.config/systemd/user/demo.service 'WantedBy=default.target' + assertFileContent home-files/.config/systemd/user/demo.service ${./demo.service} ''; } diff --git a/tests/modules/services-modular/demo.service b/tests/modules/services-modular/demo.service new file mode 100644 index 000000000..840611075 --- /dev/null +++ b/tests/modules/services-modular/demo.service @@ -0,0 +1,8 @@ +[Install] +WantedBy=default.target + +[Service] +ExecStart="@mpd@/bin/mpd" "--no-daemon" +Restart=always +RestartSec=5 +Type=simple