[PATCH] doc: cookbook: Add chapter about Guix environment.

  • Done
  • quality assurance status badge
Details
2 participants
  • Oleg Pykhalov
  • Leo Famulari
Owner
unassigned
Submitted by
Oleg Pykhalov
Severity
normal
O
O
Oleg Pykhalov wrote on 12 Aug 2020 08:06
(address . guix-patches@gnu.org)(name . Oleg Pykhalov)(address . go.wigust@gmail.com)
20200812060613.15094-1-go.wigust@gmail.com
* doc/guix-cookbook.texi (Environment management): New chapter.
---
doc/guix-cookbook.texi | 125 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 125 insertions(+)

Toggle diff (145 lines)
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 <https://github.com/direnv/direnv/issues/73#issuecomment-152284914>
+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 <https://lists.gnu.org/archive/html/guix-devel/2016-09/msg00859.html>
+ 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
--
2.28.0
L
L
Leo Famulari wrote on 22 Aug 2020 20:51
(name . Oleg Pykhalov)(address . go.wigust@gmail.com)(address . 42820@debbugs.gnu.org)
20200822185133.GA20524@jasmine.lan
On Wed, Aug 12, 2020 at 09:06:13AM +0300, Oleg Pykhalov wrote:
Toggle quote (2 lines)
> * doc/guix-cookbook.texi (Environment management): New chapter.

If it's useful for you, please go ahead and push!
O
O
Oleg Pykhalov wrote on 23 Aug 2020 09:52
(name . Leo Famulari)(address . leo@famulari.name)(address . 42820-done@debbugs.gnu.org)
877dtpvly7.fsf@gmail.com
Hi,

Leo Famulari <leo@famulari.name> writes:

Toggle quote (4 lines)
>> * doc/guix-cookbook.texi (Environment management): New chapter.
>
> If it's useful for you, please go ahead and push!

Thanks for bumping the thread, pushed to master.

Oleg.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEcjhxI46s62NFSFhXFn+OpQAa+pwFAl9CICAACgkQFn+OpQAa
+pyDkQ/+IKKSnTMbbqSl/g/q5ZeULfBqq93QOtYdRKYN1exZAEGmwWrm08fIxj5z
t5X75eQOdggCKAzN5Eq1y7YJ5cpGekunT0+knnoxzX7VKu3gK/oeu3BiNXVGnLAP
62MrVlQUo1umu7GqL9b54ji90uWX3KTGEeGS+kUEY09s1SzS1gjhbcja+DIxHwrO
vbw/qtJQS37XF6XhurVyMsgZPPzEJOX7CA0c3zZO6SFcFyf28llAuNW8eONRmYZJ
3bZEl3l/vZ6SDxgRmE286mimfGUfq63A62jq0idemItFW6iwQCOTP45EglHLxbpf
4ltIcjVwRPv/NSx/t1qZZTycikl/Hj/ZFoc9B7oxya60HoDcuxPLy3Vy0Eqd42Lx
Ma3e+hGmnciE7CV1jMcypVe8gApubdAUKlmDpaK4irInGSPWU6h5/xlu2a3bhS8k
gLpeFJSDBTEIx4/uSqGcQqnW5/kNfJ3eC88OqWsK1y8m6GWFmuMcWGyXCflidUYf
KY+GYRTeX5vekgYyBbJNhtwcjUnRkRVTaHT09/lKYDKRNsrzMxWOMvThQUZS/3+G
8D6r9cB2SJ8uj/cUdFtXT0EqZgnVAu8K5kTBya1ZDyUVZQ7gEHsWFQBDQ+Q/py7K
vFN7m+zQadUaguO4eOX67e83NSBMPLN0xNuaPajVOA2L/5s94jI=
=athU
-----END PGP SIGNATURE-----

Closed
?