From 2aac162aba2a7479bcd05153139bc535bb46360e Mon Sep 17 00:00:00 2001 From: alsaiduq-lab Date: Fri, 12 Sep 2025 16:32:37 -0600 Subject: [PATCH] npm fix update to prevent accidental dirs from being created --- hosts/modules/npm.nix | 60 +++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/hosts/modules/npm.nix b/hosts/modules/npm.nix index 7845690..aa32944 100644 --- a/hosts/modules/npm.nix +++ b/hosts/modules/npm.nix @@ -1,16 +1,6 @@ +{ config, pkgs, lib, ... }: { - config, - pkgs, - lib, - ... -}: let - npmConf = pkgs.writeText "npmrc" '' - prefix=${"$"}HOME/.npm-global - cache=${"$"}HOME/.npm - init-module=${"$"}HOME/.npm-init.js - ''; -in { - options.npm.enable = lib.mkEnableOption "system-wide npm environment"; + options.npm.enable = lib.mkEnableOption "npm setup"; config = lib.mkIf config.npm.enable { environment.systemPackages = with pkgs; [ @@ -21,31 +11,33 @@ in { nodePackages.typescript ]; - environment.etc."npmrc".source = npmConf; - - systemd.user.services.npm-global-dir = { - wantedBy = ["default.target"]; + systemd.user.services."npm-init" = { + wantedBy = [ "default.target" ]; + serviceConfig.Type = "oneshot"; script = '' - mkdir -p $HOME/.npm-global/bin - chmod u+rwx $HOME/.npm-global - ''; - serviceConfig = { - Type = "oneshot"; - }; - }; - - systemd.user.services.npm-setup = { - wantedBy = ["default.target"]; - script = '' - if [ ! -f ~/.npmrc ]; then - cp ${npmConf} ~/.npmrc - chmod u+rw ~/.npmrc + set -eu + H="$HOME" + mkdir -p "$H/.npm-global/bin" "$H/.npm" + tmp="$(mktemp)" + cat > "$tmp" <