Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions formats/kexec.nix
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"; }
];
Expand Down
9 changes: 6 additions & 3 deletions formats/raw-efi.nix
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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";
Expand Down
32 changes: 32 additions & 0 deletions lib.nix
Original file line number Diff line number Diff line change
@@ -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;
});
}