diff --git a/modules/hooks.nix b/modules/hooks.nix index 22ae7eea..43509afd 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -208,6 +208,20 @@ in }; }; }; + cabal2nix = mkOption { + description = "cabal2nix hook"; + type = types.submodule { + imports = [ hookModule ]; + options.settings = { + outputFilename = + mkOption { + type = types.str; + description = "The name of the output file generated after running `cabal2nix`."; + default = "default.nix"; + }; + }; + }; + }; clippy = mkOption { description = "clippy hook"; type = types.submodule @@ -2034,9 +2048,9 @@ in cabal2nix = { name = "cabal2nix"; - description = "Run `cabal2nix` on all `*.cabal` files to generate corresponding `default.nix` files"; + description = "Run `cabal2nix` on all `*.cabal` files to generate corresponding `.nix` files"; package = tools.cabal2nix-dir; - entry = "${hooks.cabal2nix.package}/bin/cabal2nix-dir"; + entry = "${hooks.cabal2nix.package}/bin/cabal2nix-dir --outputFileName=${hooks.cabal2nix.settings.outputFilename}"; files = "\\.cabal$"; after = [ "hpack" ]; }; diff --git a/nix/cabal2nix-dir/default.nix b/nix/cabal2nix-dir/default.nix index 18100d2c..331c7bd1 100644 --- a/nix/cabal2nix-dir/default.nix +++ b/nix/cabal2nix-dir/default.nix @@ -2,10 +2,21 @@ writeScriptBin "cabal2nix-dir" ''#!/usr/bin/env bash projectdir="$(pwd)" - for cabalFile in "''$@"; do + outputFileName="" + cabalFiles=() + + for arg in "$@"; do + if [[ "$arg" == --outputFileName=* ]]; then + outputFileName="''${arg#--outputFileName=}" + else + cabalFiles+=("$arg") + fi + done + + for cabalFile in "''${cabalFiles[@]}"; do echo "$cabalFile" dir="$(dirname $cabalFile)" cd "$projectdir/$dir" - ${cabal2nix}/bin/cabal2nix --no-hpack . > default.nix + ${cabal2nix}/bin/cabal2nix --no-hpack . > "$outputFileName" done ''