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
|
|
|
|
|
2023-08-27 07:48:57 +02:00
|
|
|
{ config, src, lib, flakelight, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
|
|
|
inherit (lib) isDerivation isFunction mkOption mkIf mapAttrs;
|
|
|
|
inherit (lib.types) lazyAttrsOf nullOr raw;
|
2023-08-27 07:48:57 +02:00
|
|
|
inherit (flakelight.types) optFunctionTo;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
|
|
|
mkCheck = pkgs: src: name: cmd:
|
|
|
|
let
|
|
|
|
cmd' = if isFunction cmd then cmd pkgs else cmd;
|
|
|
|
in
|
|
|
|
if isDerivation cmd' then cmd' else
|
|
|
|
pkgs.runCommand "check-${name}" { } ''
|
|
|
|
cp --no-preserve=mode -r ${src} src
|
|
|
|
cd src
|
|
|
|
${cmd'}
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.checks = mkOption {
|
|
|
|
type = nullOr (optFunctionTo (lazyAttrsOf raw));
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
config.perSystem = mkIf (config.checks != null) (pkgs: {
|
|
|
|
checks = mapAttrs (mkCheck pkgs src) (config.checks pkgs);
|
|
|
|
});
|
|
|
|
}
|