Skip to content

Commit

Permalink
nuke-references: support -e option
Browse files Browse the repository at this point in the history
  • Loading branch information
abbradar committed Oct 18, 2015
1 parent c81fb45 commit 3c7871a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 20 additions & 5 deletions pkgs/build-support/nuke-references/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ source $stdenv/setup
mkdir -p $out/bin
cat > $out/bin/nuke-refs <<EOF
#! $SHELL -e
for i in \$*; do
if test ! -L \$i -a -f \$i; then
cat \$i | sed "s|$NIX_STORE/[a-z0-9]*-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > \$i.tmp
if test -x \$i; then chmod +x \$i.tmp; fi
mv \$i.tmp \$i
excludes=""
while getopts e: o; do
case "\$o" in
e) storeId=\$(echo "\$OPTARG" | sed -n "s|^$NIX_STORE/\\([a-z0-9]\{32\}\\)-.*|\1|p")
if [ -z "\$storeId" ]; then
echo "-e argument must be a Nix store path"
exit 1
fi
excludes="\$excludes(?!\$storeId)"
;;
esac
done
shift \$((\$OPTIND-1))
for i in "\$@"; do
if test ! -L "\$i" -a -f "\$i"; then
cat "\$i" | $perl/bin/perl -pe "s|$NIX_STORE/\$excludes[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "\$i.tmp"

This comment has been minimized.

Copy link
@lheckemann

lheckemann Mar 6, 2017

Member

Any particular reason to write to a temporary file rather than using the -i flag for perl?

This comment has been minimized.

Copy link
@abbradar

abbradar Mar 6, 2017

Author Member

I think none, apart from me copying the old code and not knowing about this flag.

This comment has been minimized.

Copy link
@lheckemann

lheckemann Mar 6, 2017

Member

Great, thanks. Just checking, as I'm working on a similar script which would remove only specific references and was wondering if there was a reason not to use -i.

This comment has been minimized.

Copy link
@abbradar

abbradar Mar 6, 2017

Author Member

Awesome! I wanted this several times but was too lazy to implement, consider me interested :3

This comment has been minimized.

Copy link
@lheckemann

lheckemann Mar 6, 2017

Member

#23560 :)

if test -x "\$i"; then chmod +x "\$i.tmp"; fi
mv "\$i.tmp" "\$i"
fi
done
EOF
Expand Down
5 changes: 3 additions & 2 deletions pkgs/build-support/nuke-references/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# path (/nix/store/eeee...). This is useful for getting rid of
# dependencies that you know are not actually needed at runtime.

{stdenv}:
{ stdenv, perl }:

stdenv.mkDerivation {
name = "nuke-references";
builder = ./builder.sh;
}
inherit perl;
}

0 comments on commit 3c7871a

Please sign in to comment.