Add declarative ssh known hosts

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-02-25 12:28:22 +00:00
parent f843deafbe
commit a3dc4129d6
22 changed files with 258 additions and 79 deletions

View File

@@ -1,6 +1,5 @@
{ pkgs, ... }:
{
lib = {
runtime = import ./runtime { inherit pkgs; };
};
fetchers = import ./fetchers { inherit pkgs; };
runtime = import ./runtime { inherit pkgs; };
}

4
lib/fetchers/default.nix Normal file
View File

@@ -0,0 +1,4 @@
{ pkgs, ... }:
{
sshKnownHosts = import ./sshKnownHosts { inherit pkgs; };
}

View File

@@ -0,0 +1,33 @@
{ pkgs, ... }:
pkgs.lib.fetchers.withNormalizedHash { } (
{
host,
name ? "ssh-known-hosts-${host}",
outputHash,
outputHashAlgo,
port ? 22,
keyTypes ? [
"rsa"
"ecdsa"
"ed25519"
],
}:
let
keyTypeArgs = pkgs.lib.concatStringsSep "," keyTypes;
in
pkgs.runCommand name
{
inherit outputHash outputHashAlgo;
outputHashMode = "flat";
preferLocalBuild = true;
nativeBuildInputs = with pkgs; [
openssh
gnugrep
coreutils
];
}
''
ssh-keyscan -p ${toString port} -t ${keyTypeArgs} ${host} | grep -v '^#' | sort > $out
''
)

View File

@@ -148,8 +148,6 @@ cat <<EOF > "./hosts/$host/default.nix"
{ inputs, ... }:
{
imports = [
../../lib
inputs.disko.nixosModules.disko
./format.nix