feat(users): use forAllUsers' in nixos module

This commit is contained in:
Mohammad Rafiq 2025-07-07 08:51:38 +08:00
parent 07413c4ac0
commit a3ed4c608d
No known key found for this signature in database

View file

@ -1,35 +1,37 @@
{ config, lib, ... }: { config, lib, ... }:
let let
cfg = config.flake; cfg = config.flake;
inherit (config.flake.lib) forAllUsers' flattenAttrs; inherit (cfg.lib) forAllUsers';
inherit (lib.attrsets) filterAttrs; inherit (lib.lists) optional;
owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) cfg.manifest.users);
in in
{ {
flake.modules.nixos.default = flake.modules.nixos.default =
{ pkgs, config, ... }: { pkgs, config, ... }:
{ {
#TODO: move sudo/security options elsewhere #TODO: move sudo/security options elsewhere
security.sudo.wheelNeedsPassword = false; # security.sudo.wheelNeedsPassword = false;
nix.settings.trusted-users = [ "@wheel" ]; # nix.settings.trusted-users = [ "@wheel" ];
#TODO: move to shell config #TODO: move to shell config
programs.${owner.shell}.enable = true; # programs.${owner.shell}.enable = true;
#TODO: move ssh key settings elsewhere #TODO: move ssh key settings elsewhere
# users.users.root.openssh.authorizedKeys.keys = [ owner.pubkey ];
users = { users = {
mutableUsers = false; mutableUsers = false;
groups.users.gid = 100; groups.users.gid = 100;
users.root.openssh.authorizedKeys.keys = [ owner.pubkey ]; users = forAllUsers' (
users.${owner.username} = { _: value: {
isNormalUser = true; isNormalUser = true;
# hashedPasswordFile extraGroups = optional (value.primary or false) "wheel";
extraGroups = [ "wheel" ]; # FIXME: remove when we make the shell module
shell = pkgs.${owner.shell}; ignoreShellProgramCheck = true;
openssh.authorizedKeys.keys = [ owner.pubkey ]; shell = pkgs.${value.shell};
}; openssh.authorizedKeys.keys = [ value.pubkey ];
}
);
}; };
home-manager.users = forAllUsers' ( home-manager.users = forAllUsers' (
name: _: { name: _: {
#TODO: move into nixos/darwin config - should not apply to homeConfigurations
home.username = name; home.username = name;
home.homeDirectory = config.users.users.${name}.home; home.homeDirectory = config.users.users.${name}.home;
} }