nixos/modules/system/initrd.nix

45 lines
1.3 KiB
Nix
Raw Normal View History

2023-09-02 15:07:16 +08:00
inputs:
{
options.nixos.system.initrd = let inherit (inputs.lib) mkOption types; in
{
sshd =
{
enable = mkOption { type = types.bool; default = false; };
2023-11-19 17:29:15 +08:00
hostKeys = mkOption
{
type = types.listOf types.nonEmptyStr;
default = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ];
};
2023-09-02 15:07:16 +08:00
};
2024-08-01 00:31:07 +08:00
unl0kr = mkOption { type = types.nullOr (types.submodule {}); default = null; };
2023-09-02 15:07:16 +08:00
};
config = let inherit (inputs.config.nixos.system) initrd; in inputs.lib.mkMerge
[
2024-07-03 10:42:15 +08:00
{
boot =
{
initrd.systemd.enable = true;
kernelParams = [ "boot.shell_on_fail" "systemd.setenv=SYSTEMD_SULOGIN_FORCE=1" ];
};
}
(
inputs.lib.mkIf (initrd.sshd.enable)
{
boot =
2023-11-19 17:29:15 +08:00
{
2024-07-04 11:02:47 +08:00
initrd =
{
network = { enable = true; ssh = { enable = true; hostKeys = initrd.sshd.hostKeys; }; };
# resolved does not work in initrd, causing network.target to fail
services.resolved.enable = false;
};
2024-08-26 12:37:14 +08:00
# ip=dhcp only attain ipv4
2024-09-17 10:06:56 +08:00
# ip=on will reset systemd-networkd configs
# kernelParams = [ "ip=on" ];
};
}
)
2024-08-01 00:31:07 +08:00
(inputs.lib.mkIf (initrd.unl0kr != null) { boot.initrd.unl0kr.enable = true; })
];
2023-09-02 15:07:16 +08:00
}