From 94db13435362dba268a4e7d60f774b782a29dd78 Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 6 Oct 2024 18:47:32 +0200 Subject: [PATCH] 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`. --- lib/default.nix | 2 +- .../dream2nix/WIP-haskell-cabal/default.nix | 1 - modules/dream2nix/WIP-spago/default.nix | 1 - modules/dream2nix/core/deps/default.nix | 9 ++++-- modules/dream2nix/core/env/default.nix | 1 - modules/dream2nix/core/public/interface.nix | 1 - .../core/tests/packages/nixpkgs/default.nix | 32 +++++++++++++++++++ .../nodejs-granular-v3/interface.nix | 1 - modules/dream2nix/php-granular/interface.nix | 1 - 9 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 modules/dream2nix/core/tests/packages/nixpkgs/default.nix diff --git a/lib/default.nix b/lib/default.nix index 01c86fd3..d44d57a0 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -67,8 +67,8 @@ ]; specialArgs = specialArgs + // {inherit packageSets;} // { - inherit packageSets; dream2nix.modules.dream2nix = dream2nix.modules.dream2nix; dream2nix.overrides = dream2nix.overrides; dream2nix.lib.evalModules = evalModules; diff --git a/modules/dream2nix/WIP-haskell-cabal/default.nix b/modules/dream2nix/WIP-haskell-cabal/default.nix index 8f20666e..cdedec2f 100644 --- a/modules/dream2nix/WIP-haskell-cabal/default.nix +++ b/modules/dream2nix/WIP-haskell-cabal/default.nix @@ -2,7 +2,6 @@ lib, dream2nix, config, - packageSets, ... }: let cfg = config.haskell-cabal; diff --git a/modules/dream2nix/WIP-spago/default.nix b/modules/dream2nix/WIP-spago/default.nix index a828fefc..fa8229d5 100644 --- a/modules/dream2nix/WIP-spago/default.nix +++ b/modules/dream2nix/WIP-spago/default.nix @@ -2,7 +2,6 @@ lib, dream2nix, config, - packageSets, ... }: let l = lib // builtins; diff --git a/modules/dream2nix/core/deps/default.nix b/modules/dream2nix/core/deps/default.nix index 1e92b581..91ca9bc7 100644 --- a/modules/dream2nix/core/deps/default.nix +++ b/modules/dream2nix/core/deps/default.nix @@ -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 + ); } diff --git a/modules/dream2nix/core/env/default.nix b/modules/dream2nix/core/env/default.nix index 814c7257..8252e81c 100644 --- a/modules/dream2nix/core/env/default.nix +++ b/modules/dream2nix/core/env/default.nix @@ -1,7 +1,6 @@ { config, lib, - packageSets, ... }: let l = lib // builtins; diff --git a/modules/dream2nix/core/public/interface.nix b/modules/dream2nix/core/public/interface.nix index 2ded6bbc..6d24cfd7 100644 --- a/modules/dream2nix/core/public/interface.nix +++ b/modules/dream2nix/core/public/interface.nix @@ -1,7 +1,6 @@ { config, lib, - packageSets, ... }: let l = lib // builtins; diff --git a/modules/dream2nix/core/tests/packages/nixpkgs/default.nix b/modules/dream2nix/core/tests/packages/nixpkgs/default.nix new file mode 100644 index 00000000..8fbf44aa --- /dev/null +++ b/modules/dream2nix/core/tests/packages/nixpkgs/default.nix @@ -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 + ''; +} diff --git a/modules/dream2nix/nodejs-granular-v3/interface.nix b/modules/dream2nix/nodejs-granular-v3/interface.nix index 2a558d18..4a6f0d2f 100644 --- a/modules/dream2nix/nodejs-granular-v3/interface.nix +++ b/modules/dream2nix/nodejs-granular-v3/interface.nix @@ -2,7 +2,6 @@ config, lib, dream2nix, - packageSets, specialArgs, ... }: let diff --git a/modules/dream2nix/php-granular/interface.nix b/modules/dream2nix/php-granular/interface.nix index 8f5dd3ad..be0f9f66 100644 --- a/modules/dream2nix/php-granular/interface.nix +++ b/modules/dream2nix/php-granular/interface.nix @@ -2,7 +2,6 @@ config, dream2nix, lib, - packageSets, specialArgs, ... }: let