From d7c7f4634a7f0ddb2a85e1f27f965fcc8caf9092 Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Sun, 5 Nov 2023 15:14:26 -0800 Subject: [PATCH] Add support for bundlers --- api_guide.md | 36 ++++++++++++++++++++++++++++++++++++ builtinModules/bundlers.nix | 37 +++++++++++++++++++++++++++++++++++++ builtinModules/nixDir.nix | 4 ++++ 3 files changed, 77 insertions(+) create mode 100644 builtinModules/bundlers.nix diff --git a/api_guide.md b/api_guide.md index 783ead9..de5bd86 100644 --- a/api_guide.md +++ b/api_guide.md @@ -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 diff --git a/builtinModules/bundlers.nix b/builtinModules/bundlers.nix new file mode 100644 index 0000000..decc406 --- /dev/null +++ b/builtinModules/bundlers.nix @@ -0,0 +1,37 @@ +# flakelight -- Framework for simplifying flake setup +# Copyright (C) 2023 Archit Gupta +# 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; + }; + }) + ]; +} diff --git a/builtinModules/nixDir.nix b/builtinModules/nixDir.nix index 3be433b..9559ff6 100644 --- a/builtinModules/nixDir.nix +++ b/builtinModules/nixDir.nix @@ -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; })