Merge branch 'drv-parts-reflex'

This commit is contained in:
Max Headroom 2022-12-18 16:21:32 +01:00
commit 07ab289dc0
13 changed files with 258 additions and 224 deletions

View file

@ -142,6 +142,29 @@
"type": "github"
}
},
"drv-parts": {
"inputs": {
"flake-parts": [
"flake-parts"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1671279624,
"narHash": "sha256-zY+ZFkIftR/ygx59L6jK50OgJLAIcUdYljoLPMnzm7w=",
"owner": "DavHau",
"repo": "drv-parts",
"rev": "f8bdb04964ef64e74bd227937cf6f4306478001b",
"type": "github"
},
"original": {
"owner": "DavHau",
"repo": "drv-parts",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
@ -449,6 +472,7 @@
"deploy-rs": "deploy-rs",
"devshell": "devshell",
"dream2nix": "dream2nix",
"drv-parts": "drv-parts",
"flake-parts": "flake-parts",
"hercules-ci-agent": "hercules-ci-agent",
"hercules-ci-effects": "hercules-ci-effects",

View file

@ -87,6 +87,7 @@
effects = { branch, ... }: mkDeployEffects branch deployableNixosHosts;
};
imports = [
inputs.drv-parts.flakeModule
./packages/part.nix
];
};
@ -205,5 +206,13 @@
poetry2nix.follows = "poetry2nix";
};
};
drv-parts = {
url = "github:DavHau/drv-parts";
inputs = {
flake-parts.follows = "flake-parts";
nixpkgs.follows = "nixpkgs";
};
};
};
}

View file

@ -3,6 +3,8 @@
{
imports = [
./options.nix
./drv-parts
];
builders = rec {

View file

@ -0,0 +1,9 @@
{ drv-backends, ... }:
{
drv-backends.buildPythonPackage.imports = [
drv-backends.mkDerivation
./interface.nix
./implementation.nix
];
}

View file

@ -0,0 +1,101 @@
{ config, dependencySets, lib, ... }:
let
inherit (config) deps;
withDistOutput = lib.elem config.format [
"pyproject"
"setuptools"
"flit"
"wheel"
];
hasPyproject = config.format == "pyproject" && config.pyprojectToml != null;
pyproject = if hasPyproject then
lib.importTOML config.pyprojectToml
else
null;
in
{
pname = lib.mkIf hasPyproject (lib.mkDefault pyproject.tool.poetry.name);
version = lib.mkIf hasPyproject (lib.mkDefault pyproject.tool.poetry.version);
deps = { pkgs, python3Packages, ... }: {
inherit (python3Packages)
python
wrapPython
pythonRemoveTestsDirHook
pythonCatchConflictsHook
pythonRemoveBinBytecodeHook
unzip
setuptoolsBuildHook
flitBuildHook
pipBuildHook
wheelUnpackHook
eggUnpackHook eggBuildHook eggInstallHook
pipInstallHook
pythonImportsCheckHook
pythonNamespacesHook
pythonOutputDistHook
;
inherit (pkgs)
ensureNewerSourcesForZipFilesHook
;
};
nativeBuildInputs = with deps; [
python
wrapPython
ensureNewerSourcesForZipFilesHook
pythonRemoveTestsDirHook
] ++ lib.optionals config.catchConflicts [
pythonCatchConflictsHook
] ++ lib.optionals config.removeBinByteCode [
pythonRemoveBinBytecodeHook
] ++ lib.optionals (lib.hasSuffix "zip" (config.src.name or "")) [
unzip
] ++ lib.optionals (config.format == "setuptools") [
setuptoolsBuildHook
] ++ lib.optionals (config.format == "flit") [
flitBuildHook
] ++ lib.optionals (config.format == "pyproject") [
pipBuildHook
] ++ lib.optionals (config.format == "wheel") [
wheelUnpackHook
] ++ lib.optionals (config.format == "egg") [
eggUnpackHook eggBuildHook eggInstallHook
] ++ lib.optionals (!(config.format == "other") || config.dontUsePipInstall) [
pipInstallHook
] ++ lib.optionals (python.stdenv.buildPlatform == python.stdenv.hostPlatform) [
# This is a test, however, it should be ran independent of the checkPhase and checkInputs
pythonImportsCheckHook
] ++ lib.optionals (python.pythonAtLeast "3.3") [
# Optionally enforce PEP420 for python3
pythonNamespacesHook
] ++ lib.optionals withDistOutput [
pythonOutputDistHook
];
propagatedBuildInputs = with deps; [
python
];
env = {
strictDeps = if config.strictDeps == null then false else config.strictDeps;
LANG = "${if deps.python.stdenv.isDarwin then "en_US" else "C"}.UTF-8";
};
doCheck = false;
doInstallCheck = lib.mkDefault true;
installCheckInputs = lib.optionals (config.format == "setuptools") [
deps.setuptoolsCheckHook
];
postFixup = lib.mkBefore (lib.optionalString (!config.dontWrapPythonPrograms) ''
wrapPythonPrograms
'');
outputs = [ "out" ] ++ lib.optional withDistOutput "dist";
}

View file

@ -0,0 +1,36 @@
{ config, lib, ... }:
with lib;
let
flag = default: description: mkOption {
inherit description default;
type = types.bool;
};
in
{
options = {
format = mkOption {
description = "Python package source format";
type = types.enum [
"setuptools"
"pyproject"
"flit"
"wheel"
"other"
];
default = if config.pyprojectToml != null then "pyproject" else "setuptools";
defaultText = ''
"pyproject" if pyprojectToml is set, otherwise "setuptools".
'';
};
pyprojectToml = mkOption {
description = "pyproject.toml file used for extracting package metadata";
type = with types; nullOr path;
default = null;
};
catchConflicts = flag true "If true, abort package build if a package name appears more than once in dependency tree.";
dontWrapPythonPrograms = flag false "Skip wrapping of Python programs.";
removeBinByteCode = flag true "Remove bytecode from /bin. Bytecode is only created when the filenames end with .py.";
};
}

View file

@ -0,0 +1,7 @@
{
imports = [
./options.nix
./buildPythonPackage
];
}

View file

@ -0,0 +1,12 @@
{ lib, ... }:
with lib;
{
options = {
drv-backends = mkOption {
description = "drv-parts backends";
type = with types; attrsOf raw;
default = {};
};
};
}

View file

@ -0,0 +1,11 @@
{ config, inputs, ... }:
{
imports = [
./backends
./dependency-sets
];
_module.args = {
drv-backends = inputs.drv-parts.drv-backends // config.drv-backends;
};
}

View file

@ -0,0 +1,8 @@
{ pkgs, inputs', self', ... }:
{
dependencySets = {
inherit pkgs inputs' self';
inherit (pkgs) python3Packages;
};
}

View file

@ -29,6 +29,7 @@
./networking/hyprspace/project.nix
./networking/ipfs-cluster/project.nix
./servers/reflex-cache/project.nix
./websites/landing/project.nix
./websites/stop-using-nix-env/project.nix
];
@ -71,11 +72,6 @@
privatevoid-smart-card-ca-bundle = pkgs.callPackage ./data/privatevoid-smart-card-certificate-authority-bundle.nix { };
reflex-cache = poetry2nix.mkPoetryApplication {
projectDir = ./servers/reflex-cache;
meta.mainProgram = "reflex";
};
searxng = pkgs.callPackage ./web-apps/searxng { inherit pins; };
sips = pkgs.callPackage ./servers/sips { };
@ -99,19 +95,6 @@
env.NPINS_DIRECTORY.eval = "$REPO_ROOT/packages/sources";
};
reflex-cache = let
inherit (self'.packages) reflex-cache;
in {
packages = [
reflex-cache.dependencyEnv
];
tools = [
pkgs.poetry
];
env.PYTHON = reflex-cache.dependencyEnv.interpreter;
};
};
};
}

View file

@ -1,206 +0,0 @@
[[package]]
name = "base58"
version = "2.1.1"
description = "Base58 and Base58Check implementation."
category = "main"
optional = false
python-versions = ">=3.5"
[package.extras]
tests = ["PyHamcrest (>=2.0.2)", "mypy", "pytest (>=4.6)", "pytest-benchmark", "pytest-cov", "pytest-flake8"]
[[package]]
name = "certifi"
version = "2022.5.18.1"
description = "Python package for providing Mozilla's CA Bundle."
category = "main"
optional = false
python-versions = ">=3.6"
[[package]]
name = "charset-normalizer"
version = "2.0.12"
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
category = "main"
optional = false
python-versions = ">=3.5.0"
[package.extras]
unicode_backport = ["unicodedata2"]
[[package]]
name = "idna"
version = "3.3"
description = "Internationalized Domain Names in Applications (IDNA)"
category = "main"
optional = false
python-versions = ">=3.5"
[[package]]
name = "morphys"
version = "1.0"
description = "Smart conversions between unicode and bytes types for common cases"
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "multiaddr"
version = "0.0.9"
description = "Python implementation of jbenet's multiaddr"
category = "main"
optional = false
python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
[package.dependencies]
base58 = "*"
netaddr = "*"
six = "*"
varint = "*"
[[package]]
name = "netaddr"
version = "0.8.0"
description = "A network address manipulation library for Python"
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "py-multibase"
version = "1.0.3"
description = "Multibase implementation for Python"
category = "main"
optional = false
python-versions = "*"
[package.dependencies]
morphys = ">=1.0,<2.0"
python-baseconv = ">=1.2.0,<2.0"
six = ">=1.10.0,<2.0"
[[package]]
name = "python-baseconv"
version = "1.2.2"
description = "Convert numbers from base 10 integers to base X strings and back again."
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "requests"
version = "2.28.1"
description = "Python HTTP for Humans."
category = "main"
optional = false
python-versions = ">=3.7, <4"
[package.dependencies]
certifi = ">=2017.4.17"
charset-normalizer = ">=2,<3"
idna = ">=2.5,<4"
urllib3 = ">=1.21.1,<1.27"
[package.extras]
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"]
[[package]]
name = "requests-unixsocket"
version = "0.3.0"
description = "Use requests to talk HTTP via a UNIX domain socket"
category = "main"
optional = false
python-versions = "*"
[package.dependencies]
requests = ">=1.1"
[[package]]
name = "six"
version = "1.16.0"
description = "Python 2 and 3 compatibility utilities"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]]
name = "urllib3"
version = "1.26.9"
description = "HTTP library with thread-safe connection pooling, file post, and more."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
[package.extras]
brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"]
secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)"]
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
[[package]]
name = "varint"
version = "1.0.2"
description = "Simple python varint implementation"
category = "main"
optional = false
python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "^3.9"
content-hash = "1aca01c6fbf7de9a1b0713ad1cab2892c705c19f48c546c3013a405ae5b01737"
[metadata.files]
base58 = [
{file = "base58-2.1.1-py3-none-any.whl", hash = "sha256:11a36f4d3ce51dfc1043f3218591ac4eb1ceb172919cebe05b52a5bcc8d245c2"},
{file = "base58-2.1.1.tar.gz", hash = "sha256:c5d0cb3f5b6e81e8e35da5754388ddcc6d0d14b6c6a132cb93d69ed580a7278c"},
]
certifi = [
{file = "certifi-2022.5.18.1-py3-none-any.whl", hash = "sha256:f1d53542ee8cbedbe2118b5686372fb33c297fcd6379b050cca0ef13a597382a"},
{file = "certifi-2022.5.18.1.tar.gz", hash = "sha256:9c5705e395cd70084351dd8ad5c41e65655e08ce46f2ec9cf6c2c08390f71eb7"},
]
charset-normalizer = [
{file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"},
{file = "charset_normalizer-2.0.12-py3-none-any.whl", hash = "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"},
]
idna = [
{file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"},
{file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"},
]
morphys = [
{file = "morphys-1.0-py2.py3-none-any.whl", hash = "sha256:76d6dbaa4d65f597e59d332c81da786d83e4669387b9b2a750cfec74e7beec20"},
]
multiaddr = [
{file = "multiaddr-0.0.9-py2.py3-none-any.whl", hash = "sha256:5c0f862cbcf19aada2a899f80ef896ddb2e85614e0c8f04dd287c06c69dac95b"},
{file = "multiaddr-0.0.9.tar.gz", hash = "sha256:30b2695189edc3d5b90f1c303abb8f02d963a3a4edf2e7178b975eb417ab0ecf"},
]
netaddr = [
{file = "netaddr-0.8.0-py2.py3-none-any.whl", hash = "sha256:9666d0232c32d2656e5e5f8d735f58fd6c7457ce52fc21c98d45f2af78f990ac"},
{file = "netaddr-0.8.0.tar.gz", hash = "sha256:d6cc57c7a07b1d9d2e917aa8b36ae8ce61c35ba3fcd1b83ca31c5a0ee2b5a243"},
]
py-multibase = [
{file = "py-multibase-1.0.3.tar.gz", hash = "sha256:d28a20efcbb61eec28f55827a0bf329c7cea80fffd933aecaea6ae8431267fe4"},
{file = "py_multibase-1.0.3-py2.py3-none-any.whl", hash = "sha256:2677c1fafcc0ae15ddb9c7f444c5becc2530b3889124fd4fa2959ddfefb8c15b"},
]
python-baseconv = [
{file = "python-baseconv-1.2.2.tar.gz", hash = "sha256:0539f8bd0464013b05ad62e0a1673f0ac9086c76b43ebf9f833053527cd9931b"},
]
requests = [
{file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"},
{file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"},
]
requests-unixsocket = [
{file = "requests-unixsocket-0.3.0.tar.gz", hash = "sha256:28304283ea9357d45fff58ad5b11e47708cfbf5806817aa59b2a363228ee971e"},
{file = "requests_unixsocket-0.3.0-py2.py3-none-any.whl", hash = "sha256:c685c680f0809e1b2955339b1e5afc3c0022b3066f4f7eb343f43a6065fc0e5d"},
]
six = [
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
urllib3 = [
{file = "urllib3-1.26.9-py2.py3-none-any.whl", hash = "sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14"},
{file = "urllib3-1.26.9.tar.gz", hash = "sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"},
]
varint = [
{file = "varint-1.0.2.tar.gz", hash = "sha256:a6ecc02377ac5ee9d65a6a8ad45c9ff1dac8ccee19400a5950fb51d594214ca5"},
]

View file

@ -0,0 +1,38 @@
{ config, drv-backends, inputs, lib, pkgs, ... }:
let
deps = with config.dependencySets.python3Packages; [
poetry-core
requests-unixsocket
py-multibase
py-multiaddr
];
pythonForDev = pkgs.python3.withPackages (lib.const deps);
in
{
projectShells.reflex-cache = {
tools = [
pythonForDev
];
env.PYTHON = pythonForDev.interpreter;
commands.reflex.command = "${pythonForDev.interpreter} -m reflex_cache.main";
};
drvs.reflex-cache = { dependencySets, ... }: {
imports = [
drv-backends.buildPythonPackage
];
pyprojectToml = ./pyproject.toml;
inherit (pkgs) stdenv;
propagatedBuildInputs = deps;
src = with inputs.nix-filter.lib; filter {
root = ./.;
include = [
"pyproject.toml"
(inDirectory "reflex_cache")
];
};
};
}