From 145345c307fb77c321c319a7bb105a09e1ffab09 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Fri, 2 Jan 2009 16:07:01 +0000 Subject: [PATCH] system/users-groups.nix is now a configuration file. Remove user & group references from system/system.nix. svn path=/nixos/branches/fix-style/; revision=13678 --- helpers/create-users-groups.sh | 62 ------------- system/activate-configuration.sh | 4 - system/options.nix | 33 +------ system/system.nix | 5 - system/users-groups.nix | 152 +++++++++++++++++++++++++++++-- 5 files changed, 147 insertions(+), 109 deletions(-) delete mode 100644 helpers/create-users-groups.sh diff --git a/helpers/create-users-groups.sh b/helpers/create-users-groups.sh deleted file mode 100644 index 81aaacacd80..00000000000 --- a/helpers/create-users-groups.sh +++ /dev/null @@ -1,62 +0,0 @@ -cat "$2" | while true; do - read name || break - read gid - - if ! curEnt=$(getent group "$name"); then - echo "creating group $name..." - groupadd --system \ - "$name" \ - ${gid:+--gid $gid} - else - #echo "updating group $name..." - oldIFS="$IFS"; IFS=:; set -- $curEnt; IFS="$oldIFS" - prevGid=$3 - if test -n "$gid" -a "$prevGid" != "$gid"; then - groupmod "$name" --gid $gid - fi - fi -done - - -cat "$1" | while true; do - read name || break - read description - read uid - read group - read extraGroups - read home - read shell - read createHome - - if ! curEnt=$(getent passwd "$name"); then - echo "creating user $name..." - useradd --system \ - "$name" \ - --comment "$description" \ - ${uid:+--uid $uid} \ - --gid "$group" \ - --groups "$extraGroups" \ - --home "$home" \ - --shell "$shell" \ - ${createHome:+--create-home} - else - #echo "updating user $name..." - oldIFS="$IFS"; IFS=:; set -- $curEnt; IFS="$oldIFS" - prevUid=$3 - prevHome=$6 - # Don't change the UID if it's the same, otherwise usermod - # will complain. - if test "$prevUid" = "$uid"; then unset uid; fi - # Don't change the home directory if it's the same to prevent - # unnecessary warnings about logged in users. - if test "$prevHome" = "$home"; then unset home; fi - usermod \ - "$name" \ - --comment "$description" \ - ${uid:+--uid $uid} \ - --gid "$group" \ - --groups "$extraGroups" \ - ${home:+--home "$home"} \ - --shell "$shell" - fi -done diff --git a/system/activate-configuration.sh b/system/activate-configuration.sh index d71987ff9a7..c9bb6f3b66a 100644 --- a/system/activate-configuration.sh +++ b/system/activate-configuration.sh @@ -3,10 +3,6 @@ source @newActivationScript@ -# Create system users and groups. -@shell@ @createUsersGroups@ @usersList@ @groupsList@ - - # Set up Nix. mkdir -p /nix/etc/nix ln -sfn /etc/nix.conf /nix/etc/nix/nix.conf diff --git a/system/options.nix b/system/options.nix index be544d80677..a7fc27db90f 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2663,36 +2663,6 @@ root ALL=(ALL) SETENV: ALL users = { - extraUsers = mkOption { - default = []; - example = [ - { name = "alice"; - uid = 1234; - description = "Alice"; - home = "/home/alice"; - createHome = true; - group = "users"; - extraGroups = ["wheel"]; - shell = "/bin/sh"; - } - ]; - description = " - Additional user accounts to be created automatically by the system. - "; - }; - - extraGroups = mkOption { - default = []; - example = [ - { name = "students"; - gid = 1001; - } - ]; - description = " - Additional groups to be created automatically by the system. - "; - }; - ldap = { enable = mkOption { @@ -2905,6 +2875,9 @@ root ALL=(ALL) SETENV: ALL # environment (import ../etc/default.nix) + # users + (import ../system/users-groups.nix) + # newtworking (import ../upstart-jobs/dhclient.nix) diff --git a/system/system.nix b/system/system.nix index cf0ec45a9e4..7dda2b95002 100644 --- a/system/system.nix +++ b/system/system.nix @@ -182,9 +182,6 @@ rec { systemPath = config.system.path; - usersGroups = import ./users-groups.nix { inherit pkgs config defaultShell; }; - - defaultShell = config.system.shell; @@ -208,8 +205,6 @@ rec { pkgs.lib.optional (config.services.xserver.sessionType == "kde") "kcheckpass" ++ map ( x : x.program ) config.security.setuidOwners; - inherit (usersGroups) createUsersGroups usersList groupsList; - bash = pkgs.bashInteractive; adjustSetuidOwner = pkgs.lib.concatStrings (map diff --git a/system/users-groups.nix b/system/users-groups.nix index 48c4db65bdf..f1bd59a2f36 100644 --- a/system/users-groups.nix +++ b/system/users-groups.nix @@ -1,8 +1,48 @@ -{pkgs, config, defaultShell}: +{pkgs, config, ...}: -let ids = import ./ids.nix; in +###### interface +let + inherit (pkgs.lib) mkOption; -rec { + options = { + users = { + extraUsers = mkOption { + default = []; + example = [ + { name = "alice"; + uid = 1234; + description = "Alice"; + home = "/home/alice"; + createHome = true; + group = "users"; + extraGroups = ["wheel"]; + shell = "/bin/sh"; + } + ]; + description = " + Additional user accounts to be created automatically by the system. + "; + }; + + extraGroups = mkOption { + default = []; + example = [ + { name = "students"; + gid = 1001; + } + ]; + description = " + Additional groups to be created automatically by the system. + "; + }; + }; + }; +in + +###### implementation +let + ids = import ./ids.nix; + defaultShell = config.system.shell; # User accounts to be created/updated by NixOS. users = @@ -93,10 +133,106 @@ rec { in map addAttrs (defaultGroups ++ config.users.extraGroups); + inherit (pkgs.lib) concatStringsSep; - # Awful hackery necessary to pass the users/groups to the activation script. - createUsersGroups = ../helpers/create-users-groups.sh; - usersList = pkgs.writeText "users" (pkgs.lib.concatStrings (map (u: "${u.name}\n${u.description}\n${toString u.uid}\n${u.group}\n${toString (pkgs.lib.concatStringsSep "," u.extraGroups)}\n${u.home}\n${u.shell}\n${toString u.createHome}\n") users)); - groupsList = pkgs.writeText "groups" (pkgs.lib.concatStrings (map (g: "${g.name}\n${toString g.gid}\n") groups)); - + serializedUser = u: "${u.name}\n${u.description}\n${toString u.uid}\n${u.group}\n${toString (concatStringsSep "," u.extraGroups)}\n${u.home}\n${u.shell}\n${toString u.createHome}"; + serializedGroup = g: "${g.name}\n${toString g.gid}"; +in + +let + inherit (pkgs.stringsWithDeps) FullDepEntry; + + activateLib = config.system.activationScripts.lib; +in + +{ + require = [ + options + + # config.system.activationScripts + (import ../system/activate-configuration.nix) + ]; + + system = { + activationScripts = { + + users = FullDepEntry '' + while true; do + read name || break + read description + read uid + read group + read extraGroups + read home + read shell + read createHome + + if ! curEnt=$(getent passwd "$name"); then + echo "creating user $name..." + useradd --system \ + "$name" \ + --comment "$description" \ + ''${uid:+--uid $uid} \ + --gid "$group" \ + --groups "$extraGroups" \ + --home "$home" \ + --shell "$shell" \ + ''${createHome:+--create-home} + else + #echo "updating user $name..." + oldIFS="$IFS"; IFS=:; set -- $curEnt; IFS="$oldIFS" + prevUid=$3 + prevHome=$6 + # Don't change the UID if it's the same, otherwise usermod + # will complain. + if test "$prevUid" = "$uid"; then unset uid; fi + # Don't change the home directory if it's the same to prevent + # unnecessary warnings about logged in users. + if test "$prevHome" = "$home"; then unset home; fi + usermod \ + "$name" \ + --comment "$description" \ + ''${uid:+--uid $uid} \ + --gid "$group" \ + --groups "$extraGroups" \ + ''${home:+--home "$home"} \ + --shell "$shell" + fi + done <