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; port = 10471;
user = "root"; user = "root";
}; };
gay = {
hostName = "git.gay";
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHqUMVlwisg8oXuJaYp49Og8hljAgHsccxiDuxIYQ+2q";
};
}; };
}; };
}; };

View file

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