1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-15 17:51:01 +00:00
nix-darwin/tests/users-groups.nix

66 lines
3.3 KiB
Nix
Raw Normal View History

{ lib, config, pkgs, ... }:
{
users.knownGroups = [ "foo" "created.group" "deleted.group" ];
users.groups.foo.gid = 42000;
users.groups.foo.description = "Foo group";
2018-01-14 12:31:15 +00:00
users.groups.foo.members = [ "admin" "foo" ];
users.groups."created.group".gid = 42001;
users.groups."unknown.group".gid = 42002;
users.knownUsers = [ "foo" "created.user" "deleted.user" ];
users.users.foo.uid = 42000;
users.users.foo.gid = 42000;
users.users.foo.description = "Foo user";
2018-01-15 23:55:42 +00:00
users.users.foo.isHidden = false;
users.users.foo.home = "/Users/foo";
users.users.foo.createHome = true;
users.users.foo.shell = pkgs.bashInteractive;
users.users."created.user".uid = 42001;
users.users."unknown.user".uid = 42002;
test = ''
set -v
# checking group creation in /activate
grep "dscl . -create ${lib.escapeShellArg "/Groups/foo"} PrimaryGroupID 42000" ${config.out}/activate
grep "dscl . -create ${lib.escapeShellArg "/Groups/foo"} RealName 'Foo group'" ${config.out}/activate
grep "dscl . -create ${lib.escapeShellArg "/Groups/created.group"} PrimaryGroupID 42001" ${config.out}/activate
grep -qv "dscl . -delete ${lib.escapeShellArg "/Groups/created.group"}" ${config.out}/activate
# checking group deletion in /activate
grep "dscl . -delete ${lib.escapeShellArg "/Groups/deleted.group"}" ${config.out}/activate
grep -qv "dscl . -create ${lib.escapeShellArg "/Groups/deleted.group"}" ${config.out}/activate
2018-01-14 12:31:15 +00:00
echo "checking group membership in /activate" >&2
grep "dscl . -create ${lib.escapeShellArg "/Groups/foo"} GroupMembership ${lib.escapeShellArgs [ "admin" "foo" ]}" ${config.out}/activate
grep "dscl . -create ${lib.escapeShellArg "/Groups/created.group"} GroupMembership" ${config.out}/activate
2018-01-14 12:31:15 +00:00
# checking unknown group in /activate
grep -qv "dscl . -create ${lib.escapeShellArg "/Groups/unknown.group"}" ${config.out}/activate
grep -qv "dscl . -delete ${lib.escapeShellArg "/Groups/unknown.group"}" ${config.out}/activate
# checking user creation in /activate
grep "sysadminctl -addUser ${lib.escapeShellArgs [ "foo" "-UID" 42000 "-GID" 42000 "-fullName" "Foo user" "-home" "/Users/foo" "-shell" "/run/current-system/sw/bin/bash" ]}" ${config.out}/activate
grep "createhomedir -cu ${lib.escapeShellArg "foo"}" ${config.out}/activate
grep "sysadminctl -addUser ${lib.escapeShellArgs [ "created.user" "-UID" 42001 ]} .* ${lib.escapeShellArgs [ "-shell" "/sbin/nologin" ]}" ${config.out}/activate
grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate
grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate
# checking user properties always get updated in /activate
grep "dscl . -create ${lib.escapeShellArg "/Users/foo"} UserShell ${lib.escapeShellArg "/run/current-system/sw/bin/bash"}" ${config.out}/activate
# checking user deletion in /activate
grep "sysadminctl -deleteUser ${lib.escapeShellArg "deleted.user"}" ${config.out}/activate
grep -qv "sysadminctl -addUser ${lib.escapeShellArg "deleted.user"}" ${config.out}/activate
# checking unknown user in /activate
grep -qv "sysadminctl -addUser ${lib.escapeShellArg "unknown.user"}" ${config.out}/activate
grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "unknown.user"}" ${config.out}/activate
set +v
'';
}