flakelight/builtinModules/bundlers.nix

40 lines
972 B
Nix
Raw Normal View History

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