From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id mF9zElszWGFGpgAAgWs5BA (envelope-from ) for ; Sat, 02 Oct 2021 12:24:27 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id uDwMDlszWGHeBwAAbx9fmQ (envelope-from ) for ; Sat, 02 Oct 2021 10:24:27 +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 DB9F92A9C6 for ; Sat, 2 Oct 2021 12:24:26 +0200 (CEST) Received: from localhost ([::1]:52306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWcBu-0002HO-1L for larch@yhetil.org; Sat, 02 Oct 2021 06:24:26 -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 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=1633170266; 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=vyAO8nmsVb43wGwAH2hQWlFuZ/icErSi+B3RkleT4OI=; b=OAwCQHsBigTcgc+xcqxhAsDGK06yHjLRPfKG0g9UfqTbGRg9eAo7b3ovslTqUVYnlLP2xa pC8DuZgTUVyYpX+FnvGhTZLzDjsRiB2BgxyC7EOASxnLTjqQ5+TjHco2DwogZk2IlAhuRB R+QiwfMV0eEOM3bhAQy6mxRH5RiioszLa0evI71KariMQja5u4ffKYhueE+txsx34tT9E7 qUd2FVJuTxxmx21uzF+80rvGRq8hqo9MtXGpYcI96I55m+Z5Pw4FIAdtcm0yvW27mlu+Ro GawNfKz7slYAVs2e7uRi28wubNEDlWBLc4ojlFC1ye0hDCpSyPwGXnr2+90x0w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633170266; a=rsa-sha256; cv=none; b=fQmN1Ed9eQWzW2RfGCDZv+Fj5VKnnsuv7bhMjJZ0B0kmxLOHRYhGmDj62VOHhQWtrOSX1j rX7XG30jKBEQmAoQTEjYOLN+UjoC/IWm/AceXJjJFriGUp9p+5MRJCbqMs0T/3HfQZ8NJ+ 2Wkb93nl6VHGoYxyfv1x/53L6hsZu0v1RXeGA+gC7f04E186PSK721HvgHJnVL1l8Uqg41 UPkh2rpOhV4rgN65cMDOwEUzQCgTDlMh6aKAXys2QoJNq0OI2XQsks4WQ1XmP0z/Ugozml Y2PIXcuHjuNqlOAJIbLujrQrlxlu2j/31Jv0m6E9F8ir7m+XjVuvFPuf177g+A== 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.79 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: DB9F92A9C6 X-Spam-Score: 2.79 X-Migadu-Scanner: scn1.migadu.com X-TUID: UMAkvHDc270t 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 -- 2.33.0