user-password: migrate to vars

This commit is contained in:
Jörg Thalheim
2025-04-08 08:45:51 +02:00
parent 9a34977842
commit 76c7858d3f
3 changed files with 14 additions and 43 deletions

View File

@@ -25,27 +25,25 @@ in
config = {
users.mutableUsers = false;
users.users.${cfg.user} = {
hashedPasswordFile = config.clan.core.facts.services.user-password.secret.user-password-hash.path;
hashedPasswordFile = config.clan.core.vars.generators.user-password.files.user-password-hash.path;
isNormalUser = lib.mkDefault true;
};
sops.secrets = lib.mkIf (config.clan.core.facts.secretStore == "sops") {
"${config.clan.core.settings.machine.name}-user-password-hash".neededForUsers = true;
};
clan.core.vars.generators.user-password = {
files.user-password-hash.neededFor = "users";
clan.core.facts.services.user-password = {
secret.user-password = { };
secret.user-password-hash = { };
generator.prompt = (
lib.mkIf config.clan.user-password.prompt "Set the password for your user '${config.clan.user-password.user}'.
You can autogenerate a password, if you leave this prompt blank."
);
generator.path = with pkgs; [
coreutils
xkcdpass
mkpasswd
prompts.user-password.type = "hidden";
prompts.user-password.persist = true;
prompts.user-password.description = "You can autogenerate a password, if you leave this prompt blank.";
files.user-password.deploy = false;
migrateFact = "user-password";
runtimeInputs = [
pkgs.coreutils
pkgs.xkcdpass
pkgs.mkpasswd
];
generator.script = ''
script = ''
if [[ -n ''${prompt_value-} ]]; then
echo $prompt_value | tr -d "\n" > $secrets/user-password
else