mkDerivation: stop depending on all core modules

mkDerivation should be minimal, but currently it always pulls in modules like `lock` and `paths` etc. despite those not being needed for many instances, like when mkDerivation is imported by a dependency.

Modules like pip which do need some of these core modules, now need to directly depend on them.

This will remove a bunch of unneeded options which currently pollute the manual.

The remaining core dependencies of mkDerivation are now: deps, env, ui
This commit is contained in:
DavHau 2024-03-18 18:12:37 +07:00 committed by mergify[bot]
parent c4e13905aa
commit f017de2de4
21 changed files with 74 additions and 25 deletions

View File

@ -32,9 +32,12 @@ in {
default = {};
};
overrides = lib.mkOption {
# TODO: This version of deferredModuleWith might lead to an infinite
# recursion because it doesn't support specialArgs
# (see custom deferredModuleWith in ../overrides/default.nix)
type = t.lazyAttrsOf (t.deferredModuleWith {
staticModules = [
{_module.args = specialArgs;}
{_module.args = specialArgs // {inherit specialArgs;};}
];
});
description = ''

View File

@ -289,6 +289,7 @@ in {
imports = [
./interface.nix
dream2nix.modules.dream2nix.core
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.WIP-groups
];

View File

@ -47,7 +47,7 @@
else config.deps.python.pkgs.setuptools;
in {
imports = [
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.buildPythonPackage
];
config.mkDerivation.buildInputs =
lib.optionals
@ -56,8 +56,6 @@
};
in {
imports = [
dream2nix.modules.dream2nix.buildPythonPackage
../core/deps
../overrides
./interface.nix
./lock.nix

View File

@ -1,6 +1,7 @@
{
config,
lib,
dream2nix,
...
}: let
pdmConfig = config.deps.writeText "pdm-config.toml" ''
@ -32,6 +33,9 @@
popd
'';
in {
imports = [
dream2nix.modules.dream2nix.lock
];
lock.extraScripts = [script];
deps = {nixpkgs, ...}:
lib.mapAttrs (_: lib.mkDefault) {

View File

@ -8,7 +8,8 @@
in {
imports = [
./interface.nix
../mkDerivation
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.deps
];
config = {
package-func.func = config.deps.python.pkgs.buildPythonPackage;

View File

@ -146,6 +146,7 @@
in {
imports = [
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
./interface.nix
];

View File

@ -1,10 +1,10 @@
{
config,
lib,
dream2nix,
...
}: let
l = lib // builtins;
t = l.types;
cfg = config.mkDerivation;
@ -42,8 +42,10 @@
in {
imports = [
./interface.nix
../core
../package-func
dream2nix.modules.dream2nix.deps
dream2nix.modules.dream2nix.env
dream2nix.modules.dream2nix.ui
];
config.package-func.outputs = cfg.outputs;

View File

@ -291,6 +291,7 @@ in {
imports = [
./interface.nix
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
(commonModule defaultPackageName defaultPackageVersion)
];
deps = {nixpkgs, ...}:

View File

@ -18,6 +18,7 @@ in {
config.overrideType = {
imports = [
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
];
};
options = l.mapAttrs (_: l.mkOption) {
@ -49,10 +50,11 @@ in {
internal = true;
# hack because internal doesn't propagate to submodule options
visible = "shallow";
type = t.attrsOf (t.attrsOf (t.submodule {
imports = [
type = t.attrsOf (t.attrsOf (t.submoduleWith {
modules = [
cfg.overrideType
];
inherit specialArgs;
}));
};
};

View File

@ -281,6 +281,7 @@ in {
imports = [
./interface.nix
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
(commonModule defaultPackageName defaultPackageVersion)
];
deps = {nixpkgs, ...}:

View File

@ -2,7 +2,7 @@
config,
lib,
dream2nix,
packageSets,
specialArgs,
...
}: let
l = lib // builtins;
@ -34,12 +34,12 @@ in {
'';
};
deps = {
type = t.lazyAttrsOf (t.lazyAttrsOf (t.submodule {
imports = [
type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith {
modules = [
dream2nix.modules.dream2nix.core
dream2nix.modules.dream2nix.mkDerivation
];
_module.args = {inherit dream2nix packageSets;};
inherit specialArgs;
}));
};
};

View File

@ -30,6 +30,7 @@
in {
imports = [
./interface.nix
dream2nix.modules.dream2nix.core
dream2nix.modules.dream2nix.mkDerivation
];

View File

@ -5,14 +5,36 @@
...
}: let
t = lib.types;
staticModules = [
{_module.args = specialArgs;}
config.overrideType
];
# Monkey patch deferredModuleWith to accept specialArgs
# TODO: upstream specialArgs to deferredModuleWith in nixpkgs
deferredModuleWith = attrs @ {
staticModules ? [],
specialArgs ? {},
}:
t.deferredModuleWith {inherit staticModules;}
// {
inherit
(t.submoduleWith {
modules = staticModules;
inherit specialArgs;
})
getSubOptions
getSubModules
;
substSubModules = m:
deferredModuleWith (attrs
// {
staticModules = m;
});
};
in {
options = {
overrideAll = lib.mkOption {
type = t.deferredModuleWith {inherit staticModules;};
type = deferredModuleWith {
inherit specialArgs;
staticModules = [config.overrideType];
};
description = ''
Overrides applied on all dependencies.
'';
@ -23,7 +45,10 @@ in {
};
overrides = lib.mkOption {
type = t.attrsOf (t.deferredModuleWith {inherit staticModules;});
type = t.attrsOf (deferredModuleWith {
inherit specialArgs;
staticModules = [config.overrideType];
});
description = ''
Overrides applied only on dependencies matching the specified name.
'';
@ -37,7 +62,9 @@ in {
## INTERNAL
overrideType = lib.mkOption {
type = t.deferredModule;
type = deferredModuleWith {
inherit specialArgs;
};
default = {};
internal = true;
};

View File

@ -30,6 +30,7 @@ in {
imports = [
./interface.nix
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
];
# declare external dependencies

View File

@ -169,6 +169,7 @@
{config, ...}: {
imports = [
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
];
deps = {nixpkgs, ...}:
l.mapAttrs (_: l.mkDefault) {

View File

@ -24,11 +24,12 @@ in {
deps = {
internal = true;
visible = "shallow";
type = t.lazyAttrsOf (t.lazyAttrsOf (t.submodule {
imports = [
type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith {
modules = [
dream2nix.modules.dream2nix.core
cfg.overrideType
];
inherit specialArgs;
}));
};
composerInstallFlags = {

View File

@ -76,6 +76,7 @@
commonModule = {config, ...}: {
imports = [
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
../buildPythonPackage
];
config = {

View File

@ -139,8 +139,8 @@ in {
# hack because internal=true doesn't propagate to the submodule options
visible = "shallow";
type = t.lazyAttrsOf (t.submoduleWith {
inherit specialArgs;
modules = [dream2nix.modules.dream2nix.core];
specialArgs = {inherit packageSets dream2nix;};
});
description = "drv-parts modules that define python dependencies";
};

View File

@ -22,7 +22,6 @@ in {
version = "0.13.0";
deps = {nixpkgs, ...}: {
stdenv = lib.mkForce nixpkgs.stdenv;
jq = lib.mkForce nixpkgs.jq;
fetchFromGitHub = nixpkgs.fetchFromGitHub;
python = nixpkgs.python310;

View File

@ -185,6 +185,7 @@ in {
imports = [
./interface.nix
dream2nix.modules.dream2nix.mkDerivation
dream2nix.modules.dream2nix.core
];
rust-crane.depsDrv = {

View File

@ -83,7 +83,10 @@ in {
# version = "dummy-version";
# }
];
specialArgs.dream2nix = self;
specialArgs.dream2nix =
# trace website modules
# lib.trace modules
self;
specialArgs.packageSets.nixpkgs = pkgs;
};
# inputs.flake-parts.lib.evalFlakeModule