summary refs log tree commit diff
path: root/pkgs/tools/misc/units
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2022-07-19 22:28:09 -0700
committerAdam Joseph <adam@westernsemico.com>2022-07-19 22:32:00 -0700
commit3f11515a260bc195637d0c3817815eb28e6cf996 (patch)
tree6935e16575c07b0069a5d9f6596593b8993d981c /pkgs/tools/misc/units
parent7bc6fbcd8b3d4bb8eaa15ea7dc18b6d9fbf6fdf6 (diff)
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.
Diffstat (limited to 'pkgs/tools/misc/units')
-rw-r--r--pkgs/tools/misc/units/default.nix11
1 files changed, 5 insertions, 6 deletions
diff --git a/pkgs/tools/misc/units/default.nix b/pkgs/tools/misc/units/default.nix
index 04e955a78b189..ebfd913de217d 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
   '';