Generate ssh-key if none available

This commit is contained in:
Nina Chloé Kassandra Reiß
2026-02-27 21:25:08 +01:00
parent 1cd22ca95e
commit b8ca6cf5c4

View File

@@ -1,6 +1,8 @@
{ config, pkgs, lib, ... }:
let
profile = import ./profile.nix;
home-directory = "/home/${profile.username}";
ssh-filename = "${home-directory}/.ssh/id_ed25519";
in
{
@@ -37,4 +39,22 @@ in
};
};
};
systemd.services.generate-ssh-key = {
description = "Generate SSH key if missing";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "oneshot";
User = user;
};
script = ''
if [ ! -f ${ssh-filename} ]; then
mkdir -p ${home-directory}/.ssh
chmod 700 ${home-directory}/.ssh
${pkgs.openssh}/bin/ssh-keygen -t ed25519 -N "" -f ${ssh-filename}
fi
'';
};
}