From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4D6vE0s012GTNAAAgWs5BA (envelope-from ) for ; Thu, 06 Jan 2022 19:26:19 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id mF/8EEs012E2YwEA9RJhRA (envelope-from ) for ; Thu, 06 Jan 2022 19:26:19 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0114D300E3 for ; Thu, 6 Jan 2022 19:26:19 +0100 (CET) Received: from localhost ([::1]:41446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5XSs-00078v-4w for larch@yhetil.org; Thu, 06 Jan 2022 13:26:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5XRl-0006PO-Ha for guix-patches@gnu.org; Thu, 06 Jan 2022 13:25:09 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:49300) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5XRj-0000hR-24 for guix-patches@gnu.org; Thu, 06 Jan 2022 13:25:09 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n5XRh-0004yP-UD for guix-patches@gnu.org; Thu, 06 Jan 2022 13:25:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v8 04/41] guix: node-build-system: Add avoid-node-gyp-rebuild phase. References: <20211114124151.36743-1-philip@philipmcgrath.com> In-Reply-To: <20211114124151.36743-1-philip@philipmcgrath.com> Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 06 Jan 2022 18:25:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51838 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Philip McGrath Cc: 51838@debbugs.gnu.org, Timothy Sample , Pierre Langlois , Jelle Licht , Leo Famulari Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.164149347718879 (code B ref 51838); Thu, 06 Jan 2022 18:25:05 +0000 Received: (at 51838) by debbugs.gnu.org; 6 Jan 2022 18:24:37 +0000 Received: from localhost ([127.0.0.1]:42169 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5XRD-0004uE-VE for submit@debbugs.gnu.org; Thu, 06 Jan 2022 13:24:36 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5XR3-0004rf-BO for 51838@debbugs.gnu.org; Thu, 06 Jan 2022 13:24:26 -0500 Received: by mail-wm1-f66.google.com with SMTP id c66so2403789wma.5 for <51838@debbugs.gnu.org>; Thu, 06 Jan 2022 10:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:subject:to:cc:content-transfer-encoding:message-id :mime-version; bh=/V8SyXxlRwGomAx4NVz2Zwi1zWAN1TfJYiWpjL6J/xs=; b=jkPaivdPCF8GQ7Cm2gzRArripgh7408PXeYdYxNgCw/RKV2gnmc2e0SPMCs5M/Yp9I 8jGRjAXov79SgAZ6XlNTwv+ihf5LzyDrbORHwRtgtuz7zyQ+5o3seNoOPRIyZY8EJQHi 1LR/DVz3HlpuW5kiMz4s4p02Tc7v/WenAYwQjFl+Oh7Fn0UrsEUTAdmdrWlXKcIwiPg2 BBLdwvXXp9MO0CUYy9eMXLkemCLhCnuFscS1qaAOc2Ykp9M7+A19oLWxGhG4zQezYOtJ o0f2F5q3V5xXn8h2pLtqEc3rHY/iyvKsbzIXICvLEqkZf+GkgPEmWdUEhD4QM3oopCkf PDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:subject:to:cc :content-transfer-encoding:message-id:mime-version; bh=/V8SyXxlRwGomAx4NVz2Zwi1zWAN1TfJYiWpjL6J/xs=; b=Je+rzZzFUhMFECHoTd+EZVwW7Z8HaO7xTMPPtUfXLLq0CeXhQd7BOhbvmIuKPcYIiO Gt/tz/5Hdhq4tp+6Taa1ViY6qYIaI6VL3mmU+yQebt3AGkdv7YBlxatbgA8quov7Rvjb Y4HliaWTpXKyfyc6ntS7Qe8VfHyThwiP2Yk0AUXQX236sODLwtbUXu9EuiPkRUvVGDPn c8mAJuQAQ9G7EQ7Kjn4C3y4ovrokH4E/nrPq3fSxP2HpTobYf4RISgBzh9CBMLnncwtI WGENndjmNbKgUqwLpj+7gNMhEayMKeSnmPo5Ms5BOngQ4ml7w0oE4bpcWnfr5DwBpt5h +n7A== X-Gm-Message-State: AOAM531yoaUHTRg1jEHtFLUKFZ89p4AOOeITnbvv86sVqBfOAZ64860n Yf9bcmWSMI3kxaKCdIh9h6s= X-Google-Smtp-Source: ABdhPJwdqgfaXftjFRtV/z4ewE5I/hZIrrmZ0krJzXNJzWUevkKOiGTholvxdwee3O0RdEGfU2paQA== X-Received: by 2002:a05:600c:34c8:: with SMTP id d8mr8379806wmq.94.1641493459836; Thu, 06 Jan 2022 10:24:19 -0800 (PST) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id b17sm2693311wrq.91.2022.01.06.10.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 10:24:19 -0800 (PST) From: Liliana Marie Prikler Date: Thu, 30 Dec 2021 02:38:42 -0500 Content-Transfer-Encoding: 7bit Message-ID: <2329a631211eadbc790c3c8ea99aaf4acf473e8c.camel@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641493579; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/V8SyXxlRwGomAx4NVz2Zwi1zWAN1TfJYiWpjL6J/xs=; b=L1j/oy5OUfyTpMlM+qej26Y9RlaAo+U00EGB9vsEGyg1onxpPFOrmCfa8S24jcwHwYWHd9 IzK9++zV4x16UU86bCMOcv0PmVvttYhw9c8OsmV/Rn35cc0ud+IIQjy/WNDUixB37OCXlh 3eZjxYX9CxiOGb59W8wsL14VoheI4GY3cW+IpA/Z/Ul0rWvabWzMQPg93E1QYFg96vuoSl Lw5Zic3lxf4F2pBPebHPwJv4pCH7/zadEErEU748Ft3gCJ1ba/BvA50FX0xDphJ96wM2Uw wS72EH6Ju6nyDI5TMA6WxRVwJfLX7jhEQCWvSjqKYFEo0tofwE+ImSnloRH+NQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641493579; a=rsa-sha256; cv=none; b=dEpWrCLUkjQJ8qWG4+yharBgrMhqUvbBvokZ8AVaJg/T/Qcfp/Zs40WYCPZndSJQdqtfNO al1MXBdYuEn3Ccgwef/TokKZHj8zMhudfftkZsd9l7/VAUUx/BIGq3x5PG+JbkKMS6R3rw GvuAlBU7TWiAyfLPhBuHz6qiYphaPfo4qtQBSOMoeXzpaAqC713X/VEFfDko2JIaNHMvLu O8oKHOK9bA/WI/V1bMygZ/mlqt5H/OeP6feJyYQAyDjVpjf2X8hGdP3Rc5qunYu1ITNfOg Nf/EWHEWlJfxW6TB3FOuytWRjcOK9xEDI+dpXZydDZtPg7pbuzROgQuyFf1zrg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=jkPaivdP; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.00 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=jkPaivdP; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 0114D300E3 X-Spam-Score: -1.00 X-Migadu-Scanner: scn1.migadu.com X-TUID: XaoOsszOf33I Packages with native addons currently try to write to store paths when used as dependecies. This patch adds a phase to replace that behaviour with a no-op. * guix/build/node-build-system.scm (avoid-node-gyp-rebuild): New variable. (%standard-phases): Add 'avoid-node-gyp-rebuild' after 'install'. Signed-off-by: Liliana Marie Prikler --- guix/build/node-build-system.scm | 54 +++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index c6602b876b..49b3db34ad 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -239,6 +239,57 @@ (define* (install #:key outputs inputs #:allow-other-keys) "install" "../package.tgz") #t)) +(define* (avoid-node-gyp-rebuild #:key outputs #:allow-other-keys) + "Adjust the installed 'package.json' to remove an 'install' script that +would try to run 'node-gyp rebuild'." + ;; We want to take advantage of `npm install`'s automatic support for + ;; building native addons with node-gyp: in particular, it helps us avoid + ;; hard-coding the specifics of how npm's internal copy of node-gyp is + ;; currently packaged. However, the mechanism by which the automatic support + ;; is implemented causes problems for us. + ;; + ;; If a package contains a 'binding.gyp' file and does not define an + ;; 'install' or 'preinstall' script, 'npm install' runs a default install + ;; script consisting of 'node-gyp rebuild'. In our 'install' phase, this + ;; implicit 'install' script, if it is applicable, is explicitly added to + ;; the "package.json" file. However, if another Guix package were to use a + ;; Node.js package with such an 'install' script, the dependent package's + ;; build process would fail, because 'node-gyp rebuild' would try to write + ;; to the store. + ;; + ;; Here, if the installed "package.json" defines scripts.install as + ;; "node-gyp rebuild", we replace it with a no-op. Importantly, deleting the + ;; install script definition would not be enough, because the default + ;; install script would cause the same problem. + ;; + ;; For further details, see: + ;; - https://docs.npmjs.com/cli/v8/configuring-npm/package-json#default-values + ;; - https://docs.npmjs.com/cli/v8/using-npm/scripts#best-practices + (define installed-package.json + (search-input-file outputs (string-append "/lib/node_modules/" + (module-name ".") + "/package.json"))) + ;; We don't want to use an atomic replacement here, because we often don't + ;; even need to overwrite this file. Therefore, let's use some helpers + ;; that we'd otherwise not need. + (define pkg-meta + (call-with-input-file installed-package.json read-json)) + (define scripts + (jsobject-ref pkg-meta "scripts" '(@))) + (define (jsobject-set js key val) + (jsobject-update* js (list key (const val)))) + + (when (equal? "node-gyp rebuild" (jsobject-ref scripts "install" #f)) + (call-with-output-file installed-package.json + (lambda (out) + (write-json + (jsobject-set pkg-meta + "scripts" + (jsobject-set scripts + "install" + "echo Guix: avoiding node-gyp rebuild")) + out))))) + (define %standard-phases (modify-phases gnu:%standard-phases (add-after 'unpack 'set-home set-home) @@ -248,7 +299,8 @@ (define %standard-phases (replace 'build build) (replace 'check check) (add-before 'install 'repack repack) - (replace 'install install))) + (replace 'install install) + (add-after 'install 'avoid-node-gyp-rebuild avoid-node-gyp-rebuild))) (define* (node-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args) -- 2.34.0