Skip to content

Commit 898edde

Browse files
authored
Merge pull request #163 from tomeon/system-build-type-change-backcompat
Handle `config.system.build` type change from lazy attrset to submodule
2 parents 07ea008 + b34a6ac commit 898edde

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SHARE ?= $(PREFIX)/share/nixos-generator
33

44
all:
55

6-
SOURCES = formats format-module.nix configuration.nix nixos-generate.nix
6+
SOURCES = formats format-module.nix configuration.nix lib.nix nixos-generate.nix
77

88
install:
99
mkdir -p $(PREFIX)/bin $(SHARE)

formats/kexec.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
{ config, pkgs, lib, modulesPath, ... }: let
1+
{ config, pkgs, lib, modulesPath, options, ... }: let
22

33
clever-tests = builtins.fetchGit {
44
url = "https://github.com/cleverca22/nix-tests";
55
rev = "a9a316ad89bfd791df4953c1a8b4e8ed77995a18"; # master on 2021-06-13
66
};
7+
8+
inherit (import ../lib.nix { inherit lib options; }) maybe;
79
in {
810
imports = [
911
"${toString modulesPath}/installer/netboot/netboot-minimal.nix"
@@ -13,7 +15,7 @@ in {
1315
];
1416

1517
system.build = rec {
16-
kexec_tarball = lib.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {
18+
kexec_tarball = maybe.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {
1719
storeContents = [
1820
{ object = config.system.build.kexec_script; symlink = "/kexec_nixos"; }
1921
];

formats/raw-efi.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{ config, lib, pkgs, modulesPath, ... }:
2-
{
1+
{ config, lib, options, pkgs, modulesPath, ... }:
2+
3+
let
4+
inherit (import ../lib.nix { inherit lib options; }) maybe;
5+
in {
36
imports = [ ./raw.nix ];
47

58
boot.loader.grub = {
@@ -13,7 +16,7 @@
1316
fsType = "vfat";
1417
};
1518

16-
system.build.raw = lib.mkOverride 99 (import "${toString modulesPath}/../lib/make-disk-image.nix" {
19+
system.build.raw = maybe.mkOverride 99 (import "${toString modulesPath}/../lib/make-disk-image.nix" {
1720
inherit lib config pkgs;
1821
partitionTableType = "efi";
1922
diskSize = "auto";

lib.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
lib,
3+
options,
4+
}: let
5+
# See https://github.com/NixOS/nixpkgs/commit/ccb85a53b6a496984073227fd8c4d4c58889f421
6+
# This commit changed the type of `system.build` from a lazy attribute set to
7+
# a submodule. Prior to this commit, it doesn't make sense to qualify, e.g.
8+
# the `system.build.kexec_tarball` definition with `lib.mkForce`, as this
9+
# would result in setting the (final/resolved) value of
10+
# `system.build.kexec_tarball` to something like:
11+
# {
12+
# _type = "override";
13+
# content = <...>;
14+
# priority = 50;
15+
# }
16+
# However, since this commit, `system.build.kexec_tarball` *must* be defined
17+
# using `lib.mkForce`; otherwise, Nix bails out with a complaint about
18+
# `system.build.kexec_tarball` being defined in multiple locations.
19+
systemBuildIsSubmodule = options.system.build.type.name == "submodule";
20+
21+
optionsLookSane = lib.hasAttrByPath ["system" "build" "type" "name"] options;
22+
in
23+
assert (lib.assertMsg optionsLookSane "`options' must be the NixOS module `options' argument"); {
24+
maybe =
25+
{
26+
mkForce = lib.id;
27+
mkOverride = _: lib.id;
28+
}
29+
// (lib.optionalAttrs systemBuildIsSubmodule {
30+
inherit (lib) mkForce mkOverride;
31+
});
32+
}

0 commit comments

Comments
 (0)