Personal Nix setup
at main 2.2 kB view raw
1{ lib, config, pkgs, ... }: 2 3with lib; 4let 5 cfg = config.modules.development; 6 hasReactNative = config.modules.development.enable; 7 NPMRC_PATH = "${config.xdg.configHome}/npm/npmrc"; 8 BUNFIG_PATH = "${config.xdg.configHome}/.bunfig.toml"; 9 BUN_HOME = "${config.xdg.dataHome}/bun"; 10 PNPM_HOME = "${config.xdg.dataHome}/pnpm"; 11in { 12 options.modules.development.js = { 13 enable = mkOption { 14 default = cfg.enable; 15 example = true; 16 description = "Whether to enable JS configuration."; 17 type = types.bool; 18 }; 19 20 bun = mkOption { 21 default = cfg.js.enable; 22 type = types.bool; 23 }; 24 25 wasmtime = mkOption { 26 default = cfg.js.enable; 27 type = types.bool; 28 }; 29 }; 30 31 config = mkIf cfg.js.enable { 32 age.secrets."${NPMRC_PATH}" = { 33 symlink = true; 34 path = "${NPMRC_PATH}"; 35 file = ./encrypt/npmrc.age; 36 }; 37 38 home.sessionPath = [ 39 "./node_modules/.bin" 40 PNPM_HOME 41 ] ++ optionals cfg.js.bun [ BUN_HOME ]; 42 43 home.sessionVariables = { 44 inherit PNPM_HOME; 45 BUN_RUNTIME_TRANSPILER_CACHE_PATH = mkIf cfg.js.bun "${config.xdg.cacheHome}/bun/install/cache/@t@"; 46 NODE_REPL_HISTORY = "${config.xdg.stateHome}/node_repl_history"; 47 NPM_CONFIG_USERCONFIG = "${NPMRC_PATH}"; 48 NPM_CONFIG_CACHE = "${config.xdg.cacheHome}/npm"; 49 NPM_CONFIG_TMP = "$XDG_RUNTIME_DIR/npm"; 50 VOLTA_HOME = "${config.xdg.dataHome}/volta"; 51 52 COREPACK_ENABLE_AUTO_PIN = "0"; # disable corepack creating packageManager entries 53 COREPACK_INTEGRITY_KEYS = "0"; 54 COREPACK_ENABLE_STRICT = "0"; 55 }; 56 57 home.file.".yarnrc".text = '' 58 disable-self-update-check true 59 ''; 60 61 home.file."${BUNFIG_PATH}".text = mkIf cfg.js.bun '' 62 telemetry = false 63 64 [install] 65 auto = "disable" 66 globalDir = "${BUN_HOME}/global" 67 globalBinDir = "${BUN_HOME}" 68 69 [install.cache] 70 dir = "${config.xdg.cacheHome}/bun" 71 ''; 72 73 home.packages = with pkgs; [ 74 corepack_22 75 nodejs_22 76 ] 77 ++ optionals cfg.js.bun [ pkgs.bun ] 78 ++ optionals cfg.js.wasmtime [ pkgs.wasmtime ] 79 ++ optionals hasReactNative [ pkgs.flow ]; 80 }; 81}