From patchwork Thu Jul 21 04:19:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Kehayias X-Patchwork-Id: 40804 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 A4A0F27BBEA; Thu, 21 Jul 2022 05:20:21 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,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 5C66427BBE9 for ; Thu, 21 Jul 2022 05:20:21 +0100 (BST) Received: from localhost ([::1]:38496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oENfg-0007GZ-I7 for patchwork@mira.cbaines.net; Thu, 21 Jul 2022 00:20:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oENfT-0007Do-AJ for guix-patches@gnu.org; Thu, 21 Jul 2022 00:20:08 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oENfO-0002HE-HZ for guix-patches@gnu.org; Thu, 21 Jul 2022 00:20:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oENfO-0001B4-CN for guix-patches@gnu.org; Thu, 21 Jul 2022 00:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56677] [PATCH 1/2] gnu: Add glibc-for-fhs. References: <1LCXD7_zuGflSFovh_mKvhdayNcoWp8ALeguq3i2-XWwWHgzZuPak2gSBN91VLNJ84lubuFAt1dPB282Zy0pBmh_zbiI2qI-7n0LP9F03u4=@protonmail.com> In-Reply-To: <1LCXD7_zuGflSFovh_mKvhdayNcoWp8ALeguq3i2-XWwWHgzZuPak2gSBN91VLNJ84lubuFAt1dPB282Zy0pBmh_zbiI2qI-7n0LP9F03u4=@protonmail.com> Resent-From: John Kehayias Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Jul 2022 04:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56677 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: "56677@debbugs.gnu.org" <56677@debbugs.gnu.org> Received: via spool by 56677-submit@debbugs.gnu.org id=B56677.16583771754465 (code B ref 56677); Thu, 21 Jul 2022 04:20:02 +0000 Received: (at 56677) by debbugs.gnu.org; 21 Jul 2022 04:19:35 +0000 Received: from localhost ([127.0.0.1]:36416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oENex-00019x-BI for submit@debbugs.gnu.org; Thu, 21 Jul 2022 00:19:35 -0400 Received: from mail-4322.protonmail.ch ([185.70.43.22]:60437) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oENev-00019j-6V for 56677@debbugs.gnu.org; Thu, 21 Jul 2022 00:19:34 -0400 Date: Thu, 21 Jul 2022 04:19:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1658377166; x=1658636366; bh=E4XPt6GUNF5K7mvB6YU6AXhVsWBhdoXXLhzTaqM3uTc=; h=Date:To:From:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc: Date:Subject:Reply-To:Feedback-ID:Message-ID; b=pxDIJfiWu0wTgSf50eVIhy6gAu8D8xC2eyRdy1xkQrPqisGTCfKmdw8LS0sSWzHZl lf1z4BAos1uZuMaLvNO0s61HODHGHnTm7KLyUQG9kdVTAgkEf+eufga0BDGaBcuz31 /40bZykSCC/VQ0Q8yqJYZ0Hp33K0bORNiBqLr4egYwZ+pYNWvRNM64qAipRBrrjA6a QECpEIhfZGOPtiaEeJxjovwjzxfPLVRKVMp91MD7lmmX7ylmJDsXPb+u1/zv1AwChu LmED4z51lhEGVD0lJcTGZf4w0yn74qMwqW+jxYcI7ILwihRjDmK+Ugy0mSrWFaJZUB f23tzp51B1zUQ== Message-ID: Feedback-ID: 7805494:user:proton 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" Reply-to: John Kehayias X-ACL-Warn: , John Kehayias via Guix-patches X-Patchwork-Original-From: John Kehayias via Guix-patches via From: John Kehayias X-getmail-retrieved-from-mailbox: Patches Empty Message From ac94f4203423c625c06018212677a798ea46b417 Mon Sep 17 00:00:00 2001 From: John Kehayias Date: Wed, 20 Jul 2022 23:26:53 -0400 Subject: [PATCH 1/2] gnu: Add glibc-for-fhs. * gnu/packages/base.scm (glibc-for-fhs): New variable. Hidden package for use in forthcoming --emulate-fhs option for guix containers. --- gnu/packages/base.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm index 4bdc3e7792..b566057b41 100644 --- a/gnu/packages/base.scm +++ b/gnu/packages/base.scm @@ -20,6 +20,7 @@ ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2021 Guillaume Le Vaillant ;;; Copyright © 2021 Maxim Cournoyer +;;; Copyright © 2022 John Kehayias ;;; ;;; This file is part of GNU Guix. ;;; @@ -928,6 +929,20 @@ (define-public glibc (license lgpl2.0+) (home-page "https://www.gnu.org/software/libc/"))) +;; Define a variation of glibc which uses the default /etc/ld.so.cache, useful +;; in FHS containers. +(define-public glibc-for-fhs + (hidden-package + (package + (inherit glibc) + (name "glibc-for-fhs") + (source (origin (inherit (package-source glibc)) + ;; Remove Guix's patch to read ld.so.cache from /gnu/store + ;; directories, re-enabling the default /etc/ld.so.cache + ;; behavior. + (patches (delete (car (search-patches "glibc-dl-cache.patch")) + (origin-patches (package-source glibc))))))))) + ;; Below are old libc versions, which we use mostly to build locale data in ;; the old format (which the new libc cannot cope with.) (define-public glibc-2.32 -- 2.37.0 From patchwork Thu Jul 21 04:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Kehayias X-Patchwork-Id: 40803 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 884AB27BBEA; Thu, 21 Jul 2022 05:20:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,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 5B62327BBE9 for ; Thu, 21 Jul 2022 05:20:19 +0100 (BST) Received: from localhost ([::1]:38436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oENfe-0007EC-Bf for patchwork@mira.cbaines.net; Thu, 21 Jul 2022 00:20:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oENfT-0007Dp-AG for guix-patches@gnu.org; Thu, 21 Jul 2022 00:20:08 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oENfP-0002LR-3E for guix-patches@gnu.org; Thu, 21 Jul 2022 00:20:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oENfO-0001BC-VJ for guix-patches@gnu.org; Thu, 21 Jul 2022 00:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56677] [PATCH 2/2] environment: Add '--emulate-fhs'. References: <1LCXD7_zuGflSFovh_mKvhdayNcoWp8ALeguq3i2-XWwWHgzZuPak2gSBN91VLNJ84lubuFAt1dPB282Zy0pBmh_zbiI2qI-7n0LP9F03u4=@protonmail.com> In-Reply-To: <1LCXD7_zuGflSFovh_mKvhdayNcoWp8ALeguq3i2-XWwWHgzZuPak2gSBN91VLNJ84lubuFAt1dPB282Zy0pBmh_zbiI2qI-7n0LP9F03u4=@protonmail.com> Resent-From: John Kehayias Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Jul 2022 04:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56677 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: "56677@debbugs.gnu.org" <56677@debbugs.gnu.org> Received: via spool by 56677-submit@debbugs.gnu.org id=B56677.16583772004513 (code B ref 56677); Thu, 21 Jul 2022 04:20:02 +0000 Received: (at 56677) by debbugs.gnu.org; 21 Jul 2022 04:20:00 +0000 Received: from localhost ([127.0.0.1]:36420 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oENfL-0001Aj-Ps for submit@debbugs.gnu.org; Thu, 21 Jul 2022 00:20:00 -0400 Received: from mail-40134.protonmail.ch ([185.70.40.134]:34587) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oENfJ-0001AU-N0 for 56677@debbugs.gnu.org; Thu, 21 Jul 2022 00:19:58 -0400 Date: Thu, 21 Jul 2022 04:19:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1658377191; x=1658636391; bh=tvEnU35sz3TT8n+s45ZgQDoPS168AS0YWM2CzStegxc=; h=Date:To:From:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc: Date:Subject:Reply-To:Feedback-ID:Message-ID; b=lbfZwk8BW6IfJbvt0F1jFM43SAq2qtHfaHMbItxjG/wRE6Yjzy/1qm5ZSm10vlV9K PLCJx06Bjjn7ttN8pzmNnxoweKacUA87kSI9uSO1hx91W4SeJ/qTyLcrQDWmd4z4Ul S1MeIJRyJO4zYLbkN0mHjP5UW3TLX3ygTUhO+ShpVOChF0S6w+YHWnMarsl6OPTRlT SrIbtGPrV+tCCS7/oa2Dcdsq87s5mCgp0Y1qqmPrYTqIqpLLh/DeAGQLGx7TFuK0WS o+V3laRUCEO5H+t58Sq1fLdgofzn1by7K0qCycppabz6y1EMfhqppFdVxSpfVmDjT7 igab70BFE5zJg== Message-ID: Feedback-ID: 7805494:user:proton 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" Reply-to: John Kehayias X-ACL-Warn: , John Kehayias via Guix-patches X-Patchwork-Original-From: John Kehayias via Guix-patches via From: John Kehayias X-getmail-retrieved-from-mailbox: Patches Empty Message From 27d40cbd60471b79dc1692f7db4aef495b93493d Mon Sep 17 00:00:00 2001 From: John Kehayias Date: Wed, 20 Jul 2022 23:46:45 -0400 Subject: [PATCH 2/2] environment: Add '--emulate-fhs'. * guix/scripts/environment.scm (show-environment-options-help) (%options): Add '--emulate-fhs'. * guix/scripts/environment.scm (launch-environment/container): Add 'emulate-fhs?' key and implement it. Define and use FHS-MAPPINGS, FHS-SYMLINKS, and LINK-CONTENTS to set up the container to follow the Filesystem Hierarchy Standard (FHS) for /bin, /etc, and /usr. Generate /etc/ld.so.cache in the container from /etc/ld.so.conf by running the script /tmp/fhs.sh to launch the container. (guix-environment*): Add glibc-for-fhs to the container packages when 'emulate-fhs?' key is in OPTS. * doc/guix.texi (Invoking guix shell): Document '--emulate-fhs'. (Invoking guix environment): Document '--emulate-fhs'. --- doc/guix.texi | 33 ++++++++ guix/scripts/environment.scm | 156 ++++++++++++++++++++++++++++++----- 2 files changed, 167 insertions(+), 22 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 3c5864ec1a..ab3967b2e5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -106,6 +106,7 @@ Copyright @copyright{} 2022 Karl Hallsby@* Copyright @copyright{} 2022 Justin Veilleux@* Copyright @copyright{} 2022 Reily Siegel@* +Copyright @copyright{} 2022 John Kehayias@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -6155,6 +6156,22 @@ Invoking guix shell guix shell --container --expose=$HOME=/exchange guile -- guile @end example +@item --emulate-fhs +@item -F +For containers, emulate a Filesystem Hierarchy Standard (FHS) +configuration within the container, see +@uref{https://refspecs.linuxfoundation.org/fhs.shtml, the official +specification}. As Guix deviates from the FHS specification, this +option sets up the container to more closely mimic that of other +GNU/Linux distributions. This is useful for reproducing other +development environments, testing, and using programs which expect the +FHS specification to be followed. With this option, the container will +include a version of @code{glibc} which will read +@code{/etc/ld.so.cache} within the container for the shared library +cache (contrary to @code{glibc} in regular Guix usage) and set up the +expected FHS directories: @code{/bin}, @code{/etc}, @code{/lib}, and +@code{/usr} from the container's profile. + @item --rebuild-cache @cindex caching, of profiles @cindex caching, in @command{guix shell} @@ -6574,6 +6591,22 @@ Invoking guix environment @end table +@item --emulate-fhs +@item -F +For containers, emulate a Filesystem Hierarchy Standard (FHS) +configuration within the container, see +@uref{https://refspecs.linuxfoundation.org/fhs.shtml, the official +specification}. As Guix deviates from the FHS specification, this +option sets up the container to more closely mimic that of other +GNU/Linux distributions. This is useful for reproducing other +development environments, testing, and using programs which expect the +FHS specification to be followed. With this option, the container will +include a version of @code{glibc} which will read +@code{/etc/ld.so.cache} within the container for the shared library +cache (contrary to @code{glibc} in regular Guix usage) and set up the +expected FHS directories: @code{/bin}, @code{/etc}, @code{/lib}, and +@code{/usr} from the container's profile. + @command{guix environment} also supports all of the common build options that @command{guix build} supports (@pxref{Common Build Options}) as well as package diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 3216235937..f943cd89d9 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2014, 2015, 2018 David Thompson ;;; Copyright © 2015-2022 Ludovic Courtès ;;; Copyright © 2018 Mike Gerwitz +;;; Copyright © 2022 John Kehayias ;;; ;;; This file is part of GNU Guix. ;;; @@ -120,6 +121,9 @@ (define (show-environment-options-help) --expose=SPEC for containers, expose read-only host file system according to SPEC")) (display (G_ " + -F, --emulate-fhs for containers, emulate the Filesystem Hierarchy + Standard (FHS)")) + (display (G_ " -v, --verbosity=LEVEL use the given verbosity LEVEL")) (display (G_ " --bootstrap use bootstrap binaries to build the environment"))) @@ -256,6 +260,9 @@ (define %options (alist-cons 'file-system-mapping (specification->file-system-mapping arg #f) result))) + (option '(#\F "emulate-fhs") #f #f + (lambda (opt name arg result) + (alist-cons 'emulate-fhs? #t result))) (option '(#\r "root") #t #f (lambda (opt name arg result) (alist-cons 'gc-root arg result))) @@ -608,16 +615,18 @@ (define* (launch-environment/fork command profile manifest (define* (launch-environment/container #:key command bash user user-mappings profile manifest link-profile? network? - map-cwd? (white-list '())) + map-cwd? emulate-fhs? (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 NETWORK?, access to the host system network is permitted. -USER-MAPPINGS, a list of file system mappings, contains the user-specified -host file systems to mount inside the container. If USER is not #f, each -target of USER-MAPPINGS will be re-written relative to '/home/USER', and USER -will be used for the passwd entry. LINK-PROFILE? creates a symbolic link from -~/.guix-profile to the environment 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 +NETWORK?, access to the host system network is permitted. USER-MAPPINGS, a +list of file system mappings, contains the user-specified host file systems to +mount inside the container. If USER is not #f, each target of USER-MAPPINGS +will be re-written relative to '/home/USER', and USER will be used for the +passwd entry. When EMULATE-FHS?, set up the container to follow the +Filesystem Hierarchy Standard and provide a glibc that reads the cache from +/etc/ld.so.cache. LINK-PROFILE? creates a symbolic link from ~/.guix-profile +to the environment profile. Preserve environment variables whose name matches the one of the regexps in WHILE-LIST." @@ -625,6 +634,40 @@ (define* (launch-environment/container #:key command bash user user-mappings (and (file-exists? (file-system-mapping-source mapping)) (file-system-mapping->bind-mount mapping))) + ;; File system mappings for an FHS container, where the entire directory can + ;; be mapped. Others (bin and etc) will already have contents and need to + ;; use LINK-CONTENTS to symlink the directory contents. + (define fhs-mappings + (map (lambda (mapping) + (file-system-mapping + (source (string-append profile (car mapping))) + (target (cdr mapping)))) + '(("/lib" . "/lib") + ("/include" . "/usr/include") + ("/sbin" . "/sbin") + ("/libexec" . "/usr/libexec") + ("/share" . "/usr/share")))) + + ;; Additional (optional) symlinks for an FHS container. + (define fhs-symlinks + `(("/lib" . "/usr/lib") + ,(if (target-64bit?) + '("/lib" . "/lib64") + '("/lib" . "/lib32")) + ("/bin" . "/usr/bin") + ("/sbin" . "/usr/sbin"))) + + ;; A procedure to symlink the contents (at the top level) of a directory, + ;; excluding the directory itself and parent, along with any others provided + ;; in EXCLUDE. + (define* (link-contents dir #:key (exclude '())) + (for-each (lambda (file) + (symlink (string-append profile dir "/" file) + (string-append dir "/" file))) + (scandir (string-append profile dir) + (negate (cut member <> + (append exclude '("." ".." ))))))) + (define (exit/status* status) (exit/status (validate-exit-status profile command status))) @@ -682,6 +725,11 @@ (define* (launch-environment/container #:key command bash user user-mappings (filter-map optional-mapping->fs %network-file-mappings) '()) + ;; Mappings for an FHS container. + (if emulate-fhs? + (filter-map optional-mapping->fs + fhs-mappings) + '()) (map file-system-mapping->bind-mount mappings)))) (exit/status* @@ -709,6 +757,53 @@ (define* (launch-environment/container #:key command bash user user-mappings (mkdir-p home-dir) (setenv "HOME" home-dir) + ;; Set up an FHS container. + (when emulate-fhs? + ;; The FHS container sets up the expected filesystem through + ;; MAPPINGS above, the optional symlinks, and linking the + ;; contents of profile/bin and profile/etc, as these both have + ;; or will have contents for a non-FHS container so must be + ;; handled separately. + (mkdir-p "/usr") + (for-each (lambda (link) + (if (file-exists? (car link)) + (symlink (car link) (cdr link)))) + fhs-symlinks) + (link-contents "/bin" #:exclude '("sh")) + (mkdir-p "/etc") + (link-contents "/etc") + + ;; Provide a frequently expected 'cc' symlink to gcc (in case it + ;; is in the container), though this could also be done by the + ;; user in the container, e.g. in $HOME/.local/bin and adding + ;; that to $PATH. Note: we do this in /bin since that already + ;; has the sh symlink and the other (optional) FHS bin + ;; directories will link to /bin. + (symlink (string-append profile "/bin/gcc") "/bin/cc") + + ;; Guix's ldconfig doesn't seem to search in FHS default + ;; locations, so provide a minimal ld.so.conf. + (call-with-output-file "/etc/ld.so.conf" + (lambda (port) + (for-each (lambda (directory) + (display directory port) + (newline port)) + ;; /lib/nss is needed as Guix's nss puts libraries + ;; there rather than in the lib directory. + '("/lib" "/lib/nss")))) + + ;; Define an entry script to start the container: generate + ;; ld.so.cache, supplement $PATH (optional, but to better match + ;; FHS expectations), and include COMMAND. + (call-with-output-file "/tmp/fhs.sh" + (lambda (port) + (display "ldconfig -X" port) + (newline port) + (display "export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH" port) + (newline port) + (display (car command) port) + (newline port)))) + ;; If requested, link $GUIX_ENVIRONMENT to $HOME/.guix-profile; ;; this allows programs expecting that path to continue working as ;; expected within a container. @@ -746,7 +841,10 @@ (define* (launch-environment/container #:key command bash user user-mappings (primitive-exit/status ;; A container's environment is already purified, so no need to ;; request it be purified again. - (launch-environment command + (launch-environment (if emulate-fhs? + ;; Use the FHS start script. + '("/bin/sh" "/tmp/fhs.sh") + command) (if link-profile? (string-append home-dir "/.guix-profile") profile) @@ -874,16 +972,17 @@ (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?)) - (network? (assoc-ref opts 'network?)) - (no-cwd? (assoc-ref opts 'no-cwd?)) - (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) + (let* ((pure? (assoc-ref opts 'pure)) + (container? (assoc-ref opts 'container?)) + (link-prof? (assoc-ref opts 'link-profile?)) + (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? @@ -922,12 +1021,24 @@ (define (guix-environment* opts) (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~'%"))) (with-store/maybe store (with-status-verbosity (assoc-ref opts 'verbosity) (define manifest-from-opts - (options/resolve-packages store opts)) + (options/resolve-packages store + ;; For an FHS-container, add the + ;; (hidden) package glibc-for-fhs which + ;; uses the global cache at + ;; /etc/ld.so.cache. + (if emulate-fhs? + (alist-cons 'expression + '(ad-hoc-package + "(@@ (gnu packages base) glibc-for-fhs)") + opts) + opts))) (define manifest (if profile @@ -1001,7 +1112,8 @@ (define (guix-environment* opts) #:white-list white-list #:link-profile? link-prof? #:network? network? - #:map-cwd? (not no-cwd?)))) + #:map-cwd? (not no-cwd?) + #:emulate-fhs? emulate-fhs?))) (else (return -- 2.37.0