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
// {inherit packageSets;}
// {
inherit packageSets;
dream2nix.modules.dream2nix = dream2nix.modules.dream2nix;
dream2nix.overrides = dream2nix.overrides;
dream2nix.lib.evalModules = evalModules;

View File

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

View File

@ -2,7 +2,6 @@
lib,
dream2nix,
config,
packageSets,
...
}: let
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`.
'';
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;}];
specialArgs = packageSets;
};
@ -36,4 +34,11 @@ in {
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,
lib,
packageSets,
...
}: let
l = lib // builtins;

View File

@ -1,7 +1,6 @@
{
config,
lib,
packageSets,
...
}: let
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,
lib,
dream2nix,
packageSets,
specialArgs,
...
}: let

View File

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