Vars: migrate root-password from facts

This commit is contained in:
Johannes Kirschbauer
2025-01-09 09:16:57 +01:00
parent a240bbcf04
commit 4e9901ab19

View File

@@ -1,29 +1,35 @@
{ {
pkgs, pkgs,
config, config,
lib,
... ...
}: }:
{ {
users.mutableUsers = false; users.mutableUsers = false;
users.users.root.hashedPasswordFile = users.users.root.hashedPasswordFile =
config.clan.core.facts.services.root-password.secret.password-hash.path; config.clan.core.vars.generators.root-password.files.password-hash.path;
sops.secrets = lib.mkIf (config.clan.core.facts.secretStore == "sops") { clan.core.vars.generators.root-password = {
"${config.clan.core.settings.machine.name}-password-hash".neededForUsers = true; files.password-hash = {
neededFor = "users";
}; };
migrateFact = "root-password";
clan.core.facts.services.root-password = { runtimeInputs = [
secret.password = { }; pkgs.coreutils
secret.password-hash = { }; pkgs.mkpasswd
generator.path = with pkgs; [ pkgs.xkcdpass
coreutils
xkcdpass
mkpasswd
]; ];
generator.script = '' prompts.password.createFile = true;
xkcdpass --numwords 3 --delimiter - --count 1 | tr -d "\n" > $secrets/password prompts.password.type = "hidden";
cat $secrets/password | mkpasswd -s -m sha-512 | tr -d "\n" > $secrets/password-hash prompts.password.description = "You can autogenerate a password, if you leave this prompt blank.";
script = ''
prompt_value=$(cat $prompts/password)
if [[ -n ''${prompt_value-} ]]; then
echo $prompt_value | tr -d "\n" > $out/password
else
xkcdpass --numwords 3 --delimiter - --count 1 | tr -d "\n" > $out/password
fi
cat $out/password | mkpasswd -s -m sha-512 | tr -d "\n" > $out/password-hash
''; '';
}; };
} }