Skip to content

Commit

Permalink
add module arg pkgs
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
DavHau committed Oct 7, 2024
1 parent c7cb1c4 commit cd9d1a5
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
];
specialArgs =
specialArgs
// {inherit packageSets;}
// {
inherit packageSets;
dream2nix.modules.dream2nix = dream2nix.modules.dream2nix;
dream2nix.overrides = dream2nix.overrides;
dream2nix.lib.evalModules = evalModules;
Expand Down
1 change: 0 additions & 1 deletion modules/dream2nix/WIP-haskell-cabal/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
lib,
dream2nix,
config,
packageSets,
...
}: let
cfg = config.haskell-cabal;
Expand Down
1 change: 0 additions & 1 deletion modules/dream2nix/WIP-spago/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
lib,
dream2nix,
config,
packageSets,
...
}: let
l = lib // builtins;
Expand Down
9 changes: 7 additions & 2 deletions modules/dream2nix/core/deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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
);
}
1 change: 0 additions & 1 deletion modules/dream2nix/core/env/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
config,
lib,
packageSets,
...
}: let
l = lib // builtins;
Expand Down
1 change: 0 additions & 1 deletion modules/dream2nix/core/public/interface.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
config,
lib,
packageSets,
...
}: let
l = lib // builtins;
Expand Down
1 change: 0 additions & 1 deletion modules/dream2nix/nodejs-granular-v3/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
config,
lib,
dream2nix,
packageSets,
specialArgs,
...
}: let
Expand Down
1 change: 0 additions & 1 deletion modules/dream2nix/php-granular/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
config,
dream2nix,
lib,
packageSets,
specialArgs,
...
}: let
Expand Down
50 changes: 50 additions & 0 deletions tests/nix-unit/nixpkgs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
pkgs ? import <nixpkgs> {},
lib ? import <nixpkgs/lib>,
inputs ? {},
dream2nix ? import ../../.. inputs,
}: let
eval = module:
(lib.evalModules {
modules = [
dream2nix.modules.dream2nix.WIP-groups
module
];
specialArgs = {
inherit dream2nix;
packageSets.nixpkgs = pkgs;
};
})
.config;
in {
test_old = let
config = eval (
{pkgs, ...}: {
imports = [
dream2nix.modules.dream2nix.mkDerivation-mixin
dream2nix.modules.dream2nix.deps
];
deps = {nixpkgs, ...}: {
foo = nixpkgs.hello.overrideAttrs (old: {
pname = "foo";
});
};
name = "test";
version = "0.0.0";
phases = ["buildPhase"];
buildPhase = ''
# explicit package
echo ${pkgs.foo} >> $out
# implicit package
echo ${pkgs.hello} >> $out
'';
}
);
in {
expr = builtins.readFile config.public;
expected = ''
${config.deps.foo}
${pkgs.hello}
'';
};
}

0 comments on commit cd9d1a5

Please sign in to comment.