1
1
forked from extern/flakelight
flakelight/builtinModules/checks.nix

53 lines
1.5 KiB
Nix
Raw Normal View History

# flakelight -- Framework for simplifying flake setup
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT
{ config, src, lib, flakelight, genSystems, ... }:
let
2024-02-25 06:22:00 +01:00
inherit (lib) isFunction last mapAttrs mergeDefinitions mkIf mkOption
mkOptionType;
inherit (lib.types) lazyAttrsOf optionDescriptionPhrase;
inherit (flakelight.types) coercedTo' drv nullable optFunctionTo stringLike;
2024-02-25 06:22:00 +01:00
mkCheck = name: pkgs: cmd:
pkgs.runCommand "check-${name}" { } ''
cp --no-preserve=mode -r ${src} src
cd src
2024-02-25 06:22:00 +01:00
${cmd}
touch $out
'';
2024-02-25 06:22:00 +01:00
checkType = mkOptionType {
name = "checkType";
description =
let
targetDesc = optionDescriptionPhrase
(class: class == "noun" || class == "composite")
(coercedTo' stringLike (abort "") drv);
in
"${targetDesc} or function that evaluates to it";
descriptionClass = "composite";
check = x: isFunction x || drv.check x || stringLike.check x;
merge = loc: defs: pkgs:
let
targetType = coercedTo' stringLike (mkCheck (last loc) pkgs) drv;
in
(mergeDefinitions loc targetType (map
(fn: {
inherit (fn) file;
value = if isFunction fn.value then fn.value pkgs else fn.value;
})
defs)).mergedValue;
};
in
{
options.checks = mkOption {
2024-02-25 06:22:00 +01:00
type = nullable (optFunctionTo (lazyAttrsOf checkType));
default = null;
};
config.outputs = mkIf (config.checks != null) {
2024-02-25 06:22:00 +01:00
checks = genSystems (pkgs: mapAttrs (_: v: v pkgs) (config.checks pkgs));
};
}