Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-08-17 12:24:38 +03:00
parent c122daa872
commit afc80d8f42
11 changed files with 182 additions and 1 deletions

5
lib/default.nix Normal file
View File

@@ -0,0 +1,5 @@
{ 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.runCommandLocal 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
''
)

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

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

View File

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

View File

@@ -0,0 +1,11 @@
{ pkgs, ... }:
"${
pkgs.writeShellApplication {
name = "merge-key-value";
runtimeInputs = with pkgs; [
coreutils
gawk
];
text = builtins.readFile ./key-value.sh;
}
}/bin/merge-key-value"

View File

@@ -0,0 +1,15 @@
# shellcheck shell=bash
source=$(realpath -m "$1")
target=$(realpath -m "$2")
if [[ -f "$target" ]]; then
temp=$(mktemp)
awk -F '=' 'NR==FNR{a[$1]=$0;next}($1 in a){$0=a[$1]}1' "$source" "$target" > "$temp"
mv "$temp" "$target"
else
mkdir -p "$(dirname "$target")"
cp "$source" "$target"
fi
echo "Configuration file $target has been updated."