From ea00f991c09c2e77781cbe1e9d72ee1bd632774b Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 6 Aug 2021 01:20:09 +0200 Subject: [PATCH] nixos/users: Populate group members option This change makes it so that accessing config.users.groups.*.members isn't empty by default, but instead contains all the users whose `extraGroups` includes that group, allowing fancy things like { config, ... }: { users.groups.libvirt.members = config.users.groups.wheel.members; } to add all users in the wheel group to the libvirt group --- nixos/modules/config/users-groups.nix | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index d5e7745c53f9..f86be3be2c65 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -324,7 +324,7 @@ let }; - groupOpts = { name, ... }: { + groupOpts = { name, config, ... }: { options = { @@ -358,6 +358,10 @@ let config = { name = mkDefault name; + + members = mapAttrsToList (n: u: u.name) ( + filterAttrs (n: u: elem config.name u.extraGroups) cfg.users + ); }; }; @@ -419,12 +423,7 @@ let initialPassword initialHashedPassword; shell = utils.toShellPath u.shell; }) cfg.users; - groups = mapAttrsToList (n: g: - { inherit (g) name gid; - members = g.members ++ (mapAttrsToList (n: u: u.name) ( - filterAttrs (n: u: elem g.name u.extraGroups) cfg.users - )); - }) cfg.groups; + groups = attrValues cfg.groups; }); systemShells =