add options.preface.overrideSystemArgs, minor fixes

This commit is contained in:
Niklas Gollenstede 2023-12-16 13:13:58 +01:00
parent 6f44532be5
commit 4b31e64901
7 changed files with 16 additions and 11 deletions

View File

@ -128,7 +128,7 @@
"optimise", // B/E "optimise", // B/E
"ostype", // virtual box "ostype", // virtual box
"overlayed", // word "overlayed", // word
"OVMF", // package "ovmf", // package
"partlabel", // linux "partlabel", // linux
"partprobe", // program / function "partprobe", // program / function
"partuuid", // linux "partuuid", // linux
@ -194,7 +194,9 @@
"virt", // abbr (virtualization) "virt", // abbr (virtualization)
"virtfs", // qemu / filesystem "virtfs", // qemu / filesystem
"virtio", // cli arg "virtio", // cli arg
"virtualbox", // program
"virtualisation", // british english "virtualisation", // british english
"vmdk", // vbox
"wipefs", // program "wipefs", // program
"workdir", // mount overlay option "workdir", // mount overlay option
"xattr", // zfs "xattr", // zfs

Binary file not shown.

View File

@ -17,6 +17,8 @@ dirname: inputs@{ self, nixpkgs, functions, ...}: let
config = getModuleConfig mainModule inputs args; config = getModuleConfig mainModule inputs args;
in config.${preface'} or { }; 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 { in rec {
# Builds the System Configuration for a single host. # 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 if !(args?files && builtins.isAttrs files) && preface?instances then preface.instances else [ prelimName ];
in (mapMergeUnique (name: { "${name}" = let in (mapMergeUnique (name: { "${name}" = let
preface = getPreface inputs (moduleArgs // { inherit preface; }) mainModule name; # (call again, with name) 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" ] builtins.removeAttrs args [ "files" "dir" "exclude" ]
) // { ) // {
inherit name mainModule; inherit name mainModule;
@ -81,9 +83,12 @@ in rec {
options.${preface'} = { 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; }); 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; }); 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"; } ]; }) ]; _file = "${dirname}/nixos.nix#mkNixosConfigurations-extraModule"; } ];
})); }) instances))) (files'); }; in (
if preface?overrideSystemArgs then systemArgs // (preface.overrideSystemArgs systemArgs) else systemArgs
))); }) instances))) (files');
duplicate = let duplicate = let
getId = node: name: let id = node.preface.id or null; in if id == null then null else toString id; 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. # 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 ? { }, 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. # 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«). # 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), modules ? (getModulesFromInputs moduleInputs),
# (Subset of) »inputs« that »modules« will be used from. Example: »{ inherit (inputs) self flakeA flakeB; }«. # (Subset of) »inputs« that »modules« will be used from. Example: »{ inherit (inputs) self flakeA flakeB; }«.
@ -125,13 +130,13 @@ in rec {
asDefaultPackage ? false, asDefaultPackage ? false,
... }: let ... }: let
getName = if renameOutputs == false then (name: name) else renameOutputs; 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; inherit inputs modules overlays moduleArgs nixosSystem buildPlatform extraModules;
nixosArgs = (args.nixosArgs or { }) // { modules = (args.nixosArgs.modules or [ ]) ++ [ { imports = [ (args: { nixosArgs = (args.nixosArgs or { }) // { modules = (args.nixosArgs.modules or [ ]) ++ [ { imports = [ (args: {
${installer}.outputName = getName args.config._module.args.name; ${installer}.outputName = getName args.config._module.args.name;
}) ]; _file = "${dirname}/nixos.nix#mkSystemsFlake-extraModule"; } ]; }; }) ]; _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 = { in let outputs = {
inherit nixosConfigurations; inherit nixosConfigurations;
} // (forEachSystem setupPlatforms (buildSystem: let } // (forEachSystem setupPlatforms (buildSystem: let

View File

@ -72,7 +72,7 @@ in {
system.boot.loader.id = "extlinux"; system.boot.loader.id = "extlinux";
system.build.installBootLoader = "${pkgs.writeShellScript "install-extlinux.sh" '' 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 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} ${extlinux-conf-builder} "$1" -d ${esc cfg.targetDir}
partition=${esc cfg.targetPart} partition=${esc cfg.targetPart}

View File

@ -11,7 +11,7 @@ dirname: inputs: moduleArgs@{ config, pkgs, lib, utils, ... }: let lib = inputs.
in { in {
options = { 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 [ ]; }; 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 [ ]; };
}; }) ]); }; }) ]);
}; }; }; };

View File

@ -205,8 +205,6 @@ in {
}) (lib.mkIf cfg.persistenceFixes { # Cope with the consequences of having »/« (including »/{etc,var,root,...}«) cleared on every reboot. }) (lib.mkIf cfg.persistenceFixes { # Cope with the consequences of having »/« (including »/{etc,var,root,...}«) cleared on every reboot.
environment.etc = { environment.etc = {
nixos.source = "/local/etc/nixos";
# SSHd host keys: # SSHd host keys:
"ssh/ssh_host_ed25519_key".source = "/${keep}/etc/ssh/ssh_host_ed25519_key"; "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"; "ssh/ssh_host_ed25519_key.pub".source = "/${keep}/etc/ssh/ssh_host_ed25519_key.pub";