1# Run:
2# nix-build -A nixosTests.modularService
3
4{
5 evalSystem,
6 runCommand,
7 hello,
8 ...
9}:
10
11let
12 machine = evalSystem (
13 { lib, ... }:
14 let
15 hello' = lib.getExe hello;
16 in
17 {
18
19 # Test input
20
21 system.services.foo = {
22 process = {
23 argv = [
24 hello'
25 "--greeting"
26 "hoi"
27 ];
28 };
29 };
30 system.services.bar = {
31 process = {
32 argv = [
33 hello'
34 "--greeting"
35 "hoi"
36 ];
37 };
38 systemd.service = {
39 serviceConfig.X-Bar = "lol crossbar whatever";
40 };
41 services.db = {
42 process = {
43 argv = [
44 hello'
45 "--greeting"
46 "Hi, I'm a database, would you believe it"
47 ];
48 };
49 systemd.service = {
50 serviceConfig.RestartSec = "42";
51 };
52 };
53 };
54
55 # irrelevant stuff
56 system.stateVersion = "25.05";
57 fileSystems."/".device = "/test/dummy";
58 boot.loader.grub.enable = false;
59 }
60 );
61
62 inherit (machine.config.system.build) toplevel;
63in
64runCommand "test-modular-service-systemd-units"
65 {
66 passthru = {
67 inherit
68 machine
69 toplevel
70 ;
71 };
72 }
73 ''
74 echo ${toplevel}/etc/systemd/system/foo.service:
75 cat -n ${toplevel}/etc/systemd/system/foo.service
76 (
77 set -x
78 grep -F 'ExecStart="${hello}/bin/hello" "--greeting" "hoi"' ${toplevel}/etc/systemd/system/foo.service >/dev/null
79
80 grep -F 'ExecStart="${hello}/bin/hello" "--greeting" "hoi"' ${toplevel}/etc/systemd/system/bar.service >/dev/null
81 grep -F 'X-Bar=lol crossbar whatever' ${toplevel}/etc/systemd/system/bar.service >/dev/null
82
83 grep 'ExecStart="${hello}/bin/hello" "--greeting" ".*database.*"' ${toplevel}/etc/systemd/system/bar-db.service >/dev/null
84 grep -F 'RestartSec=42' ${toplevel}/etc/systemd/system/bar-db.service >/dev/null
85
86 [[ ! -e ${toplevel}/etc/systemd/system/foo.socket ]]
87 [[ ! -e ${toplevel}/etc/systemd/system/bar.socket ]]
88 [[ ! -e ${toplevel}/etc/systemd/system/bar-db.socket ]]
89 )
90 echo 🐬👍
91 touch $out
92 ''