2016-06-12 21:03:14 +02:00
|
|
|
|
{ config, lib, utils, pkgs, ... }:
|
2007-06-08 17:41:12 +02:00
|
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
|
with lib;
|
2009-01-02 17:07:01 +01:00
|
|
|
|
|
|
|
|
|
let
|
2009-05-29 16:25:56 +02:00
|
|
|
|
ids = config.ids;
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
cfg = config.users;
|
2007-06-08 17:41:12 +02:00
|
|
|
|
|
2020-06-25 02:02:29 +02:00
|
|
|
|
# Check whether a password hash will allow login.
|
|
|
|
|
allowsLogin = hash:
|
|
|
|
|
hash == "" # login without password
|
|
|
|
|
|| !(lib.elem hash
|
|
|
|
|
[ null # password login disabled
|
|
|
|
|
"!" # password login disabled
|
|
|
|
|
"!!" # a variant of "!"
|
|
|
|
|
"*" # password unset
|
|
|
|
|
]);
|
|
|
|
|
|
2014-02-05 15:07:20 +01:00
|
|
|
|
passwordDescription = ''
|
2022-08-20 18:35:28 +02:00
|
|
|
|
The options {option}`hashedPassword`,
|
|
|
|
|
{option}`password` and {option}`passwordFile`
|
2014-02-05 15:07:20 +01:00
|
|
|
|
controls what password is set for the user.
|
2022-08-20 18:35:28 +02:00
|
|
|
|
{option}`hashedPassword` overrides both
|
|
|
|
|
{option}`password` and {option}`passwordFile`.
|
|
|
|
|
{option}`password` overrides {option}`passwordFile`.
|
2014-02-05 15:07:20 +01:00
|
|
|
|
If none of these three options are set, no password is assigned to
|
|
|
|
|
the user, and the user will not be able to do password logins.
|
2022-08-20 18:35:28 +02:00
|
|
|
|
If the option {option}`users.mutableUsers` is true, the
|
2014-02-05 15:07:20 +01:00
|
|
|
|
password defined in one of the three options will only be set when
|
|
|
|
|
the user is created for the first time. After that, you are free to
|
|
|
|
|
change the password with the ordinary user management commands. If
|
2022-08-20 18:35:28 +02:00
|
|
|
|
{option}`users.mutableUsers` is false, you cannot change
|
2014-02-05 15:07:20 +01:00
|
|
|
|
user passwords, they will always be set according to the password
|
|
|
|
|
options.
|
|
|
|
|
'';
|
|
|
|
|
|
2015-01-02 17:32:33 +01:00
|
|
|
|
hashedPasswordDescription = ''
|
2022-10-09 20:35:01 +02:00
|
|
|
|
To generate a hashed password run `mkpasswd`.
|
2020-07-04 02:05:03 +02:00
|
|
|
|
|
2022-08-20 18:35:28 +02:00
|
|
|
|
If set to an empty string (`""`), this user will
|
2020-06-21 16:55:45 +02:00
|
|
|
|
be able to log in without being asked for a password (but not via remote
|
2022-08-20 18:35:28 +02:00
|
|
|
|
services such as SSH, or indirectly via {command}`su` or
|
|
|
|
|
{command}`sudo`). This should only be used for e.g. bootable
|
2020-06-21 16:55:45 +02:00
|
|
|
|
live systems. Note: this is different from setting an empty password,
|
2022-08-20 18:35:28 +02:00
|
|
|
|
which can be achieved using {option}`users.users.<name?>.password`.
|
2020-07-04 02:05:03 +02:00
|
|
|
|
|
2022-08-20 18:35:28 +02:00
|
|
|
|
If set to `null` (default) this user will not
|
|
|
|
|
be able to log in using a password (i.e. via {command}`login`
|
2020-06-21 16:55:45 +02:00
|
|
|
|
command).
|
2015-01-02 17:32:33 +01:00
|
|
|
|
'';
|
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
userOpts = { name, config, ... }: {
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
options = {
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
name = mkOption {
|
2022-06-25 13:59:43 +02:00
|
|
|
|
type = types.passwdEntry types.str;
|
2018-03-08 20:46:11 +01:00
|
|
|
|
apply = x: assert (builtins.stringLength x < 32 || abort "Username '${x}' is longer than 31 characters which is not allowed!"); x;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-04-06 12:39:51 +02:00
|
|
|
|
The name of the user account. If undefined, the name of the
|
|
|
|
|
attribute set will be used.
|
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
description = mkOption {
|
2022-06-25 13:59:43 +02:00
|
|
|
|
type = types.passwdEntry types.str;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
default = "";
|
2013-10-31 08:41:51 +01:00
|
|
|
|
example = "Alice Q. User";
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2013-10-31 08:41:51 +01:00
|
|
|
|
A short description of the user account, typically the
|
|
|
|
|
user's full name. This is actually the “GECOS” or “comment”
|
2022-07-28 23:19:15 +02:00
|
|
|
|
field in {file}`/etc/passwd`.
|
2013-10-31 08:41:51 +01:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
uid = mkOption {
|
2014-04-06 12:39:51 +02:00
|
|
|
|
type = with types; nullOr int;
|
|
|
|
|
default = null;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-08-15 01:33:20 +02:00
|
|
|
|
The account UID. If the UID is null, a free UID is picked on
|
|
|
|
|
activation.
|
2014-04-06 12:39:51 +02:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2014-04-29 10:43:38 +02:00
|
|
|
|
isSystemUser = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-04-29 10:43:38 +02:00
|
|
|
|
Indicates if the user is a system user or not. This option
|
2022-07-28 23:19:15 +02:00
|
|
|
|
only has an effect if {option}`uid` is
|
|
|
|
|
{option}`null`, in which case it determines whether
|
2014-04-29 10:43:38 +02:00
|
|
|
|
the user's UID is allocated in the range for system users
|
2022-01-02 00:57:13 +01:00
|
|
|
|
(below 1000) or in the range for normal users (starting at
|
2014-04-29 10:43:38 +02:00
|
|
|
|
1000).
|
2022-07-28 23:19:15 +02:00
|
|
|
|
Exactly one of `isNormalUser` and
|
|
|
|
|
`isSystemUser` must be true.
|
2014-04-29 10:43:38 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-15 02:07:43 +02:00
|
|
|
|
isNormalUser = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2022-08-03 22:46:41 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2022-12-23 00:43:05 +01:00
|
|
|
|
Indicates whether this is an account for a “real” user.
|
|
|
|
|
This automatically sets {option}`group` to `users`,
|
|
|
|
|
{option}`createHome` to `true`,
|
|
|
|
|
{option}`home` to {file}`/home/«username»`,
|
2022-08-03 22:46:41 +02:00
|
|
|
|
{option}`useDefaultShell` to `true`,
|
2022-12-23 00:43:05 +01:00
|
|
|
|
and {option}`isSystemUser` to `false`.
|
|
|
|
|
Exactly one of `isNormalUser` and `isSystemUser` must be true.
|
2014-08-15 02:07:43 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
group = mkOption {
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
Increase max group name length to 32 characters
With #36556, a check was introduced to make sure the user and group
names do not exceed their respective maximum length. This is in part
because systemd also enforces that length, but only at runtime.
So in general it's a good idea to catch as much as we can during
evaluation time, however the maximum length of the group name was set to
16 characters according groupadd(8).
The maximum length of the group names however is a compile-time option
and even systemd allows more than 16 characters. In the mentioned pull
request (#36556) there was already a report that this has broken
evaluation for people out there.
I have also checked what other distributions are doing and they set the
length to either 31 characters or 32 characters, the latter being more
common.
Unfortunately there is a difference between the maximum length enforced
by the shadow package and systemd, both for user name lengths and group
name lengths. However, systemd enforces both length to have a maximum of
31 characters and I'm not sure if this is intended or just a off-by-one
error in systemd.
Nevertheless, I choose 32 characters simply to bring it in par with the
maximum user name length.
For the NixOS assertion however, I use a maximum length of 31 to make
sure that nobody accidentally creates services that contain group names
that systemd considers invalid because of a length of 32 characters.
Signed-off-by: aszlig <aszlig@nix.build>
Closes: #38548
Cc: @vcunat, @fpletz, @qknight
2018-04-07 15:14:47 +02:00
|
|
|
|
apply = x: assert (builtins.stringLength x < 32 || abort "Group name '${x}' is longer than 31 characters which is not allowed!"); x;
|
2021-08-08 14:00:00 +02:00
|
|
|
|
default = "";
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc "The user's primary group.";
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
extraGroups = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.listOf types.str;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
default = [];
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc "The user's auxiliary groups.";
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
home = mkOption {
|
2022-06-25 13:59:43 +02:00
|
|
|
|
type = types.passwdEntry types.path;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
default = "/var/empty";
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc "The user's home directory.";
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2022-04-10 21:06:19 +02:00
|
|
|
|
homeMode = mkOption {
|
|
|
|
|
type = types.strMatching "[0-7]{1,5}";
|
|
|
|
|
default = "700";
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc "The user's home directory mode in numeric format. See chmod(1). The mode is only applied if {option}`users.users.<name>.createHome` is true.";
|
2022-04-10 21:06:19 +02:00
|
|
|
|
};
|
|
|
|
|
|
2015-07-02 16:46:56 +02:00
|
|
|
|
cryptHomeLuks = mkOption {
|
|
|
|
|
type = with types; nullOr str;
|
|
|
|
|
default = null;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2015-07-02 16:46:56 +02:00
|
|
|
|
Path to encrypted luks device that contains
|
|
|
|
|
the user's home directory.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-15 02:29:30 +02:00
|
|
|
|
pamMount = mkOption {
|
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
|
default = {};
|
2022-08-03 22:46:41 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2020-10-15 02:29:30 +02:00
|
|
|
|
Attributes for user's entry in
|
2022-08-03 22:46:41 +02:00
|
|
|
|
{file}`pam_mount.conf.xml`.
|
|
|
|
|
Useful attributes might include `path`,
|
|
|
|
|
`options`, `fstype`, and `server`.
|
|
|
|
|
See <http://pam-mount.sourceforge.net/pam_mount.conf.5.html>
|
2020-10-15 02:29:30 +02:00
|
|
|
|
for more information.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
shell = mkOption {
|
2022-06-25 13:59:43 +02:00
|
|
|
|
type = types.nullOr (types.either types.shellPackage (types.passwdEntry types.path));
|
2018-07-23 01:52:54 +02:00
|
|
|
|
default = pkgs.shadow;
|
2021-10-03 18:06:03 +02:00
|
|
|
|
defaultText = literalExpression "pkgs.shadow";
|
|
|
|
|
example = literalExpression "pkgs.bashInteractive";
|
2022-08-03 22:46:41 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2016-03-08 18:02:15 +01:00
|
|
|
|
The path to the user's shell. Can use shell derivations,
|
2022-08-03 22:46:41 +02:00
|
|
|
|
like `pkgs.bashInteractive`. Don’t
|
2016-03-08 18:02:15 +01:00
|
|
|
|
forget to enable your shell in
|
2022-08-03 22:46:41 +02:00
|
|
|
|
`programs` if necessary,
|
|
|
|
|
like `programs.zsh.enable = true;`.
|
2016-03-08 18:02:15 +01:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2014-06-26 02:11:28 +02:00
|
|
|
|
subUidRanges = mkOption {
|
2016-09-11 09:35:50 +02:00
|
|
|
|
type = with types; listOf (submodule subordinateUidRange);
|
2014-06-26 02:11:28 +02:00
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
|
|
|
|
{ startUid = 1000; count = 1; }
|
|
|
|
|
{ startUid = 100001; count = 65534; }
|
|
|
|
|
];
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-06-26 02:11:28 +02:00
|
|
|
|
Subordinate user ids that user is allowed to use.
|
2022-07-28 23:19:15 +02:00
|
|
|
|
They are set into {file}`/etc/subuid` and are used
|
|
|
|
|
by `newuidmap` for user namespaces.
|
2014-06-26 02:11:28 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
subGidRanges = mkOption {
|
2016-09-11 09:35:50 +02:00
|
|
|
|
type = with types; listOf (submodule subordinateGidRange);
|
2014-06-26 02:11:28 +02:00
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
|
|
|
|
{ startGid = 100; count = 1; }
|
|
|
|
|
{ startGid = 1001; count = 999; }
|
|
|
|
|
];
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-06-26 02:11:28 +02:00
|
|
|
|
Subordinate group ids that user is allowed to use.
|
2022-07-28 23:19:15 +02:00
|
|
|
|
They are set into {file}`/etc/subgid` and are used
|
|
|
|
|
by `newgidmap` for user namespaces.
|
2014-06-26 02:11:28 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-05 11:20:47 +01:00
|
|
|
|
autoSubUidGidRange = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
example = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2022-01-05 11:20:47 +01:00
|
|
|
|
Automatically allocate subordinate user and group ids for this user.
|
|
|
|
|
Allocated range is currently always of size 65536.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
createHome = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
nixos/users-groups: createHome: Ensure HOME permissions, fix description
configuration.nix(1) states
users.extraUsers.<name>.createHome
[...] If [...] the home directory already exists but is not
owned by the user, directory owner and group will be changed to
match the user.
i.e. ownership would change only if the user mismatched; the code
however ignores the owner, it is sufficient to enable `createHome`:
if ($u->{createHome}) {
make_path($u->{home}, { mode => 0700 }) if ! -e $u->{home};
chown $u->{uid}, $u->{gid}, $u->{home};
}
Furthermore, permissions are ignored on already existing directories and
therefore may allow others to read private data eventually.
Given that createHome already acts as switch to not only create but
effectively own the home directory, manage permissions in the same
manner to ensure the intended default and cover all primary attributes.
Avoid yet another configuration option to have administrators make a
clear and simple choice between securely managing home directories
and optionally defering management to own code (taking care of custom
location, ownership, mode, extended attributes, etc.).
While here, simplify and thereby fix misleading documentation.
2020-11-22 23:42:02 +01:00
|
|
|
|
Whether to create the home directory and ensure ownership as well as
|
|
|
|
|
permissions to match the user.
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
useDefaultShell = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
If true, the user's shell will be set to
|
2022-07-28 23:19:15 +02:00
|
|
|
|
{option}`users.defaultUserShell`.
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2014-02-05 15:07:20 +01:00
|
|
|
|
hashedPassword = mkOption {
|
2021-04-20 13:53:24 +02:00
|
|
|
|
type = with types; nullOr (passwdEntry str);
|
2014-02-05 15:07:20 +01:00
|
|
|
|
default = null;
|
2022-08-20 18:35:28 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-11-03 11:59:38 +01:00
|
|
|
|
Specifies the hashed password for the user.
|
2014-02-05 15:07:20 +01:00
|
|
|
|
${passwordDescription}
|
2015-01-02 17:32:33 +01:00
|
|
|
|
${hashedPasswordDescription}
|
2014-02-05 15:07:20 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
password = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
|
type = with types; nullOr str;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
default = null;
|
2022-08-20 18:35:28 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-02-05 15:07:20 +01:00
|
|
|
|
Specifies the (clear text) password for the user.
|
|
|
|
|
Warning: do not set confidential information here
|
|
|
|
|
because it is world-readable in the Nix store. This option
|
|
|
|
|
should only be used for public accounts.
|
|
|
|
|
${passwordDescription}
|
2013-10-31 08:41:51 +01:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
passwordFile = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
|
type = with types; nullOr str;
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
default = null;
|
2022-08-20 18:35:28 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-10-23 04:52:50 +02:00
|
|
|
|
The full path to a file that contains the user's password. The password
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
file is read on each system activation. The file should contain
|
|
|
|
|
exactly one line, which should be the password in an encrypted form
|
2022-08-20 18:35:28 +02:00
|
|
|
|
that is suitable for the `chpasswd -e` command.
|
2014-02-05 15:07:20 +01:00
|
|
|
|
${passwordDescription}
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
'';
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2014-11-03 11:59:38 +01:00
|
|
|
|
|
|
|
|
|
initialHashedPassword = mkOption {
|
2021-04-20 13:53:24 +02:00
|
|
|
|
type = with types; nullOr (passwdEntry str);
|
2014-11-03 11:59:38 +01:00
|
|
|
|
default = null;
|
2022-08-20 18:35:28 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-11-03 11:59:38 +01:00
|
|
|
|
Specifies the initial hashed password for the user, i.e. the
|
|
|
|
|
hashed password assigned if the user does not already
|
2022-08-20 18:35:28 +02:00
|
|
|
|
exist. If {option}`users.mutableUsers` is true, the
|
2014-11-03 11:59:38 +01:00
|
|
|
|
password can be changed subsequently using the
|
2022-08-20 18:35:28 +02:00
|
|
|
|
{command}`passwd` command. Otherwise, it's
|
|
|
|
|
equivalent to setting the {option}`hashedPassword` option.
|
2015-01-02 17:32:33 +01:00
|
|
|
|
|
2023-02-24 03:05:43 +01:00
|
|
|
|
Note that the {option}`hashedPassword` option will override
|
|
|
|
|
this option if both are set.
|
|
|
|
|
|
2015-01-02 17:32:33 +01:00
|
|
|
|
${hashedPasswordDescription}
|
2014-11-03 11:59:38 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
initialPassword = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
|
type = with types; nullOr str;
|
2014-11-03 11:59:38 +01:00
|
|
|
|
default = null;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-11-03 11:59:38 +01:00
|
|
|
|
Specifies the initial password for the user, i.e. the
|
|
|
|
|
password assigned if the user does not already exist. If
|
2022-07-28 23:19:15 +02:00
|
|
|
|
{option}`users.mutableUsers` is true, the password
|
2014-11-03 11:59:38 +01:00
|
|
|
|
can be changed subsequently using the
|
2022-07-28 23:19:15 +02:00
|
|
|
|
{command}`passwd` command. Otherwise, it's
|
|
|
|
|
equivalent to setting the {option}`password`
|
2014-11-03 11:59:38 +01:00
|
|
|
|
option. The same caveat applies: the password specified here
|
|
|
|
|
is world-readable in the Nix store, so it should only be
|
|
|
|
|
used for guest accounts or passwords that will be changed
|
|
|
|
|
promptly.
|
2023-02-24 03:05:43 +01:00
|
|
|
|
|
|
|
|
|
Note that the {option}`password` option will override this
|
|
|
|
|
option if both are set.
|
2014-11-03 11:59:38 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-11 20:31:06 +02:00
|
|
|
|
packages = mkOption {
|
|
|
|
|
type = types.listOf types.package;
|
|
|
|
|
default = [];
|
2021-10-03 18:06:03 +02:00
|
|
|
|
example = literalExpression "[ pkgs.firefox pkgs.thunderbird ]";
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2019-10-22 21:58:09 +02:00
|
|
|
|
The set of packages that should be made available to the user.
|
2022-07-28 23:19:15 +02:00
|
|
|
|
This is in contrast to {option}`environment.systemPackages`,
|
2017-05-11 20:31:06 +02:00
|
|
|
|
which adds packages to all users.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2007-06-08 17:41:12 +02:00
|
|
|
|
|
2014-08-15 02:07:43 +02:00
|
|
|
|
config = mkMerge
|
|
|
|
|
[ { name = mkDefault name;
|
|
|
|
|
shell = mkIf config.useDefaultShell (mkDefault cfg.defaultUserShell);
|
|
|
|
|
}
|
|
|
|
|
(mkIf config.isNormalUser {
|
|
|
|
|
group = mkDefault "users";
|
|
|
|
|
createHome = mkDefault true;
|
2018-10-24 19:38:56 +02:00
|
|
|
|
home = mkDefault "/home/${config.name}";
|
2022-04-10 21:06:19 +02:00
|
|
|
|
homeMode = mkDefault "700";
|
2014-08-15 02:07:43 +02:00
|
|
|
|
useDefaultShell = mkDefault true;
|
|
|
|
|
isSystemUser = mkDefault false;
|
|
|
|
|
})
|
2014-11-03 12:19:25 +01:00
|
|
|
|
# If !mutableUsers, setting ‘initialPassword’ is equivalent to
|
|
|
|
|
# setting ‘password’ (and similarly for hashed passwords).
|
|
|
|
|
(mkIf (!cfg.mutableUsers && config.initialPassword != null) {
|
|
|
|
|
password = mkDefault config.initialPassword;
|
|
|
|
|
})
|
|
|
|
|
(mkIf (!cfg.mutableUsers && config.initialHashedPassword != null) {
|
|
|
|
|
hashedPassword = mkDefault config.initialHashedPassword;
|
|
|
|
|
})
|
2022-01-05 11:20:47 +01:00
|
|
|
|
(mkIf (config.isNormalUser && config.subUidRanges == [] && config.subGidRanges == []) {
|
|
|
|
|
autoSubUidGidRange = mkDefault true;
|
|
|
|
|
})
|
2014-08-15 02:07:43 +02:00
|
|
|
|
];
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
2007-06-08 17:41:12 +02:00
|
|
|
|
|
2021-08-06 01:20:09 +02:00
|
|
|
|
groupOpts = { name, config, ... }: {
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
options = {
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
name = mkOption {
|
2022-06-25 13:59:43 +02:00
|
|
|
|
type = types.passwdEntry types.str;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-04-06 12:39:51 +02:00
|
|
|
|
The name of the group. If undefined, the name of the attribute set
|
|
|
|
|
will be used.
|
|
|
|
|
'';
|
2012-04-20 14:55:09 +02:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
gid = mkOption {
|
2014-04-06 12:39:51 +02:00
|
|
|
|
type = with types; nullOr int;
|
|
|
|
|
default = null;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-08-15 01:33:20 +02:00
|
|
|
|
The group GID. If the GID is null, a free GID is picked on
|
|
|
|
|
activation.
|
2014-04-06 12:39:51 +02:00
|
|
|
|
'';
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
members = mkOption {
|
2021-04-20 13:53:24 +02:00
|
|
|
|
type = with types; listOf (passwdEntry str);
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
default = [];
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-02-05 15:24:05 +01:00
|
|
|
|
The user names of the group members, added to the
|
2022-07-28 23:19:15 +02:00
|
|
|
|
`/etc/group` file.
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
'';
|
2012-04-20 14:55:09 +02:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
};
|
2007-06-08 17:41:12 +02:00
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
config = {
|
|
|
|
|
name = mkDefault name;
|
2021-08-06 01:20:09 +02:00
|
|
|
|
|
|
|
|
|
members = mapAttrsToList (n: u: u.name) (
|
|
|
|
|
filterAttrs (n: u: elem config.name u.extraGroups) cfg.users
|
|
|
|
|
);
|
2012-04-20 14:55:09 +02:00
|
|
|
|
};
|
2012-10-23 13:35:06 +02:00
|
|
|
|
|
2012-04-20 14:55:09 +02:00
|
|
|
|
};
|
2009-01-02 17:07:01 +01:00
|
|
|
|
|
2014-06-26 02:11:28 +02:00
|
|
|
|
subordinateUidRange = {
|
2016-09-11 09:35:50 +02:00
|
|
|
|
options = {
|
|
|
|
|
startUid = mkOption {
|
|
|
|
|
type = types.int;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2016-09-11 09:35:50 +02:00
|
|
|
|
Start of the range of subordinate user ids that user is
|
|
|
|
|
allowed to use.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
count = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 1;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc "Count of subordinate user ids";
|
2016-09-11 09:35:50 +02:00
|
|
|
|
};
|
2014-06-26 02:11:28 +02:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
subordinateGidRange = {
|
2016-09-11 09:35:50 +02:00
|
|
|
|
options = {
|
|
|
|
|
startGid = mkOption {
|
|
|
|
|
type = types.int;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2016-09-11 09:35:50 +02:00
|
|
|
|
Start of the range of subordinate group ids that user is
|
|
|
|
|
allowed to use.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
count = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 1;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc "Count of subordinate group ids";
|
2016-09-11 09:35:50 +02:00
|
|
|
|
};
|
2014-06-26 02:11:28 +02:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-25 07:57:48 +01:00
|
|
|
|
idsAreUnique = set: idAttr: !(foldr (name: args@{ dup, acc }:
|
2014-02-07 15:57:28 +01:00
|
|
|
|
let
|
|
|
|
|
id = builtins.toString (builtins.getAttr idAttr (builtins.getAttr name set));
|
|
|
|
|
exists = builtins.hasAttr id acc;
|
|
|
|
|
newAcc = acc // (builtins.listToAttrs [ { name = id; value = true; } ]);
|
|
|
|
|
in if dup then args else if exists
|
|
|
|
|
then builtins.trace "Duplicate ${idAttr} ${id}" { dup = true; acc = null; }
|
|
|
|
|
else { dup = false; acc = newAcc; }
|
|
|
|
|
) { dup = false; acc = {}; } (builtins.attrNames set)).dup;
|
2009-01-02 17:07:01 +01:00
|
|
|
|
|
2015-09-02 17:32:38 +02:00
|
|
|
|
uidsAreUnique = idsAreUnique (filterAttrs (n: u: u.uid != null) cfg.users) "uid";
|
|
|
|
|
gidsAreUnique = idsAreUnique (filterAttrs (n: g: g.gid != null) cfg.groups) "gid";
|
2022-07-22 07:32:22 +02:00
|
|
|
|
sdInitrdUidsAreUnique = idsAreUnique (filterAttrs (n: u: u.uid != null) config.boot.initrd.systemd.users) "uid";
|
|
|
|
|
sdInitrdGidsAreUnique = idsAreUnique (filterAttrs (n: g: g.gid != null) config.boot.initrd.systemd.groups) "gid";
|
2014-04-06 12:39:51 +02:00
|
|
|
|
|
2014-09-10 11:49:32 +02:00
|
|
|
|
spec = pkgs.writeText "users-groups.json" (builtins.toJSON {
|
2014-08-15 01:33:20 +02:00
|
|
|
|
inherit (cfg) mutableUsers;
|
2016-06-12 21:03:14 +02:00
|
|
|
|
users = mapAttrsToList (_: u:
|
2014-08-15 01:33:20 +02:00
|
|
|
|
{ inherit (u)
|
2022-04-10 21:06:19 +02:00
|
|
|
|
name uid group description home homeMode createHome isSystemUser
|
2014-11-03 11:59:38 +01:00
|
|
|
|
password passwordFile hashedPassword
|
2022-01-05 11:20:47 +01:00
|
|
|
|
autoSubUidGidRange subUidRanges subGidRanges
|
2014-11-03 11:59:38 +01:00
|
|
|
|
initialPassword initialHashedPassword;
|
2016-06-12 21:03:14 +02:00
|
|
|
|
shell = utils.toShellPath u.shell;
|
2015-09-02 17:32:38 +02:00
|
|
|
|
}) cfg.users;
|
2021-08-06 01:20:09 +02:00
|
|
|
|
groups = attrValues cfg.groups;
|
2014-08-15 01:33:20 +02:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-12 21:03:14 +02:00
|
|
|
|
systemShells =
|
|
|
|
|
let
|
|
|
|
|
shells = mapAttrsToList (_: u: u.shell) cfg.users;
|
|
|
|
|
in
|
|
|
|
|
filter types.shellPackage.check shells;
|
|
|
|
|
|
2014-04-06 12:39:51 +02:00
|
|
|
|
in {
|
2019-12-10 02:51:19 +01:00
|
|
|
|
imports = [
|
2022-12-30 20:43:53 +01:00
|
|
|
|
(mkAliasOptionModuleMD [ "users" "extraUsers" ] [ "users" "users" ])
|
|
|
|
|
(mkAliasOptionModuleMD [ "users" "extraGroups" ] [ "users" "groups" ])
|
2019-11-09 11:52:35 +01:00
|
|
|
|
(mkRenamedOptionModule ["security" "initialRootPassword"] ["users" "users" "root" "initialHashedPassword"])
|
2019-12-10 02:51:19 +01:00
|
|
|
|
];
|
2009-01-02 17:07:01 +01:00
|
|
|
|
|
2009-09-02 19:35:24 +02:00
|
|
|
|
###### interface
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
users.mutableUsers = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2022-08-20 18:35:28 +02:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
If set to `true`, you are free to add new users and groups to the system
|
|
|
|
|
with the ordinary `useradd` and
|
|
|
|
|
`groupadd` commands. On system activation, the
|
|
|
|
|
existing contents of the `/etc/passwd` and
|
|
|
|
|
`/etc/group` files will be merged with the
|
|
|
|
|
contents generated from the `users.users` and
|
|
|
|
|
`users.groups` options.
|
2015-01-02 17:32:33 +01:00
|
|
|
|
The initial password for a user will be set
|
2022-08-20 18:35:28 +02:00
|
|
|
|
according to `users.users`, but existing passwords
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
will not be changed.
|
2015-01-02 17:32:33 +01:00
|
|
|
|
|
2022-08-20 18:35:28 +02:00
|
|
|
|
::: {.warning}
|
|
|
|
|
If set to `false`, the contents of the user and
|
2015-01-02 17:32:33 +01:00
|
|
|
|
group files will simply be replaced on system activation. This also
|
|
|
|
|
holds for the user passwords; all changed
|
|
|
|
|
passwords will be reset according to the
|
2022-08-20 18:35:28 +02:00
|
|
|
|
`users.users` configuration on activation.
|
|
|
|
|
:::
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-07 15:57:28 +01:00
|
|
|
|
users.enforceIdUniqueness = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2014-02-07 15:57:28 +01:00
|
|
|
|
Whether to require that no two users/groups share the same uid/gid.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-02 17:32:38 +02:00
|
|
|
|
users.users = mkOption {
|
2011-11-29 07:08:55 +01:00
|
|
|
|
default = {};
|
2020-08-23 01:28:45 +02:00
|
|
|
|
type = with types; attrsOf (submodule userOpts);
|
2011-11-29 07:08:55 +01:00
|
|
|
|
example = {
|
|
|
|
|
alice = {
|
|
|
|
|
uid = 1234;
|
2013-10-31 08:41:51 +01:00
|
|
|
|
description = "Alice Q. User";
|
2011-11-29 07:08:55 +01:00
|
|
|
|
home = "/home/alice";
|
|
|
|
|
createHome = true;
|
|
|
|
|
group = "users";
|
|
|
|
|
extraGroups = ["wheel"];
|
|
|
|
|
shell = "/bin/sh";
|
|
|
|
|
};
|
|
|
|
|
};
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2009-09-02 19:35:24 +02:00
|
|
|
|
Additional user accounts to be created automatically by the system.
|
2013-08-09 03:23:22 +02:00
|
|
|
|
This can also be used to set options for root.
|
2009-09-02 19:35:24 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
2009-01-02 17:07:01 +01:00
|
|
|
|
|
2015-09-02 17:32:38 +02:00
|
|
|
|
users.groups = mkOption {
|
2012-04-20 14:55:09 +02:00
|
|
|
|
default = {};
|
2009-09-02 19:35:24 +02:00
|
|
|
|
example =
|
2012-04-20 14:55:09 +02:00
|
|
|
|
{ students.gid = 1001;
|
|
|
|
|
hackers = { };
|
|
|
|
|
};
|
2020-08-23 01:28:45 +02:00
|
|
|
|
type = with types; attrsOf (submodule groupOpts);
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
2009-09-02 19:35:24 +02:00
|
|
|
|
Additional groups to be created automatically by the system.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-09 11:52:35 +01:00
|
|
|
|
|
|
|
|
|
users.allowNoPasswordLogin = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Disable checking that at least the `root` user or a user in the `wheel` group can log in using
|
2019-11-09 11:52:35 +01:00
|
|
|
|
a password or an SSH key.
|
|
|
|
|
|
|
|
|
|
WARNING: enabling this can lock you out of your system. Enable this only if you know what are you doing.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-07-22 07:32:22 +02:00
|
|
|
|
|
|
|
|
|
# systemd initrd
|
|
|
|
|
boot.initrd.systemd.users = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Users to include in initrd.
|
|
|
|
|
'';
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf (types.submodule ({ name, ... }: {
|
|
|
|
|
options.uid = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
type = types.int;
|
|
|
|
|
description = ''
|
|
|
|
|
ID of the user in initrd.
|
|
|
|
|
'';
|
|
|
|
|
defaultText = literalExpression "config.users.users.\${name}.uid";
|
|
|
|
|
default = cfg.users.${name}.uid;
|
|
|
|
|
};
|
|
|
|
|
options.group = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
type = types.singleLineStr;
|
|
|
|
|
description = ''
|
|
|
|
|
Group the user belongs to in initrd.
|
|
|
|
|
'';
|
|
|
|
|
defaultText = literalExpression "config.users.users.\${name}.group";
|
|
|
|
|
default = cfg.users.${name}.group;
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
boot.initrd.systemd.groups = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Groups to include in initrd.
|
|
|
|
|
'';
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf (types.submodule ({ name, ... }: {
|
|
|
|
|
options.gid = mkOption {
|
|
|
|
|
visible = false;
|
|
|
|
|
type = types.int;
|
|
|
|
|
description = ''
|
|
|
|
|
ID of the group in initrd.
|
|
|
|
|
'';
|
|
|
|
|
defaultText = literalExpression "config.users.groups.\${name}.gid";
|
|
|
|
|
default = cfg.groups.${name}.gid;
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
};
|
2009-09-02 19:35:24 +02:00
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
|
2009-09-02 19:35:24 +02:00
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
2023-03-11 22:29:16 +01:00
|
|
|
|
config = let
|
|
|
|
|
cryptSchemeIdPatternGroup = "(${lib.concatStringsSep "|" pkgs.libxcrypt.enabledCryptSchemeIds})";
|
|
|
|
|
in {
|
2009-09-02 19:35:24 +02:00
|
|
|
|
|
2015-09-02 17:32:38 +02:00
|
|
|
|
users.users = {
|
2011-11-29 07:08:55 +01:00
|
|
|
|
root = {
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
uid = ids.uids.root;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
description = "System administrator";
|
|
|
|
|
home = "/root";
|
2014-08-20 21:17:48 +02:00
|
|
|
|
shell = mkDefault cfg.defaultUserShell;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
group = "root";
|
2019-11-09 11:52:35 +01:00
|
|
|
|
initialHashedPassword = mkDefault "!";
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
|
|
|
|
nobody = {
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
uid = ids.uids.nobody;
|
2021-03-07 14:54:00 +01:00
|
|
|
|
isSystemUser = true;
|
2011-11-29 07:08:55 +01:00
|
|
|
|
description = "Unprivileged account (don't use!)";
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
group = "nogroup";
|
2011-11-29 07:08:55 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-02 17:32:38 +02:00
|
|
|
|
users.groups = {
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
root.gid = ids.gids.root;
|
|
|
|
|
wheel.gid = ids.gids.wheel;
|
|
|
|
|
disk.gid = ids.gids.disk;
|
|
|
|
|
kmem.gid = ids.gids.kmem;
|
|
|
|
|
tty.gid = ids.gids.tty;
|
|
|
|
|
floppy.gid = ids.gids.floppy;
|
|
|
|
|
uucp.gid = ids.gids.uucp;
|
|
|
|
|
lp.gid = ids.gids.lp;
|
|
|
|
|
cdrom.gid = ids.gids.cdrom;
|
|
|
|
|
tape.gid = ids.gids.tape;
|
|
|
|
|
audio.gid = ids.gids.audio;
|
|
|
|
|
video.gid = ids.gids.video;
|
|
|
|
|
dialout.gid = ids.gids.dialout;
|
|
|
|
|
nogroup.gid = ids.gids.nogroup;
|
|
|
|
|
users.gid = ids.gids.users;
|
|
|
|
|
nixbld.gid = ids.gids.nixbld;
|
|
|
|
|
utmp.gid = ids.gids.utmp;
|
|
|
|
|
adm.gid = ids.gids.adm;
|
2015-03-03 20:23:32 +01:00
|
|
|
|
input.gid = ids.gids.input;
|
2018-08-15 22:10:31 +02:00
|
|
|
|
kvm.gid = ids.gids.kvm;
|
|
|
|
|
render.gid = ids.gids.render;
|
2021-12-05 00:37:43 +01:00
|
|
|
|
sgx.gid = ids.gids.sgx;
|
2020-09-24 22:28:52 +02:00
|
|
|
|
shadow.gid = ids.gids.shadow;
|
2012-04-20 14:55:09 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-09-03 17:21:36 +02:00
|
|
|
|
system.activationScripts.users = {
|
|
|
|
|
supportsDryActivation = true;
|
|
|
|
|
text = ''
|
2018-02-27 20:28:49 +01:00
|
|
|
|
install -m 0700 -d /root
|
|
|
|
|
install -m 0755 -d /home
|
|
|
|
|
|
2021-02-24 20:53:45 +01:00
|
|
|
|
${pkgs.perl.withPackages (p: [ p.FileSlurp p.JSON ])}/bin/perl \
|
|
|
|
|
-w ${./update-users-groups.pl} ${spec}
|
2010-09-13 17:41:38 +02:00
|
|
|
|
'';
|
2021-09-03 17:21:36 +02:00
|
|
|
|
};
|
2009-01-02 17:07:01 +01:00
|
|
|
|
|
2022-10-10 04:19:06 +02:00
|
|
|
|
# Warn about user accounts with deprecated password hashing schemes
|
|
|
|
|
system.activationScripts.hashes = {
|
|
|
|
|
deps = [ "users" ];
|
|
|
|
|
text = ''
|
|
|
|
|
users=()
|
|
|
|
|
while IFS=: read -r user hash tail; do
|
2023-03-11 22:29:16 +01:00
|
|
|
|
if [[ "$hash" = "$"* && ! "$hash" =~ ^\''$${cryptSchemeIdPatternGroup}\$ ]]; then
|
2022-10-10 04:19:06 +02:00
|
|
|
|
users+=("$user")
|
|
|
|
|
fi
|
|
|
|
|
done </etc/shadow
|
|
|
|
|
|
|
|
|
|
if (( "''${#users[@]}" )); then
|
|
|
|
|
echo "
|
2023-03-11 22:29:16 +01:00
|
|
|
|
WARNING: The following user accounts rely on password hashing algorithms
|
|
|
|
|
that have been removed. They need to be renewed as soon as possible, as
|
|
|
|
|
they do prevent their users from logging in."
|
2022-10-10 04:19:06 +02:00
|
|
|
|
printf ' - %s\n' "''${users[@]}"
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
Generate /etc/passwd and /etc/group at build time
This is a rather large commit that switches user/group creation from using
useradd/groupadd on activation to just generating the contents of /etc/passwd
and /etc/group, and then on activation merging the generated files with the
files that exist in the system. This makes the user activation process much
cleaner, in my opinion.
The users.extraUsers.<user>.uid and users.extraGroups.<group>.gid must all be
properly defined (if <user>.createUser is true, which it is by default). My
pull request adds a lot of uids/gids to config.ids to solve this problem for
existing nixos services, but there might be configurations that break because
this change. However, this will be discovered during the build.
Option changes introduced by this commit:
* Remove the options <user>.isSystemUser and <user>.isAlias since
they don't make sense when generating /etc/passwd statically.
* Add <group>.members as a complement to <user>.extraGroups.
* Add <user>.passwordFile for setting a user's password from an encrypted
(shadow-style) file.
* Add users.mutableUsers which is true by default. This means you can keep
managing your users as previously, by using useradd/groupadd manually. This is
accomplished by merging the generated passwd/group file with the existing files
in /etc on system activation. The merging of the files is simplistic. It just
looks at the user/group names. If a user/group exists both on the system and
in the generated files, the system entry will be kept un-changed and the
generated entries will be ignored. The merging itself is performed with the
help of vipw/vigr to properly lock the account files during edit.
If mutableUsers is set to false, the generated passwd and group files will not
be merged with the system files on activation. Instead they will simply replace
the system files, and overwrite any changes done on the running system. The
same logic holds for user password, if the <user>.password or
<user>.passwordFile options are used. If mutableUsers is false, password will
simply be replaced on activation. If true, the initial user passwords will be
set according to the configuration, but existing passwords will not be touched.
I have tested this on a couple of different systems and it seems to work fine
so far. If you think this is a good idea, please test it. This way of adding
local users has been discussed in issue #103 (and this commit solves that
issue).
2013-05-17 17:08:32 +02:00
|
|
|
|
# for backwards compatibility
|
|
|
|
|
system.activationScripts.groups = stringAfter [ "users" ] "";
|
2007-06-08 17:41:12 +02:00
|
|
|
|
|
2018-03-20 23:40:57 +01:00
|
|
|
|
# Install all the user shells
|
|
|
|
|
environment.systemPackages = systemShells;
|
|
|
|
|
|
2022-11-30 23:58:55 +01:00
|
|
|
|
environment.etc = mapAttrs' (_: { packages, name, ... }: {
|
2018-03-20 23:40:57 +01:00
|
|
|
|
name = "profiles/per-user/${name}";
|
|
|
|
|
value.source = pkgs.buildEnv {
|
|
|
|
|
name = "user-environment";
|
|
|
|
|
paths = packages;
|
|
|
|
|
inherit (config.environment) pathsToLink extraOutputsToInstall;
|
|
|
|
|
inherit (config.system.path) ignoreCollisions postBuild;
|
|
|
|
|
};
|
2022-11-30 23:58:55 +01:00
|
|
|
|
}) (filterAttrs (_: u: u.packages != []) cfg.users);
|
2018-03-20 23:40:57 +01:00
|
|
|
|
|
2019-08-10 10:28:12 +02:00
|
|
|
|
environment.profiles = [
|
|
|
|
|
"$HOME/.nix-profile"
|
|
|
|
|
"/etc/profiles/per-user/$USER"
|
|
|
|
|
];
|
2014-06-26 02:11:28 +02:00
|
|
|
|
|
2022-07-22 07:32:22 +02:00
|
|
|
|
# systemd initrd
|
|
|
|
|
boot.initrd.systemd = lib.mkIf config.boot.initrd.systemd.enable {
|
|
|
|
|
contents = {
|
|
|
|
|
"/etc/passwd".text = ''
|
|
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: { uid, group }: let
|
|
|
|
|
g = config.boot.initrd.systemd.groups.${group};
|
|
|
|
|
in "${n}:x:${toString uid}:${toString g.gid}::/var/empty:") config.boot.initrd.systemd.users)}
|
|
|
|
|
'';
|
|
|
|
|
"/etc/group".text = ''
|
|
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: { gid }: "${n}:x:${toString gid}:") config.boot.initrd.systemd.groups)}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
users = {
|
|
|
|
|
root = {};
|
|
|
|
|
nobody = {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
groups = {
|
|
|
|
|
root = {};
|
|
|
|
|
nogroup = {};
|
|
|
|
|
systemd-journal = {};
|
|
|
|
|
tty = {};
|
|
|
|
|
dialout = {};
|
|
|
|
|
kmem = {};
|
|
|
|
|
input = {};
|
|
|
|
|
video = {};
|
|
|
|
|
render = {};
|
|
|
|
|
sgx = {};
|
|
|
|
|
audio = {};
|
|
|
|
|
video = {};
|
|
|
|
|
lp = {};
|
|
|
|
|
disk = {};
|
|
|
|
|
cdrom = {};
|
|
|
|
|
tape = {};
|
|
|
|
|
kvm = {};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-06 12:39:51 +02:00
|
|
|
|
assertions = [
|
|
|
|
|
{ assertion = !cfg.enforceIdUniqueness || (uidsAreUnique && gidsAreUnique);
|
2014-08-15 01:33:20 +02:00
|
|
|
|
message = "UIDs and GIDs must be unique!";
|
2014-04-06 12:39:51 +02:00
|
|
|
|
}
|
2022-07-22 07:32:22 +02:00
|
|
|
|
{ assertion = !cfg.enforceIdUniqueness || (sdInitrdUidsAreUnique && sdInitrdGidsAreUnique);
|
|
|
|
|
message = "systemd initrd UIDs and GIDs must be unique!";
|
|
|
|
|
}
|
2015-09-02 16:09:05 +02:00
|
|
|
|
{ # If mutableUsers is false, to prevent users creating a
|
|
|
|
|
# configuration that locks them out of the system, ensure that
|
|
|
|
|
# there is at least one "privileged" account that has a
|
|
|
|
|
# password or an SSH authorized key. Privileged accounts are
|
|
|
|
|
# root and users in the wheel group.
|
2019-11-09 11:52:35 +01:00
|
|
|
|
# The check does not apply when users.disableLoginPossibilityAssertion
|
|
|
|
|
# The check does not apply when users.mutableUsers
|
|
|
|
|
assertion = !cfg.mutableUsers -> !cfg.allowNoPasswordLogin ->
|
|
|
|
|
any id (mapAttrsToList (name: cfg:
|
|
|
|
|
(name == "root"
|
2015-09-02 16:09:05 +02:00
|
|
|
|
|| cfg.group == "wheel"
|
|
|
|
|
|| elem "wheel" cfg.extraGroups)
|
|
|
|
|
&&
|
2020-06-25 02:02:29 +02:00
|
|
|
|
(allowsLogin cfg.hashedPassword
|
2015-09-02 16:09:05 +02:00
|
|
|
|
|| cfg.password != null
|
|
|
|
|
|| cfg.passwordFile != null
|
|
|
|
|
|| cfg.openssh.authorizedKeys.keys != []
|
|
|
|
|
|| cfg.openssh.authorizedKeys.keyFiles != [])
|
2022-02-05 22:37:26 +01:00
|
|
|
|
) cfg.users ++ [
|
2020-07-19 02:24:00 +02:00
|
|
|
|
config.security.googleOsLogin.enable
|
2022-02-05 22:37:26 +01:00
|
|
|
|
]);
|
2015-09-02 16:09:05 +02:00
|
|
|
|
message = ''
|
|
|
|
|
Neither the root account nor any wheel user has a password or SSH authorized key.
|
2019-11-09 11:52:35 +01:00
|
|
|
|
You must set one to prevent being locked out of your system.
|
|
|
|
|
If you really want to be locked out of your system, set users.allowNoPasswordLogin = true;
|
|
|
|
|
However you are most probably better off by setting users.mutableUsers = true; and
|
|
|
|
|
manually running passwd root to set the root password.
|
|
|
|
|
'';
|
2015-09-02 16:09:05 +02:00
|
|
|
|
}
|
2021-03-07 14:54:00 +01:00
|
|
|
|
] ++ flatten (flip mapAttrsToList cfg.users (name: user:
|
|
|
|
|
[
|
|
|
|
|
{
|
2020-06-25 02:00:56 +02:00
|
|
|
|
assertion = (user.hashedPassword != null)
|
2021-03-07 14:54:00 +01:00
|
|
|
|
-> (builtins.match ".*:.*" user.hashedPassword == null);
|
2020-06-25 02:00:56 +02:00
|
|
|
|
message = ''
|
2021-03-07 14:54:00 +01:00
|
|
|
|
The password hash of user "${user.name}" contains a ":" character.
|
|
|
|
|
This is invalid and would break the login system because the fields
|
|
|
|
|
of /etc/shadow (file where hashes are stored) are colon-separated.
|
|
|
|
|
Please check the value of option `users.users."${user.name}".hashedPassword`.'';
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
assertion = let
|
|
|
|
|
xor = a: b: a && !b || b && !a;
|
2022-01-02 00:57:13 +01:00
|
|
|
|
isEffectivelySystemUser = user.isSystemUser || (user.uid != null && user.uid < 1000);
|
2021-03-07 14:54:00 +01:00
|
|
|
|
in xor isEffectivelySystemUser user.isNormalUser;
|
|
|
|
|
message = ''
|
|
|
|
|
Exactly one of users.users.${user.name}.isSystemUser and users.users.${user.name}.isNormalUser must be set.
|
|
|
|
|
'';
|
|
|
|
|
}
|
2021-08-08 14:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
assertion = user.group != "";
|
|
|
|
|
message = ''
|
|
|
|
|
users.users.${user.name}.group is unset. This used to default to
|
|
|
|
|
nogroup, but this is unsafe. For example you can create a group
|
|
|
|
|
for this user with:
|
|
|
|
|
users.users.${user.name}.group = "${user.name}";
|
|
|
|
|
users.groups.${user.name} = {};
|
|
|
|
|
'';
|
|
|
|
|
}
|
2023-01-19 17:59:11 +01:00
|
|
|
|
] ++ (map (shell: {
|
|
|
|
|
assertion = (user.shell == pkgs.${shell}) -> (config.programs.${shell}.enable == true);
|
2023-01-19 17:28:54 +01:00
|
|
|
|
message = ''
|
2023-01-19 17:59:11 +01:00
|
|
|
|
users.users.${user.name}.shell is set to ${shell}, but
|
|
|
|
|
programs.${shell}.enable is not true. This will cause the ${shell}
|
|
|
|
|
shell to lack the basic nix directories in its PATH and might make
|
2023-01-19 17:28:54 +01:00
|
|
|
|
logging in as that user impossible. You can fix it with:
|
2023-01-19 17:59:11 +01:00
|
|
|
|
programs.${shell}.enable = true;
|
2023-01-19 17:28:54 +01:00
|
|
|
|
'';
|
2023-01-19 17:59:11 +01:00
|
|
|
|
}) [
|
|
|
|
|
"fish"
|
|
|
|
|
"xonsh"
|
|
|
|
|
"zsh"
|
|
|
|
|
])
|
2021-03-07 14:54:00 +01:00
|
|
|
|
));
|
2014-02-07 15:57:28 +01:00
|
|
|
|
|
2020-03-23 02:13:02 +01:00
|
|
|
|
warnings =
|
|
|
|
|
builtins.filter (x: x != null) (
|
2020-06-09 18:22:05 +02:00
|
|
|
|
flip mapAttrsToList cfg.users (_: user:
|
2020-03-23 02:13:02 +01:00
|
|
|
|
# This regex matches a subset of the Modular Crypto Format (MCF)[1]
|
|
|
|
|
# informal standard. Since this depends largely on the OS or the
|
|
|
|
|
# specific implementation of crypt(3) we only support the (sane)
|
|
|
|
|
# schemes implemented by glibc and BSDs. In particular the original
|
|
|
|
|
# DES hash is excluded since, having no structure, it would validate
|
|
|
|
|
# common mistakes like typing the plaintext password.
|
|
|
|
|
#
|
|
|
|
|
# [1]: https://en.wikipedia.org/wiki/Crypt_(C)
|
|
|
|
|
let
|
|
|
|
|
sep = "\\$";
|
|
|
|
|
base64 = "[a-zA-Z0-9./]+";
|
2023-03-11 22:29:16 +01:00
|
|
|
|
id = cryptSchemeIdPatternGroup;
|
2023-04-03 02:13:52 +02:00
|
|
|
|
name = "[a-z0-9-]+";
|
2020-03-23 02:13:02 +01:00
|
|
|
|
value = "[a-zA-Z0-9/+.-]+";
|
2023-04-03 02:13:52 +02:00
|
|
|
|
options = "${name}(=${value})?(,${name}=${value})*";
|
2020-03-23 02:13:02 +01:00
|
|
|
|
scheme = "${id}(${sep}${options})?";
|
2022-09-26 22:45:24 +02:00
|
|
|
|
content = "${base64}${sep}${base64}(${sep}${base64})?";
|
2020-03-23 02:13:02 +01:00
|
|
|
|
mcf = "^${sep}${scheme}${sep}${content}$";
|
|
|
|
|
in
|
2020-06-25 02:02:29 +02:00
|
|
|
|
if (allowsLogin user.hashedPassword
|
2020-06-21 17:01:34 +02:00
|
|
|
|
&& user.hashedPassword != "" # login without password
|
2020-03-23 02:13:02 +01:00
|
|
|
|
&& builtins.match mcf user.hashedPassword == null)
|
2020-06-25 02:02:29 +02:00
|
|
|
|
then ''
|
2020-06-09 18:22:05 +02:00
|
|
|
|
The password hash of user "${user.name}" may be invalid. You must set a
|
2020-06-23 15:59:14 +02:00
|
|
|
|
valid hash or the user will be locked out of their account. Please
|
2020-06-09 18:22:05 +02:00
|
|
|
|
check the value of option `users.users."${user.name}".hashedPassword`.''
|
2020-03-23 02:13:02 +01:00
|
|
|
|
else null
|
|
|
|
|
));
|
|
|
|
|
|
2009-01-02 17:07:01 +01:00
|
|
|
|
};
|
2009-09-02 19:35:24 +02:00
|
|
|
|
|
2007-11-09 19:49:45 +01:00
|
|
|
|
}
|