Skip to content

Commit 5216610

Browse files
committed
fix(nix): simplify cabal wrappers to execute speculatively
- Drop file filtering loops in cabal-fmt.nix and cabal-gild.nix - Use git ls-files -z | xargs to run formatter on all .cabal files - Avoid strict detection of cabal file args to simplify wrapper logic
1 parent dc6e962 commit 5216610

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

programs/cabal-fmt.nix

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,11 @@ in
4242
# Override command to filter out non-cabal files
4343
command = pkgs.writeShellApplication {
4444
name = "cabal-fmt-wrapper";
45-
text = ''
46-
cabal_files=()
47-
for file in "$@"; do
48-
# Only process .cabal files
49-
case "$file" in
50-
*.cabal)
51-
cabal_files+=("$file")
52-
;;
53-
*)
54-
# Skip non-cabal files (e.g., .hs files)
55-
;;
56-
esac
57-
done
58-
59-
if [ ''${#cabal_files[@]} -gt 0 ]; then
60-
${lib.getExe cfg.package} --inplace "''${cabal_files[@]}"
61-
fi
62-
'';
45+
# The cabal file needs to be formatted by a formatter along with other Haskell source code.
46+
# For example, module completion by `cabal-fmt: discover`.
47+
# It is difficult to determine this strictly.
48+
# Since formatting with cabal-fmt doesn't take much time, we execute it speculatively.
49+
text = ''${pkgs.git}/bin/git ls-files -z "*.cabal"|${pkgs.parallel}/bin/parallel --null "${lib.getExe cfg.package} --inplace {}"'';
6350
};
6451
# Clear args since we're handling them in the wrapper
6552
options = lib.mkForce [ ];

programs/cabal-gild.nix

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,11 @@ in
4646
# https://github.com/tfausak/cabal-gild/issues/35
4747
command = pkgs.writeShellApplication {
4848
name = "cabal-gild-wrapper";
49-
text = ''
50-
for file in "$@"; do
51-
# Only process .cabal files and cabal.project files
52-
case "$file" in
53-
*.cabal|cabal.project|cabal.project.local)
54-
${lib.getExe cfg.package} --io="$file"
55-
;;
56-
*)
57-
# Skip non-cabal files (e.g., .hs files)
58-
;;
59-
esac
60-
done
61-
'';
49+
# The cabal file needs to be formatted by a formatter along with other Haskell source code.
50+
# For example, module completion by `cabal-gild: discover`.
51+
# It is difficult to determine this strictly.
52+
# Since formatting with cabal-gild doesn't take much time, we execute it speculatively.
53+
text = ''${pkgs.git}/bin/git ls-files -z "*.cabal"|${pkgs.parallel}/bin/parallel --null "${lib.getExe cfg.package} --io {}"'';
6254
};
6355
};
6456
};

0 commit comments

Comments
 (0)