forked from hswaw/hscloud
Merge "nix: provide a python2 toolchain"
commit
a4a5a66f88
|
@ -1,6 +1,6 @@
|
||||||
load("@rules_python//python:defs.bzl", "py_runtime_pair")
|
load("@rules_python//python:defs.bzl", "py_runtime_pair")
|
||||||
|
|
||||||
# Python3 toolchain definition that uses //third_party/nix:python.nix (via
|
# Python toolchain definition that uses //third_party/nix:python.nix (via
|
||||||
# external repository).
|
# external repository).
|
||||||
|
|
||||||
py_runtime(
|
py_runtime(
|
||||||
|
@ -9,8 +9,16 @@ py_runtime(
|
||||||
python_version = "PY3",
|
python_version = "PY3",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
py_runtime(
|
||||||
|
name = "py2_runtime",
|
||||||
|
interpreter = "@hscloud_nix_python2//:python2",
|
||||||
|
python_version = "PY2",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
py_runtime_pair(
|
py_runtime_pair(
|
||||||
name = "py_runtime_pair",
|
name = "py_runtime_pair",
|
||||||
|
py2_runtime = ":py2_runtime",
|
||||||
py3_runtime = ":py3_runtime",
|
py3_runtime = ":py3_runtime",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,6 @@
|
||||||
with import <nixpkgs> {};
|
with import <nixpkgs> {};
|
||||||
|
|
||||||
let
|
let
|
||||||
# Add cffi for import _cffi_backend in `cryptography` to work.
|
|
||||||
py = pkgs.python37.withPackages (ps: with ps; [ cffi ]);
|
|
||||||
|
|
||||||
# We use mkDerivation instead of writeScript or writeScriptBin as we need a
|
# We use mkDerivation instead of writeScript or writeScriptBin as we need a
|
||||||
# derivation that both:
|
# derivation that both:
|
||||||
# - has a directory structure (for rules_nixpkgs to be able to use it)
|
# - has a directory structure (for rules_nixpkgs to be able to use it)
|
||||||
|
@ -20,14 +17,14 @@ let
|
||||||
# in the root path of the external repository (which is populated with a
|
# in the root path of the external repository (which is populated with a
|
||||||
# symlink tree from the nix derivation), so we can onlly directly reference
|
# symlink tree from the nix derivation), so we can onlly directly reference
|
||||||
# file in the root of a Nix derivation.
|
# file in the root of a Nix derivation.
|
||||||
in stdenv.mkDerivation {
|
generic = package: binary: stdenv.mkDerivation {
|
||||||
name = "py-wrapper";
|
name = "${binary}-wrapper";
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
unpackPhase = "";
|
unpackPhase = "";
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
cat > $out/python3 <<EOF
|
cat > $out/${binary} <<EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# pyscopg wants libpq, and uses pg_config to find paths. Inject pg_config into
|
# pyscopg wants libpq, and uses pg_config to find paths. Inject pg_config into
|
||||||
|
@ -37,10 +34,16 @@ export PATH="${pkgs.postgresql}/bin:\$PATH"
|
||||||
# uWSGI has a truly cheese-grade build system, and this is the only way to let
|
# uWSGI has a truly cheese-grade build system, and this is the only way to let
|
||||||
# it know where to find ncurses.
|
# it know where to find ncurses.
|
||||||
export LDFLAGS="-L${pkgs.ncurses}/lib"
|
export LDFLAGS="-L${pkgs.ncurses}/lib"
|
||||||
exec ${py}/bin/python3 "\$@"
|
exec ${package}/bin/${binary} "\$@"
|
||||||
EOF
|
EOF
|
||||||
'';
|
'';
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
chmod +x $out/python3
|
chmod +x $out/${binary}
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
# Add cffi for import _cffi_backend in `cryptography` to work.
|
||||||
|
python2 = generic (pkgs.python27.withPackages (ps: with ps; [ cffi ])) "python2";
|
||||||
|
python3 = generic (pkgs.python37.withPackages (ps: with ps; [ cffi ])) "python3";
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,14 +74,25 @@ def hscloud_setup_nix(revision, sha256):
|
||||||
sha256 = "8b64041bfb9760de9e797c0a985a4830880c21732489f397e217d877edd9a990",
|
sha256 = "8b64041bfb9760de9e797c0a985a4830880c21732489f397e217d877edd9a990",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load python3 from nixpkgs. Python is a large source of non-hermiticity,
|
# Load python from nixpkgs. Python is a large source of non-hermiticity,
|
||||||
# and loading it from nix vastly hermeticizes the build - well, at least to
|
# and loading it from nix vastly hermeticizes the build - well, at least to
|
||||||
# also be dependent on this Nix store state. That's still better than just
|
# also be dependent on this Nix store state. That's still better than just
|
||||||
# grabbing whatever random system Python a user might have.
|
# grabbing whatever random system Python a user might have.
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "hscloud_nix_python2",
|
||||||
|
repositories = { "nixpkgs": "@nixpkgs//:default.nix" },
|
||||||
|
nix_file = "//third_party/nix:python.nix",
|
||||||
|
attribute_path = "python2",
|
||||||
|
build_file_content = """
|
||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
exports_files(["python2"])
|
||||||
|
""",
|
||||||
|
)
|
||||||
nixpkgs_package(
|
nixpkgs_package(
|
||||||
name = "hscloud_nix_python3",
|
name = "hscloud_nix_python3",
|
||||||
repositories = { "nixpkgs": "@nixpkgs//:default.nix" },
|
repositories = { "nixpkgs": "@nixpkgs//:default.nix" },
|
||||||
nix_file = "//third_party/nix:python.nix",
|
nix_file = "//third_party/nix:python.nix",
|
||||||
|
attribute_path = "python3",
|
||||||
build_file_content = """
|
build_file_content = """
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
exports_files(["python3"])
|
exports_files(["python3"])
|
||||||
|
|
Loading…
Reference in New Issue