flakelight/builtinModules/bundlers.nix

39 lines
948 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, ... }:
let
inherit (lib) isFunction mapAttrs mkMerge mkOption mkIf;
inherit (lib.types) lazyAttrsOf nullOr;
inherit (flakelight.types) function optFunctionTo;
2023-11-06 00:14:26 +01:00
wrapBundler = pkgs: bundler: drv:
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 = nullOr function;
2023-11-06 00:14:26 +01:00
default = null;
};
bundlers = mkOption {
type = nullOr (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) {
perSystem = pkgs: {
bundlers = mapAttrs (_: wrapBundler pkgs) (config.bundlers pkgs);
2023-11-06 00:14:26 +01:00
};
})
];
}