2016-06-12 20:03:14 +01:00
|
|
|
|
{ config, lib, utils, pkgs, ... }:
|
2007-06-08 16:41:12 +01:00
|
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
|
with lib;
|
2009-01-02 16:07:01 +00:00
|
|
|
|
|
|
|
|
|
let
|
2009-05-29 15:25:56 +01: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 16:08:32 +01:00
|
|
|
|
cfg = config.users;
|
2007-06-08 16:41:12 +01:00
|
|
|
|
|
2014-02-05 14:07:20 +00:00
|
|
|
|
passwordDescription = ''
|
2014-11-03 10:59:38 +00:00
|
|
|
|
The options <option>hashedPassword</option>,
|
|
|
|
|
<option>password</option> and <option>passwordFile</option>
|
2014-02-05 14:07:20 +00:00
|
|
|
|
controls what password is set for the user.
|
2014-11-03 10:59:38 +00:00
|
|
|
|
<option>hashedPassword</option> overrides both
|
|
|
|
|
<option>password</option> and <option>passwordFile</option>.
|
|
|
|
|
<option>password</option> overrides <option>passwordFile</option>.
|
2014-02-05 14:07:20 +00: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.
|
2014-11-03 10:59:38 +00:00
|
|
|
|
If the option <option>users.mutableUsers</option> is true, the
|
2014-02-05 14:07:20 +00: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
|
2014-11-03 10:59:38 +00:00
|
|
|
|
<option>users.mutableUsers</option> is false, you cannot change
|
2014-02-05 14:07:20 +00:00
|
|
|
|
user passwords, they will always be set according to the password
|
|
|
|
|
options.
|
|
|
|
|
'';
|
|
|
|
|
|
2015-01-02 16:32:33 +00:00
|
|
|
|
hashedPasswordDescription = ''
|
2016-01-02 20:37:20 +00:00
|
|
|
|
To generate hashed password install <literal>mkpasswd</literal>
|
2015-01-02 16:32:33 +00:00
|
|
|
|
package and run <literal>mkpasswd -m sha-512</literal>.
|
|
|
|
|
'';
|
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
userOpts = { name, config, ... }: {
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
options = {
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
name = mkOption {
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2014-04-06 11:39:51 +01:00
|
|
|
|
description = ''
|
|
|
|
|
The name of the user account. If undefined, the name of the
|
|
|
|
|
attribute set will be used.
|
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
description = mkOption {
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2011-11-29 06:08:55 +00:00
|
|
|
|
default = "";
|
2013-10-31 07:41:51 +00:00
|
|
|
|
example = "Alice Q. User";
|
|
|
|
|
description = ''
|
|
|
|
|
A short description of the user account, typically the
|
|
|
|
|
user's full name. This is actually the “GECOS” or “comment”
|
|
|
|
|
field in <filename>/etc/passwd</filename>.
|
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
uid = mkOption {
|
2014-04-06 11:39:51 +01:00
|
|
|
|
type = with types; nullOr int;
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
2014-08-15 00:33:20 +01:00
|
|
|
|
The account UID. If the UID is null, a free UID is picked on
|
|
|
|
|
activation.
|
2014-04-06 11:39:51 +01:00
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2014-04-29 09:43:38 +01:00
|
|
|
|
isSystemUser = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Indicates if the user is a system user or not. This option
|
2014-08-15 00:33:20 +01:00
|
|
|
|
only has an effect if <option>uid</option> is
|
2014-04-29 09:43:38 +01:00
|
|
|
|
<option>null</option>, in which case it determines whether
|
|
|
|
|
the user's UID is allocated in the range for system users
|
|
|
|
|
(below 500) or in the range for normal users (starting at
|
|
|
|
|
1000).
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-15 01:07:43 +01:00
|
|
|
|
isNormalUser = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Indicates whether this is an account for a “real” user. This
|
|
|
|
|
automatically sets <option>group</option> to
|
|
|
|
|
<literal>users</literal>, <option>createHome</option> to
|
|
|
|
|
<literal>true</literal>, <option>home</option> to
|
|
|
|
|
<filename>/home/<replaceable>username</replaceable></filename>,
|
|
|
|
|
<option>useDefaultShell</option> to <literal>true</literal>,
|
|
|
|
|
and <option>isSystemUser</option> to
|
|
|
|
|
<literal>false</literal>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
group = mkOption {
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2011-11-29 06:08:55 +00:00
|
|
|
|
default = "nogroup";
|
|
|
|
|
description = "The user's primary group.";
|
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
extraGroups = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = types.listOf types.str;
|
2011-11-29 06:08:55 +00:00
|
|
|
|
default = [];
|
|
|
|
|
description = "The user's auxiliary groups.";
|
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
home = mkOption {
|
2016-06-12 20:03:14 +01:00
|
|
|
|
type = types.path;
|
2011-11-29 06:08:55 +00:00
|
|
|
|
default = "/var/empty";
|
|
|
|
|
description = "The user's home directory.";
|
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2015-07-02 15:46:56 +01:00
|
|
|
|
cryptHomeLuks = mkOption {
|
|
|
|
|
type = with types; nullOr str;
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
|
|
|
|
Path to encrypted luks device that contains
|
|
|
|
|
the user's home directory.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
shell = mkOption {
|
2016-06-12 20:03:14 +01:00
|
|
|
|
type = types.either types.shellPackage types.path;
|
|
|
|
|
default = pkgs.nologin;
|
|
|
|
|
defaultText = "pkgs.nologin";
|
|
|
|
|
example = literalExample "pkgs.bashInteractive";
|
2016-03-08 17:02:15 +00:00
|
|
|
|
description = ''
|
|
|
|
|
The path to the user's shell. Can use shell derivations,
|
|
|
|
|
like <literal>pkgs.bashInteractive</literal>. Don’t
|
|
|
|
|
forget to enable your shell in
|
|
|
|
|
<literal>programs</literal> if necessary,
|
|
|
|
|
like <code>programs.zsh.enable = true;</code>.
|
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2014-06-26 01:11:28 +01:00
|
|
|
|
subUidRanges = mkOption {
|
2016-09-11 08:35:50 +01:00
|
|
|
|
type = with types; listOf (submodule subordinateUidRange);
|
2014-06-26 01:11:28 +01:00
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
|
|
|
|
{ startUid = 1000; count = 1; }
|
|
|
|
|
{ startUid = 100001; count = 65534; }
|
|
|
|
|
];
|
|
|
|
|
description = ''
|
|
|
|
|
Subordinate user ids that user is allowed to use.
|
|
|
|
|
They are set into <filename>/etc/subuid</filename> and are used
|
|
|
|
|
by <literal>newuidmap</literal> for user namespaces.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
subGidRanges = mkOption {
|
2016-09-11 08:35:50 +01:00
|
|
|
|
type = with types; listOf (submodule subordinateGidRange);
|
2014-06-26 01:11:28 +01:00
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
|
|
|
|
{ startGid = 100; count = 1; }
|
|
|
|
|
{ startGid = 1001; count = 999; }
|
|
|
|
|
];
|
|
|
|
|
description = ''
|
|
|
|
|
Subordinate group ids that user is allowed to use.
|
|
|
|
|
They are set into <filename>/etc/subgid</filename> and are used
|
|
|
|
|
by <literal>newgidmap</literal> for user namespaces.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
createHome = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
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 16:08:32 +01:00
|
|
|
|
description = ''
|
|
|
|
|
If true, the home directory will be created automatically. If this
|
|
|
|
|
option is true and the home directory already exists but is not
|
|
|
|
|
owned by the user, directory owner and group will be changed to
|
|
|
|
|
match the user.
|
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
useDefaultShell = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
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 16:08:32 +01:00
|
|
|
|
description = ''
|
|
|
|
|
If true, the user's shell will be set to
|
2014-11-03 10:59:38 +00:00
|
|
|
|
<option>users.defaultUserShell</option>.
|
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 16:08:32 +01:00
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2014-02-05 14:07:20 +00:00
|
|
|
|
hashedPassword = mkOption {
|
|
|
|
|
type = with types; uniq (nullOr str);
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
2014-11-03 10:59:38 +00:00
|
|
|
|
Specifies the hashed password for the user.
|
2014-02-05 14:07:20 +00:00
|
|
|
|
${passwordDescription}
|
2015-01-02 16:32:33 +00:00
|
|
|
|
${hashedPasswordDescription}
|
2014-02-05 14:07:20 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
password = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = with types; uniq (nullOr str);
|
2011-11-29 06:08:55 +00:00
|
|
|
|
default = null;
|
2013-10-31 07:41:51 +00:00
|
|
|
|
description = ''
|
2014-02-05 14:07:20 +00: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 07:41:51 +00:00
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01: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 16:08:32 +01:00
|
|
|
|
passwordFile = mkOption {
|
|
|
|
|
type = with types; uniq (nullOr string);
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
2014-10-23 03:52:50 +01: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 16:08:32 +01:00
|
|
|
|
file is read on each system activation. The file should contain
|
|
|
|
|
exactly one line, which should be the password in an encrypted form
|
|
|
|
|
that is suitable for the <literal>chpasswd -e</literal> command.
|
2014-02-05 14:07:20 +00: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 16:08:32 +01:00
|
|
|
|
'';
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2014-11-03 10:59:38 +00:00
|
|
|
|
|
|
|
|
|
initialHashedPassword = mkOption {
|
|
|
|
|
type = with types; uniq (nullOr str);
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies the initial hashed password for the user, i.e. the
|
|
|
|
|
hashed password assigned if the user does not already
|
|
|
|
|
exist. If <option>users.mutableUsers</option> is true, the
|
|
|
|
|
password can be changed subsequently using the
|
|
|
|
|
<command>passwd</command> command. Otherwise, it's
|
2015-09-02 15:09:05 +01:00
|
|
|
|
equivalent to setting the <option>hashedPassword</option> option.
|
2015-01-02 16:32:33 +00:00
|
|
|
|
|
|
|
|
|
${hashedPasswordDescription}
|
2014-11-03 10:59:38 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
initialPassword = mkOption {
|
|
|
|
|
type = with types; uniq (nullOr str);
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies the initial password for the user, i.e. the
|
|
|
|
|
password assigned if the user does not already exist. If
|
|
|
|
|
<option>users.mutableUsers</option> is true, the password
|
|
|
|
|
can be changed subsequently using the
|
|
|
|
|
<command>passwd</command> command. Otherwise, it's
|
|
|
|
|
equivalent to setting the <option>password</option>
|
|
|
|
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-11 19:31:06 +01:00
|
|
|
|
packages = mkOption {
|
|
|
|
|
type = types.listOf types.package;
|
|
|
|
|
default = [];
|
|
|
|
|
example = literalExample "[ pkgs.firefox pkgs.thunderbird ]";
|
|
|
|
|
description = ''
|
|
|
|
|
The set of packages that should be made availabe to the user.
|
|
|
|
|
This is in contrast to <option>environment.systemPackages</option>,
|
|
|
|
|
which adds packages to all users.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2007-06-08 16:41:12 +01:00
|
|
|
|
|
2014-08-15 01:07:43 +01:00
|
|
|
|
config = mkMerge
|
|
|
|
|
[ { name = mkDefault name;
|
|
|
|
|
shell = mkIf config.useDefaultShell (mkDefault cfg.defaultUserShell);
|
|
|
|
|
}
|
|
|
|
|
(mkIf config.isNormalUser {
|
|
|
|
|
group = mkDefault "users";
|
|
|
|
|
createHome = mkDefault true;
|
|
|
|
|
home = mkDefault "/home/${name}";
|
|
|
|
|
useDefaultShell = mkDefault true;
|
|
|
|
|
isSystemUser = mkDefault false;
|
|
|
|
|
})
|
2014-11-03 11:19:25 +00: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;
|
|
|
|
|
})
|
2014-08-15 01:07:43 +01:00
|
|
|
|
];
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
2007-06-08 16:41:12 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
groupOpts = { name, config, ... }: {
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
options = {
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
name = mkOption {
|
2013-10-30 10:02:04 +00:00
|
|
|
|
type = types.str;
|
2014-04-06 11:39:51 +01:00
|
|
|
|
description = ''
|
|
|
|
|
The name of the group. If undefined, the name of the attribute set
|
|
|
|
|
will be used.
|
|
|
|
|
'';
|
2012-04-20 13:55:09 +01:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
gid = mkOption {
|
2014-04-06 11:39:51 +01:00
|
|
|
|
type = with types; nullOr int;
|
|
|
|
|
default = null;
|
|
|
|
|
description = ''
|
2014-08-15 00:33:20 +01:00
|
|
|
|
The group GID. If the GID is null, a free GID is picked on
|
|
|
|
|
activation.
|
2014-04-06 11:39:51 +01: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 16:08:32 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
members = mkOption {
|
|
|
|
|
type = with types; listOf string;
|
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
2014-02-05 14:24:05 +00:00
|
|
|
|
The user names of the group members, added to the
|
|
|
|
|
<literal>/etc/group</literal> 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 16:08:32 +01:00
|
|
|
|
'';
|
2012-04-20 13:55:09 +01:00
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
};
|
2007-06-08 16:41:12 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
config = {
|
|
|
|
|
name = mkDefault name;
|
|
|
|
|
};
|
2012-10-23 12:35:06 +01:00
|
|
|
|
|
2012-04-20 13:55:09 +01:00
|
|
|
|
};
|
2009-01-02 16:07:01 +00:00
|
|
|
|
|
2014-06-26 01:11:28 +01:00
|
|
|
|
subordinateUidRange = {
|
2016-09-11 08:35:50 +01:00
|
|
|
|
options = {
|
|
|
|
|
startUid = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
description = ''
|
|
|
|
|
Start of the range of subordinate user ids that user is
|
|
|
|
|
allowed to use.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
count = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 1;
|
|
|
|
|
description = ''Count of subordinate user ids'';
|
|
|
|
|
};
|
2014-06-26 01:11:28 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
subordinateGidRange = {
|
2016-09-11 08:35:50 +01:00
|
|
|
|
options = {
|
|
|
|
|
startGid = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
description = ''
|
|
|
|
|
Start of the range of subordinate group ids that user is
|
|
|
|
|
allowed to use.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
count = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 1;
|
|
|
|
|
description = ''Count of subordinate group ids'';
|
|
|
|
|
};
|
2014-06-26 01:11:28 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mkSubuidEntry = user: concatStrings (
|
|
|
|
|
map (range: "${user.name}:${toString range.startUid}:${toString range.count}\n")
|
2014-09-05 16:40:09 +01:00
|
|
|
|
user.subUidRanges);
|
2014-06-26 01:11:28 +01:00
|
|
|
|
|
2015-09-02 16:32:38 +01:00
|
|
|
|
subuidFile = concatStrings (map mkSubuidEntry (attrValues cfg.users));
|
2014-06-26 01:11:28 +01:00
|
|
|
|
|
|
|
|
|
mkSubgidEntry = user: concatStrings (
|
|
|
|
|
map (range: "${user.name}:${toString range.startGid}:${toString range.count}\n")
|
|
|
|
|
user.subGidRanges);
|
|
|
|
|
|
2015-09-02 16:32:38 +01:00
|
|
|
|
subgidFile = concatStrings (map mkSubgidEntry (attrValues cfg.users));
|
2014-06-26 01:11:28 +01:00
|
|
|
|
|
2014-02-07 14:57:28 +00:00
|
|
|
|
idsAreUnique = set: idAttr: !(fold (name: args@{ dup, acc }:
|
|
|
|
|
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 16:07:01 +00:00
|
|
|
|
|
2015-09-02 16:32:38 +01:00
|
|
|
|
uidsAreUnique = idsAreUnique (filterAttrs (n: u: u.uid != null) cfg.users) "uid";
|
|
|
|
|
gidsAreUnique = idsAreUnique (filterAttrs (n: g: g.gid != null) cfg.groups) "gid";
|
2014-04-06 11:39:51 +01:00
|
|
|
|
|
2014-09-10 10:49:32 +01:00
|
|
|
|
spec = pkgs.writeText "users-groups.json" (builtins.toJSON {
|
2014-08-15 00:33:20 +01:00
|
|
|
|
inherit (cfg) mutableUsers;
|
2016-06-12 20:03:14 +01:00
|
|
|
|
users = mapAttrsToList (_: u:
|
2014-08-15 00:33:20 +01:00
|
|
|
|
{ inherit (u)
|
2016-06-12 20:03:14 +01:00
|
|
|
|
name uid group description home createHome isSystemUser
|
2014-11-03 10:59:38 +00:00
|
|
|
|
password passwordFile hashedPassword
|
|
|
|
|
initialPassword initialHashedPassword;
|
2016-06-12 20:03:14 +01:00
|
|
|
|
shell = utils.toShellPath u.shell;
|
2015-09-02 16:32:38 +01:00
|
|
|
|
}) cfg.users;
|
2014-08-15 00:33:20 +01:00
|
|
|
|
groups = mapAttrsToList (n: g:
|
|
|
|
|
{ inherit (g) name gid;
|
2014-09-22 18:18:08 +01:00
|
|
|
|
members = g.members ++ (mapAttrsToList (n: u: u.name) (
|
2015-09-02 16:32:38 +01:00
|
|
|
|
filterAttrs (n: u: elem g.name u.extraGroups) cfg.users
|
2014-09-22 18:18:08 +01:00
|
|
|
|
));
|
2015-09-02 16:32:38 +01:00
|
|
|
|
}) cfg.groups;
|
2014-08-15 00:33:20 +01:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-12 20:03:14 +01:00
|
|
|
|
systemShells =
|
|
|
|
|
let
|
|
|
|
|
shells = mapAttrsToList (_: u: u.shell) cfg.users;
|
|
|
|
|
in
|
|
|
|
|
filter types.shellPackage.check shells;
|
|
|
|
|
|
2014-04-06 11:39:51 +01:00
|
|
|
|
in {
|
2009-01-02 16:07:01 +00:00
|
|
|
|
|
2009-09-02 18:35:24 +01:00
|
|
|
|
###### interface
|
2009-01-02 16:07:01 +00:00
|
|
|
|
|
2009-09-02 18:35:24 +01:00
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01: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 16:08:32 +01:00
|
|
|
|
users.mutableUsers = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
2015-01-02 16:32:33 +00:00
|
|
|
|
If set to <literal>true</literal>, you are free to add new users and groups to the system
|
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 16:08:32 +01:00
|
|
|
|
with the ordinary <literal>useradd</literal> and
|
|
|
|
|
<literal>groupadd</literal> commands. On system activation, the
|
|
|
|
|
existing contents of the <literal>/etc/passwd</literal> and
|
|
|
|
|
<literal>/etc/group</literal> files will be merged with the
|
2015-09-02 16:32:38 +01:00
|
|
|
|
contents generated from the <literal>users.users</literal> and
|
|
|
|
|
<literal>users.groups</literal> options.
|
2015-01-02 16:32:33 +00:00
|
|
|
|
The initial password for a user will be set
|
2015-09-02 16:32:38 +01:00
|
|
|
|
according to <literal>users.users</literal>, 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 16:08:32 +01:00
|
|
|
|
will not be changed.
|
2015-01-02 16:32:33 +00:00
|
|
|
|
|
2015-01-03 15:32:00 +00:00
|
|
|
|
<warning><para>
|
2015-01-02 16:32:33 +00:00
|
|
|
|
If set to <literal>false</literal>, the contents of the user and
|
|
|
|
|
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
|
2015-09-02 16:32:38 +01:00
|
|
|
|
<literal>users.users</literal> configuration on activation.
|
2015-01-03 15:32:00 +00:00
|
|
|
|
</para></warning>
|
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 16:08:32 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-07 14:57:28 +00:00
|
|
|
|
users.enforceIdUniqueness = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether to require that no two users/groups share the same uid/gid.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-02 16:32:38 +01:00
|
|
|
|
users.users = mkOption {
|
2011-11-29 06:08:55 +00:00
|
|
|
|
default = {};
|
2016-09-11 08:35:50 +01:00
|
|
|
|
type = with types; loaOf (submodule userOpts);
|
2011-11-29 06:08:55 +00:00
|
|
|
|
example = {
|
|
|
|
|
alice = {
|
|
|
|
|
uid = 1234;
|
2013-10-31 07:41:51 +00:00
|
|
|
|
description = "Alice Q. User";
|
2011-11-29 06:08:55 +00:00
|
|
|
|
home = "/home/alice";
|
|
|
|
|
createHome = true;
|
|
|
|
|
group = "users";
|
|
|
|
|
extraGroups = ["wheel"];
|
|
|
|
|
shell = "/bin/sh";
|
|
|
|
|
};
|
|
|
|
|
};
|
2009-09-02 18:35:24 +01:00
|
|
|
|
description = ''
|
|
|
|
|
Additional user accounts to be created automatically by the system.
|
2013-08-09 02:23:22 +01:00
|
|
|
|
This can also be used to set options for root.
|
2009-09-02 18:35:24 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2009-01-02 16:07:01 +00:00
|
|
|
|
|
2015-09-02 16:32:38 +01:00
|
|
|
|
users.groups = mkOption {
|
2012-04-20 13:55:09 +01:00
|
|
|
|
default = {};
|
2009-09-02 18:35:24 +01:00
|
|
|
|
example =
|
2012-04-20 13:55:09 +01:00
|
|
|
|
{ students.gid = 1001;
|
|
|
|
|
hackers = { };
|
|
|
|
|
};
|
2016-09-11 08:35:50 +01:00
|
|
|
|
type = with types; loaOf (submodule groupOpts);
|
2009-09-02 18:35:24 +01:00
|
|
|
|
description = ''
|
|
|
|
|
Additional groups to be created automatically by the system.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-03 11:30:54 +00:00
|
|
|
|
# FIXME: obsolete - will remove.
|
2014-02-05 14:07:20 +00:00
|
|
|
|
security.initialRootPassword = mkOption {
|
|
|
|
|
type = types.str;
|
2014-05-08 23:04:48 +01:00
|
|
|
|
default = "!";
|
|
|
|
|
example = "";
|
2014-11-03 11:30:54 +00:00
|
|
|
|
visible = false;
|
2014-02-05 14:07:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-09-02 18:35:24 +01:00
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2009-09-02 18:35:24 +01:00
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
2015-09-02 16:32:38 +01:00
|
|
|
|
users.users = {
|
2011-11-29 06:08:55 +00: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 16:08:32 +01:00
|
|
|
|
uid = ids.uids.root;
|
2011-11-29 06:08:55 +00:00
|
|
|
|
description = "System administrator";
|
|
|
|
|
home = "/root";
|
2014-08-20 20:17:48 +01:00
|
|
|
|
shell = mkDefault cfg.defaultUserShell;
|
2011-11-29 06:08:55 +00:00
|
|
|
|
group = "root";
|
2014-11-03 11:30:54 +00:00
|
|
|
|
initialHashedPassword = mkDefault config.security.initialRootPassword;
|
2011-11-29 06:08:55 +00: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 16:08:32 +01:00
|
|
|
|
uid = ids.uids.nobody;
|
2011-11-29 06:08:55 +00: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 16:08:32 +01:00
|
|
|
|
group = "nogroup";
|
2011-11-29 06:08:55 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-12 20:03:14 +01:00
|
|
|
|
# Install all the user shells
|
|
|
|
|
environment.systemPackages = systemShells;
|
|
|
|
|
|
2015-09-02 16:32:38 +01: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 16:08:32 +01: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 19:23:32 +00:00
|
|
|
|
input.gid = ids.gids.input;
|
2012-04-20 13:55:09 +01:00
|
|
|
|
};
|
|
|
|
|
|
2014-08-15 00:33:20 +01:00
|
|
|
|
system.activationScripts.users = stringAfter [ "etc" ]
|
|
|
|
|
''
|
|
|
|
|
${pkgs.perl}/bin/perl -w \
|
|
|
|
|
-I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl \
|
|
|
|
|
-I${pkgs.perlPackages.JSON}/lib/perl5/site_perl \
|
|
|
|
|
${./update-users-groups.pl} ${spec}
|
2010-09-13 16:41:38 +01:00
|
|
|
|
'';
|
2009-01-02 16:07:01 +00: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 16:08:32 +01:00
|
|
|
|
# for backwards compatibility
|
|
|
|
|
system.activationScripts.groups = stringAfter [ "users" ] "";
|
2007-06-08 16:41:12 +01:00
|
|
|
|
|
2014-06-26 01:11:28 +01:00
|
|
|
|
environment.etc."subuid" = {
|
|
|
|
|
text = subuidFile;
|
|
|
|
|
mode = "0644";
|
|
|
|
|
};
|
|
|
|
|
environment.etc."subgid" = {
|
|
|
|
|
text = subgidFile;
|
|
|
|
|
mode = "0644";
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-06 11:39:51 +01:00
|
|
|
|
assertions = [
|
|
|
|
|
{ assertion = !cfg.enforceIdUniqueness || (uidsAreUnique && gidsAreUnique);
|
2014-08-15 00:33:20 +01:00
|
|
|
|
message = "UIDs and GIDs must be unique!";
|
2014-04-06 11:39:51 +01:00
|
|
|
|
}
|
2015-09-02 15:09:05 +01: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.
|
|
|
|
|
assertion = !cfg.mutableUsers ->
|
|
|
|
|
any id (mapAttrsToList (name: cfg:
|
|
|
|
|
(name == "root"
|
|
|
|
|
|| cfg.group == "wheel"
|
|
|
|
|
|| elem "wheel" cfg.extraGroups)
|
|
|
|
|
&&
|
|
|
|
|
((cfg.hashedPassword != null && cfg.hashedPassword != "!")
|
|
|
|
|
|| cfg.password != null
|
|
|
|
|
|| cfg.passwordFile != null
|
|
|
|
|
|| cfg.openssh.authorizedKeys.keys != []
|
|
|
|
|
|| cfg.openssh.authorizedKeys.keyFiles != [])
|
2015-09-02 16:32:38 +01:00
|
|
|
|
) cfg.users);
|
2015-09-02 15:09:05 +01:00
|
|
|
|
message = ''
|
|
|
|
|
Neither the root account nor any wheel user has a password or SSH authorized key.
|
|
|
|
|
You must set one to prevent being locked out of your system.'';
|
|
|
|
|
}
|
2014-04-06 11:39:51 +01:00
|
|
|
|
];
|
2014-02-07 14:57:28 +00:00
|
|
|
|
|
2009-01-02 16:07:01 +00:00
|
|
|
|
};
|
2009-09-02 18:35:24 +01:00
|
|
|
|
|
2015-10-14 17:05:50 +01:00
|
|
|
|
imports =
|
|
|
|
|
[ (mkAliasOptionModule [ "users" "extraUsers" ] [ "users" "users" ])
|
|
|
|
|
(mkAliasOptionModule [ "users" "extraGroups" ] [ "users" "groups" ])
|
2017-05-11 19:31:06 +01:00
|
|
|
|
{
|
|
|
|
|
environment = {
|
|
|
|
|
etc = mapAttrs' (name: { packages, ... }: {
|
|
|
|
|
name = "per-user-pkgs/${name}";
|
|
|
|
|
value.source = pkgs.symlinkJoin {
|
|
|
|
|
name = "per-user-pkgs.${name}";
|
|
|
|
|
paths = packages;
|
|
|
|
|
};
|
|
|
|
|
}) (filterAttrs (_: { packages, ... }: packages != []) cfg.users);
|
|
|
|
|
profiles = ["/etc/per-user-pkgs/$LOGNAME"];
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-10-14 17:05:50 +01:00
|
|
|
|
];
|
2007-11-09 18:49:45 +00:00
|
|
|
|
}
|