2023-08-27 07:48:57 +02:00
|
|
|
# flakelight -- Framework for simplifying flake setup
|
2023-08-25 06:14:55 +02:00
|
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-01-10 10:16:24 +01:00
|
|
|
{ config, src, lib, flakelight, genSystems, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
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;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-02-25 06:22:00 +01:00
|
|
|
mkCheck = name: pkgs: cmd:
|
2023-08-25 06:14:55 +02:00
|
|
|
pkgs.runCommand "check-${name}" { } ''
|
|
|
|
cp --no-preserve=mode -r ${src} src
|
|
|
|
cd src
|
2024-02-25 06:22:00 +01:00
|
|
|
${cmd}
|
2023-08-25 06:14:55 +02:00
|
|
|
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;
|
|
|
|
};
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.checks = mkOption {
|
2024-02-25 06:22:00 +01:00
|
|
|
type = nullable (optFunctionTo (lazyAttrsOf checkType));
|
2023-08-25 06:14:55 +02:00
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2024-01-10 10:16:24 +01:00
|
|
|
config.outputs = mkIf (config.checks != null) {
|
2024-02-25 06:22:00 +01:00
|
|
|
checks = genSystems (pkgs: mapAttrs (_: v: v pkgs) (config.checks pkgs));
|
2024-01-10 10:16:24 +01:00
|
|
|
};
|
2023-08-25 06:14:55 +02:00
|
|
|
}
|