summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorsternenseemann <sternenseemann@systemli.org>2021-12-15 11:30:31 +0100
committersternenseemann <sternenseemann@systemli.org>2021-12-15 11:30:31 +0100
commitd860ba7f0990548b2485ec77126c760789ba3fd9 (patch)
tree9e21a8f88db01fb1eadb062002f1af3bfe538f0d /pkgs/build-support
parentdfe70100691395c0b3fe6d1737b3b719209b0cc6 (diff)
parent8a8ab455d06d6e770aa17955fa854552344e8064 (diff)
downloadnixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.tar
nixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.tar.gz
nixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.tar.bz2
nixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.tar.lz
nixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.tar.xz
nixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.tar.zst
nixpkgs-d860ba7f0990548b2485ec77126c760789ba3fd9.zip
Merge remote-tracking branch 'origin/master' into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/writers/aliases.nix35
-rw-r--r--pkgs/build-support/writers/default.nix43
-rw-r--r--pkgs/build-support/writers/test.nix31
3 files changed, 95 insertions, 14 deletions
diff --git a/pkgs/build-support/writers/aliases.nix b/pkgs/build-support/writers/aliases.nix
new file mode 100644
index 00000000000..fb108a6fd85
--- /dev/null
+++ b/pkgs/build-support/writers/aliases.nix
@@ -0,0 +1,35 @@
+lib: prev:
+
+let
+  # Removing recurseForDerivation prevents derivations of aliased attribute
+  # set to appear while listing all the packages available.
+  removeRecurseForDerivations = alias: with lib;
+    if alias.recurseForDerivations or false then
+      removeAttrs alias ["recurseForDerivations"]
+    else alias;
+
+  # Disabling distribution prevents top-level aliases for non-recursed package
+  # sets from building on Hydra.
+  removeDistribute = alias: with lib;
+    if isDerivation alias then
+      dontDistribute alias
+    else alias;
+
+  # Make sure that we are not shadowing something from
+  # writers.
+  checkInPkgs = n: alias: if builtins.hasAttr n prev
+                          then throw "Alias ${n} is still in writers"
+                          else alias;
+
+  mapAliases = aliases:
+    lib.mapAttrs (n: alias: removeDistribute
+                             (removeRecurseForDerivations
+                              (checkInPkgs n alias)))
+                     aliases;
+
+in
+mapAliases ({
+  /* Cleanup before 22.05, Added 2021-12-11 */
+  writePython2 = "Python 2 is EOL and the use of writers.writePython2 is deprecated.";
+  writePython2Bin = "Python 2 is EOL and the use of writers.writePython2Bin is deprecated.";
+})
diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix
index 3797df56afa..30301e3b2e5 100644
--- a/pkgs/build-support/writers/default.nix
+++ b/pkgs/build-support/writers/default.nix
@@ -1,7 +1,9 @@
-{ pkgs, buildPackages, lib, stdenv, libiconv, gawk, gnused, gixy }:
+{ pkgs, config, buildPackages, lib, stdenv, libiconv, gawk, gnused, gixy }:
 
-with lib;
-rec {
+let
+  aliases = if (config.allowAliases or true) then (import ./aliases.nix lib) else prev: {};
+
+  writers = with lib; rec {
   # Base implementation for non-compiled executables.
   # Takes an interpreter, for example `${pkgs.bash}/bin/bash`
   #
@@ -245,11 +247,11 @@ rec {
     '');
   } name;
 
-  # writePython2 takes a name an attributeset with libraries and some python2 sourcecode and
+  # writePyPy2 takes a name an attributeset with libraries and some pypy2 sourcecode and
   # returns an executable
   #
   # Example:
-  # writePython2 "test_python2" { libraries = [ pkgs.python2Packages.enum ]; } ''
+  # writePyPy2 "test_pypy2" { libraries = [ pkgs.pypy2Packages.enum ]; } ''
   #   from enum import Enum
   #
   #   class Test(Enum):
@@ -257,11 +259,11 @@ rec {
   #
   #   print Test.a
   # ''
-  writePython2 = makePythonWriter pkgs.python2 pkgs.python2Packages;
+  writePyPy2 = makePythonWriter pkgs.pypy2 pkgs.pypy2Packages;
 
-  # writePython2Bin takes the same arguments as writePython2 but outputs a directory (like writeScriptBin)
-  writePython2Bin = name:
-    writePython2 "/bin/${name}";
+  # writePyPy2Bin takes the same arguments as writePyPy2 but outputs a directory (like writeScriptBin)
+  writePyPy2Bin = name:
+    writePyPy2 "/bin/${name}";
 
   # writePython3 takes a name an attributeset with libraries and some python3 sourcecode and
   # returns an executable
@@ -280,4 +282,25 @@ rec {
   # writePython3Bin takes the same arguments as writePython3 but outputs a directory (like writeScriptBin)
   writePython3Bin = name:
     writePython3 "/bin/${name}";
-}
+
+  # writePyPy3 takes a name an attributeset with libraries and some pypy3 sourcecode and
+  # returns an executable
+  #
+  # Example:
+  # writePyPy3 "test_pypy3" { libraries = [ pkgs.pypy3Packages.pyyaml ]; } ''
+  #   import yaml
+  #
+  #   y = yaml.load("""
+  #     - test: success
+  #   """)
+  #   print(y[0]['test'])
+  # ''
+  writePyPy3 = makePythonWriter pkgs.pypy3 pkgs.pypy3Packages;
+
+  # writePyPy3Bin takes the same arguments as writePyPy3 but outputs a directory (like writeScriptBin)
+  writePyPy3Bin = name:
+    writePyPy3 "/bin/${name}";
+
+};
+in
+writers // (aliases writers)
diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix
index 69bc7dd2c61..decd7e42d5c 100644
--- a/pkgs/build-support/writers/test.nix
+++ b/pkgs/build-support/writers/test.nix
@@ -3,8 +3,9 @@
 , lib
 , nodePackages
 , perlPackages
-, python2Packages
+, pypy2Packages
 , python3Packages
+, pypy3Packages
 , runCommand
 , writers
 , writeText
@@ -54,7 +55,7 @@ let
       print "success\n" if true;
     '';
 
-    python2 = writePython2Bin "test-writers-python2-bin" { libraries = [ python2Packages.enum ]; } ''
+    pypy2 = writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } ''
       from enum import Enum
 
 
@@ -73,6 +74,15 @@ let
       """)
       print(y[0]['test'])
     '';
+
+    pypy3 = writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } ''
+      import yaml
+
+      y = yaml.load("""
+        - test: success
+      """)
+      print(y[0]['test'])
+    '';
   };
 
   simple = {
@@ -111,7 +121,7 @@ let
       print "success\n" if true;
     '';
 
-    python2 = writePython2 "test-writers-python2" { libraries = [ python2Packages.enum ]; } ''
+    pypy2 = writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages.enum ]; } ''
       from enum import Enum
 
 
@@ -131,13 +141,26 @@ let
       print(y[0]['test'])
     '';
 
-    python2NoLibs = writePython2 "test-writers-python2-no-libs" {} ''
+    pypy3 = writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages.pyyaml ]; } ''
+      import yaml
+
+      y = yaml.load("""
+        - test: success
+      """)
+      print(y[0]['test'])
+    '';
+
+    pypy2NoLibs = writePyPy2 "test-writers-pypy2-no-libs" {} ''
       print("success")
     '';
 
     python3NoLibs = writePython3 "test-writers-python3-no-libs" {} ''
       print("success")
     '';
+
+    pypy3NoLibs = writePyPy3 "test-writers-pypy3-no-libs" {} ''
+      print("success")
+    '';
   };