pkgs: diff-flake: use 'makeWrapper'

This makes it easier to test the script, as I just run it normally
without building it.
This commit is contained in:
Bruno BELANYI 2021-04-27 17:14:49 +00:00
parent 12475ff3a8
commit 2a1dda12d4
2 changed files with 23 additions and 17 deletions

View file

@ -1,13 +1,14 @@
{ coreutils, git, gnused, lib, shellcheck, stdenvNoCC }: { coreutils, git, gnused, makeWrapper, lib, shellcheck, stdenvNoCC }:
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation rec {
pname = "diff-flake"; pname = "diff-flake";
version = "0.1.0"; version = "0.1.0";
src = ./diff-flake; src = ./diff-flake;
phases = [ "buildPhase" "installPhase" ]; phases = [ "buildPhase" "installPhase" "fixupPhase" ];
buildInputs = [ buildInputs = [
makeWrapper
shellcheck shellcheck
]; ];
@ -17,15 +18,20 @@ stdenvNoCC.mkDerivation {
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp $src $out/bin/diff-flake cp $src $out/bin/${pname}
substituteAllInPlace $out/bin/diff-flake chmod a+x $out/bin/${pname}
patchShebangs $out/bin/diff-flake
''; '';
cat = "${coreutils}/bin/cat"; wrapperPath = lib.makeBinPath [
mktemp = "${coreutils}/bin/mktemp"; coreutils
git = "${git}/bin/git"; git
sed = "${gnused}/bin/sed"; gnused
];
fixupPhase = ''
patchShebangs $out/bin/${pname}
wrapProgram $out/bin/${pname} --prefix PATH : "${wrapperPath}"
'';
meta = with lib; { meta = with lib; {
description = "Nix flake helper to visualize changes in closures"; description = "Nix flake helper to visualize changes in closures";

View file

@ -3,7 +3,7 @@
set -eu set -eu
NEW_REV= NEW_REV=
PREVIOUS_REV="$(@git@ rev-parse @~)" PREVIOUS_REV="$(git rev-parse @~)"
OUTPUT_FILE=/dev/stdout OUTPUT_FILE=/dev/stdout
FLAKE_OUTPUTS=() FLAKE_OUTPUTS=()
NIX_BUILD_ARGS=() NIX_BUILD_ARGS=()
@ -14,9 +14,9 @@ print_err() {
sanitize_output() { sanitize_output() {
if [ "$OUTPUT_FILE" != "/dev/stdout" ]; then if [ "$OUTPUT_FILE" != "/dev/stdout" ]; then
@sed@ 's/\x1b\[[0-9;]*m//g' sed 's/\x1b\[[0-9;]*m//g'
else else
@cat@ cat
fi fi
} }
@ -61,11 +61,11 @@ parse_args() {
shift shift
;; ;;
-n|--new-rev) -n|--new-rev)
NEW_REV="$(@git@ rev-parse "$1")" NEW_REV="$(git rev-parse "$1")"
shift shift
;; ;;
-p|--previous-rev) -p|--previous-rev)
PREVIOUS_REV="$(@git@ rev-parse "$1")" PREVIOUS_REV="$(git rev-parse "$1")"
shift shift
;; ;;
--) --)
@ -98,8 +98,8 @@ fill_default_outputs() {
diff_output() { diff_output() {
local PREV NEW; local PREV NEW;
PREV="$(@mktemp@ --dry-run)" PREV="$(mktemp --dry-run)"
NEW="$(@mktemp@ --dry-run)" NEW="$(mktemp --dry-run)"
nix build "${NIX_BUILD_ARGS[@]}" ".?rev=${PREVIOUS_REV}#$1" -o "$PREV" nix build "${NIX_BUILD_ARGS[@]}" ".?rev=${PREVIOUS_REV}#$1" -o "$PREV"
nix build "${NIX_BUILD_ARGS[@]}" ".${NEW_REV:+?rev=$NEW_REV}#$1" -o "$NEW" nix build "${NIX_BUILD_ARGS[@]}" ".${NEW_REV:+?rev=$NEW_REV}#$1" -o "$NEW"