From 06ff4af597a75a0854cbcb9c822b1fe38a466a98 Mon Sep 17 00:00:00 2001 From: Allen Nelson Date: Thu, 21 May 2015 23:32:03 -0500 Subject: [PATCH 1/4] Adding documentation to wrap.sh, added ability to retain any desired environment variables. --- .../python-modules/generic/default.nix | 15 ++++++++++++++- pkgs/development/python-modules/generic/wrap.sh | 14 +++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pkgs/development/python-modules/generic/default.nix b/pkgs/development/python-modules/generic/default.nix index b962e9f8472..211c781b5d4 100644 --- a/pkgs/development/python-modules/generic/default.nix +++ b/pkgs/development/python-modules/generic/default.nix @@ -47,11 +47,24 @@ # Execute after shell hook , postShellHook ? "" +# Environment variables to set in wrapper scripts, in addition to +# PYTHONPATH and PATH. +, setEnvVars ? [] + , ... } @ attrs: # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. -if disabled then throw "${name} not supported for interpreter ${python.executable}" else python.stdenv.mkDerivation (attrs // { +if disabled +then throw "${name} not supported for interpreter ${python.executable}" +else + +let + inherit (builtins) hasAttr; + inherit (lib) mapAttrs concatStringsSep optionals hasSuffix; +in + +python.stdenv.mkDerivation (attrs // { inherit doCheck; name = namePrefix + name; diff --git a/pkgs/development/python-modules/generic/wrap.sh b/pkgs/development/python-modules/generic/wrap.sh index 45f86df4dcf..f9a65c6a33f 100644 --- a/pkgs/development/python-modules/generic/wrap.sh +++ b/pkgs/development/python-modules/generic/wrap.sh @@ -41,9 +41,17 @@ wrapPythonProgramsIn() { # wrapProgram creates the executable shell script described # above. The script will set PYTHONPATH and PATH variables.! # (see pkgs/build-support/setup-hooks/make-wrapper.sh) - wrapProgram $f \ - --prefix PYTHONPATH ':' $program_PYTHONPATH \ - --prefix PATH ':' $program_PATH + local wrap_args="$f \ + --prefix PYTHONPATH ':' $program_PYTHONPATH \ + --prefix PATH ':' $program_PATH" + + # Add any additional environment variables to propagate. + for env_var in $setEnvVars; do + # Look up the value of this variable + local value=$(eval "echo \$$env_var") + wrap_args="$wrap_args --set $env_var $value" + done + wrapProgram $wrap_args fi fi done From bf1a16bbeac462ee46674e4d340a7f1edffddb0a Mon Sep 17 00:00:00 2001 From: Allen Nelson Date: Fri, 22 May 2015 09:57:42 -0500 Subject: [PATCH 2/4] removing superfluous lets --- pkgs/development/python-modules/generic/default.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkgs/development/python-modules/generic/default.nix b/pkgs/development/python-modules/generic/default.nix index 211c781b5d4..9856682ba89 100644 --- a/pkgs/development/python-modules/generic/default.nix +++ b/pkgs/development/python-modules/generic/default.nix @@ -59,11 +59,6 @@ if disabled then throw "${name} not supported for interpreter ${python.executable}" else -let - inherit (builtins) hasAttr; - inherit (lib) mapAttrs concatStringsSep optionals hasSuffix; -in - python.stdenv.mkDerivation (attrs // { inherit doCheck; From 6bb2e47abf8317364c86d84808a04a72e40ff1f0 Mon Sep 17 00:00:00 2001 From: Allen Nelson Date: Sun, 24 May 2015 10:19:13 -0500 Subject: [PATCH 3/4] using makeWrapperArgs instead of setEnvVars --- pkgs/development/python-modules/generic/default.nix | 6 +++--- pkgs/development/python-modules/generic/wrap.sh | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pkgs/development/python-modules/generic/default.nix b/pkgs/development/python-modules/generic/default.nix index 9856682ba89..378f047939f 100644 --- a/pkgs/development/python-modules/generic/default.nix +++ b/pkgs/development/python-modules/generic/default.nix @@ -47,9 +47,9 @@ # Execute after shell hook , postShellHook ? "" -# Environment variables to set in wrapper scripts, in addition to -# PYTHONPATH and PATH. -, setEnvVars ? [] +# Additional arguments to pass to the makeWrapper function, which wraps +# generated binaries. +, makeWrapperArgs ? [] , ... } @ attrs: diff --git a/pkgs/development/python-modules/generic/wrap.sh b/pkgs/development/python-modules/generic/wrap.sh index f9a65c6a33f..33b9a06f608 100644 --- a/pkgs/development/python-modules/generic/wrap.sh +++ b/pkgs/development/python-modules/generic/wrap.sh @@ -45,11 +45,10 @@ wrapPythonProgramsIn() { --prefix PYTHONPATH ':' $program_PYTHONPATH \ --prefix PATH ':' $program_PATH" - # Add any additional environment variables to propagate. - for env_var in $setEnvVars; do - # Look up the value of this variable - local value=$(eval "echo \$$env_var") - wrap_args="$wrap_args --set $env_var $value" + # Add any additional arguments provided by makeWrapperArgs + # argument to buildPythonPackage. + for arg in $makeWrapperArgs; do + wrap_args="$wrap_args $arg" done wrapProgram $wrap_args fi From d2cbcc68be00173e58a7c5e60079d485f95a63e3 Mon Sep 17 00:00:00 2001 From: Allen Nelson Date: Sun, 24 May 2015 22:22:20 -0500 Subject: [PATCH 4/4] added documentation for makeWrapperArgs --- doc/language-support.xml | 108 ++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/doc/language-support.xml b/doc/language-support.xml index da709b34a94..1e1bdf75eda 100644 --- a/doc/language-support.xml +++ b/doc/language-support.xml @@ -245,14 +245,14 @@ are provided with all modules included. Name of the folder in ${python}/lib/ for corresponding interpreter. - + interpreter Alias for ${python}/bin/${executable}. - + buildEnv @@ -260,29 +260,29 @@ are provided with all modules included. See for usage and documentation. - + sitePackages Alias for lib/${libPrefix}/site-packages. - + executable Name of the interpreter executable, ie python3.4. - +
<varname>buildPythonPackage</varname> function - + The function is implemented in pkgs/development/python-modules/generic/default.nix. Example usage: - + twisted = buildPythonPackage { name = "twisted-8.1.0"; @@ -308,27 +308,27 @@ twisted = buildPythonPackage { python27Packages, python32Packages, python33Packages, python34Packages and pypyPackages. - + buildPythonPackage mainly does four things: - + In the configurePhase, it patches setup.py to always include setuptools before distutils for monkeypatching machinery to take place. - + - In the buildPhase, it calls + In the buildPhase, it calls ${python.interpreter} setup.py build ... - + - In the installPhase, it calls + In the installPhase, it calls ${python.interpreter} setup.py install ... - + In the postFixup phase, wrapPythonPrograms bash function is called to wrap all programs in $out/bin/* @@ -337,23 +337,23 @@ twisted = buildPythonPackage { - - By default doCheck = true is set and tests are run with + + By default doCheck = true is set and tests are run with ${python.interpreter} setup.py test command in checkPhase. - + propagatedBuildInputs packages are propagated to user environment. - + By default meta.platforms is set to the same value as the interpreter unless overriden otherwise. - + <varname>buildPythonPackage</varname> parameters (all parameters from <varname>mkDerivation</varname> function are still supported) - + namePrefix @@ -363,7 +363,7 @@ twisted = buildPythonPackage { if you're packaging an application or a command line tool. - + disabled @@ -373,21 +373,21 @@ twisted = buildPythonPackage { for examples. - + setupPyInstallFlags List of flags passed to setup.py install command. - + setupPyBuildFlags List of flags passed to setup.py build command. - + pythonPath @@ -396,21 +396,21 @@ twisted = buildPythonPackage { (contrary to propagatedBuildInputs). - + preShellHook Hook to execute commands before shellHook. - + postShellHook Hook to execute commands after shellHook. - + distutilsExtraCfg @@ -419,15 +419,29 @@ twisted = buildPythonPackage { configuration). - + + + makeWrapperArgs + + A list of strings. Arguments to be passed to + makeWrapper, which wraps generated binaries. By + default, the arguments to makeWrapper set + PATH and PYTHONPATH environment + variables before calling the binary. Additional arguments here can + allow a developer to set environment variables which will be + available when the binary is run. For example, + makeWrapperArgs = ["--set FOO BAR" "--set BAZ QUX"]. + + + - +
<function>python.buildEnv</function> function Create Python environments using low-level pkgs.buildEnv function. Example default.nix: - + {}; @@ -436,31 +450,31 @@ python.buildEnv.override { ignoreCollisions = true; }]]> - + Running nix-build will create /nix/store/cf1xhjwzmdki7fasgr4kz6di72ykicl5-python-2.7.8-env with wrapped binaries in bin/. - + <function>python.buildEnv</function> arguments - + extraLibs List of packages installed inside the environment. - + postBuild Shell command executed after the build of environment. - + ignoreCollisions @@ -504,13 +518,13 @@ exist in community to help save time. No tool is preferred at the moment. additional logic inside shellPhase to run ${python.interpreter} setup.py develop for the package. - + shellPhase is executed only if setup.py exists. - + Given a default.nix: - + {}; @@ -522,18 +536,18 @@ buildPythonPackage { src = ./.; }]]> - + Running nix-shell with no arguments should give you the environment in which the package would be build with nix-build. - + Shortcut to setup environments with C headers/libraries and python packages: - + $ nix-shell -p pythonPackages.pyramid zlib libjpeg git - + There is a boolean value lib.inNixShell set to true if nix-shell is invoked. @@ -562,12 +576,12 @@ buildPythonPackage { Known bug in setuptools install_data does not respect --prefix. Example of such package using the feature is pkgs/tools/X11/xpra/default.nix. As workaround install it as an extra preInstall step: - + ${python.interpreter} setup.py install_data --install-dir=$out --root=$out sed -i '/ = data_files/d' setup.py - + Rationale of non-existent global site-packages @@ -616,7 +630,7 @@ sed -i '/ = data_files/d' setup.py this into a nix expression that contains all Gem dependencies automatically. For example, to package sensu, we did: - + - Though, more complicated package should be placed in a seperate file in + Though, more complicated package should be placed in a seperate file in pkgs/development/lua-modules.