about summary refs log tree commit diff
path: root/nixos/tests/systemd-misc.nix
blob: 0ddd51100463eed44786214c6af7ecb8d30b5852 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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-misc";

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

    users.users.limited = {
      isNormalUser = true;
      uid = 1000;
    };

    systemd.units."user-1000.slice.d/limits.conf" = {
      text = ''
        [Slice]
        TasksAccounting=yes
        TasksMax=100
      '';
    };
  };

  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'")

    machine.succeed("systemctl show --property TasksMax --value user-1000.slice | grep 100")
  '';
})