From 5a7c295cb1ff3edc97d8053061ef67d7dc36aa2a Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Fri, 29 Sep 2023 15:37:25 +0200 Subject: [PATCH] Move checks to project.ncl 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 https://github.com/nickel-lang/organist/issues/58. --- flake.nix | 25 ------------------------- lib/builders.ncl | 4 ++-- project.ncl | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/flake.nix b/flake.nix index 62bc8a09..95d693f5 100644 --- a/flake.nix +++ b/flake.nix @@ -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 - ''; } ); } diff --git a/lib/builders.ncl b/lib/builders.ncl index ce90c208..ed2f231f 100644 --- a/lib/builders.ncl +++ b/lib/builders.ncl @@ -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 @@ -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, } diff --git a/project.ncl b/project.ncl index 3616fae8..4a43707c 100644 --- a/project.ncl +++ b/project.ncl @@ -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