Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/nixos/common: add initrd ssh #1383

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions modules/nixos/common/security.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
{
config,
inputs,
lib,
...
}:
let
initrd_host_key = "/etc/ssh/initrd_host_ed25519_key";
in
{
# Make sure that the firewall is enabled, even if it's the default.
networking.firewall.enable = true;

# allow to access emergency shell with a password
boot.initrd.systemd.emergencyAccess = "$6$he2fblfl/H7I.kvz$WbSCMXu8ztmqfj5jG4czqvu/rkMHxufxqHgy1urzXFSN.jZB4QiW5lOjR08vk8pZTyim3TT1wFkMaNE9zZ3sc1";

boot.initrd.network = {
enable = true;
ssh = {
enable = true;
authorizedKeyFiles = lib.filesystem.listFilesRecursive "${inputs.self}/users/keys";
hostKeys = [ initrd_host_key ];
};
};

system.activationScripts.initrd-ssh-host-key = ''
[[ -f ${initrd_host_key} ]] || ${config.programs.ssh.package}/bin/ssh-keygen -q -t ed25519 -N "" -f ${initrd_host_key}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will fail on the first deployment, but than work on the second one. So probably fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will fail on the first deployment

Could you explain please?

Copy link
Member

@Mic92 Mic92 Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activation phase is run after the boot loader is installed in nixos-rebuild. So on the first deployment this will fail.

'';

services.openssh = {
hostKeys = [
{
Expand Down