From cdecdcd3730147928afd1a8037c5ea8d847bc098 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Mon, 9 Nov 2026 08:59:34 -0800 Subject: [PATCH] nixos/top-level: keep nix flake check catching failed assertions If we make toplevel its own type, we can make `nix flake check` continue to check and `nix flake show` fast. --- nixos/modules/system/activation/top-level.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index c374e45a66b0..e28154ef4849 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -156,7 +156,24 @@ in system.build = { toplevel = mkOption { - type = types.package; + type = lib.mkOptionType { + name = "nixosToplevel"; + description = "package"; + descriptionClass = "noun"; + # Only check for the existence of `drvPath` and `outPath` so that `nix flake show` is fast + check = x: x ? drvPath && x ? outPath; + merge = + loc: defs: + let + toplevel = lib.mergeOneOption loc defs; + in + toplevel + // { + # Check assertions when something asks about the type (e.g. `nix flake check`), + # leaving `name` cheap so that `nix flake show` is fast. + type = lib.asserts.checkAssertWarn config.assertions [ ] toplevel.type; + }; + }; readOnly = true; description = '' This option contains the store path that typically represents a NixOS system.