about summary refs log tree commit diff
path: root/nixos/tests/systemd-template-override.nix
blob: d8ef4a6c1c9bd8beda86cf09789b32d5b634c1a1 (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
import ./make-test-python.nix {
  name = "systemd-template-override";

  machine = { pkgs, lib, ... }: let
    touchTmp = pkgs.writeTextFile {
      name = "touch-tmp@.service";
      text = ''
        [Service]
        Type=oneshot
        ExecStart=${pkgs.coreutils}/bin/touch /tmp/%I
      '';
      destination = "/etc/systemd/system/touch-tmp@.service";
    };
  in {
    systemd.packages = [ touchTmp ];

    systemd.services."touch-tmp@forbidden" = {
      serviceConfig.ExecStart = [ "" ''
        ${pkgs.coreutils}/bin/true
      ''];
    };

    systemd.services."touch-tmp@intercept" = {
      serviceConfig.ExecStart = [ "" ''
        ${pkgs.coreutils}/bin/touch /tmp/renamed
      ''];
    };
  };

  testScript = ''
    machine.wait_for_unit("default.target")

    machine.succeed("systemctl start touch-tmp@normal")
    machine.succeed("systemctl start touch-tmp@forbbidden")
    machine.succeed("systemctl start touch-tmp@intercept")

    machine.succeed("[ -e /tmp/normal ]")
    machine.succeed("[ ! -e /tmp/forbidden ]")
    machine.succeed("[ -e /tmp/renamed ]")
  '';
}