From 848ed261f527c6af44b664895b4a42ab434f297b Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 2 Apr 2020 20:56:42 +0200 Subject: [PATCH 1/3] nfs-utils: Add enablePython argument If turned off, all binaries that need python are excluded With the argument disabled, this reduces closure size from 219.5M to 160.3M --- pkgs/os-specific/linux/nfs-utils/default.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/nfs-utils/default.nix b/pkgs/os-specific/linux/nfs-utils/default.nix index 74363be47f42..20dc6a094e7a 100644 --- a/pkgs/os-specific/linux/nfs-utils/default.nix +++ b/pkgs/os-specific/linux/nfs-utils/default.nix @@ -1,6 +1,7 @@ { stdenv, fetchurl, fetchpatch, lib, pkgconfig, utillinux, libcap, libtirpc, libevent , sqlite, kerberos, kmod, libuuid, keyutils, lvm2, systemd, coreutils, tcp_wrappers , python3, buildPackages, nixosTests +, enablePython ? true }: let @@ -25,8 +26,7 @@ stdenv.mkDerivation rec { buildInputs = [ libtirpc libcap libevent sqlite lvm2 libuuid keyutils kerberos tcp_wrappers - python3 - ]; + ] ++ lib.optional enablePython python3; enableParallelBuilding = true; @@ -96,6 +96,9 @@ stdenv.mkDerivation rec { -e "s,/sbin/modprobe,${kmod}/bin/modprobe,g" \ -e "s,/usr/sbin,$out/bin,g" \ $out/etc/systemd/system/* + '' + lib.optionalString (!enablePython) '' + # Remove all scripts that require python (currently mountstats and nfsiostat) + grep -l /usr/bin/python $out/bin/* | xargs -I {} rm -v {} ''; # One test fails on mips. From 12c1fdda091a405fd8cc8257d131c99a019cce39 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 2 Apr 2020 21:09:37 +0200 Subject: [PATCH 2/3] zfs: Use callPackages instead of callPackage to allow overriding --- pkgs/top-level/all-packages.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e5a0e81f4a76..1778cc8bd703 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16918,7 +16918,7 @@ in zenpower = callPackage ../os-specific/linux/zenpower { }; - inherit (callPackage ../os-specific/linux/zfs { + inherit (callPackages ../os-specific/linux/zfs { configFile = "kernel"; inherit kernel; }) zfsStable zfsUnstable; @@ -17557,7 +17557,7 @@ in zenmonitor = callPackage ../os-specific/linux/zenmonitor { }; - inherit (callPackage ../os-specific/linux/zfs { + inherit (callPackages ../os-specific/linux/zfs { configFile = "user"; }) zfsStable zfsUnstable; From 0a43c6e0f9bc13b00df67e74a0182f48d98ec2f6 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 2 Apr 2020 21:10:16 +0200 Subject: [PATCH 3/3] zfs: Add enablePython argument Reduces closure size with it disabled from 236.0M to 176.7M --- pkgs/os-specific/linux/zfs/default.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/zfs/default.nix b/pkgs/os-specific/linux/zfs/default.nix index 738171bb5ec8..a75b22abc2cb 100644 --- a/pkgs/os-specific/linux/zfs/default.nix +++ b/pkgs/os-specific/linux/zfs/default.nix @@ -11,6 +11,7 @@ # Kernel dependencies , kernel ? null +, enablePython ? true }: with stdenv.lib; @@ -51,7 +52,12 @@ let '' + optionalString buildUser '' substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount" "${utillinux}/bin/umount" \ --replace "/bin/mount" "${utillinux}/bin/mount" - substituteInPlace ./lib/libshare/nfs.c --replace "/usr/sbin/exportfs" "${nfs-utils}/bin/exportfs" + substituteInPlace ./lib/libshare/nfs.c --replace "/usr/sbin/exportfs" "${ + # We don't *need* python support, but we set it like this to minimize closure size: + # If it's disabled by default, no need to enable it, even if we have python enabled + # And if it's enabled by default, only change that if we explicitly disable python to remove python from the closure + nfs-utils.override (old: { enablePython = old.enablePython or true && enablePython; }) + }/bin/exportfs" substituteInPlace ./config/user-systemd.m4 --replace "/usr/lib/modules-load.d" "$out/etc/modules-load.d" substituteInPlace ./config/zfs-build.m4 --replace "\$sysconfdir/init.d" "$out/etc/init.d" substituteInPlace ./etc/zfs/Makefile.am --replace "\$(sysconfdir)" "$out/etc" @@ -86,7 +92,8 @@ let nativeBuildInputs = [ autoreconfHook nukeReferences ] ++ optionals buildKernel (kernel.moduleBuildDependencies ++ [ perl ]); buildInputs = optionals buildUser [ zlib libuuid attr ] - ++ optionals (buildUser) [ openssl python3 ] + ++ optional buildUser openssl + ++ optional (buildUser && enablePython) python3 ++ optional stdenv.hostPlatform.isMusl libtirpc; # for zdb to get the rpath to libgcc_s, needed for pthread_cancel to work @@ -96,7 +103,7 @@ let configureFlags = [ "--with-config=${configFile}" - (withFeatureAs buildUser "python" python3.interpreter) + (withFeatureAs (buildUser && enablePython) "python" python3.interpreter) ] ++ optionals buildUser [ "--with-dracutdir=$(out)/lib/dracut" "--with-udevdir=$(out)/lib/udev"