From patchwork Sat Oct 2 10:22:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 33542 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 E576927BBE1; Sat, 2 Oct 2021 11:24:54 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8942727BBE1 for ; Sat, 2 Oct 2021 11:24:54 +0100 (BST) Received: from localhost ([::1]:52306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWcCJ-0002HO-Qx for patchwork@mira.cbaines.net; Sat, 02 Oct 2021 06:24:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWcBW-0002Fv-KQ for guix-patches@gnu.org; Sat, 02 Oct 2021 06:24:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWcBW-0000B3-CV for guix-patches@gnu.org; Sat, 02 Oct 2021 06:24:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mWcBW-0007Ym-9w for guix-patches@gnu.org; Sat, 02 Oct 2021 06:24:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50960] [PATCH 04/10] DRAFT shell: By default load the local 'guix.scm' or 'manifest.scm' file. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 02 Oct 2021 10:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50960 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50960@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 50960-submit@debbugs.gnu.org id=B50960.163317019128942 (code B ref 50960); Sat, 02 Oct 2021 10:24:02 +0000 Received: (at 50960) by debbugs.gnu.org; 2 Oct 2021 10:23:11 +0000 Received: from localhost ([127.0.0.1]:57961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWcAh-0007Wd-AF for submit@debbugs.gnu.org; Sat, 02 Oct 2021 06:23:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33126) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWcAU-0007UI-EU for 50960@debbugs.gnu.org; Sat, 02 Oct 2021 06:22:59 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49194) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWcAP-0007ct-8y; Sat, 02 Oct 2021 06:22:53 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=36460 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWcAO-0007gb-Tv; Sat, 02 Oct 2021 06:22:53 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 2 Oct 2021 12:22:34 +0200 Message-Id: <20211002102240.27815-4-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211002102240.27815-1-ludo@gnu.org> References: <20211002102240.27815-1-ludo@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" X-getmail-retrieved-from-mailbox: Patches DRAFT: Add doc. * guix/scripts/shell.scm (parse-args): Add call to 'auto-detect-manifest'. (find-file-in-parent-directories, auto-detect-manifest): New procedures. * tests/guix-shell.sh: Add test. --- guix/scripts/shell.scm | 44 ++++++++++++++++++++++++++++++++++++++++-- tests/guix-shell.sh | 16 +++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm index 6a4b7a5092..2f15befbd3 100644 --- a/guix/scripts/shell.scm +++ b/guix/scripts/shell.scm @@ -22,6 +22,8 @@ #:autoload (guix scripts build) (show-build-options-help) #:autoload (guix transformations) (show-transformation-options-help) #:use-module (guix scripts) + #:use-module (guix packages) + #:use-module (guix profiles) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) @@ -121,13 +123,51 @@ interactive shell in that environment.\n")) ;; The '--' token is used to separate the command to run from the rest of ;; the operands. (let ((args command (break (cut string=? "--" <>) args))) - (let ((opts (parse-command-line args %options (list %default-options) - #:argument-handler handle-argument))) + (let ((opts (auto-detect-manifest + (parse-command-line args %options (list %default-options) + #:argument-handler handle-argument)))) (match command (() opts) (("--") opts) (("--" command ...) (alist-cons 'exec command opts)))))) +(define (find-file-in-parent-directories candidates) + "Find one of CANDIDATES in the current directory or one of its ancestors." + (let loop ((directory (getcwd))) + (and (= (stat:uid (stat directory)) (getuid)) + (or (any (lambda (candidate) + (let ((candidate (string-append directory "/" candidate))) + (and (file-exists? candidate) candidate))) + candidates) + (loop (string-append directory "/..")))))) ;Unix ".." resolution + +(define (auto-detect-manifest opts) + "If OPTS do not specify packages or a manifest, load a \"guix.scm\" or +\"manifest.scm\" file from the current directory or one of its ancestors. +Return the modified OPTS." + (define (options-contain-payload? opts) + (match opts + (() #f) + ((('package . _) . _) #t) + ((('load . _) . _) #t) + ((('manifest . _) . _) #t) + ((('expression . _) . _) #t) + ((_ . rest) (options-contain-payload? rest)))) + + (if (options-contain-payload? opts) + opts + (match (find-file-in-parent-directories '("guix.scm" "manifest.scm")) + (#f + (warning (G_ "no packages specified; creating an empty environment~%")) + opts) + (file + (info (G_ "loading environment from '~a'...~%") file) + (match (basename file) + ("guix.scm" + (alist-cons 'load `(package ,file) opts)) + ("manifest.scm" + (alist-cons 'manifest file opts))))))) + (define-command (guix-shell . args) (category development) diff --git a/tests/guix-shell.sh b/tests/guix-shell.sh index f08637f7ff..498c1c5515 100644 --- a/tests/guix-shell.sh +++ b/tests/guix-shell.sh @@ -31,6 +31,16 @@ guix shell --bootstrap --pure guile-bootstrap -- guile --version # '--ad-hoc' is a thing of the past. ! guix shell --ad-hoc guile-bootstrap +# Honoring the local 'manifest.scm' file. +cat > "$tmpdir/manifest.scm" <manifest '("guile-bootstrap")) +EOF +profile1="$(cd "$tmpdir"; guix shell --bootstrap -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT')" +profile2="$(guix shell --bootstrap guile-bootstrap -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT')" +test -n "$profile1" +test "$profile1" = "$profile2" +rm "$tmpdir/manifest.scm" + if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null then # Compute the build environment for the initial GNU Make. @@ -51,4 +61,10 @@ then # 'make-boot0' itself must not be listed. ! guix gc --references "$profile" | grep make-boot0 + + # Honoring the local 'guix.scm' file. + echo '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/guix.scm" + (cd "$tmpdir"; guix shell --bootstrap --search-paths --pure > "b") + cmp "$tmpdir/a" "$tmpdir/b" + rm "$tmpdir/guix.scm" fi