From 89feb64c5c503319ab47c7c257fcd65193360e84 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Wed, 15 May 2024 15:11:33 +0530 Subject: [PATCH] nodejs-granular: allow overrides for specific and all nodejsDeps --- modules/dream2nix/nodejs-granular/default.nix | 21 ++++-- .../dream2nix/nodejs-granular/interface.nix | 73 +++++++++++-------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/modules/dream2nix/nodejs-granular/default.nix b/modules/dream2nix/nodejs-granular/default.nix index f1442d8f5d..d64850e1ea 100644 --- a/modules/dream2nix/nodejs-granular/default.nix +++ b/modules/dream2nix/nodejs-granular/default.nix @@ -71,18 +71,23 @@ nodejsDeps = lib.mapAttrs - (name: versions: - lib.genAttrs - versions - (version: - makeDependencyModule name version)) + ( + name: versions: + lib.genAttrs + versions + (version: {...}: { + imports = [ + (commonModule name version) + (makeDependencyModule name version) + cfg.overrideAll + (cfg.overrides.${name} or {}) + ]; + }) + ) packageVersions; # Generates a derivation for a specific package name + version makeDependencyModule = name: version: {config, ...}: { - imports = [ - (commonModule name version) - ]; name = lib.replaceStrings ["@" "/"] ["__at__" "__slash__"] name; inherit version; env = { diff --git a/modules/dream2nix/nodejs-granular/interface.nix b/modules/dream2nix/nodejs-granular/interface.nix index df24f7d083..5bac4d524b 100644 --- a/modules/dream2nix/nodejs-granular/interface.nix +++ b/modules/dream2nix/nodejs-granular/interface.nix @@ -7,40 +7,53 @@ }: let l = lib // builtins; t = l.types; + cfg = config.nodejs-granular; + mkSubmodule = import ../../../lib/internal/mkSubmodule.nix {inherit lib specialArgs;}; in { - options.nodejs-granular = l.mapAttrs (_: l.mkOption) { - buildScript = { - type = t.nullOr (t.oneOf [t.str t.path t.package]); - description = '' - A command or script to execute instead of `npm run build`. - Is only executed if `runBuild = true`. - ''; - }; - installMethod = { - type = t.enum [ - "symlink" - "copy" + options.nodejs-granular = mkSubmodule { + imports = [ + ../overrides + ]; + config.overrideType = { + imports = [ + dream2nix.modules.dream2nix.mkDerivation + dream2nix.modules.dream2nix.core ]; - description = '' - Strategy to use for populating ./node_modules. - Symlinking is quicker, but often introduces compatibility issues with bundlers like webpack and other build tools. - Copying is slow, but more reliable; - ''; - }; - runBuild = { - type = t.bool; - description = '' - Whether to run a package's build script (aka. `npm run build`) - ''; }; - deps = { - type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith { - modules = [ - dream2nix.modules.dream2nix.core - dream2nix.modules.dream2nix.mkDerivation + + options = l.mapAttrs (_: l.mkOption) { + buildScript = { + type = t.nullOr (t.oneOf [t.str t.path t.package]); + description = '' + A command or script to execute instead of `npm run build`. + Is only executed if `runBuild = true`. + ''; + }; + installMethod = { + type = t.enum [ + "symlink" + "copy" ]; - inherit specialArgs; - })); + description = '' + Strategy to use for populating ./node_modules. + Symlinking is quicker, but often introduces compatibility issues with bundlers like webpack and other build tools. + Copying is slow, but more reliable; + ''; + }; + runBuild = { + type = t.bool; + description = '' + Whether to run a package's build script (aka. `npm run build`) + ''; + }; + deps = { + type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith { + modules = [ + cfg.overrideType + ]; + inherit specialArgs; + })); + }; }; }; }