Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an option to cabal2nix hook for specifying output filename. #531

Merged
merged 5 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
''
Loading