summaryrefslogtreecommitdiffstats
path: root/nixos/tests/systemd-misc.nix
blob: 30f9fe720059fc13900e9f73feda6c4978cae211 (plain)
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
63
64
65
66
67
68
69
{ 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")

    with subtest("modprobe@ services work"):
      modprobe_service_status = machine.succeed("systemctl show --property ExecMainStatus modprobe@configfs.service")
      print(modprobe_service_status)
      t.assertEqual("ExecMainStatus=0\n", modprobe_service_status)
  '';
}