From 4b31e64901edddad6bc1283a3b0862d836e0866c Mon Sep 17 00:00:00 2001 From: Niklas Gollenstede Date: Sat, 16 Dec 2023 13:13:58 +0100 Subject: [PATCH] add options.preface.overrideSystemArgs, minor fixes --- .vscode/settings.json | 4 +++- flake.lock | Bin 1669 -> 1669 bytes lib/nixos.nix | 15 ++++++++++----- lib/setup-scripts/maintenance.sh | 2 +- modules/bootloader/extlinux.nix.md | 2 +- modules/filesystems/format-args.nix.md | 2 +- modules/setup/temproot.nix.md | 2 -- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3647185..083dace 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -128,7 +128,7 @@ "optimise", // B/E "ostype", // virtual box "overlayed", // word - "OVMF", // package + "ovmf", // package "partlabel", // linux "partprobe", // program / function "partuuid", // linux @@ -194,7 +194,9 @@ "virt", // abbr (virtualization) "virtfs", // qemu / filesystem "virtio", // cli arg + "virtualbox", // program "virtualisation", // british english + "vmdk", // vbox "wipefs", // program "workdir", // mount overlay option "xattr", // zfs diff --git a/flake.lock b/flake.lock index 5b68ff35064e607200aadc4dc86c634f4dfe27c7..50402252499469b4d506a2aa983d74664f43d877 100644 GIT binary patch delta 359 zcmWm9IZgsm0D$43pcSzc3k|VQf+oIwF*c~k;yTV`bm-=7f`T9kiwCf=GI{rqf@^pS zFXDKBKVSZj;z#jovc@4{0Q$ws_Ca66gSUDdC83))8ax1n=2iS?R59JyvrOR6eDG+MU+8@I7bFhrc7#8$~2Z%>r^^lE}Sku zb33_p#E8TI|KrtJyBkF+4iR#VRuvZlt>1v~1vo)i&?7LOb4hfq*3TLR3DMiLIB?Y6} RD2Y?(Br`xNzAP7P?hoUZY6}1W delta 361 zcmXZWIZgsm007XSj8w!@8V#XP5=`drf4;F{2?zlJHU$?hcTQoj`q zI?!8 diff --git a/lib/nixos.nix b/lib/nixos.nix index 0b7302b..5852d01 100644 --- a/lib/nixos.nix +++ b/lib/nixos.nix @@ -17,6 +17,8 @@ dirname: inputs@{ self, nixpkgs, functions, ...}: let config = getModuleConfig mainModule inputs args; in config.${preface'} or { }; + getFlakeDir = input: error: if input.sourceInfo.outPath == input.sourceInfo.outPath || lib.hasPrefix input.sourceInfo.outPath input.outPath then input.outPath else throw error; + in rec { # Builds the System Configuration for a single host. @@ -71,7 +73,7 @@ in rec { in if !(args?files && builtins.isAttrs files) && preface?instances then preface.instances else [ prelimName ]; in (mapMergeUnique (name: { "${name}" = let preface = getPreface inputs (moduleArgs // { inherit preface; }) mainModule name; # (call again, with name) - in { inherit preface; } // (mkNixosConfiguration (( + in { inherit preface; } // (mkNixosConfiguration (let systemArgs = ( builtins.removeAttrs args [ "files" "dir" "exclude" ] ) // { inherit name mainModule; @@ -81,9 +83,12 @@ in rec { options.${preface'} = { instances = lib.mkOption { description = "List of host names to instantiate this host config for, instead of just for the file name."; type = lib.types.listOf lib.types.str; readOnly = true; } // (lib.optionalAttrs (!preface?instances) { default = instances; }); id = lib.mkOption { description = "This system's ID. If set, »mkSystemsFlake« will ensure that the ID is unique among all »moduleArgs.nodes«."; type = lib.types.nullOr (lib.types.either lib.types.int lib.types.str); readOnly = true; apply = id: if id == null then null else toString id; } // (lib.optionalAttrs (!preface?id) { default = null; }); + overrideSystemArgs = lib.mkOption { description = "Function that may override any of the arguments to »mkNixosConfiguration«."; type = lib.types.functionTo lib.types.attrs; readOnly = true; } // (lib.optionalAttrs (!preface?overrideSystemArgs) { default = args: args; }); }; }) ]; _file = "${dirname}/nixos.nix#mkNixosConfigurations-extraModule"; } ]; - })); }) instances))) (files'); + }; in ( + if preface?overrideSystemArgs then systemArgs // (preface.overrideSystemArgs systemArgs) else systemArgs + ))); }) instances))) (files'); duplicate = let getId = node: name: let id = node.preface.id or null; in if id == null then null else toString id; @@ -100,7 +105,7 @@ in rec { # An attrset of imported Nix flakes, for example the argument(s) passed to the flake »outputs« function. All other arguments are optional (and have reasonable defaults) if this is provided and contains »self« and the standard »nixpkgs«. This is also the second argument passed to the individual host's top level config files. inputs ? { }, # Arguments »{ files, dir, exclude, }« to »mkNixosConfigurations«, see there for details. May also be a list of those attrsets, in which case those multiple sets of hosts will be built separately by »mkNixosConfigurations«, allowing for separate sets of »peers« passed to »mkNixosConfiguration«. Each call will receive all other arguments, and the resulting sets of hosts will be merged. - systems ? ({ dir = "${inputs.self}/hosts"; exclude = [ ]; }), # TODO: (before nix 2.14) this is not relative to the flake.nix, but relative to the root of the repo + hosts ? ({ dir = "${getFlakeDir inputs.self "Can't determine flake dir from »inputs.self«. Supply »mkSystemsFlake.hosts.dir« explicitly!"}/hosts"; exclude = [ ]; }), # List of Modules to import for all hosts, in addition to the default ones in »nixpkgs«. The host-individual module should selectively enable these. Defaults to ».nixosModules.default« of all »moduleInputs«/»inputs« (including »inputs.self«). modules ? (getModulesFromInputs moduleInputs), # (Subset of) »inputs« that »modules« will be used from. Example: »{ inherit (inputs) self flakeA flakeB; }«. @@ -125,13 +130,13 @@ in rec { asDefaultPackage ? false, ... }: let getName = if renameOutputs == false then (name: name) else renameOutputs; - otherArgs = (builtins.removeAttrs args [ "systems" "moduleInputs" "overlayInputs" "renameOutputs" "asDefaultPackage" ]) // { + otherArgs = (builtins.removeAttrs args [ "hosts" "moduleInputs" "overlayInputs" "renameOutputs" "asDefaultPackage" ]) // { inherit inputs modules overlays moduleArgs nixosSystem buildPlatform extraModules; nixosArgs = (args.nixosArgs or { }) // { modules = (args.nixosArgs.modules or [ ]) ++ [ { imports = [ (args: { ${installer}.outputName = getName args.config._module.args.name; }) ]; _file = "${dirname}/nixos.nix#mkSystemsFlake-extraModule"; } ]; }; }; - nixosConfigurations = if builtins.isList systems then mergeAttrsUnique (map (systems: mkNixosConfigurations (otherArgs // systems)) systems) else mkNixosConfigurations (otherArgs // systems); + nixosConfigurations = if builtins.isList hosts then mergeAttrsUnique (map (hosts: mkNixosConfigurations (otherArgs // hosts)) hosts) else mkNixosConfigurations (otherArgs // hosts); in let outputs = { inherit nixosConfigurations; } // (forEachSystem setupPlatforms (buildSystem: let diff --git a/lib/setup-scripts/maintenance.sh b/lib/setup-scripts/maintenance.sh index 6b17e9a..f95935b 100644 --- a/lib/setup-scripts/maintenance.sh +++ b/lib/setup-scripts/maintenance.sh @@ -206,7 +206,7 @@ function mount-keystore-luks { @{native.util-linux}/bin/mount -o nodev,umask=0077,fmask=0077,dmask=0077,ro /dev/mapper/$keystore /run/$keystore && prepend_trap "@{native.util-linux}/bin/umount /run/$keystore" EXIT || return } -## Opens the keystore with the primary unlock method, which may not be convenient to use, but should always be defined. +## Opens the keystore with the primary unlock method, which may not be convenient to use, but should always be defined. function mount-keystore-luks-primary { local usage=luks/keystore-@{config.networking.hostName!hashString.sha256:0:8}/0 local method=@{config.setup.keystore.keys[$usage]%%=*} diff --git a/modules/bootloader/extlinux.nix.md b/modules/bootloader/extlinux.nix.md index 0b8ed8a..f41f3df 100644 --- a/modules/bootloader/extlinux.nix.md +++ b/modules/bootloader/extlinux.nix.md @@ -72,7 +72,7 @@ in { system.boot.loader.id = "extlinux"; system.build.installBootLoader = "${pkgs.writeShellScript "install-extlinux.sh" '' if [[ ! ''${1:-} || $1 != /nix/store/* ]] ; then echo "Usage: ${builtins.placeholder "out"} TOPLEVEL_PATH" 1>&2 ; exit 1 ; fi - export PATH=$PATH:${pkgs.stdenv}/bin + export PATH=${lib.makeBinPath pkgs.stdenvNoCC.initialPath} ${extlinux-conf-builder} "$1" -d ${esc cfg.targetDir} partition=${esc cfg.targetPart} diff --git a/modules/filesystems/format-args.nix.md b/modules/filesystems/format-args.nix.md index b41f6b7..3b514bf 100644 --- a/modules/filesystems/format-args.nix.md +++ b/modules/filesystems/format-args.nix.md @@ -11,7 +11,7 @@ dirname: inputs: moduleArgs@{ config, pkgs, lib, utils, ... }: let lib = inputs. in { options = { - fileSystems = lib.mkOption { type = lib.types.attrsOf (lib.types.submodule [ ({ config, ...}@_: { options = { + fileSystems = lib.mkOption { type = lib.types.attrsOf (lib.types.submodule [ ({ config, ... }@_: { options = { formatArgs = lib.mkOption { description = "Arguments passed to mkfs for this filesystem during OS installation."; type = lib.types.listOf lib.types.str; default = if (lib.isString config.formatOptions or null) && config.formatOptions != "" then lib.splitString " " config.formatOptions else [ ]; }; }; }) ]); }; }; diff --git a/modules/setup/temproot.nix.md b/modules/setup/temproot.nix.md index 561080c..b1a06ab 100644 --- a/modules/setup/temproot.nix.md +++ b/modules/setup/temproot.nix.md @@ -205,8 +205,6 @@ in { }) (lib.mkIf cfg.persistenceFixes { # Cope with the consequences of having »/« (including »/{etc,var,root,...}«) cleared on every reboot. environment.etc = { - nixos.source = "/local/etc/nixos"; - # SSHd host keys: "ssh/ssh_host_ed25519_key".source = "/${keep}/etc/ssh/ssh_host_ed25519_key"; "ssh/ssh_host_ed25519_key.pub".source = "/${keep}/etc/ssh/ssh_host_ed25519_key.pub";