summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-15 02:07:43 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-15 02:16:04 +0200
commita323d146b7be3bc066b4ec74db72888ea32792fb (patch)
treef05ed60f89df9d0546560c4aff93afa567122628
parent1a75958be52f5c2f062ace0935c1a2d43c8f7f55 (diff)
downloadnixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.tar
nixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.tar.gz
nixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.tar.bz2
nixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.tar.lz
nixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.tar.xz
nixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.tar.zst
nixpkgs-a323d146b7be3bc066b4ec74db72888ea32792fb.zip
Add user attribute isNormalUser
This is shorthand for setting group, createHome, home, useDefaultShell
and isSystemUser.
-rw-r--r--nixos/doc/manual/configuration.xml4
-rw-r--r--nixos/modules/config/users-groups.nix31
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl6
-rw-r--r--nixos/modules/profiles/demo.nix7
-rw-r--r--nixos/tests/common/user-account.nix6
5 files changed, 33 insertions, 21 deletions
diff --git a/nixos/doc/manual/configuration.xml b/nixos/doc/manual/configuration.xml
index ce7ccf6cc5e..110d1a00eeb 100644
--- a/nixos/doc/manual/configuration.xml
+++ b/nixos/doc/manual/configuration.xml
@@ -1033,11 +1033,9 @@ states that a user account named <literal>alice</literal> shall exist:
 
 <programlisting>
 users.extraUsers.alice =
-  { createHome = true;
-    home = "/home/alice";
+  { isNormalUser = true;
     description = "Alice Foobar";
     extraGroups = [ "wheel" "networkmanager" ];
-    useDefaultShell = true;
     openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... alice@foobar" ];
   };
 </programlisting>
diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix
index 75d1b6f7ff4..f32138a814d 100644
--- a/nixos/modules/config/users-groups.nix
+++ b/nixos/modules/config/users-groups.nix
@@ -70,6 +70,21 @@ let
         '';
       };
 
+      isNormalUser = mkOption {
+        type = types.bool;
+        default = false;
+        description = ''
+          Indicates whether this is an account for a “real” user. This
+          automatically sets <option>group</option> to
+          <literal>users</literal>, <option>createHome</option> to
+          <literal>true</literal>, <option>home</option> to
+          <filename>/home/<replaceable>username</replaceable></filename>,
+          <option>useDefaultShell</option> to <literal>true</literal>,
+          and <option>isSystemUser</option> to
+          <literal>false</literal>.
+        '';
+      };
+
       group = mkOption {
         type = types.str;
         default = "nogroup";
@@ -148,10 +163,18 @@ let
       };
     };
 
-    config = {
-      name = mkDefault name;
-      shell = mkIf config.useDefaultShell (mkDefault cfg.defaultUserShell);
-    };
+    config = mkMerge
+      [ { name = mkDefault name;
+          shell = mkIf config.useDefaultShell (mkDefault cfg.defaultUserShell);
+        }
+        (mkIf config.isNormalUser {
+          group = mkDefault "users";
+          createHome = mkDefault true;
+          home = mkDefault "/home/${name}";
+          useDefaultShell = mkDefault true;
+          isSystemUser = mkDefault false;
+        })
+      ];
 
   };
 
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl
index 66a8152a3a6..c507f7f979f 100644
--- a/nixos/modules/installer/tools/nixos-generate-config.pl
+++ b/nixos/modules/installer/tools/nixos-generate-config.pl
@@ -490,12 +490,8 @@ $bootLoaderConfig
 
   # Define a user account. Don't forget to set a password with ‘passwd’.
   # users.extraUsers.guest = {
-  #   name = "guest";
-  #   group = "users";
+  #   isNormalUser = true;
   #   uid = 1000;
-  #   createHome = true;
-  #   home = "/home/guest";
-  #   shell = "/run/current-system/sw/bin/bash";
   # };
 
 }
diff --git a/nixos/modules/profiles/demo.nix b/nixos/modules/profiles/demo.nix
index 605cc6aad1d..ef6fd77b5f8 100644
--- a/nixos/modules/profiles/demo.nix
+++ b/nixos/modules/profiles/demo.nix
@@ -4,12 +4,9 @@
   imports = [ ./graphical.nix ];
 
   users.extraUsers.demo =
-    { description = "Demo user account";
-      group = "users";
+    { isNormalUser = true;
+      description = "Demo user account";
       extraGroups = [ "wheel" ];
-      home = "/home/demo";
-      createHome = true;
-      useDefaultShell = true;
       password = "demo";
       uid = 1000;
     };
diff --git a/nixos/tests/common/user-account.nix b/nixos/tests/common/user-account.nix
index 0239a3c4d08..aa3a0b82bcd 100644
--- a/nixos/tests/common/user-account.nix
+++ b/nixos/tests/common/user-account.nix
@@ -1,11 +1,9 @@
 { pkgs, ... }:
 
 { users.extraUsers = pkgs.lib.singleton
-    { name = "alice";
+    { isNormalUser = true;
+      name = "alice";
       description = "Alice Foobar";
-      home = "/home/alice";
-      createHome = true;
-      useDefaultShell = true;
       password = "foobar";
       uid = 1000;
     };