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:
parent
782a4324a8
commit
4ff7b8e18f
5 changed files with 42 additions and 15 deletions
|
@ -61,7 +61,7 @@
|
||||||
(inputs.import-tree ./nix)
|
(inputs.import-tree ./nix)
|
||||||
// {
|
// {
|
||||||
systems = import inputs.systems;
|
systems = import inputs.systems;
|
||||||
flake.root = ./.;
|
flake.paths.root = ./.;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,17 +18,22 @@ in
|
||||||
type = lazyAttrsOf raw;
|
type = lazyAttrsOf raw;
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
root = mkOption {
|
paths = {
|
||||||
type = path;
|
root = mkOption { type = path; };
|
||||||
default = "";
|
secrets = mkOption {
|
||||||
|
type = path;
|
||||||
|
readOnly = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
admin = mkOption {
|
admin = mkOption {
|
||||||
type = lazyAttrsOf raw;
|
type = lazyAttrsOf raw;
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
config.flake = {
|
||||||
config.flake.admin = cfg.manifest.users.${username} // {
|
paths.secrets = cfg.paths.root + "/secrets";
|
||||||
inherit username;
|
admin = cfg.manifest.users.${username} // {
|
||||||
|
inherit username;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,9 @@ in
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||||
config.sops = {
|
config.sops.age.sshKeyPaths = [
|
||||||
defaultSopsFile = "${cfg.root}/secrets/secrets.yaml";
|
"/persist${config.users.defaultUserHome}/${username}/.ssh/id_ed25519"
|
||||||
age.sshKeyPaths = [
|
];
|
||||||
"/persist${config.users.defaultUserHome}/${username}/.ssh/id_ed25519"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.flake;
|
cfg = config.flake;
|
||||||
inherit (cfg.lib.modules) forAllUsers';
|
inherit (cfg.lib.modules) userListToAttrs forAllUsers';
|
||||||
inherit (lib.lists) optional;
|
inherit (lib.lists) optional;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -19,13 +19,20 @@ in
|
||||||
mutableUsers = false;
|
mutableUsers = false;
|
||||||
groups.users.gid = 100;
|
groups.users.gid = 100;
|
||||||
users = forAllUsers' (
|
users = forAllUsers' (
|
||||||
_: value: {
|
name: value: {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
|
hashedPasswordFile = config.sops.secrets."${name}/hashedPassword".path;
|
||||||
extraGroups = optional (value.primary or false) "wheel";
|
extraGroups = optional (value.primary or false) "wheel";
|
||||||
openssh.authorizedKeys.keys = [ value.pubkey ];
|
openssh.authorizedKeys.keys = [ value.pubkey ];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
sops.secrets = userListToAttrs (name: {
|
||||||
|
"${name}/hashedPassword" = {
|
||||||
|
neededForUsers = true;
|
||||||
|
sopsFile = cfg.paths.secrets + "/users.yaml";
|
||||||
|
};
|
||||||
|
});
|
||||||
home-manager.users = forAllUsers' (
|
home-manager.users = forAllUsers' (
|
||||||
name: _: {
|
name: _: {
|
||||||
home.username = name;
|
home.username = name;
|
||||||
|
|
18
secrets/users.yaml
Normal file
18
secrets/users.yaml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
rafiq:
|
||||||
|
password: ENC[AES256_GCM,data:8KAfatz+YSaNozd5VGo=,iv:LNRxt47iBKSWzMZuBHSxv/qDZ2h6JiTIPps7OK/o7uU=,tag:oiSfLyRVswb/wxSTE69QMA==,type:str]
|
||||||
|
hashedPassword: ENC[AES256_GCM,data:NogYQ3kR1TseC79HIXARrXhIncCnvxzf9zMF2QrUyTmojTffPXRGtMdjNpfMEFj5dkKfZujBL/QTIpPFFTm1py7Dreg5/9VSKQ==,iv:IwfZsrsJbLYG1ELte6aBHUtff6hIQu9rHT5tSvILIGQ=,tag:oav3paDcUY+cl4FJlZa90A==,type:str]
|
||||||
|
sops:
|
||||||
|
age:
|
||||||
|
- recipient: age12l33pas8eptwjc7ewux3d8snyzfzwz0tn9qg5kw8le79fswmjgjqdjgyy6
|
||||||
|
enc: |
|
||||||
|
-----BEGIN AGE ENCRYPTED FILE-----
|
||||||
|
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBVd09tYkhKUkVjNTBRdld6
|
||||||
|
a1RkUnZqdnRqMlFTSGgwUFVCZlRhL0tLTnpVCjNXVjZldzNUOE9DQ0ZGejhWakY2
|
||||||
|
TmRIZnpobE0ydDhNSDdJQUp2U3pSTzgKLS0tIDkxU3Fxa2lMUkhZY0g1Wm02T2ZE
|
||||||
|
UkQwOWZtVXVPSGJiRk1qRHVHYkN2cDgKLiYiA0q5se/oHfGRqvHLn3gRRDfmefEZ
|
||||||
|
z2U2N1Tjt0QgCfYOOXVfPV9F36a7PpabFva5ElSazawHgvI+Bot6og==
|
||||||
|
-----END AGE ENCRYPTED FILE-----
|
||||||
|
lastmodified: "2025-07-07T08:56:26Z"
|
||||||
|
mac: ENC[AES256_GCM,data:2uGjIMxRgk7uWToQC4MrHpHFAt4bI7sEhaHvPU6Ae3bvRVH/TdJxZtikSPe95LEwReOuBmPajbcM580/d3Jt6VbA7nZzj1JduVscrRkSAFCzZp9Ti/mbOGITPJa6xWSGwVF1wSN3BnHXYIHDcKeSGtUdP7L7nBZr1KXPkok4NCo=,iv:+ELIes7lzb8M6CvOemAcyoq7Rx7L6NkNmHwntJN/RSc=,tag:ubyxO6VllH9cQK3VbvxiGg==,type:str]
|
||||||
|
unencrypted_suffix: _unencrypted
|
||||||
|
version: 3.10.2
|
Loading…
Add table
Add a link
Reference in a new issue