From patchwork Thu Nov 10 16:05:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 44429 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8463227BBEB; Thu, 10 Nov 2022 16:07:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED,URI_HEX autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A1CFE27BBE9 for ; Thu, 10 Nov 2022 16:07:23 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otA58-0002xe-J3; Thu, 10 Nov 2022 11:07:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otA51-0002u0-68 for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otA50-0003C1-U6 for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otA50-0000YT-ET for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#58812] [PATCH v3 1/4] Makefile.am: Sort EXTRA_DIST entries. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 10 Nov 2022 16:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58812 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58812@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58812-submit@debbugs.gnu.org id=B58812.16680963752018 (code B ref 58812); Thu, 10 Nov 2022 16:07:02 +0000 Received: (at 58812) by debbugs.gnu.org; 10 Nov 2022 16:06:15 +0000 Received: from localhost ([127.0.0.1]:44041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4E-0000WT-Qq for submit@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:15 -0500 Received: from mail-qt1-f170.google.com ([209.85.160.170]:33670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4A-0000W2-A1 for 58812@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:13 -0500 Received: by mail-qt1-f170.google.com with SMTP id w4so1192733qts.0 for <58812@debbugs.gnu.org>; Thu, 10 Nov 2022 08:06:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XGrPvhQ/9qGJmUplPfL27tDsvHuvx+A+Tne09I59vJU=; b=GsfOTu/Ye3sOjZh94z0ApIzOK/vLd9ZYyB+qDvKzZBLLEH+PAT1i3b7iyQIrwsnMs5 3kLP6BhLSAQgx4PSSHAmKEikf+L06CiJlWA56fWY01IE/YXCEERlvb1zZ00L4KRmnEXr Ph9M5JTJyFP42zv7xFwNrT2CmmP7R2NPVBW1kdxw4ePPfTqOKikgOpjFj7gDAjPxi9Aa q8GGPwFre0P5CHsn54dilzxOUj53IaG/4tyxb/IcUokNCVQDvLsBQhQXCXb5U7jjV9uG /ZujiMDFBDfzFBrnFwlGXKu0O0Ix9JvtuZeiJNZ6t21Jnfzl0sy2PafU08zZL6JJ9llu Ri5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XGrPvhQ/9qGJmUplPfL27tDsvHuvx+A+Tne09I59vJU=; b=G6jzOH/rAU7VEwG09V+piLB+T0LVp9mNZ25RcxzLcKEHHBs69m0PHhiv/KSDN+HTUu Y2Ehce6KIr+nUhwr452PBBIW+QCE4tLwdPP22b9AZGyTNcNW1jUlKFBMUfABI1VXDvda o4zn9urJrA2wO4VYvC8VSYq7aFeTWgvggjFi+oJQIU6Rxb7IBXwgKe8PJvx120Qf3cVL /wMO3FY1RUOzH8TxsGSGAQ/KG2P/KIZNENDZcwpRsUki3PG6mfr0rLuajF+Dbo1STgdW 83BhOMM9ntQ7MZzamAmMkBivlnqaKAxgIcYUwT1qHgY7nc+PpkjDn2xIx9hz44T5M/7K 1Wqw== X-Gm-Message-State: ACrzQf2FvFbLC9sZt0nhQjHhJ8IcPQ57JJwowMVSTnhaIgPDCjnGZWvL lyeZ7G6rBXgnUoMyUYpqWd4k/jMA+Qs= X-Google-Smtp-Source: AMsMyM4zVKXGBGZM/wWQAFeCdh3yAy81wcN4GFDZPx6qA1jTERQtrMcmXBQnpE0MnAHDok4iyNhUyg== X-Received: by 2002:ac8:6bc8:0:b0:397:c806:2162 with SMTP id b8-20020ac86bc8000000b00397c8062162mr1347218qtt.171.1668096364599; Thu, 10 Nov 2022 08:06:04 -0800 (PST) Received: from localhost.localdomain ([2607:fad8:4:3::1001]) by smtp.gmail.com with ESMTPSA id t18-20020a37ea12000000b006fafc111b12sm6344916qkj.83.2022.11.10.08.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 08:06:04 -0800 (PST) From: Maxim Cournoyer Date: Thu, 10 Nov 2022 11:05:47 -0500 Message-Id: <20221110160550.4366-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <87sfiqhp1u.fsf@gnu.org> References: <87sfiqhp1u.fsf@gnu.org> 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * Makefile.am (EXTRA_DIST): Sort. --- Makefile.am | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Makefile.am b/Makefile.am index 47886721fa..c3af23b68e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -660,49 +660,49 @@ dist_fishcompletion_DATA = etc/completion/fish/guix.fish nodist_selinux_policy_DATA = etc/guix-daemon.cil EXTRA_DIST += \ - HACKING \ - ROADMAP \ - TODO \ - CODE-OF-CONDUCT \ .dir-locals.el \ .guix-authorizations \ .guix-channel \ - scripts/guix.in \ - etc/disarchive-manifest.scm \ - etc/guix-install.sh \ - etc/news.scm \ - etc/release-manifest.scm \ - etc/source-manifest.scm \ - etc/system-tests.scm \ - etc/time-travel-manifest.scm \ - etc/historical-authorizations \ + CODE-OF-CONDUCT \ + HACKING \ + ROADMAP \ + TODO \ + bootstrap \ build-aux/build-self.scm \ - build-aux/compile-all.scm \ - build-aux/cuirass/hurd-manifest.scm \ - build-aux/check-final-inputs-self-contained.scm \ build-aux/check-channel-news.scm \ + build-aux/check-final-inputs-self-contained.scm \ + build-aux/compile-all.scm \ build-aux/compile-as-derivation.scm \ + build-aux/config.rpath \ build-aux/convert-xref.scm \ + build-aux/cuirass/hurd-manifest.scm \ build-aux/generate-authors.scm \ build-aux/test-driver.scm \ - build-aux/update-guix-package.scm \ build-aux/update-NEWS.scm \ - tests/test.drv \ + build-aux/update-guix-package.scm \ + doc/build.scm \ + etc/disarchive-manifest.scm \ + etc/guix-install.sh \ + etc/historical-authorizations \ + etc/news.scm \ + etc/release-manifest.scm \ + etc/source-manifest.scm \ + etc/system-tests.scm \ + etc/time-travel-manifest.scm \ + scripts/guix.in \ tests/cve-sample.json \ - tests/keys/signing-key.pub \ - tests/keys/signing-key.sec \ tests/keys/civodul.pub \ - tests/keys/rsa.pub \ tests/keys/dsa.pub \ - tests/keys/ed25519.pub \ - tests/keys/ed25519.sec \ tests/keys/ed25519-2.pub \ tests/keys/ed25519-2.sec \ tests/keys/ed25519-3.pub \ tests/keys/ed25519-3.sec \ - build-aux/config.rpath \ - bootstrap \ - doc/build.scm \ + tests/keys/ed25519.pub \ + tests/keys/ed25519.sec \ + tests/keys/rsa.pub \ + tests/keys/signing-key.pub \ + tests/keys/signing-key.sec \ + tests/test.drv \ $(TESTS) if !BUILD_DAEMON_OFFLOAD From patchwork Thu Nov 10 16:05:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 44428 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C1A4F27BBEB; Thu, 10 Nov 2022 16:07:20 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4D68B27BBE9 for ; Thu, 10 Nov 2022 16:07:19 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otA58-0002xn-JZ; Thu, 10 Nov 2022 11:07:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otA51-0002u1-AS for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otA51-0003CE-2U for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otA50-0000Yc-Tj for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#58812] [PATCH v3 2/4] install: Validate symlink target in evaluate-populate-directive. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 10 Nov 2022 16:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58812 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58812@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58812-submit@debbugs.gnu.org id=B58812.16680963772033 (code B ref 58812); Thu, 10 Nov 2022 16:07:02 +0000 Received: (at 58812) by debbugs.gnu.org; 10 Nov 2022 16:06:17 +0000 Received: from localhost ([127.0.0.1]:44045 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4H-0000Wi-BZ for submit@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:17 -0500 Received: from mail-qt1-f181.google.com ([209.85.160.181]:34561) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4F-0000WC-Ke for 58812@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:16 -0500 Received: by mail-qt1-f181.google.com with SMTP id e15so1174921qts.1 for <58812@debbugs.gnu.org>; Thu, 10 Nov 2022 08:06:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zrkjGIBtzayhHZQrYnnG/gG6ymHR3J6x5PRzXc/KVf4=; b=ppiVJj8OjcamSEDw8VrTouNF+kWeQAzWkkdGuBuszLhux9+uPX4aVuv00hEbB+uQDp 7RoU09nD8SSGgYNpXW2H3SUQuEOFxcTkGkTHBtP9jjs4lwUrutzScGGjYuGUKUVBfoBr pqVb5PY661Gu2y9OA7LrsRviltzjQosOFTxL1eL52bsKaLBGA1CPcBVlOOz3te8a1z9x AkSMszeOp8qAtn0aqmKjOgnlCgCamDblqcUA9Y045Z3o+ZbYU8h6e24YeUbkqFp88e9y wn/zZ8sArdEsewsvt05kXhe5JGRii9fksAL9efEzmiKxzNow8YTlTGn+cHMhhvR1JBfC DKlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zrkjGIBtzayhHZQrYnnG/gG6ymHR3J6x5PRzXc/KVf4=; b=dUu9DA/erGVzPgB0VlUfsVThCfbFT5sObQdmk78adJ4npbhLRr0y6gHXrIw7GDEUoz xci7y9xz9xPt8bD60sTXwG1xAbZAY0eYCwLGRaSrUIeVTWv5rNIXusDfd0TShutgDpNJ MwStE1iSgb/MjfClB0UNC/QEP/Zuwi5R7WtvEo4hJpSdH5yzhNJvmx1El6U5BBQ1p38B AFuHtblRyPclAatGixbMOC9GJ66O6j2AYevhiklFWm6P3Phf6kwDw7Jja5Mcz2cHoQoP vcKhGPRp3bapGgCiZHp9mWibVnGJ3HZB1kTwUC04TlPh+10d2qg+3C4TiQJUVYUYgmkj umTw== X-Gm-Message-State: ANoB5pkVjwVcFkplAdREbvlVIEGPlKB5fRGoVBy9EVRoI10xXTCY5g2S 9oaDy0ZMOJ2pMZFT+DwC1U46EzpAVKI= X-Google-Smtp-Source: AA0mqf43uru6AFvMrE0DdVpO4DVqAkfu1kQYydlnoemQPib17jc5v8xzUekZAo3BKQ2/kR0owG8tzA== X-Received: by 2002:ac8:7755:0:b0:3a5:925a:b33a with SMTP id g21-20020ac87755000000b003a5925ab33amr15592955qtu.69.1668096368522; Thu, 10 Nov 2022 08:06:08 -0800 (PST) Received: from localhost.localdomain ([2607:fad8:4:3::1001]) by smtp.gmail.com with ESMTPSA id t18-20020a37ea12000000b006fafc111b12sm6344916qkj.83.2022.11.10.08.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 08:06:08 -0800 (PST) From: Maxim Cournoyer Date: Thu, 10 Nov 2022 11:05:48 -0500 Message-Id: <20221110160550.4366-2-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221110160550.4366-1-maxim.cournoyer@gmail.com> References: <87sfiqhp1u.fsf@gnu.org> <20221110160550.4366-1-maxim.cournoyer@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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/build/install.scm (evaluate-populate-directive): By default, error when the target of a symlink doesn't exist. Always ensure TARGET ends with "/". (populate-root-file-system): Call evaluate-populate-directive with #:error-on-dangling-symlink #t and add comment. --- gnu/build/install.scm | 60 ++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/gnu/build/install.scm b/gnu/build/install.scm index f5c8407b89..33a9616c0d 100644 --- a/gnu/build/install.scm +++ b/gnu/build/install.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2016 Chris Marusich +;;; Copyright © 2022 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -56,19 +57,24 @@ (define (install-boot-config bootcfg bootcfg-location mount-point) (define* (evaluate-populate-directive directive target #:key (default-gid 0) - (default-uid 0)) + (default-uid 0) + (error-on-dangling-symlink? #t)) "Evaluate DIRECTIVE, an sexp describing a file or directory to create under directory TARGET. DEFAULT-UID and DEFAULT-GID are the default UID and GID in the context of the caller. If the directive matches those defaults then, -'chown' won't be run." +'chown' won't be run. When ERROR-ON-DANGLING-SYMLINK? is true, abort with an +error when a dangling symlink would be created." + (define target* (if (string-suffix? "/" target) + target + (string-append target "/"))) (let loop ((directive directive)) (catch 'system-error (lambda () (match directive (('directory name) - (mkdir-p (string-append target name))) + (mkdir-p (string-append target* name))) (('directory name uid gid) - (let ((dir (string-append target name))) + (let ((dir (string-append target* name))) (mkdir-p dir) ;; If called from a context without "root" permissions, "chown" ;; to root will fail. In that case, do not try to run "chown" @@ -78,27 +84,38 @@ (define* (evaluate-populate-directive directive target (chown dir uid gid)))) (('directory name uid gid mode) (loop `(directory ,name ,uid ,gid)) - (chmod (string-append target name) mode)) + (chmod (string-append target* name) mode)) (('file name) - (call-with-output-file (string-append target name) + (call-with-output-file (string-append target* name) (const #t))) (('file name (? string? content)) - (call-with-output-file (string-append target name) + (call-with-output-file (string-append target* name) (lambda (port) (display content port)))) ((new '-> old) - (let try () - (catch 'system-error - (lambda () - (symlink old (string-append target new))) - (lambda args - ;; When doing 'guix system init' on the current '/', some - ;; symlinks may already exists. Override them. - (if (= EEXIST (system-error-errno args)) - (begin - (delete-file (string-append target new)) - (try)) - (apply throw args)))))))) + (let ((new* (string-append target* new))) + (let try () + (catch 'system-error + (lambda () + (when error-on-dangling-symlink? + ;; When the symbolic link points to a relative path, + ;; checking if its target exists must be done relatively + ;; to the link location. + (unless (if (string-prefix? "/" old) + (file-exists? old) + (with-directory-excursion (dirname new*) + (file-exists? old))) + (error (format #f "symlink `~a' points to nonexistent \ +file `~a'" new* old)))) + (symlink old new*)) + (lambda args + ;; When doing 'guix system init' on the current '/', some + ;; symlinks may already exists. Override them. + (if (= EEXIST (system-error-errno args)) + (begin + (delete-file new*) + (try)) + (apply throw args))))))))) (lambda args ;; Usually we can only get here when installing to an existing root, ;; as with 'guix system init foo.scm /'. @@ -142,7 +159,10 @@ (define* (populate-root-file-system system target includes /etc, /var, /run, /bin/sh, etc., and all the symlinks to SYSTEM. EXTRAS is a list of directives appended to the built-in directives to populate TARGET." - (for-each (cut evaluate-populate-directive <> target) + ;; It's expected that some symbolic link targets do not exist yet, so do not + ;; error on dangling links. + (for-each (cut evaluate-populate-directive <> target + #:error-on-dangling-symlink? #f) (append (directives (%store-directory)) extras)) ;; Add system generation 1. From patchwork Thu Nov 10 16:05:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 44431 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id BBB0A27BBE9; Thu, 10 Nov 2022 16:07:40 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 776E527BBEA for ; Thu, 10 Nov 2022 16:07:38 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otA5B-0002xx-B6; Thu, 10 Nov 2022 11:07:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otA51-0002u4-TV for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otA51-0003CO-Lj for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otA51-0000Yl-CE for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#58812] [PATCH v3 3/4] guix: shell: Add '--symlink' option. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 10 Nov 2022 16:07:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58812 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58812@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58812-submit@debbugs.gnu.org id=B58812.16680963822052 (code B ref 58812); Thu, 10 Nov 2022 16:07:03 +0000 Received: (at 58812) by debbugs.gnu.org; 10 Nov 2022 16:06:22 +0000 Received: from localhost ([127.0.0.1]:44048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4K-0000X0-RC for submit@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:21 -0500 Received: from mail-qt1-f173.google.com ([209.85.160.173]:36720) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4H-0000WI-0v for 58812@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:17 -0500 Received: by mail-qt1-f173.google.com with SMTP id fz10so1168976qtb.3 for <58812@debbugs.gnu.org>; Thu, 10 Nov 2022 08:06:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XlMVXdyLxHvxImaTRx/NY5OoFVEnXKMdxvcqdMhajjA=; b=k1GIz/AnK2ytx4YLVMqLPptW6O18W1+FW+Xzkr+m1Z+6r3IgM8Ak9U9fO6fH+4mf1u pKjcgg7Xw/764I70hIywx3tCyTkBcCyi8lVuHHhif31glSBbIeY0siXRO5S97QvI0EcH WnqTOieZtbs6pupU30r+W6rCnQXn1sXtsLnl/UYqzIMDC366DNkBwmVALtmg7gzpTWL5 9bKt2f1h+7ekqhQK/ogzSOdVyqVGwoeVMJZ+qDHwrRrUtlqw5xxtJIePRpLLBCRBJvdG XQcM7UD/YHiIpzZAFqH9PiMTDjmNMpz1jOGEFhcrfmSUZdaP8v1tJTmGwjjjfYjwYY1p bmHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XlMVXdyLxHvxImaTRx/NY5OoFVEnXKMdxvcqdMhajjA=; b=X3YQExuWOPyhs15hSdG136eiE7v33j5NABWb32RrhoY5nmzI97q0aE15HA+2qGA9PD JDD6r26BlyIzDfVuDLPbAi8Hpje+UUvZvUz37KRfaWKNTMfmqZPwKsVxTNGLIazou2Ij qhgs2Be1pfylzV/iY57Y5DTCQvNz7RoxmIBDu+m2l3wlN0nsWpIUvCSu6pc6Fi7ZhYnD q2RH3FGYb+GAsv/ENgzjLV1x6gGAaa1KS2PJpS1d/PLBSb7Q5Eogn8lC4lPbgAK1N8Cu yVXaqr5ELljllb/mJmkRmYo1WCvHbVzvysgvWQUPqZ/MPX1pQepW0h8B+ecCNwAynS5C 776g== X-Gm-Message-State: ACrzQf0mm/sxKng5wJFPhR+GAJ3m4IpthmwaYNk9+b8g8WgWVMyTn4ss CT6+jLhor4kcfHEWnXDif21XFaeDEpY= X-Google-Smtp-Source: AMsMyM4UULa5p8A/fFiXxpQ8Sux1L1yw76OwcKnjNHs2AWzeJaskx0mm7dTFr/GRcmO0LS4HfYPwMQ== X-Received: by 2002:a05:622a:138a:b0:39c:e18e:758f with SMTP id o10-20020a05622a138a00b0039ce18e758fmr1371947qtk.187.1668096371231; Thu, 10 Nov 2022 08:06:11 -0800 (PST) Received: from localhost.localdomain ([2607:fad8:4:3::1001]) by smtp.gmail.com with ESMTPSA id t18-20020a37ea12000000b006fafc111b12sm6344916qkj.83.2022.11.10.08.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 08:06:10 -0800 (PST) From: Maxim Cournoyer Date: Thu, 10 Nov 2022 11:05:49 -0500 Message-Id: <20221110160550.4366-3-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221110160550.4366-1-maxim.cournoyer@gmail.com> References: <87sfiqhp1u.fsf@gnu.org> <20221110160550.4366-1-maxim.cournoyer@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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/pack.scm (%options): Extract symlink parsing logic to... (symlink-spec-option-parser): ... here. (self-contained-tarball/builder): Add a comment mentioning why a relative file name is used for the link target. * guix/scripts/environment.scm (show-environment-options-help): Document new --symlink option. (%default-options): Add default value for symlinks. (%options): Register new symlink option. (launch-environment/container): Add #:symlinks argument and extend doc, and create symlinks using evaluate-populate-directive. (guix-environment*): Pass symlinks arguments to launch-environment/container. * doc/guix.texi (Invoking guix shell): Document it. * tests/guix-shell.sh: Add a --symlink (negative) test. * tests/guix-environment-container.sh: Add tests. --- doc/guix.texi | 9 +++++- guix/scripts/environment.scm | 43 ++++++++++++++++++++++------- guix/scripts/pack.scm | 39 ++++++++++++++------------ tests/guix-environment-container.sh | 9 ++++++ tests/guix-shell.sh | 3 ++ 5 files changed, 75 insertions(+), 28 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 3f76184495..94c3f29790 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -49,7 +49,7 @@ Copyright @copyright{} 2017 humanitiesNerd@* Copyright @copyright{} 2017, 2021 Christine Lemmer-Webber@* Copyright @copyright{} 2017, 2018, 2019, 2020, 2021, 2022 Marius Bakke@* Copyright @copyright{} 2017, 2019, 2020, 2022 Hartmut Goebel@* -Copyright @copyright{} 2017, 2019, 2020, 2021 Maxim Cournoyer@* +Copyright @copyright{} 2017, 2019, 2020, 2021, 2022 Maxim Cournoyer@* Copyright @copyright{} 2017–2022 Tobias Geerinckx-Rice@* Copyright @copyright{} 2017 George Clemmer@* Copyright @copyright{} 2017 Andy Wingo@* @@ -6242,6 +6242,12 @@ directory: guix shell --container --expose=$HOME=/exchange guile -- guile @end example +@cindex symbolic links, guix shell +@item --symlink=@var{spec} +@itemx -S @var{spec} +For containers, create the symbolic links specified by @var{spec}, as +documented in @ref{pack-symlink-option}. + @cindex file system hierarchy standard (FHS) @cindex FHS (file system hierarchy standard) @item --emulate-fhs @@ -7034,6 +7040,7 @@ Compress the resulting tarball using @var{tool}---one of @code{gzip}, @code{zstd}, @code{bzip2}, @code{xz}, @code{lzip}, or @code{none} for no compression. +@anchor{pack-symlink-option} @item --symlink=@var{spec} @itemx -S @var{spec} Add the symlinks specified by @var{spec} to the pack. This option can diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index de9bc8f98d..13c6f6cb5c 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -33,8 +33,10 @@ (define-module (guix scripts environment) #:use-module ((guix gexp) #:select (lower-object)) #:use-module (guix scripts) #:use-module (guix scripts build) + #:autoload (guix scripts pack) (symlink-spec-option-parser) #:use-module (guix transformations) #:autoload (ice-9 ftw) (scandir) + #:use-module (gnu build install) #:autoload (gnu build linux-container) (call-with-container %namespaces user-namespace-supported? unprivileged-user-namespace-supported? @@ -120,6 +122,9 @@ (define (show-environment-options-help) --expose=SPEC for containers, expose read-only host file system according to SPEC")) (display (G_ " + -S, --symlink=SPEC for containers, add symlinks to the profile according + to SPEC, e.g. \"/usr/bin/env=bin/env\".")) + (display (G_ " -v, --verbosity=LEVEL use the given verbosity LEVEL")) (display (G_ " --bootstrap use bootstrap binaries to build the environment"))) @@ -157,6 +162,7 @@ (define (show-help) (define %default-options `((system . ,(%current-system)) (substitutes? . #t) + (symlinks . ()) (offload? . #t) (graft? . #t) (print-build-trace? . #t) @@ -256,6 +262,7 @@ (define %options (alist-cons 'file-system-mapping (specification->file-system-mapping arg #f) result))) + (option '(#\S "symlink") #t #f symlink-spec-option-parser) (option '(#\r "root") #t #f (lambda (opt name arg result) (alist-cons 'gc-root arg result))) @@ -672,7 +679,7 @@ (define* (launch-environment/fork command profile manifest (define* (launch-environment/container #:key command bash user user-mappings profile manifest link-profile? network? map-cwd? emulate-fhs? (setup-hook #f) - (white-list '())) + (symlinks '()) (white-list '())) "Run COMMAND within a container that features the software in PROFILE. Environment variables are set according to the search paths of MANIFEST. The global shell is BASH, a file name for a GNU Bash binary in the store. When @@ -690,6 +697,9 @@ (define* (launch-environment/container #:key command bash user user-mappings LINK-PROFILE? creates a symbolic link from ~/.guix-profile to the environment profile. +SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be +added to the container. + Preserve environment variables whose name matches the one of the regexps in WHILE-LIST." (define (optional-mapping->fs mapping) @@ -797,6 +807,15 @@ (define fhs-mappings (mkdir-p home-dir) (setenv "HOME" home-dir) + ;; Create symlinks. + (let ((symlink->directives + (match-lambda + ((source '-> target) + `((directory ,(dirname source)) + (,source -> ,(string-append profile "/" target))))))) + (for-each (cut evaluate-populate-directive <> ".") + (append-map symlink->directives symlinks))) + ;; Call an additional setup procedure, if provided. (when setup-hook (setup-hook profile)) @@ -970,6 +989,7 @@ (define (guix-environment* opts) (let* ((pure? (assoc-ref opts 'pure)) (container? (assoc-ref opts 'container?)) (link-prof? (assoc-ref opts 'link-profile?)) + (symlinks (assoc-ref opts 'symlinks)) (network? (assoc-ref opts 'network?)) (no-cwd? (assoc-ref opts 'no-cwd?)) (emulate-fhs? (assoc-ref opts 'emulate-fhs?)) @@ -1010,15 +1030,17 @@ (define-syntax-rule (with-store/maybe store exp ...) (when container? (assert-container-features)) - (when (and (not container?) link-prof?) - (leave (G_ "'--link-profile' cannot be used without '--container'~%"))) - (when (and (not container?) user) - (leave (G_ "'--user' cannot be used without '--container'~%"))) - (when (and (not container?) no-cwd?) - (leave (G_ "--no-cwd cannot be used without '--container'~%"))) - (when (and (not container?) emulate-fhs?) - (leave (G_ "'--emulate-fhs' cannot be used without '--container~%'"))) - + (when (not container?) + (when link-prof? + (leave (G_ "'--link-profile' cannot be used without '--container'~%"))) + (when user + (leave (G_ "'--user' cannot be used without '--container'~%"))) + (when no-cwd? + (leave (G_ "--no-cwd cannot be used without '--container'~%"))) + (when emulate-fhs? + (leave (G_ "'--emulate-fhs' cannot be used without '--container~%'"))) + (when (pair? symlinks) + (leave (G_ "'--symlink' cannot be used without '--container~%'")))) (with-store/maybe store (with-status-verbosity (assoc-ref opts 'verbosity) @@ -1099,6 +1121,7 @@ (define manifest #:network? network? #:map-cwd? (not no-cwd?) #:emulate-fhs? emulate-fhs? + #:symlinks symlinks #:setup-hook (and emulate-fhs? setup-fhs)))) diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index 06849e4761..a611922db3 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -61,7 +61,9 @@ (define-module (guix scripts pack) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) #:use-module (ice-9 match) - #:export (self-contained-tarball + #:export (symlink-spec-option-parser + + self-contained-tarball debian-archive docker-image squashfs-image @@ -160,6 +162,21 @@ (define str (string-join names "-")) ((_) str) ((names ... _) (loop names)))))) +(define (symlink-spec-option-parser opt name arg result) + "A SRFI-37 option parser for the --symlink option." + ;; Note: Using 'string-split' allows us to handle empty + ;; TARGET (as in "/opt/guile=", meaning that /opt/guile is + ;; a symlink to the profile) correctly. + (match (string-split arg (char-set #\=)) + ((source target) + (let ((symlinks (assoc-ref result 'symlinks))) + (alist-cons 'symlinks + `((,source -> ,target) ,@symlinks) + (alist-delete 'symlinks result eq?)))) + (x + (leave (G_ "~a: invalid symlink specification~%") + arg)))) + ;;; ;;; Tarball format. @@ -226,8 +243,9 @@ (define symlink->directives `(,@(if (string=? parent "/") '() `((directory ,parent))) - (,source - -> ,(relative-file-name parent target))))))) + ;; Use a relative file name for compatibility with + ;; relocatable packs. + (,source -> ,(relative-file-name parent target))))))) (define directives ;; Fully-qualified symlinks. @@ -1208,20 +1226,7 @@ (define %options (lambda (opt name arg result) (alist-cons 'compressor (lookup-compressor arg) result))) - (option '(#\S "symlink") #t #f - (lambda (opt name arg result) - ;; Note: Using 'string-split' allows us to handle empty - ;; TARGET (as in "/opt/guile=", meaning that /opt/guile is - ;; a symlink to the profile) correctly. - (match (string-split arg (char-set #\=)) - ((source target) - (let ((symlinks (assoc-ref result 'symlinks))) - (alist-cons 'symlinks - `((,source -> ,target) ,@symlinks) - (alist-delete 'symlinks result eq?)))) - (x - (leave (G_ "~a: invalid symlink specification~%") - arg))))) + (option '(#\S "symlink") #t #f symlink-spec-option-parser) (option '("save-provenance") #f #f (lambda (opt name arg result) (alist-cons 'save-provenance? #t result))) diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index fb2c19b193..82192375c7 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh @@ -241,3 +241,12 @@ guix shell -CF --bootstrap guile-bootstrap glibc \ "glibc-for-fhs") 0 1))' + +# '--symlink' works. +echo "TESTING SYMLINK IN CONTAINER" +guix shell --bootstrap guile-bootstrap --container \ + --symlink=/usr/bin/guile=bin/guile -- \ + /usr/bin/guile --version + +# A dangling symlink causes the command to fail. +! guix shell --bootstrap -CS /usr/bin/python=bin/python guile-bootstrap -- exit diff --git a/tests/guix-shell.sh b/tests/guix-shell.sh index 9a6b055264..cb2b53466d 100644 --- a/tests/guix-shell.sh +++ b/tests/guix-shell.sh @@ -32,6 +32,9 @@ export XDG_CONFIG_HOME guix shell --bootstrap --pure guile-bootstrap -- guile --version +# '--symlink' can only be used with --container. +! guix shell --bootstrap guile-bootstrap -S /dummy=bin/guile + # '--ad-hoc' is a thing of the past. ! guix shell --ad-hoc guile-bootstrap From patchwork Thu Nov 10 16:05:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 44430 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B08A727BBEA; Thu, 10 Nov 2022 16:07:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id DC82027BBE9 for ; Thu, 10 Nov 2022 16:07:25 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otA5B-0002xz-BW; Thu, 10 Nov 2022 11:07:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otA52-0002u7-Cb for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otA52-0003CV-3n for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otA51-0000Yt-UG for guix-patches@gnu.org; Thu, 10 Nov 2022 11:07:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#58812] [PATCH v3 4/4] shell: Detect --symlink spec problems early. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 10 Nov 2022 16:07:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58812 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58812@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58812-submit@debbugs.gnu.org id=B58812.16680963852069 (code B ref 58812); Thu, 10 Nov 2022 16:07:03 +0000 Received: (at 58812) by debbugs.gnu.org; 10 Nov 2022 16:06:25 +0000 Received: from localhost ([127.0.0.1]:44050 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4O-0000XI-27 for submit@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:25 -0500 Received: from mail-qt1-f178.google.com ([209.85.160.178]:34567) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otA4K-0000Wb-KR for 58812@debbugs.gnu.org; Thu, 10 Nov 2022 11:06:22 -0500 Received: by mail-qt1-f178.google.com with SMTP id e15so1175120qts.1 for <58812@debbugs.gnu.org>; Thu, 10 Nov 2022 08:06:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=amwygdAfcIWzrVj5Rglf6tQ3uRSbDoPtHhmeDYo2uP8=; b=WIfeiiMIrEGPmQCYZUrdGQACWeXco1QR9uGGtYUoNned3DKU8p5Liy1GvtCugbr9wo oXULeObz6fpZvAfCeHBnbRRB3dBfw0IUUuhqbW0edUvgEJJ26LYYucAA8X9gX+XToVPA 3mS7LRwZaZxcJm53bRuXu7ikS0RrdF3h/3p5BXB6tx4KPr6F2E/lnXmorhY6qUCT4whP h/jfVtxIlgOc3z6QqHq9Po22jfgMLFZcpGG5k0COApY/ZsZbFBEDD4A9F5m9PvSI6Oh+ ou8iPqt6AkDvqm24rpCqinIc3H1MJoN6lgQTw5ghEB5BXLlGGHK8dI6Ag7tCK7wiWFve 781Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=amwygdAfcIWzrVj5Rglf6tQ3uRSbDoPtHhmeDYo2uP8=; b=MFboyFhxZv9tEvB5ZI4VHqd+Pzhd68WaVRbVEyDMlHmKngL8CwfcTHZkD7Sx7XLxJg MIWcr1kMNzGNHPNvKSJuNcZHaP6B20W1pRXvRqPmlvT1IWsgMoylwVOoeTg7n+oLaJ79 v42vRRJ4BqcpZ5uEnpNObgggbAXR80eKy/Fq+N21GuYiQTeJjNh5Dj5T02Q542Y/LUlX 0XG7FK67N9Oarm3TJFkUldHrdraUQ9CrqY+xhZygrbKa/kmvxfJ4tC/eiqHNiZr+8Dd6 wDt2MfmRIREJbm3UCtqtCoYfAhN15+SK55zYoFm6YiNyV5uvOy9q2fgUQKtX924qiiOL z6rA== X-Gm-Message-State: ANoB5pnQlcI4CL1dcoAtg8M+/eabvbFrvFPrFmgIE3ZJEdQYiwAP4wKW 10Y93UOtZUGSaxnW12obxetSxy+/KJI= X-Google-Smtp-Source: AA0mqf58Vr9tbw62gI5pXOAhV9OT38RVWP7Ri3NVQWW6nJS+Slg7m9rb8M6wqAOagNPE58N2DfbcJw== X-Received: by 2002:a05:622a:6107:b0:3a5:9062:1f91 with SMTP id hg7-20020a05622a610700b003a590621f91mr16462261qtb.332.1668096374318; Thu, 10 Nov 2022 08:06:14 -0800 (PST) Received: from localhost.localdomain ([2607:fad8:4:3::1001]) by smtp.gmail.com with ESMTPSA id t18-20020a37ea12000000b006fafc111b12sm6344916qkj.83.2022.11.10.08.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 08:06:13 -0800 (PST) From: Maxim Cournoyer Date: Thu, 10 Nov 2022 11:05:50 -0500 Message-Id: <20221110160550.4366-4-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221110160550.4366-1-maxim.cournoyer@gmail.com> References: <87sfiqhp1u.fsf@gnu.org> <20221110160550.4366-1-maxim.cournoyer@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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/pack.scm (symlink-spec-option-parser): Remove extraneous char-set. Raise an exception when the target is an absolute file name. (guix-pack): Move with-error-handler earlier. * guix/scripts/shell.scm (guix-shell): Likewise. * guix/scripts/environment.scm (guix-environment): Wrap the whole guix-environment* call with the with-error-handling handler. * tests/guix-environment-container.sh: Add tests. * tests/guix-pack.sh: Adjust symlink spec. --- guix/scripts/environment.scm | 294 ++++++++++++++-------------- guix/scripts/pack.scm | 155 ++++++++------- guix/scripts/shell.scm | 77 ++++---- tests/guix-environment-container.sh | 3 + tests/guix-pack.sh | 2 +- 5 files changed, 276 insertions(+), 255 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 13c6f6cb5c..64597f6e9f 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -980,158 +980,158 @@ (define-command (guix-environment . args) (category development) (synopsis "spawn one-off software environments (deprecated)") - (guix-environment* (parse-args args))) + (with-error-handling + (guix-environment* (parse-args args)))) (define (guix-environment* opts) "Run the 'guix environment' command on OPTS, an alist resulting for command-line option processing with 'parse-command-line'." - (with-error-handling - (let* ((pure? (assoc-ref opts 'pure)) - (container? (assoc-ref opts 'container?)) - (link-prof? (assoc-ref opts 'link-profile?)) - (symlinks (assoc-ref opts 'symlinks)) - (network? (assoc-ref opts 'network?)) - (no-cwd? (assoc-ref opts 'no-cwd?)) - (emulate-fhs? (assoc-ref opts 'emulate-fhs?)) - (user (assoc-ref opts 'user)) - (bootstrap? (assoc-ref opts 'bootstrap?)) - (system (assoc-ref opts 'system)) - (profile (assoc-ref opts 'profile)) - (command (or (assoc-ref opts 'exec) - ;; Spawn a shell if the user didn't specify - ;; anything in particular. - (if container? - ;; The user's shell is likely not available - ;; within the container. - '("/bin/sh") - (list %default-shell)))) - (mappings (pick-all opts 'file-system-mapping)) - (white-list (pick-all opts 'inherit-regexp))) - - (define store-needed? - ;; Whether connecting to the daemon is needed. - (or container? (not profile))) - - (define-syntax-rule (with-store/maybe store exp ...) - ;; Evaluate EXP... with STORE bound to a connection, unless - ;; STORE-NEEDED? is false, in which case STORE is bound to #f. - (let ((proc (lambda (store) exp ...))) - (if store-needed? - (with-store s - (set-build-options-from-command-line s opts) - (with-build-handler (build-notifier #:use-substitutes? - (assoc-ref opts 'substitutes?) - #:verbosity - (assoc-ref opts 'verbosity) - #:dry-run? - (assoc-ref opts 'dry-run?)) - (proc s))) - (proc #f)))) - - (when container? (assert-container-features)) - - (when (not container?) - (when link-prof? - (leave (G_ "'--link-profile' cannot be used without '--container'~%"))) - (when user - (leave (G_ "'--user' cannot be used without '--container'~%"))) - (when no-cwd? - (leave (G_ "--no-cwd cannot be used without '--container'~%"))) - (when emulate-fhs? - (leave (G_ "'--emulate-fhs' cannot be used without '--container~%'"))) - (when (pair? symlinks) - (leave (G_ "'--symlink' cannot be used without '--container~%'")))) - - (with-store/maybe store - (with-status-verbosity (assoc-ref opts 'verbosity) - (define manifest-from-opts - (options/resolve-packages store opts)) - - (define manifest - (if profile - (profile-manifest profile) - manifest-from-opts)) - - (when (and profile - (> (length (manifest-entries manifest-from-opts)) 0)) - (leave (G_ "'--profile' cannot be used with package options~%"))) - - (when (null? (manifest-entries manifest)) - (warning (G_ "no packages specified; creating an empty environment~%"))) - - ;; Use the bootstrap Guile when requested. - (parameterize ((%graft? (assoc-ref opts 'graft?)) - (%guile-for-build - (and store-needed? - (package-derivation - store - (if bootstrap? - %bootstrap-guile - (default-guile)))))) - (run-with-store store - ;; Containers need a Bourne shell at /bin/sh. - (mlet* %store-monad ((bash (environment-bash container? - bootstrap? - system)) - (prof-drv (if profile - (return #f) - (manifest->derivation - manifest system bootstrap?))) - (profile -> (if profile - (readlink* profile) - (derivation->output-path prof-drv))) - (gc-root -> (assoc-ref opts 'gc-root))) - - ;; First build the inputs. This is necessary even for - ;; --search-paths. Additionally, we might need to build bash for - ;; a container. - (mbegin %store-monad - (mwhen store-needed? - (built-derivations (append - (if prof-drv (list prof-drv) '()) - (if (derivation? bash) (list bash) '())))) - (mwhen gc-root - (register-gc-root profile gc-root)) - - (mwhen (assoc-ref opts 'check?) - (return - (if container? - (warning (G_ "'--check' is unnecessary \ + (let* ((pure? (assoc-ref opts 'pure)) + (container? (assoc-ref opts 'container?)) + (link-prof? (assoc-ref opts 'link-profile?)) + (symlinks (assoc-ref opts 'symlinks)) + (network? (assoc-ref opts 'network?)) + (no-cwd? (assoc-ref opts 'no-cwd?)) + (emulate-fhs? (assoc-ref opts 'emulate-fhs?)) + (user (assoc-ref opts 'user)) + (bootstrap? (assoc-ref opts 'bootstrap?)) + (system (assoc-ref opts 'system)) + (profile (assoc-ref opts 'profile)) + (command (or (assoc-ref opts 'exec) + ;; Spawn a shell if the user didn't specify + ;; anything in particular. + (if container? + ;; The user's shell is likely not available + ;; within the container. + '("/bin/sh") + (list %default-shell)))) + (mappings (pick-all opts 'file-system-mapping)) + (white-list (pick-all opts 'inherit-regexp))) + + (define store-needed? + ;; Whether connecting to the daemon is needed. + (or container? (not profile))) + + (define-syntax-rule (with-store/maybe store exp ...) + ;; Evaluate EXP... with STORE bound to a connection, unless + ;; STORE-NEEDED? is false, in which case STORE is bound to #f. + (let ((proc (lambda (store) exp ...))) + (if store-needed? + (with-store s + (set-build-options-from-command-line s opts) + (with-build-handler (build-notifier #:use-substitutes? + (assoc-ref opts 'substitutes?) + #:verbosity + (assoc-ref opts 'verbosity) + #:dry-run? + (assoc-ref opts 'dry-run?)) + (proc s))) + (proc #f)))) + + (when container? (assert-container-features)) + + (when (not container?) + (when link-prof? + (leave (G_ "'--link-profile' cannot be used without '--container'~%"))) + (when user + (leave (G_ "'--user' cannot be used without '--container'~%"))) + (when no-cwd? + (leave (G_ "--no-cwd cannot be used without '--container'~%"))) + (when emulate-fhs? + (leave (G_ "'--emulate-fhs' cannot be used without '--container~%'"))) + (when (pair? symlinks) + (leave (G_ "'--symlink' cannot be used without '--container~%'")))) + + (with-store/maybe store + (with-status-verbosity (assoc-ref opts 'verbosity) + (define manifest-from-opts + (options/resolve-packages store opts)) + + (define manifest + (if profile + (profile-manifest profile) + manifest-from-opts)) + + (when (and profile + (> (length (manifest-entries manifest-from-opts)) 0)) + (leave (G_ "'--profile' cannot be used with package options~%"))) + + (when (null? (manifest-entries manifest)) + (warning (G_ "no packages specified; creating an empty environment~%"))) + + ;; Use the bootstrap Guile when requested. + (parameterize ((%graft? (assoc-ref opts 'graft?)) + (%guile-for-build + (and store-needed? + (package-derivation + store + (if bootstrap? + %bootstrap-guile + (default-guile)))))) + (run-with-store store + ;; Containers need a Bourne shell at /bin/sh. + (mlet* %store-monad ((bash (environment-bash container? + bootstrap? + system)) + (prof-drv (if profile + (return #f) + (manifest->derivation + manifest system bootstrap?))) + (profile -> (if profile + (readlink* profile) + (derivation->output-path prof-drv))) + (gc-root -> (assoc-ref opts 'gc-root))) + + ;; First build the inputs. This is necessary even for + ;; --search-paths. Additionally, we might need to build bash for + ;; a container. + (mbegin %store-monad + (mwhen store-needed? + (built-derivations (append + (if prof-drv (list prof-drv) '()) + (if (derivation? bash) (list bash) '())))) + (mwhen gc-root + (register-gc-root profile gc-root)) + + (mwhen (assoc-ref opts 'check?) + (return + (if container? + (warning (G_ "'--check' is unnecessary \ when using '--container'; doing nothing~%")) - (validate-child-shell-environment profile manifest)))) - - (cond - ((assoc-ref opts 'search-paths) - (show-search-paths profile manifest #:pure? pure?) - (return #t)) - (container? - (let ((bash-binary - (if bootstrap? - (derivation->output-path bash) - (string-append (derivation->output-path bash) - "/bin/sh")))) - (launch-environment/container #:command command - #:bash bash-binary - #:user user - #:user-mappings mappings - #:profile profile - #:manifest manifest - #:white-list white-list - #:link-profile? link-prof? - #:network? network? - #:map-cwd? (not no-cwd?) - #:emulate-fhs? emulate-fhs? - #:symlinks symlinks - #:setup-hook - (and emulate-fhs? - setup-fhs)))) - - (else - (return - (exit/status - (launch-environment/fork command profile manifest - #:white-list white-list - #:pure? pure?)))))))))))))) + (validate-child-shell-environment profile manifest)))) + + (cond + ((assoc-ref opts 'search-paths) + (show-search-paths profile manifest #:pure? pure?) + (return #t)) + (container? + (let ((bash-binary + (if bootstrap? + (derivation->output-path bash) + (string-append (derivation->output-path bash) + "/bin/sh")))) + (launch-environment/container #:command command + #:bash bash-binary + #:user user + #:user-mappings mappings + #:profile profile + #:manifest manifest + #:white-list white-list + #:link-profile? link-prof? + #:network? network? + #:map-cwd? (not no-cwd?) + #:emulate-fhs? emulate-fhs? + #:symlinks symlinks + #:setup-hook + (and emulate-fhs? + setup-fhs)))) + + (else + (return + (exit/status + (launch-environment/fork command profile manifest + #:white-list white-list + #:pure? pure?))))))))))))) ;;; Local Variables: ;;; eval: (put 'with-store/maybe 'scheme-indent-function 1) diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index a611922db3..f81b3e6501 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -42,6 +42,7 @@ (define-module (guix scripts pack) #:use-module (guix profiles) #:use-module (guix describe) #:use-module (guix derivations) + #:use-module (guix diagnostics) #:use-module (guix search-paths) #:use-module (guix build-system gnu) #:use-module (guix scripts build) @@ -59,6 +60,7 @@ (define-module (guix scripts pack) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-35) #:use-module (srfi srfi-37) #:use-module (ice-9 match) #:export (symlink-spec-option-parser @@ -163,12 +165,27 @@ (define str (string-join names "-")) ((names ... _) (loop names)))))) (define (symlink-spec-option-parser opt name arg result) - "A SRFI-37 option parser for the --symlink option." + "A SRFI-37 option parser for the --symlink option. The symlink spec accepts +the link file name as its left-hand side value and its target as its +right-hand side value. The target must be a relative link." ;; Note: Using 'string-split' allows us to handle empty ;; TARGET (as in "/opt/guile=", meaning that /opt/guile is ;; a symlink to the profile) correctly. - (match (string-split arg (char-set #\=)) + (match (string-split arg #\=) ((source target) + (when (string-prefix? "/" target) + (raise-exception + (make-compound-condition + (formatted-message (G_ "symlink target is absolute: '~a'~%") target) + (condition + (&fix-hint (hint (format #f (G_ "The target of the symlink must be +relative rather than absolute, as it is relative to the profile created. +Perhaps the source and target components of the symlink spec were inverted? +Below is a valid example, where the @file{/usr/bin/env} symbolic link is to +target the profile's @file{bin/env} file: +@example +--symlink=/usr/bin/env=bin/env +@end example")))))))) (let ((symlinks (assoc-ref result 'symlinks))) (alist-cons 'symlinks `((,source -> ,target) ,@symlinks) @@ -1326,74 +1343,74 @@ (define-command (guix-pack . args) (category development) (synopsis "create application bundles") - (define opts - (parse-command-line args %options (list %default-options))) - - (define maybe-package-argument - ;; Given an option pair, return a package, a package/output tuple, or #f. - (match-lambda - (('argument . spec) - (call-with-values - (lambda () - (specification->package+output spec)) - list)) - (('expression . exp) - (read/eval-package-expression exp)) - (x #f))) - - (define (manifest-from-args store opts) - (let* ((transform (options->transformation opts)) - (packages (map (match-lambda - (((? package? package) output) - (list (transform package) output)) - ((? package? package) - (list (transform package) "out"))) - (reverse - (filter-map maybe-package-argument opts)))) - (manifests (filter-map (match-lambda - (('manifest . file) file) - (_ #f)) - opts))) - (define with-provenance - (if (assoc-ref opts 'save-provenance?) - (lambda (manifest) - (map-manifest-entries - (lambda (entry) - (let ((entry (manifest-entry-with-provenance entry))) - (unless (assq 'provenance (manifest-entry-properties entry)) - (warning (G_ "could not determine provenance of package ~a~%") - (manifest-entry-name entry))) - entry)) - manifest)) - identity)) - - (with-provenance - (cond - ((and (not (null? manifests)) (not (null? packages))) - (leave (G_ "both a manifest and a package list were given~%"))) - ((not (null? manifests)) - (concatenate-manifests - (map (lambda (file) - (let ((user-module (make-user-module - '((guix profiles) (gnu))))) - (load* file user-module))) - manifests))) - (else - (packages->manifest packages)))))) - - (define (process-file-arg opts name) - ;; Validate that the file exists and return it as a object, - ;; else #f. - (let ((value (assoc-ref opts name))) - (match value - ((and (? string?) (not (? file-exists?))) - (leave (G_ "file provided with option ~a does not exist: ~a~%") - (string-append "--" (symbol->string name)) value)) - ((? string?) - (local-file value)) - (#f #f)))) - (with-error-handling + (define opts + (parse-command-line args %options (list %default-options))) + + (define maybe-package-argument + ;; Given an option pair, return a package, a package/output tuple, or #f. + (match-lambda + (('argument . spec) + (call-with-values + (lambda () + (specification->package+output spec)) + list)) + (('expression . exp) + (read/eval-package-expression exp)) + (x #f))) + + (define (manifest-from-args store opts) + (let* ((transform (options->transformation opts)) + (packages (map (match-lambda + (((? package? package) output) + (list (transform package) output)) + ((? package? package) + (list (transform package) "out"))) + (reverse + (filter-map maybe-package-argument opts)))) + (manifests (filter-map (match-lambda + (('manifest . file) file) + (_ #f)) + opts))) + (define with-provenance + (if (assoc-ref opts 'save-provenance?) + (lambda (manifest) + (map-manifest-entries + (lambda (entry) + (let ((entry (manifest-entry-with-provenance entry))) + (unless (assq 'provenance (manifest-entry-properties entry)) + (warning (G_ "could not determine provenance of package ~a~%") + (manifest-entry-name entry))) + entry)) + manifest)) + identity)) + + (with-provenance + (cond + ((and (not (null? manifests)) (not (null? packages))) + (leave (G_ "both a manifest and a package list were given~%"))) + ((not (null? manifests)) + (concatenate-manifests + (map (lambda (file) + (let ((user-module (make-user-module + '((guix profiles) (gnu))))) + (load* file user-module))) + manifests))) + (else + (packages->manifest packages)))))) + + (define (process-file-arg opts name) + ;; Validate that the file exists and return it as a object, + ;; else #f. + (let ((value (assoc-ref opts name))) + (match value + ((and (? string?) (not (? file-exists?))) + (leave (G_ "file provided with option ~a does not exist: ~a~%") + (string-append "--" (symbol->string name)) value)) + ((? string?) + (local-file value)) + (#f #f)))) + (with-store store (with-status-verbosity (assoc-ref opts 'verbosity) ;; Set the build options before we do anything else. diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm index 7a379122ae..2fc1dc942a 100644 --- a/guix/scripts/shell.scm +++ b/guix/scripts/shell.scm @@ -534,43 +534,44 @@ (define-command (guix-shell . args) (category development) (synopsis "spawn one-off software environments") - (define (cache-entries directory) - (filter-map (match-lambda - ((or "." "..") #f) - (file (string-append directory "/" file))) - (or (scandir directory) '()))) - - (define* (entry-expiration file) - ;; Return the time at which FILE, a cached profile, is considered expired. - (match (false-if-exception (lstat file)) - (#f 0) ;FILE may have been deleted in the meantime - (st (+ (stat:atime st) (* 60 60 24 7))))) - - (define opts - (parse-args args)) - - (define interactive? - (not (assoc-ref opts 'exec))) - - (if (assoc-ref opts 'check?) - (record-hint 'shell-check) - (when (and interactive? - (not (hint-given? 'shell-check)) - (not (assoc-ref opts 'container?)) - (not (assoc-ref opts 'search-paths))) - (display-hint (G_ "Consider passing the @option{--check} option once + (with-error-handling + (define (cache-entries directory) + (filter-map (match-lambda + ((or "." "..") #f) + (file (string-append directory "/" file))) + (or (scandir directory) '()))) + + (define* (entry-expiration file) + ;; Return the time at which FILE, a cached profile, is considered expired. + (match (false-if-exception (lstat file)) + (#f 0) ;FILE may have been deleted in the meantime + (st (+ (stat:atime st) (* 60 60 24 7))))) + + (define opts + (parse-args args)) + + (define interactive? + (not (assoc-ref opts 'exec))) + + (if (assoc-ref opts 'check?) + (record-hint 'shell-check) + (when (and interactive? + (not (hint-given? 'shell-check)) + (not (assoc-ref opts 'container?)) + (not (assoc-ref opts 'search-paths))) + (display-hint (G_ "Consider passing the @option{--check} option once to make sure your shell does not clobber environment variables."))) ) - ;; Clean the cache in EXIT-HOOK so that (1) it happens after potential use - ;; of cached profiles, and (2) cleanup actually happens, even when - ;; 'guix-environment*' calls 'exit'. - (add-hook! exit-hook - (lambda _ - (maybe-remove-expired-cache-entries - (%profile-cache-directory) - cache-entries - #:entry-expiration entry-expiration))) - - (if (assoc-ref opts 'export-manifest?) - (export-manifest opts (current-output-port)) - (guix-environment* opts))) + ;; Clean the cache in EXIT-HOOK so that (1) it happens after potential use + ;; of cached profiles, and (2) cleanup actually happens, even when + ;; 'guix-environment*' calls 'exit'. + (add-hook! exit-hook + (lambda _ + (maybe-remove-expired-cache-entries + (%profile-cache-directory) + cache-entries + #:entry-expiration entry-expiration))) + + (if (assoc-ref opts 'export-manifest?) + (export-manifest opts (current-output-port)) + (guix-environment* opts)))) diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index 82192375c7..0306fc1744 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh @@ -250,3 +250,6 @@ guix shell --bootstrap guile-bootstrap --container \ # A dangling symlink causes the command to fail. ! guix shell --bootstrap -CS /usr/bin/python=bin/python guile-bootstrap -- exit + +# An invalid symlink spec causes the command to fail. +! guix shell --bootstrap -CS bin/guile=/usr/bin/guile guile-bootstrap -- exit diff --git a/tests/guix-pack.sh b/tests/guix-pack.sh index f19a0f754e..6fc9e3723b 100644 --- a/tests/guix-pack.sh +++ b/tests/guix-pack.sh @@ -103,7 +103,7 @@ fi guix pack --dry-run --bootstrap -f docker guile-bootstrap # Build a Docker image with a symlink. -guix pack --dry-run --bootstrap -f docker -S /opt/gnu=/ guile-bootstrap +guix pack --dry-run --bootstrap -f docker -S /opt/gnu= guile-bootstrap # Build a tarball pack of cross-compiled software. Use coreutils because # guile-bootstrap is not intended to be cross-compiled.