From 3f11515a260bc195637d0c3817815eb28e6cf996 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 19 Jul 2022 22:28:09 -0700 Subject: [PATCH] units: fix build with enableCurrenciesUpdater=false; pythonPackages=null; Units allows to build it without a python dependency by setting { enableCurrenciesUpdater=false; pythonPackages=null; }. Unfortunately this feature is currently broken due to two problems: 1. The `pythonEnv` string is part of the builder environment, so it is not evaluated lazily. This means that `pythonPackages==null` will always cause eval to fail. 2. `pythonEnv` is used unconditionally in an antiquotation in the `prePatch` phase; if it is null this will fail. Let's fix these so we can build a pythonless "units" package. This is helpful when cross-compiling, because right now a lot of python packages (especially python-cryptography) fail to cross-compile. --- pkgs/tools/misc/units/default.nix | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkgs/tools/misc/units/default.nix b/pkgs/tools/misc/units/default.nix index 04e955a78b1..ebfd913de21 100644 --- a/pkgs/tools/misc/units/default.nix +++ b/pkgs/tools/misc/units/default.nix @@ -9,7 +9,10 @@ assert enableCurrenciesUpdater -> pythonPackages != null; -stdenv.mkDerivation rec { +let pythonEnv = pythonPackages.python.withPackages(ps: [ + ps.requests + ]); +in stdenv.mkDerivation rec { pname = "units"; version = "2.21"; @@ -18,16 +21,12 @@ stdenv.mkDerivation rec { sha256 = "sha256-bD6AqfmAWJ/ZYqWFKiZ0ZCJX2xxf1bJ8TZ5mTzSGy68="; }; - pythonEnv = pythonPackages.python.withPackages(ps: [ - ps.requests - ]); - buildInputs = [ readline ] ++ lib.optionals enableCurrenciesUpdater [ pythonEnv ] ; - prePatch = '' + prePatch = lib.optionalString enableCurrenciesUpdater '' substituteInPlace units_cur \ --replace "#!/usr/bin/env python" ${pythonEnv}/bin/python '';