From 66da4ffe1751dd8069cb8a5e9555734a790692f3 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Tue, 4 Aug 2020 22:51:27 +0200 Subject: [PATCH 1/3] feat(build): check that we copied all binaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometmmes a new binary is added to an output, like in the `dhall-yaml` case, where yaml-to-dhall was added. This uses `lr` because I can’t be bothered to figure out how to use `find` to the same effect. --- build.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/build.nix b/build.nix index 1575ef2..a531338 100644 --- a/build.nix +++ b/build.nix @@ -24,7 +24,15 @@ pkgs.stdenv.mkDerivation rec { installPhase = '' mkdir -p $out/bin binPath="$out/bin/${binName}" - install -D -m555 -T ${binName} "$binPath" + install -D -m555 -T "${binName}" "$binPath" + rm "${binName}" + + # check that we didn’t forget any files (maybe a new binary was added) + if [ ! -z "$(${pkgs.lr}/bin/lr -1 -t 'depth == 1' .)" ]; then + echo "still some files remaining!" >&2 + ${pkgs.lr}/bin/lr . + exit 1 + fi "$binPath" --bash-completion-script "$binPath" > "${binName}.bash" installShellCompletion --bash "${binName}.bash" From f0270205ee1a4871aba36869969af9595ac68d81 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Tue, 4 Aug 2020 23:04:23 +0200 Subject: [PATCH 2/3] feat(build): allow multiple binaries I gave in because I wanted to use yaml-to-dhall, so this implements copying multiple binaries. --- build.nix | 27 +++++++++++++++++---------- dhall-bash-simple.nix | 2 +- dhall-lsp-simple.nix | 2 +- dhall-nix-simple.nix | 2 +- dhall-simple.nix | 2 +- dhall-yaml-simple.nix | 2 +- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/build.nix b/build.nix index a531338..22ea7e8 100644 --- a/build.nix +++ b/build.nix @@ -1,6 +1,6 @@ { pkgs, release }: -{ simpleName, binName, attrName }: +{ simpleName, binNames, attrName }: let release = import ./release.nix; @@ -23,9 +23,22 @@ pkgs.stdenv.mkDerivation rec { installPhase = '' mkdir -p $out/bin - binPath="$out/bin/${binName}" - install -D -m555 -T "${binName}" "$binPath" - rm "${binName}" + + ${pkgs.lib.concatMapStringsSep "\n" (binName: '' + binPath="$out/bin/${binName}" + install -D -m555 -T "${binName}" "$binPath" + rm "${binName}" + + "$binPath" --bash-completion-script "$binPath" > "${binName}.bash" + installShellCompletion --bash "${binName}.bash" + rm "${binName}.bash" + "$binPath" --zsh-completion-script "$binPath" > "${binName}.zsh" + installShellCompletion --zsh "${binName}.zsh" + rm "${binName}.zsh" + "$binPath" --fish-completion-script "$binPath" > "${binName}.fish" + installShellCompletion --fish "${binName}.fish" + rm "${binName}.fish" + '') binNames} # check that we didn’t forget any files (maybe a new binary was added) if [ ! -z "$(${pkgs.lr}/bin/lr -1 -t 'depth == 1' .)" ]; then @@ -34,11 +47,5 @@ pkgs.stdenv.mkDerivation rec { exit 1 fi - "$binPath" --bash-completion-script "$binPath" > "${binName}.bash" - installShellCompletion --bash "${binName}.bash" - "$binPath" --zsh-completion-script "$binPath" > "${binName}.zsh" - installShellCompletion --zsh "${binName}.zsh" - "$binPath" --fish-completion-script "$binPath" > "${binName}.fish" - installShellCompletion --fish "${binName}.fish" ''; } diff --git a/dhall-bash-simple.nix b/dhall-bash-simple.nix index 79cd13e..2704763 100644 --- a/dhall-bash-simple.nix +++ b/dhall-bash-simple.nix @@ -2,6 +2,6 @@ import ./build.nix { inherit pkgs; release = import ./release.nix; } { simpleName = "dhall-bash-simple"; - binName = "dhall-to-bash"; + binNames = [ "dhall-to-bash" ]; attrName = "dhall-bash"; } diff --git a/dhall-lsp-simple.nix b/dhall-lsp-simple.nix index 943ed1c..9c12846 100644 --- a/dhall-lsp-simple.nix +++ b/dhall-lsp-simple.nix @@ -2,6 +2,6 @@ import ./build.nix { inherit pkgs; release = import ./release.nix; } { simpleName = "dhall-lsp-simple"; - binName = "dhall-lsp-server"; + binNames = [ "dhall-lsp-server" ]; attrName = "dhall-lsp-server"; } diff --git a/dhall-nix-simple.nix b/dhall-nix-simple.nix index 5c7f59f..3c3c5c5 100644 --- a/dhall-nix-simple.nix +++ b/dhall-nix-simple.nix @@ -2,6 +2,6 @@ import ./build.nix { inherit pkgs; release = import ./release.nix; } { simpleName = "dhall-nix-simple"; - binName = "dhall-to-nix"; + binNames = [ "dhall-to-nix" ]; attrName = "dhall-nix"; } diff --git a/dhall-simple.nix b/dhall-simple.nix index 3a023ba..f37bef5 100644 --- a/dhall-simple.nix +++ b/dhall-simple.nix @@ -2,6 +2,6 @@ import ./build.nix { inherit pkgs; release = import ./release.nix; } { simpleName = "dhall-simple"; - binName = "dhall"; + binNames = [ "dhall" ]; attrName = "dhall"; } diff --git a/dhall-yaml-simple.nix b/dhall-yaml-simple.nix index 7fe8c33..1c0a8cd 100644 --- a/dhall-yaml-simple.nix +++ b/dhall-yaml-simple.nix @@ -2,6 +2,6 @@ import ./build.nix { inherit pkgs; release = import ./release.nix; } { simpleName = "dhall-yaml-simple"; - binName = "dhall-to-yaml-ng"; + binNames = [ "dhall-to-yaml-ng" "yaml-to-dhall" ]; attrName = "dhall-yaml"; } From 953cf8b3eac3f6ef438b2d519797f940e057ad5d Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Tue, 4 Aug 2020 23:05:20 +0200 Subject: [PATCH 3/3] feat(dhall-json): use build.nix Since we now support multiple binaries in build.nix, we can also use it for dhall-json. --- dhall-json-simple.nix | 51 ++++--------------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/dhall-json-simple.nix b/dhall-json-simple.nix index bb99ba7..cceb52a 100644 --- a/dhall-json-simple.nix +++ b/dhall-json-simple.nix @@ -1,50 +1,7 @@ { pkgs ? import {} }: -let - release = import ./release.nix; -in - -pkgs.stdenv.mkDerivation rec { - name = "dhall-json-simple"; - - src = if pkgs.stdenv.isDarwin - then pkgs.fetchzip { - url = release.dhall-json-darwin.url; - sha256 = release.dhall-json-darwin.hash; - } - else pkgs.fetchzip { - url = release.dhall-json-linux.url; - sha256 = release.dhall-json-linux.hash; - }; - - nativeBuildInputs = [ pkgs.installShellFiles ]; - - installPhase = '' - mkdir -p $out/bin - DHALL_TO_JSON=$out/bin/dhall-to-json - DHALL_TO_YAML=$out/bin/dhall-to-yaml - JSON_TO_DHALL=$out/bin/json-to-dhall - install -D -m555 -T dhall-to-json $DHALL_TO_JSON - install -D -m555 -T dhall-to-yaml $DHALL_TO_YAML - install -D -m555 -T json-to-dhall $JSON_TO_DHALL - - "$DHALL_TO_JSON" --bash-completion-script "$DHALL_TO_JSON" > "dhall-to-json.bash" - "$DHALL_TO_YAML" --bash-completion-script "$DHALL_TO_YAML" > "dhall-to-yaml.bash" - "$JSON_TO_DHALL" --bash-completion-script "$JSON_TO_DHALL" > "json-to-dhall.bash" - installShellCompletion --bash "dhall-to-json.bash" - installShellCompletion --bash "dhall-to-yaml.bash" - installShellCompletion --bash "json-to-dhall.bash" - "$DHALL_TO_JSON" --zsh-completion-script "$DHALL_TO_JSON" > "dhall-to-json.zsh" - "$DHALL_TO_YAML" --zsh-completion-script "$DHALL_TO_YAML" > "dhall-to-yaml.zsh" - "$JSON_TO_DHALL" --zsh-completion-script "$JSON_TO_DHALL" > "json-to-dhall.zsh" - installShellCompletion --zsh "dhall-to-json.zsh" - installShellCompletion --zsh "dhall-to-yaml.zsh" - installShellCompletion --zsh "json-to-dhall.zsh" - "$DHALL_TO_JSON" --fish-completion-script "$DHALL_TO_JSON" > "dhall-to-json.fish" - "$DHALL_TO_YAML" --fish-completion-script "$DHALL_TO_YAML" > "dhall-to-yaml.fish" - "$JSON_TO_DHALL" --fish-completion-script "$JSON_TO_DHALL" > "json-to-dhall.fish" - installShellCompletion --fish "dhall-to-json.fish" - installShellCompletion --fish "dhall-to-yaml.fish" - installShellCompletion --fish "json-to-dhall.fish" - ''; +import ./build.nix { inherit pkgs; release = import ./release.nix; } { + simpleName = "dhall-json-simple"; + binNames = [ "dhall-to-json" "dhall-to-yaml" "json-to-dhall" ]; + attrName = "dhall-json"; }