diff options
author | r-vdp <ramses@well-founded.dev> | 2024-03-21 14:52:12 +0100 |
---|---|---|
committer | r-vdp <ramses@well-founded.dev> | 2024-04-15 11:32:45 +0200 |
commit | 9258f57625b474c542938a295ee0e85c9c5533ff (patch) | |
tree | 28d3864e9dc7f762c4fd1ba6c0627e88196be1b5 /nixos/tests/systemd.nix | |
parent | b432281d974471484e95a2f625c358f449a54d0d (diff) |
systemd: add a name option to all systemd units
This allows us to set things like dependencies in a way that we can catch typos at eval time. So instead of ```nix systemd.services.foo.wants = [ "bar.service" ]; ``` we can write ```nix systemd.services.foo.wants = [ config.systemd.services.bar.name ]; ``` which will throw an error if no such service has been defined. Not all cases can be done like this (eg template services), but in a lot of cases this will allow to avoid typos. There is a matching option on the unit option (`systemd.units."foo.service".name`) as well.
Diffstat (limited to 'nixos/tests/systemd.nix')
-rw-r--r-- | nixos/tests/systemd.nix | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/nixos/tests/systemd.nix b/nixos/tests/systemd.nix index 1a39cc73c8868..4b087d403f37d 100644 --- a/nixos/tests/systemd.nix +++ b/nixos/tests/systemd.nix @@ -1,7 +1,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { name = "systemd"; - nodes.machine = { lib, ... }: { + nodes.machine = { config, lib, ... }: { imports = [ common/user-account.nix common/x11.nix ]; virtualisation.emptyDiskImages = [ 512 512 ]; @@ -38,9 +38,18 @@ import ./make-test-python.nix ({ pkgs, ... }: { script = "true"; }; + systemd.services.testDependency1 = { + description = "Test Dependency 1"; + wantedBy = [ config.systemd.services."testservice1".name ]; + serviceConfig.Type = "oneshot"; + script = '' + true + ''; + }; + systemd.services.testservice1 = { description = "Test Service 1"; - wantedBy = [ "multi-user.target" ]; + wantedBy = [ config.systemd.targets.multi-user.name ]; serviceConfig.Type = "oneshot"; script = '' if [ "$XXX_SYSTEM" = foo ]; then |