feat(nixos): add user password secrets to sops

This commit adds the user password secrets to sops.
It leverages the `userListToAttrs` lib function.
This commit is contained in:
Mohammad Rafiq 2025-07-07 17:26:57 +08:00
parent f53a6c6c99
commit 033755b4bb
No known key found for this signature in database
2 changed files with 24 additions and 2 deletions

View file

@ -1,7 +1,7 @@
{ config, lib, ... }:
let
cfg = config.flake;
inherit (cfg.lib.modules) forAllUsers';
inherit (cfg.lib.modules) userListToAttrs forAllUsers';
inherit (lib.lists) optional;
in
{
@ -19,13 +19,17 @@ in
mutableUsers = false;
groups.users.gid = 100;
users = forAllUsers' (
_: value: {
name: value: {
isNormalUser = true;
hashedPasswordFile = config.sops.secrets."${name}/hashedPassword".path;
extraGroups = optional (value.primary or false) "wheel";
openssh.authorizedKeys.keys = [ value.pubkey ];
}
);
};
sops.secrets = userListToAttrs (name: {
"${name}/hashedPassword".neededForUsers = true;
});
home-manager.users = forAllUsers' (
name: _: {
home.username = name;