add module arg pkgs

This change adds a `pkgs` arguments to the module args.

Accessing packages from nixpkgs becomes easier as the user is not forced to go through `config.deps` anymore.

`config.deps` can still be used to override packages from `pkgs`.
This commit is contained in:
DavHau 2024-10-06 18:47:32 +02:00
parent c7cb1c48c3
commit 94db134353
9 changed files with 40 additions and 9 deletions

View File

@ -67,8 +67,8 @@
]; ];
specialArgs = specialArgs =
specialArgs specialArgs
// {inherit packageSets;}
// { // {
inherit packageSets;
dream2nix.modules.dream2nix = dream2nix.modules.dream2nix; dream2nix.modules.dream2nix = dream2nix.modules.dream2nix;
dream2nix.overrides = dream2nix.overrides; dream2nix.overrides = dream2nix.overrides;
dream2nix.lib.evalModules = evalModules; dream2nix.lib.evalModules = evalModules;

View File

@ -2,7 +2,6 @@
lib, lib,
dream2nix, dream2nix,
config, config,
packageSets,
... ...
}: let }: let
cfg = config.haskell-cabal; cfg = config.haskell-cabal;

View File

@ -2,7 +2,6 @@
lib, lib,
dream2nix, dream2nix,
config, config,
packageSets,
... ...
}: let }: let
l = lib // builtins; l = lib // builtins;

View File

@ -22,8 +22,6 @@ in {
So deps should be specific, but not overly specific. For instance, the caller shouldn't have to know the version of a dependency in order to override it. The name should suffice. (e.g. `nix = nixVersions.nix_2_12` instead of `inherit (nixVersions) nix_2_12`. So deps should be specific, but not overly specific. For instance, the caller shouldn't have to know the version of a dependency in order to override it. The name should suffice. (e.g. `nix = nixVersions.nix_2_12` instead of `inherit (nixVersions) nix_2_12`.
''; '';
type = t.submoduleWith { type = t.submoduleWith {
# TODO: This could be made stricter by removing the freeformType
# Maybe add option `strictDeps = true/false` ? ;P
modules = [{freeformType = t.lazyAttrsOf t.raw;}]; modules = [{freeformType = t.lazyAttrsOf t.raw;}];
specialArgs = packageSets; specialArgs = packageSets;
}; };
@ -36,4 +34,11 @@ in {
default = {}; default = {};
}; };
}; };
config._module.args.pkgs =
config.deps
// lib.optionalAttrs (packageSets ? nixpkgs) (
builtins.mapAttrs
(name: pkg: config.deps.${name} or pkg)
packageSets.nixpkgs
);
} }

View File

@ -1,7 +1,6 @@
{ {
config, config,
lib, lib,
packageSets,
... ...
}: let }: let
l = lib // builtins; l = lib // builtins;

View File

@ -1,7 +1,6 @@
{ {
config, config,
lib, lib,
packageSets,
... ...
}: let }: let
l = lib // builtins; l = lib // builtins;

View File

@ -0,0 +1,32 @@
{
dream2nix,
pkgs,
config,
...
}: {
imports = [
dream2nix.modules.dream2nix.mkDerivation-mixin
dream2nix.modules.dream2nix.core
];
deps = {nixpkgs, ...}: {
foo = nixpkgs.hello.overrideAttrs (old: {
pname = "foo";
phases = ["buildPhase"];
buildPhase = "echo -n hello > $out";
});
};
name = "test";
version = "0.0.0";
phases = ["buildPhase"];
buildPhase = ''
# explicit package
echo ${pkgs.foo} >> $out
# implicit package
echo ${pkgs.hello} >> $out
if [ "${pkgs.foo}" != "${config.deps.foo}" ]; then
echo "foo mismatch: ${pkgs.foo} != ${config.deps.foo}" >&2
exit 1
fi
'';
}

View File

@ -2,7 +2,6 @@
config, config,
lib, lib,
dream2nix, dream2nix,
packageSets,
specialArgs, specialArgs,
... ...
}: let }: let

View File

@ -2,7 +2,6 @@
config, config,
dream2nix, dream2nix,
lib, lib,
packageSets,
specialArgs, specialArgs,
... ...
}: let }: let