enable host key generation on first boot

This commit is contained in:
Florian Agbuya 2024-01-15 15:06:35 +08:00
parent dad71891b6
commit bd4885c597
2 changed files with 136 additions and 0 deletions

View File

@ -17,6 +17,7 @@
./network.patch ./network.patch
./pr-28.patch ./pr-28.patch
./pr-29.patch ./pr-29.patch
./pr-30.patch
]; ];
}; };

135
pr-30.patch Normal file
View File

@ -0,0 +1,135 @@
diff --git a/base.nix b/base.nix
index 7eaee32..622cbf1 100644
--- a/base.nix
+++ b/base.nix
@@ -120,10 +120,6 @@ with lib;
root:x:0:
nixbld:x:30000:nixbld1,nixbld10,nixbld2,nixbld3,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9
'';
- "ssh/ssh_host_rsa_key.pub".source = ./ssh/ssh_host_rsa_key.pub;
- "ssh/ssh_host_rsa_key" = { mode = "0600"; source = ./ssh/ssh_host_rsa_key; };
- "ssh/ssh_host_ed25519_key.pub".source = ./ssh/ssh_host_ed25519_key.pub;
- "ssh/ssh_host_ed25519_key" = { mode = "0600"; source = ./ssh/ssh_host_ed25519_key; };
};
boot.kernelParams = [ "systemConfig=${config.system.build.toplevel}" ];
boot.kernelPackages = lib.mkDefault (if pkgs.system == "armv7l-linux" then pkgs.linuxPackages_rpi1 else pkgs.linuxPackages);
diff --git a/gen_keys b/gen_keys
deleted file mode 100755
index ee586a2..0000000
--- a/gen_keys
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-mkdir ssh
-ssh-keygen -t rsa -b 4096 -f ssh/ssh_host_rsa_key -N ""
-ssh-keygen -t ed25519 -f ssh/ssh_host_ed25519_key -N ""
diff --git a/runit.nix b/runit.nix
index d7b0bf3..6d602b6 100644
--- a/runit.nix
+++ b/runit.nix
@@ -2,7 +2,6 @@
let
sshd_config = pkgs.writeText "sshd_config" ''
- HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
Port 22
PidFile /run/sshd.pid
@@ -30,6 +29,13 @@ in
{
"runit/1".source = pkgs.writeScript "1" ''
#!${pkgs.runtimeShell}
+
+ ED25519_KEY="/etc/ssh/ssh_host_ed25519_key"
+
+ if [ ! -f $ED25519_KEY ]; then
+ ${pkgs.openssh}/bin/ssh-keygen -t ed25519 -f $ED25519_KEY -N ""
+ fi
+
${lib.optionalString config.not-os.simpleStaticIp ''
ip addr add 10.0.2.15 dev eth0
ip link set eth0 up
diff --git a/ssh/ssh_host_ed25519_key b/ssh/ssh_host_ed25519_key
deleted file mode 100644
index 62f3b04..0000000
--- a/ssh/ssh_host_ed25519_key
+++ /dev/null
@@ -1,7 +0,0 @@
------BEGIN OPENSSH PRIVATE KEY-----
-b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
-QyNTUxOQAAACCyu5b2+49W47G9KYQj+7xz1YuY3w3Iz1kb/eIgNWPF7wAAAJhmBZVCZgWV
-QgAAAAtzc2gtZWQyNTUxOQAAACCyu5b2+49W47G9KYQj+7xz1YuY3w3Iz1kb/eIgNWPF7w
-AAAEBALOVU4aPZln0n7z7AR5jOoVnT7OhWAJiROqTw9ecEILK7lvb7j1bjsb0phCP7vHPV
-i5jfDcjPWRv94iA1Y8XvAAAAEGNsZXZlckBhbWQtbml4b3MBAgMEBQ==
------END OPENSSH PRIVATE KEY-----
diff --git a/ssh/ssh_host_ed25519_key.pub b/ssh/ssh_host_ed25519_key.pub
deleted file mode 100644
index c636ae4..0000000
--- a/ssh/ssh_host_ed25519_key.pub
+++ /dev/null
@@ -1 +0,0 @@
-ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILK7lvb7j1bjsb0phCP7vHPVi5jfDcjPWRv94iA1Y8Xv clever@amd-nixos
diff --git a/ssh/ssh_host_rsa_key b/ssh/ssh_host_rsa_key
deleted file mode 100644
index d9c3b46..0000000
--- a/ssh/ssh_host_rsa_key
+++ /dev/null
@@ -1,51 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIJKAIBAAK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XISkf84gM4=
------END RSA PRIVATE KEY-----
diff --git a/ssh/ssh_host_rsa_key.pub b/ssh/ssh_host_rsa_key.pub
deleted file mode 100644
index 63dbd02..0000000
--- a/ssh/ssh_host_rsa_key.pub
+++ /dev/null
@@ -1 +0,0 @@
-ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDFMHZqYRB1GfEoqhOmbzUTJ13SBKCKi13RSN6D54SQCsvCVa/qCOh40TNw0fy1nSDeyOTVJWF5k3F0dYJeomcv8QimgafxU1bumBE/VmBbjzA+Mnt03x697/bx3ZAINgSRk0NOMfMMQc/9PGeCMDqWWLQpfpJ8lspSapH+R2fwDk2myMwGaND9SQxMAf8obceFIdGiWMcWzJ8rD3Xtre471qEuIScWKHfr9X1qeOWNugRkC7Fco0VQkVaSf5A8Yuc9C2s/zllS1IQWLCM4JyMJy2mz6aJEnBmw0cTZ6up6Ulslvu8Kr6lqh9/FzbtTt2G8ujPZ/1dqVbhKPyYvjmTLKys3hYFIPGLXOc+PEPo+42xpsJ5MGKwePYzT1m/uFkihHncm/pyPBmgwvkw3pUDbJz84Chi8MAkRP9lE+SXy3PO8xehj5t/JSK1gDcUmMEicWb6aZWQdOqL9XtLAUpYZdGEA7YlTRxRdSsPIjs4qc1LhW56Hk7tQcaG0G+gUsOmSv0YnA0k1le010rvt5Bc8OS/STapBwtlAsZFHiEFMgv0YCATeeUIazps3D46BqJYypwvCh7wgF6rRYOuNEMS7Kgg5EQBBhnS3BiuG9PmsteHP0gmdTKfs/u5fj+La0NbLeI8ckc20VIPaUsD7G5cDrGhbVER8veUKkgdm2mik/w== clever@amd-nixos