summary refs log tree commit diff
path: root/nixos/tests/systemd-unit-path.nix
blob: 5998a187188a19ad688b947db7ca5f2610698e40 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ./make-test-python.nix ({ pkgs, ... }:

let
  exampleScript = pkgs.writeTextFile {
    name = "example.sh";
    text = ''
      #! ${pkgs.runtimeShell} -e

      while true; do
          echo "Example script running" >&2
          ${pkgs.coreutils}/bin/sleep 1
      done
    '';
    executable = true;
  };

  unitFile = pkgs.writeTextFile {
    name = "example.service";
    text = ''
      [Unit]
      Description=Example systemd service unit file

      [Service]
      ExecStart=${exampleScript}

      [Install]
      WantedBy=multi-user.target
    '';
  };
in
{
  name = "systemd-unit-path";

  machine = { pkgs, lib, ... }: {
    boot.extraSystemdUnitPaths = [ "/etc/systemd-rw/system" ];
  };

  testScript = ''
    machine.wait_for_unit("multi-user.target")
    machine.succeed("mkdir -p /etc/systemd-rw/system")
    machine.succeed(
        "cp ${unitFile} /etc/systemd-rw/system/example.service"
    )
    machine.succeed("systemctl start example.service")
    machine.succeed("systemctl status example.service | grep 'Active: active'")
  '';
})