feat(mach-nix): wip, split nixpkgsAttrs -> module

This commit is contained in:
phaer 2023-03-08 01:01:02 +01:00 committed by DavHau
parent 169da1c545
commit 173d76b688
5 changed files with 63 additions and 38 deletions

View File

@ -0,0 +1,34 @@
{config, lib, ...}: let
l = lib // builtins;
t = l.types;
# Attributes we never want to copy from nixpkgs
excludedNixpkgsAttrs = l.genAttrs
[
"all"
"args"
"builder"
"name"
"pname"
"version"
"src"
"outputs"
]
(name: null);
extractOverrideAttrs = overrideFunc:
(overrideFunc (old: {passthru.old = old;}))
.old;
extractPythonAttrs = pythonPackage: let
pythonAttrs = extractOverrideAttrs pythonPackage.overridePythonAttrs;
in
l.filterAttrs (name: _: ! excludedNixpkgsAttrs ? ${name}) pythonAttrs;
in {
imports = [
./interface.nix
];
config.attrs-from-nixpkgs.lib = { inherit extractOverrideAttrs extractPythonAttrs; };
}

View File

@ -0,0 +1,26 @@
{config, lib, ...}: let
l = lib // builtins;
t = l.types;
in {
options.attrs-from-nixpkgs = {
lib.extractOverrideAttrs = l.mkOption {
type = t.functionTo t.attrs;
description = ''
Helper function to extract attrs from nixpkgs to be re-used as overrides.
'';
readOnly = true;
};
# Extracts derivation args from a nixpkgs python package.
lib.extractPythonAttrs = l.mkOption {
type = t.functionTo t.attrs;
description = ''
Helper function to extract python attrs from nixpkgs to be re-used as overrides.
'';
readOnly = true;
};
};
}

View File

@ -87,36 +87,12 @@
(name: deps: map (dep: finalDistsPaths.${dep}) deps)
cfg.manualSetupDeps;
# Attributes we never want to copy from nixpkgs
excludedNixpkgsAttrs = l.genAttrs
[
"all"
"args"
"builder"
"name"
"pname"
"version"
"src"
"outputs"
]
(name: null);
# Extracts derivation args from a nixpkgs python package.
extractPythonAttrs = pythonPackage: let
extractOverrideAttrs = overrideFunc:
(pythonPackage.${overrideFunc} (old: {passthru.old = old;}))
.old;
pythonAttrs = extractOverrideAttrs "overridePythonAttrs";
allAttrs = pythonAttrs;
in
l.filterAttrs (name: _: ! excludedNixpkgsAttrs ? ${name}) allAttrs;
# build a wheel for a given sdist
mkWheelDist = pname: version: distDir: let
# re-use package attrs from nixpkgs
# (treat nixpkgs as a source of community overrides)
extractedAttrs = l.optionalAttrs (python.pkgs ? ${pname})
extractPythonAttrs python.pkgs.${pname};
config.attrs-from-nixpkgs.lib.extractPythonAttrs python.pkgs.${pname};
in
python.pkgs.buildPythonPackage (
# nixpkgs attrs
@ -158,12 +134,11 @@ in {
../buildPythonPackage
./interface.nix
../eval-cache
../attrs-from-nixpkgs
];
config = {
mach-nix.lib = {inherit extractPythonAttrs;};
mach-nix.drvs = l.flip l.mapAttrs preparedWheels.patchedWheels (name: dist:
drv-parts.lib.makeModule {
packageFunc = dist;

View File

@ -48,16 +48,6 @@ in {
description = "drv-parts modules that define python dependencies";
};
# LIB
lib.extractPythonAttrs = l.mkOption {
type = t.functionTo t.attrs;
description = ''
Helper function to extract python attrs from nixpkgs to be re-used as overrides.
'';
readOnly = true;
};
# INTERNAL
dists = l.mkOption {

View File

@ -1,7 +1,7 @@
{config, lib, drv-parts, ...}: let
l = lib // builtins;
python = config.deps.python;
extractPythonAttrs = config.mach-nix.lib.extractPythonAttrs;
extractPythonAttrs = config.attrs-from-nixpkgs.lib.extractPythonAttrs;
nixpkgsAttrs = extractPythonAttrs python.pkgs.apache-airflow;