Add support for bundlers

This commit is contained in:
Archit Gupta 2023-11-05 15:14:26 -08:00
parent 6d00e0f544
commit d7c7f4634a
3 changed files with 77 additions and 0 deletions

View File

@ -610,6 +610,42 @@ For example, to set Rust and Zig formatters:
}
```
### bundlers
The `bundler` and `bundlers` options allow you to set `bundlers.${system}`
outputs.
`bundlers` is an attribute set of bundler functions or a function that takes
packages and returns an attribute set of bundler functions.
`bundler` sets `bundlers.default`.
For example, a bundler that returns the passed package:
```nix
{
inputs.flakelight.url = "github:accelbread/flakelight";
outputs = { flakelight, ... }:
flakelight ./. {
bundler = x: x;
};
}
```
As another example, a bundler that always returns `hello`:
```nix
{
inputs.flakelight.url = "github:accelbread/flakelight";
outputs = { flakelight, ... }:
flakelight ./. {
bundlers = { hello, ... }: {
default = x: hello;
};
};
}
```
### nixosConfigurations and homeConfigurations
The `nixosConfigurations` and `homeConfigurations` attributes let you set

View File

@ -0,0 +1,37 @@
# flakelight -- Framework for simplifying flake setup
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT
{ config, lib, flakelight, ... }:
let
inherit (lib) mkMerge mkOption mkIf;
inherit (lib.types) functionTo lazyAttrsOf nullOr package uniq;
inherit (flakelight.types) optFunctionTo;
bundler = uniq (functionTo package);
in
{
options = {
bundler = mkOption {
type = nullOr bundler;
default = null;
};
bundlers = mkOption {
type = nullOr (optFunctionTo (lazyAttrsOf bundler));
default = { };
};
};
config = mkMerge [
(mkIf (config.bundler != null) {
bundlers.default = config.bundler;
})
(mkIf (config.bundlers != null) {
perSystem = pkgs: {
bundlers = config.bundlers pkgs;
};
})
];
}

View File

@ -35,6 +35,8 @@ in
template = autoImportArgs' "template";
templates = autoImportArgs' "templates";
formatters = autoImport' "formatters";
bundler = autoImport' "bundler";
bundlers = autoImport' "bundlers";
nixosModule = autoImport' "nixosModule";
nixosModules = autoImportArgs' "nixosModules";
nixosConfigurations = autoImportArgs' [ "nixosConfigurations" "nixos" ];
@ -72,6 +74,8 @@ in
(mkIf (template != null) { inherit template; })
(mkIf (templates != null) { inherit templates; })
(mkIf (formatters != null) { inherit formatters; })
(mkIf (bundler != null) { inherit bundler; })
(mkIf (bundlers != null) { inherit bundlers; })
(mkIf (nixosModule != null) { inherit nixosModule; })
(mkIf (nixosModules != null) { inherit nixosModules; })
(mkIf (nixosConfigurations != null) { inherit nixosConfigurations; })