feat(gengetsu): nfs root fs

This commit is contained in:
arcnmx 2024-11-24 15:34:08 -08:00
parent 3c5e7179bb
commit 179ac7ac55
5 changed files with 54 additions and 15 deletions

View file

@ -6,7 +6,7 @@
... ...
}: let }: let
inherit (gensokyo-zone.lib) mkAlmostOptionDefault; inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
inherit (lib.modules) mkDefault; inherit (lib.modules) mkIf mkDefault;
in { in {
hardware.enableRedistributableFirmware = mkDefault true; hardware.enableRedistributableFirmware = mkDefault true;
boot.zfs.package = mkDefault pkgs.zfs_unstable; boot.zfs.package = mkDefault pkgs.zfs_unstable;
@ -29,4 +29,8 @@ in {
useTmpfs = mkAlmostOptionDefault true; useTmpfs = mkAlmostOptionDefault true;
tmpfsSize = mkAlmostOptionDefault "80%"; tmpfsSize = mkAlmostOptionDefault "80%";
}; };
system.switch.enableNg = mkIf (config.boot.supportedFilesystems.nfs or false) (
# XXX: workaround for nixos switch bug
mkAlmostOptionDefault false
);
} }

View file

@ -7,7 +7,7 @@
... ...
}: let }: let
inherit (lib.options) mkOption mkEnableOption mkPackageOption; inherit (lib.options) mkOption mkEnableOption mkPackageOption;
inherit (lib.modules) mkIf mkDefault mkMerge; inherit (lib.modules) mkIf mkMerge mkOptionDefault mkDefault;
cfg = config.gensokyo-zone.netboot; cfg = config.gensokyo-zone.netboot;
nfsEnabled = config.boot.initrd.supportedFilesystems.nfs or config.boot.initrd.supportedFilesystems.nfs4 or false; nfsEnabled = config.boot.initrd.supportedFilesystems.nfs or config.boot.initrd.supportedFilesystems.nfs4 or false;
defaultCacheTimeoutMax = 60 * 60; # 1h defaultCacheTimeoutMax = 60 * 60; # 1h
@ -20,6 +20,9 @@ in {
package = mkPackageOption pkgs "nfs-utils" { package = mkPackageOption pkgs "nfs-utils" {
example = "pkgs.mkinitcpio-nfs-utils"; example = "pkgs.mkinitcpio-nfs-utils";
}; };
host = mkOption {
type = str;
};
security = mkOption { security = mkOption {
type = str; type = str;
default = "sys"; default = "sys";
@ -39,6 +42,20 @@ in {
}; };
}; };
config = { config = {
gensokyo-zone.netboot = {
nfs = {
host = let
nfsUrl = access.proxyUrlFor {
serviceName = "nfs";
scheme = "";
defaultPort = 2049;
# XXX: consider using dns hostname here instead? (does this require the dns_resolver kernel module?)
getAddressFor = "getAddress4For";
};
in
mkOptionDefault nfsUrl;
};
};
boot = { boot = {
initrd = { initrd = {
network = { network = {
@ -75,15 +92,7 @@ in {
}; };
}; };
fileSystems = let fileSystems = let
nfsUrl = nfsUrl = "${cfg.nfs.host}:/srv/fs/kyuuto/systems/${systemConfig.name}";
access.proxyUrlFor {
serviceName = "nfs";
scheme = "";
defaultPort = 2049;
# XXX: consider using dns hostname here instead? (does this require the dns_resolver kernel module?)
getAddressFor = "getAddress4For";
}
+ ":/srv/fs/kyuuto/systems/${systemConfig.name}";
nfsOpts = nfsOpts =
[ [
"sec=${cfg.nfs.security}" "sec=${cfg.nfs.security}"
@ -101,5 +110,8 @@ in {
options = nfsOpts; options = nfsOpts;
}; };
}; };
systemd.services.systemd-remount-fs = mkIf (config.fileSystems."/".fsType == "nfs") {
unitConfig.ConditionPathExists = "/tmp/systemd-remount-fs-broken";
};
}; };
} }

View file

@ -107,6 +107,10 @@ in {
]; ];
adminClients = [ adminClients = [
"@admin" "@admin"
# TODO: "@personal-admin" host group too...
# shanghai.tail:
"fd7a:115c:a1e0::4e01:2d2c/128"
"100.107.45.44/32"
# XXX: include tailscale addresses of trusted machines here too? # XXX: include tailscale addresses of trusted machines here too?
]; ];
tailClients = optionals config.services.tailscale.enable cidrForNetwork.tail.all; tailClients = optionals config.services.tailscale.enable cidrForNetwork.tail.all;

View file

@ -7,14 +7,14 @@
inherit (meta) nixos; inherit (meta) nixos;
in [ in [
nixos.hw.c4130 nixos.hw.c4130
#nixos.netboot.kyuuto nixos.netboot.kyuuto
]; ];
fileSystems = { fileSystems = {
"/" = { "/mnt/root-old" = {
device = "/dev/disk/by-uuid/bf317f5d-ffc2-45fd-9621-b645ff7223fc"; device = "/dev/disk/by-uuid/bf317f5d-ffc2-45fd-9621-b645ff7223fc";
fsType = "xfs"; fsType = "xfs";
options = ["lazytime" "noatime"]; options = ["x-systemd.automount" "lazytime" "noatime" "noauto" "nofail"];
}; };
"/boot" = { "/boot" = {
device = "/dev/disk/by-label/boot"; device = "/dev/disk/by-label/boot";

View file

@ -1,4 +1,11 @@
{meta, ...}: { {
config,
gensokyo-zone,
meta,
...
}: let
inherit (gensokyo-zone.lib) domain;
in {
imports = let imports = let
inherit (meta) nixos; inherit (meta) nixos;
in [ in [
@ -7,5 +14,17 @@
nixos.base nixos.base
]; ];
fileSystems = let
inherit (config.gensokyo-zone) netboot;
#nfsHost = netboot.nfs.host;
nfsHost = "nfs.local.${domain}";
in {
"/mnt/goliath/boot" = {
device = "${nfsHost}:/srv/fs/kyuuto/systems/goliath/boot";
options = ["sec=sys" "nofail"] ++ netboot.nfs.flags;
fsType = "nfs";
};
};
system.stateVersion = "24.05"; system.stateVersion = "24.05";
} }