Skip to content

Commit

Permalink
Move checks to project.ncl
Browse files Browse the repository at this point in the history
It's unclear if we need to implement runCommand ourselves, it's quite
simple to achieve necesary result with plaing NixpkgsPkg override.

Introduce NixEnvironmentVariable contract to handle all possible things
than might end up in `env`.

Part of #58.
  • Loading branch information
YorikSar committed Sep 29, 2023
1 parent 136b6be commit 5a7c295
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
25 changes: 0 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,6 @@
program = pkgs.lib.getExe testScript;
};
};

checks.alejandra = pkgs.runCommand "check-alejandra" {} ''
${pkgs.lib.getExe pkgs.alejandra} --check ${self}
touch $out
'';

checks.nickel-format =
pkgs.runCommand "check-nickel-format" {
buildInputs = [
inputs.nickel.packages.${system}.nickel-lang-cli
];
} ''
cd ${self}
failed=""
for f in $(find . -name future -prune -or -name '*.ncl' -print); do
if ! diff -u "$f" <(nickel format -f "$f"); then
failed="$failed $f"
fi
done
if [ "$failed" != "" ]; then
echo "Following files need to be formatted: $failed"
exit 1
fi
touch $out
'';
}
);
}
4 changes: 2 additions & 2 deletions lib/builders.ncl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let { NickelDerivation, Derivation, NixString, .. } = import "contracts.ncl" in
let { NickelDerivation, Derivation, NixString, NixEnvironmentVariable, .. } = import "contracts.ncl" in

let lib = import "lib.ncl" in

Expand Down Expand Up @@ -56,7 +56,7 @@ in
},
structured_env = {},
env = {
stdenv = lib.import_nix "nixpkgs#stdenv"
stdenv | default = lib.import_nix "nixpkgs#stdenv",
},
nix_drv = env & structured_env,
}
Expand Down
40 changes: 40 additions & 0 deletions project.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,45 @@ let import_nix = organist.lib.import_nix in
nls = import_nix "nickel#lsp-nls",
},
},

flake.checks
| {
_ | {
version
= "",
env.stdenv
= import_nix "nixpkgs#stdenvNoCC",
..
}
}
| { _ | organist.builders.NixpkgsPkg }
= {
alejandra = {
name = "check-alejandra",
env.buildCommand = nix-s%"
%{import_nix "nixpkgs#alejandra"}/bin/alejandra --check %{import_nix "self"}
touch $out
"%,
},

nickel-format = {
name = "check-nickel-format",
env.buildInputs.nickel = import_nix "nickel#nickel-lang-cli",
env.buildCommand = nix-s%"
cd %{import_nix "self"}
failed=""
for f in $(find . -name future -prune -or -name '*.ncl' -print); do
if ! diff -u "$f" <(nickel format -f "$f"); then
failed="$failed $f"
fi
done
if [ "$failed" != "" ]; then
echo "Following files need to be formatted: $failed"
exit 1
fi
touch $out
"%,
},
},
}
| organist.contracts.OrganistExpression

0 comments on commit 5a7c295

Please sign in to comment.