From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WKCFFT+wZGG2KgEAgWs5BA (envelope-from ) for ; Mon, 11 Oct 2021 23:44:31 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YPuyDz+wZGGZPwAAB5/wlQ (envelope-from ) for ; Mon, 11 Oct 2021 21:44:31 +0000 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 069C628380 for ; Mon, 11 Oct 2021 23:44:31 +0200 (CEST) Received: from localhost ([::1]:41706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ma35y-0002gZ-5N for larch@yhetil.org; Mon, 11 Oct 2021 17:44:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ma30h-0006aT-2t for guix-patches@gnu.org; Mon, 11 Oct 2021 17:39:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ma30g-0004qP-R4 for guix-patches@gnu.org; Mon, 11 Oct 2021 17:39:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ma30g-0001Pb-OB for guix-patches@gnu.org; Mon, 11 Oct 2021 17:39:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50960] [PATCH v2 04/11] 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: Mon, 11 Oct 2021 21:39: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.16339883175314 (code B ref 50960); Mon, 11 Oct 2021 21:39:02 +0000 Received: (at 50960) by debbugs.gnu.org; 11 Oct 2021 21:38:37 +0000 Received: from localhost ([127.0.0.1]:32903 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ma30G-0001NS-S3 for submit@debbugs.gnu.org; Mon, 11 Oct 2021 17:38:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45458) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ma309-0001M2-5T for 50960@debbugs.gnu.org; Mon, 11 Oct 2021 17:38:30 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40570) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ma303-0004WO-Ty; Mon, 11 Oct 2021 17:38:23 -0400 Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:53321 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 1ma303-0007Y0-KX; Mon, 11 Oct 2021 17:38:23 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 11 Oct 2021 23:38:02 +0200 Message-Id: <20211011213809.17482-5-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011213809.17482-1-ludo@gnu.org> References: <20211002102116.27726-1-ludo@gnu.org> <20211011213809.17482-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633988671; 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; bh=1J+1sOtkqT00YpFr2CyGtRm1LYYaBUnLmhn5OTg8F5M=; b=myWpM/TDZaSKJ5amE28U/xguSCTjUPXYnzE8LBsDd4Rbnp3089JBs/9fV3e81AvGnQPcsk wHhwXrQ0AS1FfU3PtNo9U991WDBknSXnHaBEh41lvEa5j6pK/W2dRxo6T790C1HnlTkSxt aOLwqboPvlbormwKlCHqVALR1ekTqO37kb+OKQdY5NeMU6zqA6xLtfnEGK98+F0rQF0OeU IOn17nvH2dOeGNKYW3nguBsE6xOA1CuFaNTMnIANVheX8qSr4PwpwOHkGvUhtC4WojE3rI Oe5Ld6gKfiXzAd0ZSpnEG9GEAWDfP2Kg41dA64f+0pymA6XC0DUpREkXLF90OA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633988671; a=rsa-sha256; cv=none; b=dkxsSuHdhmw+gffOTEM7Q72fDSnDMetOllgw2Zzlks8n36qXAWA8UqvbqYhi8eVQeMNx99 spPzydjp2G2pgJIa0C38oPjaYWmgloNdfl+/8THCSbrvleZdfNTH30zNgeSTKWQWJHS/ri oM8WWQgZRX2G6fmcvPDj2cco4NeWMQ12+Dd86aM6388kLVI+6wHUL8NpKDcnBrgmHH59fB jKVLZzkGhL23LhJRjSlfJ9MG89KDOxQY1uz8cuiPK1AeGOswqY3qEY2gGhOaR+YFbI6Q0f 78pyj92fW9WACICmJzqaZzhhrs21RMnIGQdZnstGeAz9nKs600QTuTi4w3uYaw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 2.08 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 069C628380 X-Spam-Score: 2.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: DIRbBGTJLsx+ 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 | 67 ++++++++++++++++++++++++++++++++++++++---- tests/guix-shell.sh | 36 +++++++++++++++++++++++ 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm index 190dd8837d..39d843bde7 100644 --- a/guix/scripts/shell.scm +++ b/guix/scripts/shell.scm @@ -22,6 +22,8 @@ (define-module (guix scripts shell) #: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) @@ -41,6 +43,8 @@ (define (show-help) (display (G_ " -f, --file=FILE create environment for the package that the code within FILE evaluates to")) + (display (G_ " + -q inhibit loading of 'guix.scm' and 'manifest.scm'")) (show-environment-options-help) (newline) @@ -99,7 +103,10 @@ (define %options (option '(#\f "file") #t #f (lambda (opt name arg result) (alist-cons 'load (tag-package-arg result arg) - result)))) + result))) + (option '(#\q) #f #f + (lambda (opt name arg result) + (alist-cons 'explicit-loading? #t result)))) (filter-map (lambda (opt) (and (not (any (lambda (name) (member name to-remove)) @@ -122,10 +129,60 @@ (define (handle-argument arg result) (let ((args command (break (cut string=? "--" <>) args))) (let ((opts (parse-command-line args %options (list %default-options) #:argument-handler handle-argument))) - (match command - (() opts) - (("--") opts) - (("--" command ...) (alist-cons 'exec command opts)))))) + (auto-detect-manifest + (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." + (define start (getcwd)) + (define device (stat:dev (stat start))) + + (let loop ((directory start)) + (let ((stat (stat directory))) + (and (= (stat:uid stat) (getuid)) + (= (stat:dev stat) device) + (or (any (lambda (candidate) + (let ((candidate (string-append directory "/" candidate))) + (and (file-exists? candidate) candidate))) + candidates) + (and (not (string=? directory "/")) + (loop (dirname directory)))))))) ;lexical ".." 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)))) + + (define interactive? + (not (assoc-ref opts 'exec))) + + (define disallow-implicit-load? + (assoc-ref opts 'explicit-loading?)) + + (if (or (not interactive?) + disallow-implicit-load? + (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) diff --git a/tests/guix-shell.sh b/tests/guix-shell.sh index f08637f7ff..0988ca0a75 100644 --- a/tests/guix-shell.sh +++ b/tests/guix-shell.sh @@ -31,6 +31,36 @@ guix shell --bootstrap --pure guile-bootstrap -- guile --version # '--ad-hoc' is a thing of the past. ! guix shell --ad-hoc guile-bootstrap +# Ignoring 'manifest.scm' and 'guix.scm' in non-interactive use. +cat > "$tmpdir/guix.scm" < "$tmpdir/manifest.scm" <manifest '("guile-bootstrap")) +EOF +cat > "$tmpdir/fake-shell.sh" < "$tmpdir/manifest.scm" +(cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap -q) +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 +81,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 -- 2.33.0