2020-01-12 23:11:02 -08:00
|
|
|
# modules/dev/node.nix --- https://nodejs.org/en/
|
|
|
|
#
|
|
|
|
# JS is one of those "when it's good, it's alright, when it's bad, it's a
|
|
|
|
# disaster" languages.
|
2019-08-06 10:56:54 -07:00
|
|
|
|
2020-04-06 20:27:35 -07:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
2020-10-01 15:46:04 -07:00
|
|
|
|
2020-04-06 20:27:35 -07:00
|
|
|
with lib;
|
2020-10-01 15:46:04 -07:00
|
|
|
with lib.my;
|
|
|
|
let cfg = config.modules.dev.node;
|
2021-08-05 22:30:07 -07:00
|
|
|
node = pkgs.nodejs_latest;
|
2020-10-01 15:46:04 -07:00
|
|
|
in {
|
2020-04-06 20:27:35 -07:00
|
|
|
options.modules.dev.node = {
|
2020-10-01 15:46:04 -07:00
|
|
|
enable = mkBoolOpt false;
|
2021-08-05 22:30:07 -07:00
|
|
|
enableGlobally = mkBoolOpt false;
|
2020-04-06 20:27:35 -07:00
|
|
|
};
|
2019-08-06 10:56:54 -07:00
|
|
|
|
2021-08-05 22:30:07 -07:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.enableGlobally {
|
|
|
|
user.packages = with pkgs; [
|
|
|
|
node
|
|
|
|
yarn
|
|
|
|
];
|
2020-01-12 16:47:33 -08:00
|
|
|
|
2021-08-05 22:30:07 -07:00
|
|
|
# Run locally installed bin-script, e.g. n coffee file.coffee
|
|
|
|
environment.shellAliases = {
|
|
|
|
n = "PATH=\"$(${node}/bin/npm bin):$PATH\"";
|
|
|
|
ya = "yarn";
|
|
|
|
};
|
2020-01-12 16:47:33 -08:00
|
|
|
|
2021-08-05 22:30:07 -07:00
|
|
|
env.PATH = [ "$(${pkgs.yarn}/bin/yarn global bin)" ];
|
|
|
|
})
|
2020-10-01 15:46:04 -07:00
|
|
|
|
2021-08-05 22:30:07 -07:00
|
|
|
{
|
|
|
|
env.NPM_CONFIG_USERCONFIG = "$XDG_CONFIG_HOME/npm/config";
|
|
|
|
env.NPM_CONFIG_CACHE = "$XDG_CACHE_HOME/npm";
|
|
|
|
env.NPM_CONFIG_TMP = "$XDG_RUNTIME_DIR/npm";
|
|
|
|
env.NPM_CONFIG_PREFIX = "$XDG_CACHE_HOME/npm";
|
|
|
|
env.NODE_REPL_HISTORY = "$XDG_CACHE_HOME/node/repl_history";
|
|
|
|
|
|
|
|
home.configFile."npm/config".text = ''
|
|
|
|
cache=$XDG_CACHE_HOME/npm
|
|
|
|
prefix=$XDG_DATA_HOME/npm
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
]);
|
2019-08-06 10:56:54 -07:00
|
|
|
}
|