diff options
author | zimbatm <zimbatm@zimbatm.com> | 2016-06-12 20:03:14 +0100 |
---|---|---|
committer | zimbatm <zimbatm@zimbatm.com> | 2016-06-12 20:35:34 +0100 |
commit | 2974b6f4c8224ab1097e9386d6b3a0d570f95531 (patch) | |
tree | 5e096917408ec3b8099685c0db35fa372914d01e | |
parent | e2413ad5a8b6a80e5552306518fdf16e68b6c6d7 (diff) |
Use shell packages to select the user's shell
The string type is still available for backward-compatiblity.
-rw-r--r-- | lib/types.nix | 4 | ||||
-rw-r--r-- | nixos/lib/utils.nix | 6 | ||||
-rw-r--r-- | nixos/modules/config/shells-environment.nix | 8 | ||||
-rw-r--r-- | nixos/modules/config/users-groups.nix | 25 | ||||
-rw-r--r-- | nixos/modules/programs/bash/bash.nix | 2 | ||||
-rw-r--r-- | nixos/modules/programs/shadow.nix | 18 |
6 files changed, 43 insertions, 20 deletions
diff --git a/lib/types.nix b/lib/types.nix index 91b39f3a9cf8..83f624e6b448 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -100,6 +100,10 @@ rec { in if isDerivation res then res else toDerivation res; }; + shellPackage = package // { + check = x: (package.check x) && (hasAttr "shellPath" x); + }; + path = mkOptionType { name = "path"; # Hacky: there is no ‘isPath’ primop. diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix index 7b8be2050c13..871fbb121d03 100644 --- a/nixos/lib/utils.nix +++ b/nixos/lib/utils.nix @@ -8,4 +8,10 @@ rec { replaceChars ["/" "-" " "] ["-" "\\x2d" "\\x20"] (if hasPrefix "/" s then substring 1 (stringLength s) s else s); + # Returns a system path for a given shell package + toShellPath = shell: + if types.shellPackage.check shell then + "/run/current-system/sw${shell.shellPath}" + else + shell; } diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix index 9642981803bf..f458bc39adaa 100644 --- a/nixos/modules/config/shells-environment.nix +++ b/nixos/modules/config/shells-environment.nix @@ -1,7 +1,7 @@ # This module defines a global environment configuration and # a common configuration for all shells. -{ config, lib, pkgs, ... }: +{ config, lib, utils, pkgs, ... }: with lib; @@ -135,13 +135,13 @@ in environment.shells = mkOption { default = []; - example = [ "/run/current-system/sw/bin/zsh" ]; + example = literalExample "[ pkgs.bashInteractive pkgs.zsh ]"; description = '' A list of permissible login shells for user accounts. No need to mention <literal>/bin/sh</literal> here, it is placed into this list implicitly. ''; - type = types.listOf types.path; + type = types.listOf (types.either types.shellPackage types.path); }; }; @@ -158,7 +158,7 @@ in environment.etc."shells".text = '' - ${concatStringsSep "\n" cfg.shells} + ${concatStringsSep "\n" (map utils.toShellPath cfg.shells)} /bin/sh ''; diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index e643b2d059b5..95b3e3ca1857 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -1,9 +1,8 @@ -{ config, lib, pkgs, ... }: +{ config, lib, utils, pkgs, ... }: with lib; let - ids = config.ids; cfg = config.users; @@ -103,7 +102,7 @@ let }; home = mkOption { - type = types.str; + type = types.path; default = "/var/empty"; description = "The user's home directory."; }; @@ -118,8 +117,10 @@ let }; shell = mkOption { - type = types.str; - default = "/run/current-system/sw/bin/nologin"; + type = types.either types.shellPackage types.path; + default = pkgs.nologin; + defaultText = "pkgs.nologin"; + example = literalExample "pkgs.bashInteractive"; description = "The path to the user's shell."; }; @@ -359,11 +360,12 @@ let spec = pkgs.writeText "users-groups.json" (builtins.toJSON { inherit (cfg) mutableUsers; - users = mapAttrsToList (n: u: + users = mapAttrsToList (_: u: { inherit (u) - name uid group description home shell createHome isSystemUser + name uid group description home createHome isSystemUser password passwordFile hashedPassword initialPassword initialHashedPassword; + shell = utils.toShellPath u.shell; }) cfg.users; groups = mapAttrsToList (n: g: { inherit (g) name gid; @@ -373,6 +375,12 @@ let }) cfg.groups; }); + systemShells = + let + shells = mapAttrsToList (_: u: u.shell) cfg.users; + in + filter types.shellPackage.check shells; + in { ###### interface @@ -478,6 +486,9 @@ in { }; }; + # Install all the user shells + environment.systemPackages = systemShells; + users.groups = { root.gid = ids.gids.root; wheel.gid = ids.gids.wheel; diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix index e4e264ec0036..c09bcfb70e24 100644 --- a/nixos/modules/programs/bash/bash.nix +++ b/nixos/modules/programs/bash/bash.nix @@ -200,7 +200,7 @@ in # Configuration for readline in bash. environment.etc."inputrc".source = ./inputrc; - users.defaultUserShell = mkDefault "/run/current-system/sw/bin/bash"; + users.defaultUserShell = mkDefault pkgs.bashInteractive; environment.pathsToLink = optionals cfg.enableCompletion [ "/etc/bash_completion.d" diff --git a/nixos/modules/programs/shadow.nix b/nixos/modules/programs/shadow.nix index 566398d839fd..6398509357a6 100644 --- a/nixos/modules/programs/shadow.nix +++ b/nixos/modules/programs/shadow.nix @@ -1,6 +1,6 @@ # Configuration for the pwdutils suite of tools: passwd, useradd, etc. -{ config, lib, pkgs, ... }: +{ config, lib, utils, pkgs, ... }: with lib; @@ -43,13 +43,13 @@ in users.defaultUserShell = lib.mkOption { description = '' This option defines the default shell assigned to user - accounts. This must not be a store path, since the path is + accounts. This can be either a full system path or a shell package. + + This must not be a store path, since the path is used outside the store (in particular in /etc/passwd). - Rather, it should be the path of a symlink that points to the - actual shell in the Nix store. ''; - example = "/run/current-system/sw/bin/zsh"; - type = types.path; + example = literalExample "pkgs.zsh"; + type = types.either types.path types.shellPackage; }; }; @@ -60,7 +60,9 @@ in config = { environment.systemPackages = - lib.optional config.users.mutableUsers pkgs.shadow; + lib.optional config.users.mutableUsers pkgs.shadow ++ + lib.optional (types.shellPackage.check config.users.defaultUserShell) + config.users.defaultUserShell; environment.etc = [ { # /etc/login.defs: global configuration for pwdutils. You @@ -74,7 +76,7 @@ in '' GROUP=100 HOME=/home - SHELL=${config.users.defaultUserShell} + SHELL=${utils.toShellPath config.users.defaultUserShell} ''; target = "default/useradd"; } |