From 8fb3bbe77c74f2b7249d769d2eb462df917bbdc1 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:22:28 -0400 Subject: [PATCH] Change `autoWire` to be an enum type (#143) --- CHANGELOG.md | 1 + nix/flake-module.nix | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea7fcb7..f254851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - #134: Add `autoWire` option to control generation of flake outputs - #138: Add `checks` to `outputs` submodule + - #143: Changed `autoWire` to be an enum type, for granular controlling of which outputs to autowire. ## 0.2.0 (Mar 13, 2023) diff --git a/nix/flake-module.nix b/nix/flake-module.nix index 04dee0b..d533b26 100644 --- a/nix/flake-module.nix +++ b/nix/flake-module.nix @@ -263,17 +263,21 @@ in This is an internal option, not meant to be set by the user. ''; }; - autoWire = mkOption { - type = types.bool; - description = '' - Automatically wire up the project outputs to the flake outputs. + autoWire = + let + outputTypes = [ "packages" "checks" "devShells" ]; + in + mkOption { + type = types.listOf (types.enum outputTypes); + description = '' + List of flake output types to autowire. - Disable this if you want to control the flake outputs - yourself. Useful, for example, when overriding the default - shell. - ''; - default = true; - }; + Using an empty list will disable autowiring entirely, + enabling you to manually wire them using + `config.haskellProjects..outputs`. + ''; + default = outputTypes; + }; }; }) ]; @@ -291,6 +295,7 @@ in let # Like mapAttrs, but merges the values (also attrsets) of the resulting attrset. mergeMapAttrs = f: attrs: lib.mkMerge (lib.mapAttrsToList f attrs); + contains = k: vs: lib.any (x: x == k) vs; in { packages = @@ -305,19 +310,19 @@ in then packageName else "${name}-${packageName}"; in - lib.optionalAttrs project.autoWire (mapKeys dropDefaultPrefix project.outputs.localPackages)) + lib.optionalAttrs (contains "packages" project.autoWire) (mapKeys dropDefaultPrefix project.outputs.localPackages)) config.haskellProjects; devShells = mergeMapAttrs (name: project: - lib.optionalAttrs (project.autoWire && project.devShell.enable) { + lib.optionalAttrs (contains "devShells" project.autoWire && project.devShell.enable) { "${name}" = project.outputs.devShell; }) config.haskellProjects; checks = mergeMapAttrs (name: project: - lib.optionalAttrs project.autoWire project.outputs.checks + lib.optionalAttrs (contains "checks" project.autoWire) project.outputs.checks ) config.haskellProjects; };