flakelight/builtinModules/nixosConfigurations.nix
Archit Gupta 366733be87 Wrap NixOS build checks
NixOS build checks significantly slowed down `nix flake show` as it
prints out the derivation names, which for NixOS derivations requires a
large amount of evaluation. By wrapping the derivations, we now give
them trivial names. The NixOS configurations are still built when
running checks as they are a dependency of the wrappers.
2023-12-05 00:38:45 -08:00

42 lines
1.2 KiB
Nix

# flakelight -- Framework for simplifying flake setup
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT
{ config, lib, flakelight, autoloadArgs, ... }:
let
inherit (builtins) isAttrs mapAttrs;
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
recursiveUpdate;
inherit (lib.types) lazyAttrsOf;
inherit (flakelight.types) optFunctionTo;
nixosConfiguration = mkOptionType {
name = "nixosConfiguration";
description = "nixosConfiguration";
descriptionClass = "noun";
check = x: isAttrs x
&& x ? config.nixpkgs.system
&& x ? config.system.build.toplevel;
merge = mergeOneOption;
};
configs = mapAttrs (_: f: f autoloadArgs) config.nixosConfigurations;
in
{
options.nixosConfigurations = mkOption {
type = lazyAttrsOf (optFunctionTo nixosConfiguration);
default = { };
};
config.outputs = mkIf (config.nixosConfigurations != { }) {
nixosConfigurations = configs;
checks = foldl recursiveUpdate { } (mapAttrsToList
(n: v: {
${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
"check-nixos-${n}"
{ } "echo ${v.config.system.build.toplevel} > $out";
})
configs);
};
}