nuclei: 3.3.5 -> 3.3.6 (#358083)
[NixPkgs.git] / maintainers / scripts / dep-licenses.sh
blob816dcf6d7f768d4b60da9700e12d4eb25c661167
1 #!/bin/sh
3 attr=$1
5 : ${NIXPKGS=/etc/nixos/nixpkgs}
7 tmp=$(mktemp --tmpdir -d nixpkgs-dep-license.XXXXXX)
9 exitHandler() {
10 exitCode=$?
11 rm -rf "$tmp"
12 return $exitCode
15 trap "exitHandler" EXIT
17 # fetch the trace and the drvPath of the attribute.
18 nix-instantiate $NIXPKGS -A $attr --show-trace > "$tmp/drvPath" 2> "$tmp/trace" || {
19 cat 1>&2 - "$tmp/trace" <<EOF
20 An error occurred while evaluating $attr.
21 EOF
22 exit 1
25 # generate a sed script based on the trace output.
26 sed '
27 \,@:.*:@, {
28 # \1 *.drv file
29 # \2 License terms
30 s,.*@:drv:\(.*\):\(.*\):@.*,s!\1!\1: \2!; t;,
31 s!Str(\\\"\([^,]*\)\\\",\[\])!\1!g
35 ' "$tmp/trace" > "$tmp/filter.sed"
37 if test $(wc -l "$tmp/filter.sed" | sed 's/ .*//') == 0; then
38 echo 1>&2 "
39 No derivation mentionned in the stack trace. Either your derivation does
40 not use stdenv.mkDerivation or you forgot to use the stdenv adapter named
41 traceDrvLicenses.
43 - defaultStdenv = allStdenvs.stdenv;
44 + defaultStdenv = traceDrvLicenses allStdenvs.stdenv;
46 exit 1
50 # remove all dependencies which are using stdenv.mkDerivation
51 echo '
53 ' >> "$tmp/filter.sed"
55 nix-store -q --tree $(cat "$tmp/drvPath") | sed -f "$tmp/filter.sed"
57 exit 0;