From b34a6ac4e6d05facc93487e8b7685870c575590c Mon Sep 17 00:00:00 2001 From: Matt Schreiber Date: Tue, 17 May 2022 12:15:45 -0400 Subject: [PATCH] No lib.mkForce in system.build.kexec_tarball def'n on nixpkgs versions prior to the commit that changed config.system.build's type from a lazy attribute set to a submodule. Prior to this type change, there is no system.build.kexec_tarball option declared, so the NixOS module system does not resolve priorities/overrides in the config.build.kexec_tarball definition. That is, with lib.mkForce, the config.build.kexec_tarball definition ends up being something like: { _type = "override"; content = <...>; priority = 50; } Removing lib.mkForce allows us to successfully and sensibly interpolate the value (== outPath) of system.build.kexec_tarball in system.build.kexec_bundle's builder script. Likewise, no lib.mkOverride for system.build.raw. --- Makefile | 2 +- formats/kexec.nix | 6 ++++-- formats/raw-efi.nix | 9 ++++++--- lib.nix | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 lib.nix diff --git a/Makefile b/Makefile index 439bfe0..50acd4e 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHARE ?= $(PREFIX)/share/nixos-generator all: -SOURCES = formats format-module.nix configuration.nix nixos-generate.nix +SOURCES = formats format-module.nix configuration.nix lib.nix nixos-generate.nix install: mkdir -p $(PREFIX)/bin $(SHARE) diff --git a/formats/kexec.nix b/formats/kexec.nix index a124454..47878fb 100644 --- a/formats/kexec.nix +++ b/formats/kexec.nix @@ -1,9 +1,11 @@ -{ config, pkgs, lib, modulesPath, ... }: let +{ config, pkgs, lib, modulesPath, options, ... }: let clever-tests = builtins.fetchGit { url = "https://github.com/cleverca22/nix-tests"; rev = "a9a316ad89bfd791df4953c1a8b4e8ed77995a18"; # master on 2021-06-13 }; + + inherit (import ../lib.nix { inherit lib options; }) maybe; in { imports = [ "${toString modulesPath}/installer/netboot/netboot-minimal.nix" @@ -13,7 +15,7 @@ in { ]; system.build = rec { - kexec_tarball = lib.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" { + kexec_tarball = maybe.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" { storeContents = [ { object = config.system.build.kexec_script; symlink = "/kexec_nixos"; } ]; diff --git a/formats/raw-efi.nix b/formats/raw-efi.nix index e566e0a..6ebabad 100644 --- a/formats/raw-efi.nix +++ b/formats/raw-efi.nix @@ -1,5 +1,8 @@ -{ config, lib, pkgs, modulesPath, ... }: -{ +{ config, lib, options, pkgs, modulesPath, ... }: + +let + inherit (import ../lib.nix { inherit lib options; }) maybe; +in { imports = [ ./raw.nix ]; boot.loader.grub = { @@ -13,7 +16,7 @@ fsType = "vfat"; }; - system.build.raw = lib.mkOverride 99 (import "${toString modulesPath}/../lib/make-disk-image.nix" { + system.build.raw = maybe.mkOverride 99 (import "${toString modulesPath}/../lib/make-disk-image.nix" { inherit lib config pkgs; partitionTableType = "efi"; diskSize = "auto"; diff --git a/lib.nix b/lib.nix new file mode 100644 index 0000000..83e365e --- /dev/null +++ b/lib.nix @@ -0,0 +1,32 @@ +{ + lib, + options, +}: let + # See https://github.com/NixOS/nixpkgs/commit/ccb85a53b6a496984073227fd8c4d4c58889f421 + # This commit changed the type of `system.build` from a lazy attribute set to + # a submodule. Prior to this commit, it doesn't make sense to qualify, e.g. + # the `system.build.kexec_tarball` definition with `lib.mkForce`, as this + # would result in setting the (final/resolved) value of + # `system.build.kexec_tarball` to something like: + # { + # _type = "override"; + # content = <...>; + # priority = 50; + # } + # However, since this commit, `system.build.kexec_tarball` *must* be defined + # using `lib.mkForce`; otherwise, Nix bails out with a complaint about + # `system.build.kexec_tarball` being defined in multiple locations. + systemBuildIsSubmodule = options.system.build.type.name == "submodule"; + + optionsLookSane = lib.hasAttrByPath ["system" "build" "type" "name"] options; +in + assert (lib.assertMsg optionsLookSane "`options' must be the NixOS module `options' argument"); { + maybe = + { + mkForce = lib.id; + mkOverride = _: lib.id; + } + // (lib.optionalAttrs systemBuildIsSubmodule { + inherit (lib) mkForce mkOverride; + }); + }