From patchwork Wed Aug 12 06:06:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Pykhalov X-Patchwork-Id: 23595 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 E1F0227BBE3; Wed, 12 Aug 2020 07:07:08 +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.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,T_DKIM_INVALID,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 ESMTP id 2119C27BBE4 for ; Wed, 12 Aug 2020 07:07:08 +0100 (BST) Received: from localhost ([::1]:33748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k5jul-00087K-LP for patchwork@mira.cbaines.net; Wed, 12 Aug 2020 02:07:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5jug-00087A-Dv for guix-patches@gnu.org; Wed, 12 Aug 2020 02:07:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:59387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k5jug-00070a-4m for guix-patches@gnu.org; Wed, 12 Aug 2020 02:07:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k5juf-0003sf-Vf for guix-patches@gnu.org; Wed, 12 Aug 2020 02:07:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42820] [PATCH] doc: cookbook: Add chapter about Guix environment. Resent-From: Oleg Pykhalov Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 12 Aug 2020 06:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 42820 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42820@debbugs.gnu.org Cc: Oleg Pykhalov X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.159721242014907 (code B ref -1); Wed, 12 Aug 2020 06:07:01 +0000 Received: (at submit) by debbugs.gnu.org; 12 Aug 2020 06:07:00 +0000 Received: from localhost ([127.0.0.1]:42700 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k5jud-0003sN-Uo for submit@debbugs.gnu.org; Wed, 12 Aug 2020 02:07:00 -0400 Received: from lists.gnu.org ([209.51.188.17]:36216) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k5jua-0003sD-U4 for submit@debbugs.gnu.org; Wed, 12 Aug 2020 02:06:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5jua-00086x-Pm for guix-patches@gnu.org; Wed, 12 Aug 2020 02:06:56 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]:36908) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k5juY-0006zG-UK for guix-patches@gnu.org; Wed, 12 Aug 2020 02:06:56 -0400 Received: by mail-lj1-x22f.google.com with SMTP id w14so928296ljj.4 for ; Tue, 11 Aug 2020 23:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SbKzDRUBlkmD9wi40d1GTNL43sd8MsdghpCfefFugFo=; b=HhKhP2sjRe9zJON20jAcxIWQ/pbnN+hIRABXPk9v+UjczMvAYtGSwHbMshckE0ZDX0 gcrxCNwye7dfjVf5kfmLl73q/whE7aUfVxs+1AgrXwJ/qVVCFTVJh/yj+z0H9BHBqzbF +QEVJ7+EEFL1NHOwFqxPtz/5XbkQgUxtMO2lGWbto98CbchXGOHH5ITxzuNN0DTbt3Wi U5aVtzFwuMbdHinfoEUsQwFhzA3jvt89i1oGLmbFZRWekkwH6b5HTTPjR3QlONnQT5ic sb1Rf+uC7H4waqdw8txnyS6FEVPtvVZMpFYOhRaa7nClEN7rgHDesevWsqxtXVZs4UPc +opA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SbKzDRUBlkmD9wi40d1GTNL43sd8MsdghpCfefFugFo=; b=bQ/8QI9Izqq8sVnslvxSEgVSjECs/yuXwURq/0QRMYdS8BjzkWaW9GWjjCO+FbLdhO mmZXHHZb3Op0qS4b5ZxkFyPFahfsVawObW0cX8kysvd3GsBIwmTvzkAunKsp3H4ijJq1 7Qgu3+TZGCk1G7oc2/D3T6aXimhoAWwVHIcF28vK501PRvG9NlFOJULl92b38AkgNDFD nHSkV7M5GK857ZcsHsJql/LVDPuZzRhahh8sLPUoHLfsIfvuQmhlvqk70TvKEpuu7goD Zzx2OB1nqqJGgBd0UkGcGoaFrvwYt77p5aB7bG3oEOtxZGCgebG7OqPCft/qIkUlSq+t OTbw== X-Gm-Message-State: AOAM532jL9ygfergdqY3x8MAPS7EnX40RhsOi5HjU5yAS6vIBPwV++zn j/jCdj+5vh2osUZTdDbqy1DSWNK7 X-Google-Smtp-Source: ABdhPJzL2e2lNdEnxIi/D3k6zT2KUKYk9cIwxSYOTofffumPx8YNF2Acolxhpy2t1knPxc0GLh+EHw== X-Received: by 2002:a2e:b814:: with SMTP id u20mr4390971ljo.202.1597212412268; Tue, 11 Aug 2020 23:06:52 -0700 (PDT) Received: from localhost.localdomain (ppp91-122-98-213.pppoe.avangarddsl.ru. [91.122.98.213]) by smtp.gmail.com with ESMTPSA id a2sm215455ljj.40.2020.08.11.23.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 23:06:51 -0700 (PDT) From: Oleg Pykhalov Date: Wed, 12 Aug 2020 09:06:13 +0300 Message-Id: <20200812060613.15094-1-go.wigust@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22f; envelope-from=go.wigust@gmail.com; helo=mail-lj1-x22f.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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 * doc/guix-cookbook.texi (Environment management): New chapter. --- doc/guix-cookbook.texi | 125 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index f541592d13..326675c48b 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -64,6 +64,7 @@ Translation Project}. * Packaging:: Packaging tutorials * System Configuration:: Customizing the GNU System * Advanced package management:: Power to the users! +* Environment management:: Control environment * Acknowledgments:: Thanks! * GNU Free Documentation License:: The license of this document. @@ -2268,6 +2269,130 @@ mkdir -p "$GUIX_EXTRA_PROFILES/my-project" It's safe to delete the Guix channel profile you've just installed with the channel specification, the project profile does not depend on it. +@c ********************************************************************* +@node Environment management +@chapter Environment management + +Guix provides multiple tools to manage environment. This chapter +demonstrate such utilities. + +@menu +* Guix environment via direnv:: Setup Guix environment with direnv +@end menu + +@node Guix environment via direnv +@section Guix environment via direnv + +Guix provides a @samp{direnv} package, which could extend shell after +directory change. This tool could be used to prepare a pure Guix +environment. + +The following example provides a shell function for @file{~/.direnvrc} +file, which could be used from Guix Git repository in +@file{~/src/guix/.envrc} file to setup a build environment similar to +described in @pxref{Building from Git,,, guix, GNU Guix Reference +Manual}. + +Create a @file{~/.direnvrc} with a Bash code: + +@example +# Thanks +export_function() +@{ + local name=$1 + local alias_dir=$PWD/.direnv/aliases + mkdir -p "$alias_dir" + PATH_add "$alias_dir" + local target="$alias_dir/$name" + if declare -f "$name" >/dev/null; then + echo "#!$SHELL" > "$target" + declare -f "$name" >> "$target" 2>/dev/null + # Notice that we add shell variables to the function trigger. + echo "$name \$*" >> "$target" + chmod +x "$target" + fi +@} + +use_guix() +@{ + # Set GitHub token. + export GUIX_GITHUB_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + # Unset 'GUIX_PACKAGE_PATH'. + export GUIX_PACKAGE_PATH="" + + # Recreate a garbage collector root. + gcroots="$HOME/.config/guix/gcroots" + mkdir -p "$gcroots" + gcroot="$gcroots/guix" + if [ -L "$gcroot" ] + then + rm -v "$gcroot" + fi + + # Miscellaneous packages. + PACKAGES_MAINTENANCE=( + direnv + git + git:send-email + git-cal + gnupg + guile-colorized + guile-readline + less + ncurses + openssh + xdot + ) + + # Environment packages. + PACKAGES=(help2man guile-sqlite3 guile-gcrypt) + + # Thanks + eval "$(guix environment --search-paths --root="$gcroot" --pure guix --ad-hoc $@{PACKAGES[@@]@} $@{PACKAGES_MAINTENANCE[@@]@} "$@@")" + + # Predefine configure flags. + configure() + @{ + ./configure --localstatedir=/var --prefix= + @} + export_function configure + + # Run make and optionally build something. + build() + @{ + make -j 2 + if [ $# -gt 0 ] + then + ./pre-inst-env guix build "$@@" + fi + @} + export_function build + + # Predefine push Git command. + push() + @{ + git push --set-upstream origin + @} + export_function push + + clear # Clean up the screen. + git-cal # Show contributions calendar. + + # Show commands help. + echo " +build build a package or just a project if no argument provided +configure run ./configure with predefined parameters +push push to upstream Git repository +" +@} +@end example + +Every project containing @file{.envrc} with a string @code{use guix} +will have predefined environment variables and procedures. + +Run @command{direnv allow} to setup the environment for the first time. + @c ********************************************************************* @node Acknowledgments @chapter Acknowledgments