Skip to content

Commit

Permalink
Merge pull request #531 from rsrohitsingh682/cabal2nix
Browse files Browse the repository at this point in the history
feat: add an option to `cabal2nix` hook for specifying output filename.
  • Loading branch information
sandydoo authored Dec 21, 2024
2 parents 0ddd26d + a971492 commit f0f0dc4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
18 changes: 16 additions & 2 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" ];
};
Expand Down
15 changes: 13 additions & 2 deletions nix/cabal2nix-dir/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
''

0 comments on commit f0f0dc4

Please sign in to comment.