From 00efa9c2dd8b397a09b3123dd2d720798bc28433 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sat, 21 Nov 2009 17:50:00 +0000 Subject: [PATCH] * Add a script to retrieve licenses of the current derivation and of all its dependencies. To make it works, you need to change the default stdenv as documented in the error message. ./maintainers/scripts/dep-licenses.sh svn path=/nixpkgs/trunk/; revision=18508 --- maintainers/scripts/dep-licenses.sh | 57 +++++++++++++++++++++++++++++ pkgs/stdenv/adapters.nix | 25 +++++++++++++ 2 files changed, 82 insertions(+) create mode 100755 maintainers/scripts/dep-licenses.sh diff --git a/maintainers/scripts/dep-licenses.sh b/maintainers/scripts/dep-licenses.sh new file mode 100755 index 000000000000..48c1efdeebc5 --- /dev/null +++ b/maintainers/scripts/dep-licenses.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +attr=$1 + +: ${NIXPKGS=/etc/nixos/nixpkgs} + +tmp=$(mktemp --tmpdir -d nixpkgs-dep-license.XXXXXX) + +exitHandler() { + exitCode=$? + rm -rf "$tmp" + exit $exitCode +} + +trap "exitHandler" EXIT + +# fetch the trace and the drvPath of the attribute. +nix-instantiate $NIXPKGS -A $attr --show-trace > "$tmp/drvPath" 2> "$tmp/trace" || { + cat 1>&2 - "$tmp/trace" < "$tmp/filter.sed" + +if test $(wc -l "$tmp/filter.sed" | sed 's/ .*//') == 0; then + echo 1>&2 " +No derivation mentionned in the stack trace. Either your derivation does +not use stdenv.mkDerivation or you forgot to use the stdenv adapter named +traceDrvLicenses. + +- defaultStdenv = allStdenvs.stdenv; ++ defaultStdenv = traceDrvLicenses allStdenvs.stdenv; +" + exit 1 +fi + + +# remove all dependencies which are using stdenv.mkDerivation +echo ' +d +' >> "$tmp/filter.sed" + +nix-store -q --tree $(cat "$tmp/drvPath") | sed -f "$tmp/filter.sed" + +exit 0; diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 5760c4459ad5..410cc16838d1 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -202,4 +202,29 @@ rec { (stdenv.mkDerivation args) { meta.maintainers = maintainers; }; }; + + + /* Use the trace output to report all processed derivations with their + license name. + + */ + traceDrvLicenses = stdenv: stdenv // + { mkDerivation = args: + let + pkg = stdenv.mkDerivation args; + printDrvPath = val: let + drvPath = builtins.unsafeDiscardStringContext pkg.drvPath; + license = + if pkg ? meta && pkg.meta ? license then + pkg.meta.license + else + null; + in + builtins.trace "@:drv:${toString drvPath}:${builtins.exprToString license}:@" + val; + in pkg // { + outPath = printDrvPath pkg.outPath; + drvPath = printDrvPath pkg.drvPath; + }; + }; }