Generate ssh-key if none available
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
profile = import ./profile.nix;
|
profile = import ./profile.nix;
|
||||||
|
home-directory = "/home/${profile.username}";
|
||||||
|
ssh-filename = "${home-directory}/.ssh/id_ed25519";
|
||||||
in
|
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
|
||||||
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user