packages: Add wrapper script for nixf-tidy

Now it's possible to use this package in the ci.
This commit is contained in:
Donovan Glover 2024-08-08 22:39:00 -04:00
parent 6e5c2c606b
commit db29d97fe2
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65

83
packages/nixf-tidy.nix Normal file
View File

@ -0,0 +1,83 @@
{
lib,
stdenvNoCC,
writeTextFile,
makeWrapper,
git,
fd,
jq,
nixf,
}:
let
script = writeTextFile {
name = "nixf-tidy";
text = # fish
''
#!/usr/bin/env fish
if test "$(git rev-parse --is-inside-work-tree)" != "true"
echo "Not inside a git directory. Aborting."
exit 1
end
echo " Checking for issues with nixf-tidy..."
set DID_ERROR 0
for FILE in **/*.nix
set RESULT $(cat "$FILE" | nixf-tidy --variable-lookup)
if test "$RESULT" != "[]"
echo "===================================="
echo " nixd found issues in $FILE:"
echo "===================================="
echo "$RESULT" | jq ".[] | .message, .args, .range.lCur.line"
set DID_ERROR 1
else
echo " $FILE"
end
end
exit $DID_ERROR
'';
};
in
stdenvNoCC.mkDerivation {
pname = "nixf-tidy";
version = "0.1.0";
dontUnpack = true;
nativeBuildInputs = [
makeWrapper
];
installPhase = ''
runHook preInstall
install -Dm755 ${script} $out/bin/nixf-tidy
runHook postInstall
'';
postInstall = ''
wrapProgram $out/bin/nixf-tidy \
--prefix PATH ":" "${lib.makeBinPath [
git
fd
jq
nixf
]}"
'';
meta = {
homepage = "https://github.com/nix-community/nixd/blob/main/libnixf/README.md#nixf-tidy";
description = "Dedicated tool tailored for linting Nix projects";
license = lib.licenses.lgpl3Plus;
maintainers = with lib.maintainers; [ donovanglover ];
mainProgram = "nixf-tidy";
platforms = lib.platforms.linux;
};
}