feat: merge attrs-from-... into nixpkgs-overrides

This commit is contained in:
phaer 2023-03-13 13:18:40 +01:00
parent 1d36c7f3ce
commit 0007206ea1
5 changed files with 44 additions and 85 deletions

View File

@ -1,38 +0,0 @@
{
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

@ -1,27 +0,0 @@
{
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

@ -7,20 +7,8 @@
l = lib // builtins;
cfg = config.nixpkgs-overrides;
# Attributes we never want to copy from nixpkgs
excludedNixpkgsAttrs =
l.genAttrs
[
"all"
"args"
"builder"
"name"
"pname"
"version"
"src"
"outputs"
]
(name: null);
l.genAttrs cfg.excludedNixpkgsAttrs (name: null);
extractOverrideAttrs = overrideFunc:
(overrideFunc (old: {passthru.old = old;}))
@ -37,7 +25,12 @@ in {
./interface.nix
];
config = l.mkIf cfg.enable {
package-func.args = extracted;
};
config = l.mkMerge [
(l.mkIf cfg.enable {
package-func.args = extracted;
})
{
nixpkgs-overrides.lib = {inherit extractOverrideAttrs extractPythonAttrs;};
}
];
}

View File

@ -7,6 +7,38 @@
t = l.types;
in {
options.nixpkgs-overrides = {
enable = l.mkEnableOption "Whether to apply override from nixpkgs";
enable = l.mkEnableOption "Whether to copy attributes, except those in `excludedNixpkgsAttrs` from nixpkgs";
excludedNixpkgsAttrs = l.mkOption {
type = t.listOf t.str;
description = "Attributes we do not want to copy from nixpkgs";
default = [
"all"
"args"
"builder"
"name"
"pname"
"version"
"src"
"outputs"
];
};
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

@ -6,13 +6,12 @@
}: let
l = lib // builtins;
python = config.deps.python;
extractPythonAttrs = config.attrs-from-nixpkgs.lib.extractPythonAttrs;
extractPythonAttrs = config.nixpkgs-overrides.lib.extractPythonAttrs;
nixpkgsAttrs = extractPythonAttrs python.pkgs.apache-airflow;
in {
imports = [
../../drv-parts/mach-nix-xs
../../drv-parts/attrs-from-nixpkgs
../../drv-parts/nixpkgs-overrides
];
deps = {