Skip to content

Commit

Permalink
Add nixfmt tool
Browse files Browse the repository at this point in the history
  • Loading branch information
tbidne committed Feb 9, 2024
1 parent 0daf260 commit 76ae0cb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- nixfmt

pull_request:
branches:
Expand All @@ -26,6 +27,8 @@ jobs:
cmd: "nix run .#fourmolu -- --help"
- name: "hlint"
cmd: "nix run .#hlint -- --help"
- name: "nixfmt"
cmd: "nix run .#nixfmt"
- name: "nixpkgs-fmt"
cmd: "nix run .#nixpkgs-fmt"
- name: "ormolu"
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
[![Static Badge](https://img.shields.io/badge/hie-0.1.4.0-orange)](#hie)

###### Nix Formatters
[![Static Badge](https://img.shields.io/badge/nixfmt-?.?.?-orange)](#nixfmt)
[![Static Badge](https://img.shields.io/badge/nixpkgs--fmt-1.3.0-orange)](#nixpkgs-fmt)

</div>
Expand Down Expand Up @@ -216,6 +217,20 @@ nix run github:tbidne/nix-hs-tools#hie

## Nix Formatters

### Nixfmt

**Source:** https://github.com/serokell/nixfmt

**Description:** The `nixfmt` formatter. Recursively formats all `*.nix` files in the current directory or `--dir`.

**Usage:** `nixfmt [--dir PATH] <args>`.

**Examples:**

```
nix run github:tbidne/nix-hs-tools#nixpkgs-fmt
```

### Nixpkgs-Fmt

**Source:** https://github.com/nix-community/nixpkgs-fmt
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
\tHaskell Miscellaneous:
\t - hie: ${compiler.implicit-hie.version}
\tNix Formatters:
\t - nixfmt: ${pkgs.nixfmt.version}
\t - nixpkgs-fmt: ${pkgs.nixpkgs-fmt.version}
\tInformation:
\t - help
Expand Down Expand Up @@ -79,6 +80,7 @@

hie = import ./tools/hie.nix compilerPkgs;
hlint = import ./tools/hlint.nix compilerPkgs;
nixfmt = import ./tools/nixfmt.nix { inherit nix-hs-utils pkgs; };
nixpkgs-fmt = import ./tools/nixpkgs-fmt.nix { inherit nix-hs-utils pkgs; };
ormolu = import ./tools/ormolu.nix compilerPkgs;
stylish = import ./tools/stylish.nix compilerPkgs;
Expand Down
29 changes: 29 additions & 0 deletions tools/nixfmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ nix-hs-utils
, pkgs
}:

nix-hs-utils.mkShellApp {
inherit pkgs;
name = "nixfmt";
text = ''
set -e
args=()
dir=.
while [ $# -gt 0 ]; do
if [[ $1 == "--nh-help" ]]; then
echo "usage: nixfmt [--dir PATH] <args>"
exit 0
elif [[ $1 == "--dir" ]]; then
dir=$2
shift 1
else
args+=("$1")
fi
shift
done
# shellcheck disable=SC2086
${pkgs.nixfmt}/bin/nixfmt $dir "''${args[@]}"
'';
runtimeInputs = [ pkgs.nixfmt ];
}

0 comments on commit 76ae0cb

Please sign in to comment.