summary refs log tree commit diff
path: root/nixos/tests/mutable-users.nix
blob: e590703ab2f48f5644605244cf3d7e615f78a5ac (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
# Mutable users tests.

import ./make-test.nix ({ pkgs, ...} : {
  name = "mutable-users";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ gleber ];
  };

  nodes = {
    machine = { ... }: {
      users.mutableUsers = false;
    };
    mutable = { ... }: {
      users.mutableUsers = true;
    };
  };

  testScript = {nodes, ...}: let
    immutableSystem = nodes.machine.config.system.build.toplevel;
    mutableSystem = nodes.mutable.config.system.build.toplevel;
  in ''
    $machine->start();
    $machine->waitForUnit("default.target");

    # Machine starts in immutable mode. Add a user and test if reactivating
    # configuration removes the user.
    $machine->fail("cat /etc/passwd | grep ^foobar:");
    $machine->succeed("sudo useradd foobar");
    $machine->succeed("cat /etc/passwd | grep ^foobar:");
    $machine->succeed("${immutableSystem}/bin/switch-to-configuration test");
    $machine->fail("cat /etc/passwd | grep ^foobar:");

    # In immutable mode passwd is not wrapped, while in mutable mode it is
    # wrapped.
    $machine->succeed('which passwd | grep /run/current-system/');
    $machine->succeed("${mutableSystem}/bin/switch-to-configuration test");
    $machine->succeed('which passwd | grep /run/wrappers/');
  '';
})