Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs-granular: allow overrides for specific and all nodejsDeps #958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions modules/dream2nix/nodejs-granular/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
73 changes: 43 additions & 30 deletions modules/dream2nix/nodejs-granular/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}));
};
};
};
}