Merge pull request #31569 from gleber/add-mutable-users-test

nixos/tests: add a test for config.users.mutableUsers.

authored by Franz Pletz and committed by GitHub f367bb4d 68d05c06

+41
+1
nixos/release-combined.nix
··· 95 95 #(all nixos.tests.lightdm) 96 96 (all nixos.tests.login) 97 97 (all nixos.tests.misc) 98 + (all nixos.tests.mutableUsers) 98 99 (all nixos.tests.nat.firewall) 99 100 (all nixos.tests.nat.standalone) 100 101 (all nixos.tests.networking.scripted.loopback)
+1
nixos/release.nix
··· 291 291 tests.mongodb = callTest tests/mongodb.nix {}; 292 292 tests.mumble = callTest tests/mumble.nix {}; 293 293 tests.munin = callTest tests/munin.nix {}; 294 + tests.mutableUsers = callTest tests/mutable-users.nix {}; 294 295 tests.mysql = callTest tests/mysql.nix {}; 295 296 tests.mysqlBackup = callTest tests/mysql-backup.nix {}; 296 297 tests.mysqlReplication = callTest tests/mysql-replication.nix {};
+39
nixos/tests/mutable-users.nix
··· 1 + # Mutable users tests. 2 + 3 + import ./make-test.nix ({ pkgs, ...} : { 4 + name = "mutable-users"; 5 + meta = with pkgs.stdenv.lib.maintainers; { 6 + maintainers = [ gleber ]; 7 + }; 8 + 9 + nodes = { 10 + machine = { config, lib, pkgs, ... }: { 11 + users.mutableUsers = false; 12 + }; 13 + mutable = { config, lib, pkgs, ... }: { 14 + users.mutableUsers = true; 15 + }; 16 + }; 17 + 18 + testScript = {nodes, ...}: let 19 + immutableSystem = nodes.machine.config.system.build.toplevel; 20 + mutableSystem = nodes.mutable.config.system.build.toplevel; 21 + in '' 22 + $machine->start(); 23 + $machine->waitForUnit("default.target"); 24 + 25 + # Machine starts in immutable mode. Add a user and test if reactivating 26 + # configuration removes the user. 27 + $machine->fail("cat /etc/passwd | grep ^foobar:"); 28 + $machine->succeed("sudo useradd foobar"); 29 + $machine->succeed("cat /etc/passwd | grep ^foobar:"); 30 + $machine->succeed("${immutableSystem}/bin/switch-to-configuration test"); 31 + $machine->fail("cat /etc/passwd | grep ^foobar:"); 32 + 33 + # In immutable mode passwd is not wrapped, while in mutable mode it is 34 + # wrapped. 35 + $machine->succeed('which passwd | grep /run/current-system/'); 36 + $machine->succeed("${mutableSystem}/bin/switch-to-configuration test"); 37 + $machine->succeed('which passwd | grep /run/wrappers/'); 38 + ''; 39 + })