flakelight/builtinModules/bundlers.nix
Archit Gupta 82f9fe67c3 Improve performance of per-system attributes
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.
2024-01-11 17:35:01 -08:00

38 lines
958 B
Nix

# flakelight -- Framework for simplifying flake setup
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT
{ config, lib, flakelight, genSystems, ... }:
let
inherit (lib) isFunction mapAttrs mkMerge mkOption mkIf;
inherit (lib.types) lazyAttrsOf nullOr;
inherit (flakelight.types) function optFunctionTo;
wrapBundler = pkgs: bundler: drv:
if isFunction (bundler (pkgs // drv)) then bundler pkgs drv else bundler drv;
in
{
options = {
bundler = mkOption {
type = nullOr function;
default = null;
};
bundlers = mkOption {
type = nullOr (optFunctionTo (lazyAttrsOf function));
default = null;
};
};
config = mkMerge [
(mkIf (config.bundler != null) {
bundlers.default = config.bundler;
})
(mkIf (config.bundlers != null) {
outputs.bundlers = genSystems (pkgs:
mapAttrs (_: wrapBundler pkgs) (config.bundlers pkgs));
})
];
}