Skip to content

Commit

Permalink
feat(back): #1332 add check flag to nixfmt
Browse files Browse the repository at this point in the history
- Run check only in CI, locally it will format the code
- Update docs to show the use of nixfmt
instead of Alejandra

Signed-off-by: Robin Quintero <rohaquinlop301@gmail.com>
  • Loading branch information
rohaquinlop committed Jun 24, 2024
1 parent dcb3432 commit 8bd145f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/api/builtins/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Example:
## formatNix

Ensure that Nix code is formatted
according to [Alejandra](https://github.com/kamadorueda/alejandra).
according to [nixfmt](https://github.com/NixOS/nixfmt).

Types:

Expand Down
15 changes: 15 additions & 0 deletions smiley.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{system ? builtins.currentSystem}: let
agnostic = import ./src/args/agnostic.nix {inherit system;};

args =
agnostic
// {
outputs."/cli/env/runtime" =
import ./makes/cli/env/runtime/main.nix args;
outputs."/cli/env/runtime/pypi" =
import ./makes/cli/env/runtime/pypi/main.nix args;
projectPath = import ./src/args/project-path args;
projectSrc = ./.;
};
in
import ./makes/main.nix args
6 changes: 5 additions & 1 deletion src/args/format-nix/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

function main {
source __argTargets__/template local targets
local args=()

info Formatting Nix code \
&& if running_in_ci_cd_provider; then
args+=(--check)
fi \
&& for target in "${targets[@]}"; do
info Formatting "${target}" \
&& if ! nixfmt "${target}"; then
&& if ! nixfmt "${args[@]}" "${target}"; then
info Source code was formated, the job will fail \
&& error Failing as promised...
fi \
Expand Down

0 comments on commit 8bd145f

Please sign in to comment.