-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
132 lines (123 loc) · 4.57 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{
inputs,
flake-parts-lib,
...
}: {
imports = [
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.languages = {
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
pkgs,
config,
...
}: let
inherit (lib) types mkOption literalExpression;
cfg = config.snow-blower.languages.javascript;
in {
options.snow-blower.languages.javascript = {
enable = lib.mkEnableOption "tools for JavaScript development";
directory = lib.mkOption {
type = lib.types.str;
default = config.snow-blower.paths.root;
defaultText = lib.literalExpression "config.snow-blower.paths.root";
description = ''
The JavaScript project's root directory. Defaults to the root of the devenv project.
Can be an absolute path or one relative to the root of the snow blower project.
'';
example = "./directory";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.nodejs-slim;
defaultText = lib.literalExpression "pkgs.nodejs-slim";
description = "The Node.js package to use.";
};
corepack = {
enable = lib.mkEnableOption "wrappers for npm, pnpm and Yarn via Node.js Corepack";
};
npm = {
enable = lib.mkEnableOption "install npm";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.nodejs;
defaultText = lib.literalExpression "pkgs.nodejs";
description = "The Node.js package to use.";
};
install.enable = lib.mkEnableOption "npm install during snow blower initialisation";
};
pnpm = {
enable = lib.mkEnableOption "install pnpm";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.nodePackages.pnpm;
defaultText = lib.literalExpression "pkgs.nodePackages.pnpm";
description = "The pnpm package to use.";
};
install.enable = lib.mkEnableOption "pnpm install during snow blower initialisation";
};
yarn = {
enable = lib.mkEnableOption "install yarn";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.yarn;
defaultText = lib.literalExpression "pkgs.yarn";
description = "The yarn package to use.";
};
install.enable = lib.mkEnableOption "yarn install during snow blower initialisation";
};
bun = {
enable = lib.mkEnableOption "install bun";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.bun;
defaultText = lib.literalExpression "pkgs.bun";
description = "The bun package to use.";
};
install.enable = lib.mkEnableOption "bun install during snow blower initialisation";
};
};
config.snow-blower = lib.mkIf cfg.enable {
packages = with pkgs;
[
cfg.package
]
++ lib.optional cfg.npm.enable cfg.npm.package
++ lib.optional cfg.pnpm.enable cfg.pnpm.package
++ lib.optional cfg.yarn.enable (cfg.yarn.package.override {nodejs = cfg.package;})
++ lib.optional cfg.bun.enable cfg.bun.package
++ lib.optional cfg.corepack.enable (pkgs.runCommand "corepack-enable" {} ''
mkdir -p $out/bin
${cfg.package}/bin/corepack enable --install-directory $out/bin
'');
env = {
NODEJS_HOME = cfg.package;
NPM_CONFIG_CACHE = config.snow-blower.env.PROJECT_STATE + "/npm";
NPM_CONFIG_USERCONFIG = config.snow-blower.env.PROJECT_STATE + "/npm/config";
NPM_CONFIG_TMP = config.snow-blower.env.PROJECT_RUNTIME + "/npm";
};
shell.startup = [
(
lib.concatStringsSep
"\n"
(
(lib.optional cfg.npm.install.enable ''
source ${(./init-npm.nix {inherit pkgs lib config;})}
'')
++ (lib.optional cfg.pnpm.install.enable ''
source ${(./init-pnpm.nix {inherit pkgs lib config;})}
'')
++ (lib.optional cfg.yarn.install.enable ''
source ${(./init-yarn.nix {inherit pkgs lib config;})}
'')
++ (lib.optional cfg.bun.install.enable ''
source ${(./init-bun.nix {inherit pkgs lib config;})}
'')
)
)
];
};
});
};
}