Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/systemd-sysusers: make uid/gid allocation stable #297250

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions nixos/modules/system/boot/systemd/sysusers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let
${lib.concatLines (lib.mapAttrsToList
(username: opts:
let
uid = if opts.uid == null then "-" else toString opts.uid;
uid = if opts.uid == null then "/var/lib/nixos/uid/${username}" else toString opts.uid;
in
''u ${username} ${uid}:${opts.group} "${opts.description}" ${opts.home} ${utils.toShellPath opts.shell}''
)
Expand All @@ -21,7 +21,7 @@ let

# Groups
${lib.concatLines (lib.mapAttrsToList
(groupname: opts: ''g ${groupname} ${if opts.gid == null then "-" else toString opts.gid}'') userCfg.groups)
(groupname: opts: ''g ${groupname} ${if opts.gid == null then "/var/lib/nixos/gid/${groupname}" else toString opts.gid}'') userCfg.groups)
}

# Group membership
Expand Down Expand Up @@ -106,6 +106,23 @@ in
};
})
(lib.filterAttrs (_username: opts: opts.home != "/var/empty") userCfg.users);

# Create uid/gid marker files for those without an explicit id
tmpfiles.settings.nixos-uid = lib.mapAttrs'
(username: opts: lib.nameValuePair "/var/lib/nixos/uid/${username}" {
f = {
user = username;
};
})
(lib.filterAttrs (_username: opts: opts.uid == null) userCfg.users);

tmpfiles.settings.nixos-gid = lib.mapAttrs'
(groupname: opts: lib.nameValuePair "/var/lib/nixos/gid/${groupname}" {
f = {
group = groupname;
};
})
(lib.filterAttrs (_groupname: opts: opts.gid == null) userCfg.groups);
})

(lib.mkIf config.users.mutableUsers {
Expand Down