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

View file

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