From e1e88dfdba75c5da792357471804c8b98e570f62 Mon Sep 17 00:00:00 2001 From: chn Date: Sat, 2 Sep 2023 15:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=20system.initrd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 40 +++++++++++++++++++------------------- modules/boot/default.nix | 38 ------------------------------------ modules/default.nix | 2 +- modules/system/default.nix | 1 + modules/system/initrd.nix | 28 ++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 59 deletions(-) delete mode 100644 modules/boot/default.nix create mode 100644 modules/system/initrd.nix diff --git a/flake.nix b/flake.nix index 7483b961..7d4617b3 100644 --- a/flake.nix +++ b/flake.nix @@ -250,6 +250,11 @@ grub.installDevice = "/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:0"; march = "sandybridge"; nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; + initrd = + { + network.enable = true; + sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; + }; }; packages.packageSet = "server"; services = @@ -280,11 +285,6 @@ synapse-proxy."synapse.chn.moe" = {}; nebula = { enable = true; lighthouse = null; }; }; - boot = - { - network.enable = true; - sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; - }; };}) ]; "vps4" = @@ -315,6 +315,11 @@ grub.installDevice = "/dev/disk/by-path/pci-0000:00:04.0"; march = "znver3"; nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; + initrd = + { + network.enable = true; + sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; + }; }; packages.packageSet = "server"; services = @@ -324,11 +329,6 @@ sops = { enable = true; keyPathPrefix = "/nix/persistent"; }; sshd.enable = true; }; - boot = - { - network.enable = true; - sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; - }; };}) ]; "vps7" = @@ -359,6 +359,11 @@ grub.installDevice = "/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:0"; march = "broadwell"; nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; + initrd = + { + network.enable = true; + sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; + }; }; packages = { @@ -376,11 +381,6 @@ misskey = { enable = true; hostname = "xn--s8w913fdga.chn.moe"; }; synapse.enable = true; }; - boot = - { - network.enable = true; - sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; - }; };}) ]; "nas" = @@ -411,6 +411,11 @@ grub.installDevice = "/dev/disk/by-path/pci-0000:00:04.0"; march = "silvermont"; nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; + initrd = + { + network.enable = true; + sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; + }; }; packages.packageSet = "server"; services = @@ -420,11 +425,6 @@ sops = { enable = true; keyPathPrefix = "/nix/persistent"; }; sshd.enable = true; }; - boot = - { - network.enable = true; - sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; - }; };}) ]; "xmupc1" = diff --git a/modules/boot/default.nix b/modules/boot/default.nix deleted file mode 100644 index 35cb753c..00000000 --- a/modules/boot/default.nix +++ /dev/null @@ -1,38 +0,0 @@ -inputs: -{ - options.nixos.boot = let inherit (inputs.lib) mkOption types; in - { - network.enable = mkOption { type = types.bool; default = false; }; - sshd = - { - enable = mkOption { type = types.bool; default = false; }; - hostKeys = mkOption { type = types.listOf types.nonEmptyStr; default = []; }; - }; - }; - config = - let - inherit (inputs.lib) mkMerge mkIf; - inherit (inputs.localLib) mkConditional attrsToList stripeTabs; - inherit (inputs.config.nixos) boot; - inherit (builtins) concatStringsSep map; - in mkMerge - [ - # generic - { - boot = - { - initrd.systemd.enable = true; - }; - } - # network - ( - mkIf boot.network.enable - { boot = { initrd.network.enable = true; kernelParams = [ "ip=dhcp" ]; }; } - ) - # sshd - ( - mkIf boot.sshd.enable - { boot.initrd.network.ssh = { enable = true; hostKeys = boot.sshd.hostKeys; };} - ) - ]; -} diff --git a/modules/default.nix b/modules/default.nix index cda5178d..66c7795e 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -30,6 +30,6 @@ inputs: deploy-rs = { inherit (prev) deploy-rs; inherit ((topInputs.deploy-rs.overlay final prev).deploy-rs) lib; }; }) ];}) - ./kernel ./hardware ./packages ./boot ./system ./virtualization ./services ./bugs ./users + ./kernel ./hardware ./packages ./system ./virtualization ./services ./bugs ./users ]; } diff --git a/modules/system/default.nix b/modules/system/default.nix index fe969007..02dff4d4 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -5,6 +5,7 @@ inputs: ./nix.nix ./fileSystems.nix ./grub.nix + ./initrd.nix ]; options.nixos.system = let inherit (inputs.lib) mkOption types; in { diff --git a/modules/system/initrd.nix b/modules/system/initrd.nix new file mode 100644 index 00000000..e23801ff --- /dev/null +++ b/modules/system/initrd.nix @@ -0,0 +1,28 @@ +inputs: +{ + options.nixos.system.initrd = let inherit (inputs.lib) mkOption types; in + { + network.enable = mkOption { type = types.bool; default = false; }; + sshd = + { + enable = mkOption { type = types.bool; default = false; }; + hostKeys = mkOption { type = types.listOf types.nonEmptyStr; default = []; }; + }; + }; + config = + let + inherit (inputs.config.nixos.system) initrd; + in { boot = + { + initrd = + { + systemd.enable = true; + network = + { + enable = initrd.network.enable; + ssh = { enable = true; hostKeys = initrd.sshd.hostKeys; }; + }; + }; + kernelParams = if initrd.network.enable then [ "ip=dhcp" ] else []; + };}; +}