summary refs log tree commit diff
path: root/gnu/packages/node.scm
diff options
context:
space:
mode:
authorPhilip McGrath <philip@philipmcgrath.com>2021-12-16 21:02:44 -0500
committerLiliana Marie Prikler <liliana.prikler@gmail.com>2021-12-24 01:37:45 +0100
commit71adecd51a034a1efcd6e57ab3b63acece6c43a6 (patch)
treeb5707a58105cbba5641d99c3d5acb62b523bc2ce /gnu/packages/node.scm
parentbcaf6f14a1e32c4a3c7dec1b3e60a5ef541dc944 (diff)
downloadguix-71adecd51a034a1efcd6e57ab3b63acece6c43a6.tar.gz
gnu: node: Add an npmrc file to set nodedir.
* gnu/packages/node.scm (node, node-lts)[arguments]: Add a phase
'install-npmrc to create a "built-in" npmrc file that configures
"nodedir" to point to the output store path.
(libnode)[arguments]: Delete the 'install-npmrc phase.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
Diffstat (limited to 'gnu/packages/node.scm')
-rw-r--r--gnu/packages/node.scm20
1 files changed, 19 insertions, 1 deletions
diff --git a/gnu/packages/node.scm b/gnu/packages/node.scm
index 3bd98c715e..51a393caab 100644
--- a/gnu/packages/node.scm
+++ b/gnu/packages/node.scm
@@ -261,7 +261,24 @@
                 (find-files (search-input-directory outputs "lib/node_modules")
                             (lambda (file stat)
                               (executable-file? file))
-                            #:stat lstat))))))))
+                            #:stat lstat)))))
+         (add-after 'install 'install-npmrc
+           ;; Note: programs like node-gyp only receive these values if
+           ;; they are started via `npm` or `npx`.
+           ;; See: https://github.com/nodejs/node-gyp#npm-configuration
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out")))
+               (with-output-to-file
+                   ;; Use the config file "primarily for distribution
+                   ;; maintainers" rather than "{prefix}/etc/npmrc",
+                   ;; especially because node-build-system uses --prefix
+                   ;; to install things to their store paths:
+                   (string-append out "/lib/node_modules/npm/npmrc")
+                 (lambda ()
+                   ;; Tell npm (mostly node-gyp) where to find our
+                   ;; installed headers so it doesn't try to
+                   ;; download them from the internet:
+                   (format #t "nodedir=~a\n" out)))))))))
     (native-inputs
      `(;; Runtime dependencies for binaries used as a bootstrap.
        ("c-ares" ,c-ares)
@@ -822,4 +839,5 @@ source files.")
         `(cons* "--shared" "--without-npm" ,flags))
        ((#:phases phases '%standard-phases)
         `(modify-phases ,phases
+           (delete 'install-npmrc)
            (delete 'patch-nested-shebangs)))))))