1 import ./make-test-python.nix ({ lib, ... }:
4 meta.maintainers = with lib.maintainers; [ azahi ];
9 users.users = lib.mkMerge [
11 (n: lib.nameValuePair n { isNormalUser = true; })
12 (lib.genList (x: "user${toString x}") 6)))
14 user0.extraGroups = [ "wheel" ];
20 wheelNeedsPassword = false;
22 user2_run_true_as_root = {
25 rule = "/run/current-system/sw/bin/true";
28 user4_edit_etc_hosts_as_root = {
41 with subtest("root: can run anything by default"):
42 machine.succeed('please true')
43 with subtest("root: can edit anything by default"):
44 machine.succeed('EDITOR=cat pleaseedit /etc/hosts')
46 with subtest("user0: can run as root because it's in the wheel group"):
47 machine.succeed('su - user0 -c "please -u root true"')
48 with subtest("user1: cannot run as root because it's not in the wheel group"):
49 machine.fail('su - user1 -c "please -u root true"')
51 with subtest("user0: can edit as root"):
52 machine.succeed('su - user0 -c "EDITOR=cat pleaseedit /etc/hosts"')
53 with subtest("user1: cannot edit as root"):
54 machine.fail('su - user1 -c "EDITOR=cat pleaseedit /etc/hosts"')
56 with subtest("user2: can run 'true' as root"):
57 machine.succeed('su - user2 -c "please -u root true"')
58 with subtest("user3: cannot run 'true' as root"):
59 machine.fail('su - user3 -c "please -u root true"')
61 with subtest("user4: can edit /etc/hosts"):
62 machine.succeed('su - user4 -c "EDITOR=cat pleaseedit /etc/hosts"')
63 with subtest("user5: cannot edit /etc/hosts"):
64 machine.fail('su - user5 -c "EDITOR=cat pleaseedit /etc/hosts"')