improve ssh module using optionalString

This commit is contained in:
jacekpoz 2024-10-18 21:16:03 +02:00
parent a182bb4a2d
commit 021401540d
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 9 additions and 11 deletions

View file

@ -68,6 +68,10 @@ _: {
port = 10471;
user = "root";
};
gay = {
hostName = "git.gay";
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHqUMVlwisg8oXuJaYp49Og8hljAgHsccxiDuxIYQ+2q";
};
};
};
};

View file

@ -10,7 +10,7 @@
inherit (lib.modules) mkIf mkMerge;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) attrsOf bool listOf nullOr number port str submodule;
inherit (lib.strings) concatStrings;
inherit (lib.strings) concatStrings optionalString;
inherit (lib.attrsets) mapAttrsToList;
ksshaskpass = getExe' pkgs.libsForQt5.ksshaskpass "ksshaskpass";
@ -98,16 +98,10 @@ in {
Host ${name}
HostName ${value.hostName}
User ${value.user}
${
if value.port != null then
"Port ${toString value.port}"
else ""
}
${
if value.publicKey != null then
"IdentityFile ${pkgs.writeText "${name}.pub" value.publicKey}"
else ""
}
${optionalString (value.port != null)
"Port ${toString value.port}"}
${optionalString (value.publicKey != null)
"IdentityFile ${pkgs.writeText "${name}.pub" value.publicKey}"}
'') cfg.agent.hostAliases)}
'';
};