nodejs-granular: allow overrides for specific and all nodejsDeps

This commit is contained in:
shivaraj-bh 2024-05-15 15:11:33 +05:30
parent 69ce9f24c0
commit 89feb64c5c
2 changed files with 56 additions and 38 deletions

View File

@ -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 = {

View File

@ -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;
}));
};
};
};
}