mirror of
https://github.com/nix-community/flakelight.git
synced 2024-11-25 08:53:15 +01:00
82f9fe67c3
Using `perSystem` to implement per-system attributes ties all the per-system attributes together; all the `perSystem` functions must run to determine output attrs. By generating them separately, the generation can be done lazily.
34 lines
894 B
Nix
34 lines
894 B
Nix
# flakelight -- Framework for simplifying flake setup
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
{ config, src, lib, flakelight, genSystems, ... }:
|
|
let
|
|
inherit (lib) isDerivation isFunction mkOption mkIf mapAttrs;
|
|
inherit (lib.types) lazyAttrsOf nullOr raw;
|
|
inherit (flakelight.types) optFunctionTo;
|
|
|
|
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.outputs = mkIf (config.checks != null) {
|
|
checks = genSystems (pkgs:
|
|
mapAttrs (mkCheck pkgs src) (config.checks pkgs));
|
|
};
|
|
}
|