git.iko.soy/typeable/nixpkgs
on master help sign in
p7zip: clarify license and remove unRAR code from src drv

The code under Compress/Rar* is licensed under a specific unRAR license Also Compress/LzfseDecoder.cpp is covered by BSD3 The unRAR code is removed from the source drv since the license posits you agree or remove the code from your hard drive This adds some complexity to updating p7zip so there is also an update script Meta has been updated and tweaked

commit4a7586cda14a078898d87c3731d5b298279c288a author06kellyjac <dev@j-k.io> dateWed 16 Mar 2022, 13:38 (5 years ago) parentdab246a
2 files changed+71−11
pkgs/tools/archivers/p7zip/default.nix+24−11 pkgs/tools/archivers/p7zip/update.sh+47
pkgs/tools/archivers/p7zip/default.nix+24−11
@@ -8,7 +8,18 @@ stdenv.mkDerivation rec {
88 owner = "jinfeihan57";
99 repo = pname;
1010 rev = "v${version}";
11− sha256 = "sha256-19F4hPV0nKVuFZNbOcXrcA1uW6Y3HQolaHVIYXGmh18=";
11+ sha256 = {
12+ free = "sha256-DrBuf2VPdcprHI6pMSmL7psm2ofOrUf0Oj0qwMjXzkk=";
13+ unfree = "sha256-19F4hPV0nKVuFZNbOcXrcA1uW6Y3HQolaHVIYXGmh18=";
14+ }.${if enableUnfree then "unfree" else "free"};
15+ # remove the unRAR related code from the src drv
16+ # > the license requires that you agree to these use restrictions,
17+ # > or you must remove the software (source and binary) from your hard disks
18+ # https://fedoraproject.org/wiki/Licensing:Unrar
19+ extraPostFetch = lib.optionalString (!enableUnfree) ''
20+ rm -r $out/CPP/7zip/Compress/Rar*
21+ find $out -name makefile'*' -exec sed -i '/Rar/d' {} +
22+ '';
1223 };
1324
1425 # Default makefile is full of impurities on Darwin. The patch doesn't hurt Linux so I'm leaving it unconditional
@@ -25,11 +36,6 @@ stdenv.mkDerivation rec {
2536 substituteInPlace makefile.machine \
2637 --replace 'CC=gcc' 'CC=${stdenv.cc.targetPrefix}gcc' \
2738 --replace 'CXX=g++' 'CXX=${stdenv.cc.targetPrefix}g++'
28− '' + lib.optionalString (!enableUnfree) ''
29− # Remove non-free RAR source code
30− # (see DOC/License.txt, https://fedoraproject.org/wiki/Licensing:Unrar)
31− rm -r CPP/7zip/Compress/Rar*
32− find . -name makefile'*' -exec sed -i '/Rar/d' {} +
3339 '';
3440
3541 makeFlags = [ "DEST_HOME=${placeholder "out"}" ];
@@ -46,13 +52,20 @@ stdenv.mkDerivation rec {
4652
4753 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=c++11-narrowing";
4854
49− meta = {
55+ passthru.updateScript = ./update.sh;
56+
57+ meta = with lib; {
5058 homepage = "https://github.com/jinfeihan57/p7zip";
5159 description = "A new p7zip fork with additional codecs and improvements (forked from https://sourceforge.net/projects/p7zip/)";
52− platforms = lib.platforms.unix;
53− maintainers = [ lib.maintainers.raskin ];
60+ license = with licenses;
61+ # p7zip code is largely lgpl2Plus
62+ # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
63+ [ lgpl2Plus /* and */ bsd3 ] ++
64+ # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
65+ # the unRAR compression code is disabled by default
66+ lib.optionals enableUnfree [ unfree ];
67+ maintainers = with maintainers; [ raskin jk ];
68+ platforms = platforms.unix;
5469 mainProgram = "7z";
55− # RAR code is under non-free UnRAR license, but we remove it
56− license = if enableUnfree then lib.licenses.unfree else lib.licenses.lgpl2Plus;
5770 };
5871}
pkgs/tools/archivers/p7zip/update.shnew file+47
@@ -0,0 +1,47 @@
1+#! /usr/bin/env nix-shell
2+#! nix-shell -i bash -p coreutils gnused curl jq
3+set -euo pipefail
4+cd "$(dirname "${BASH_SOURCE[0]}")"
5+
6+DRV_DIR="$PWD"
7+
8+OLD_VERSION="$(sed -nE 's/\s*version = "(.*)".*/\1/p' ./default.nix)"
9+
10+NEW_VERSION="$(curl https://api.github.com/repos/jinfeihan57/p7zip/releases/latest | jq .tag_name -r | tr -d 'v')"
11+
12+echo "comparing versions $OLD_VERSION => $NEW_VERSION"
13+if [[ "$OLD_VERSION" == "$NEW_VERSION" ]]; then
14+ echo "Already up to date! Doing nothing"
15+ exit 0
16+fi
17+
18+NIXPKGS_ROOT="$(realpath "$DRV_DIR/../../../..")"
19+
20+echo "getting free source hash"
21+OLD_FREE_HASH="$(nix-instantiate --eval --strict -E "with import $NIXPKGS_ROOT {}; p7zip.src.drvAttrs.outputHash" | tr -d '"')"
22+echo "getting unfree source hash"
23+OLD_UNFREE_HASH="$(nix-instantiate --eval --strict -E "with import $NIXPKGS_ROOT {}; (p7zip.override { enableUnfree = true; }).src.drvAttrs.outputHash" | tr -d '"')"
24+
25+
26+NEW_FREE_HASH=$(nix-prefetch -f "$NIXPKGS_ROOT" -E "p7zip.src" --rev "v$NEW_VERSION")
27+
28+NEW_UNFREE_OUT=$(nix-prefetch -f "$NIXPKGS_ROOT" -E "(p7zip.override { enableUnfree = true; }).src" --rev "v$NEW_VERSION" --output raw --print-path)
29+# first line of raw output is the hash
30+NEW_UNFREE_HASH="$(echo "$NEW_UNFREE_OUT" | sed -n 1p)"
31+# second line of raw output is the src path
32+NEW_UNFREE_SRC="$(echo "$NEW_UNFREE_OUT" | sed -n 2p)"
33+# make sure to nuke the unfree src from the updater's machine
34+# > the license requires that you agree to these use restrictions, or you must remove the software (source and binary) from your hard disks
35+# https://fedoraproject.org/wiki/Licensing:Unrar
36+nix-store --delete "$NEW_UNFREE_SRC"
37+
38+
39+echo "updating version"
40+sed -i "s/version = \"$OLD_VERSION\";/version = \"$NEW_VERSION\";/" "$DRV_DIR/default.nix"
41+
42+echo "updating free hash"
43+sed -i "s@free = \"$OLD_FREE_HASH\";@free = \"$NEW_FREE_HASH\";@" "$DRV_DIR/default.nix"
44+echo "updating unfree hash"
45+sed -i "s@unfree = \"$OLD_UNFREE_HASH\";@unfree = \"$NEW_UNFREE_HASH\";@" "$DRV_DIR/default.nix"
46+
47+echo "done"