From 3d7ab284be8b1f07d7f22031ece0a7b28cbfacc6 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 7 Feb 2022 14:15:38 +0100 Subject: [PATCH 1/4] [rde] Setup GNU Guix Reproducible Development Environment --- .bash_profile | 8 ++++++++ .bashrc | 34 ++++++++++++++++++++++++++++++++++ README.org | 7 +++++++ channels-lock.scm | 11 +++++++++++ etc/profile | 33 +++++++++++++++++++++++++++++++++ run.sh | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+) create mode 100644 .bash_profile create mode 100644 .bashrc create mode 100644 channels-lock.scm create mode 100755 etc/profile create mode 100755 run.sh diff --git a/.bash_profile b/.bash_profile new file mode 100644 index 0000000..384ef2a --- /dev/null +++ b/.bash_profile @@ -0,0 +1,8 @@ +# Setups system and user profiles and related variables +# /etc/profile will be sourced by bash automatically +# Setups home environment profile +if [ -f ~/.profile ]; then source ~/.profile; fi + +# Honor per-interactive-shell startup file +if [ -f ~/.bashrc ]; then source ~/.bashrc; fi + export HISTFILE=$XDG_CACHE_HOME/.bash_history diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..cc9a472 --- /dev/null +++ b/.bashrc @@ -0,0 +1,34 @@ +# Bash initialization for interactive non-login shells and +# for remote shells (info "(bash) Bash Startup Files"). + +# Export 'SHELL' to child processes. Programs such as 'screen' +# honor it and otherwise use /bin/sh. +export SHELL + +if [[ $- != *i* ]] +then + # We are being invoked from a non-interactive shell. If this + # is an SSH session (as in "ssh host command"), source + # /etc/profile so we get PATH and other essential variables. + [[ -n "$SSH_CLIENT" ]] && source /etc/profile + + # Don't do anything else. + return +fi + +# Source the system-wide file. +# source /etc/bashrc + +source /usr/etc/profile + +# Adjust the prompt depending on whether we're in 'guix environment'. +if [ -n "$GUIX_ENVIRONMENT" ] +then + PS1='\u@\h \w [env]\$ ' +else + PS1='\u@\h \w\$ ' +fi +alias ls='ls -p --color=auto' +alias ll='ls -l' +alias grep='grep --color=auto' +alias clear="printf '\e[2J\e[H'" diff --git a/README.org b/README.org index a496415..cc8524e 100644 --- a/README.org +++ b/README.org @@ -35,6 +35,13 @@ You can also parse individual Org files using [[file:./laundry/cli.rkt]]. #+begin_src bash :results drawer laundry/cli.rkt docs/thoughts.org laundry/test.org #+end_src + +* Reproducible Development Environment +To have a (GNU Guix) fully Reproducible Development Environment run +#+begin_src bash :results drawer +./run.sh +#+end_src + * Status Laundry can parse most of Org syntax, though there are still issues with the correctness of the parse in a number of cases. diff --git a/channels-lock.scm b/channels-lock.scm new file mode 100644 index 0000000..e75140f --- /dev/null +++ b/channels-lock.scm @@ -0,0 +1,11 @@ +(list (channel + (name 'guix) + (url "https://git.savannah.gnu.org/git/guix.git") + (branch "master") + (commit + "67817299808a03e2750cfb630dc09fe8eb99c468") + (introduction + (make-channel-introduction + "9edb3f66fd807b096b48283debdcddccfea34bad" + (openpgp-fingerprint + "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA"))))) diff --git a/etc/profile b/etc/profile new file mode 100755 index 0000000..9816c04 --- /dev/null +++ b/etc/profile @@ -0,0 +1,33 @@ +# /etc/profile + +ri () { + set -x + raco pkg install --deps search-auto laundry + { retval="$?"; } 2>/dev/null + { set +x; } 2>/dev/null + return $retval +} + +rt () { + set -x + raco test --package laundry + { retval="$?"; } 2>/dev/null + { set +x; } 2>/dev/null + return $retval +} + +go () { + ri && rt +} + +cat << EOF +========================================= + ____ _ _ _ _ ____ _ + / ___| \ | | | | | / ___|_ _(_)_ __ +| | _| \| | | | | | | _| | | | \ \/ / +| |_| | |\ | |_| | | |_| | |_| | |> < + \____|_| \_|\___/ \____|\__,_|_/_/\_\\ + +Available commands: ri rt go +========================================= +EOF diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..6c39d45 --- /dev/null +++ b/run.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# GNU Guix Reproducible Development Environment + +WD=$(pwd) # WD=$(dirname "$0") # i.e. path to this file + +# --container run command within an isolated container +# --network allow containers to access the network +# --no-cwd don't share current working directory with an isolated container +# --preserve preserve environment variables that match the REGEXP +# --expose expose read-only host file system according to SPEC +# The --preserve and --expose parameters are needed so that `raco test laundry` +# doesn't complain: +# raco test: (submod "~/.local/share/racket/8.3/pkgs/laundry/colorer.rkt" test) +# Unable to init server: Could not connect: Connection refused +# Gtk initialization failed for display ":0" +# ... +# raco test: "~/.local/share/racket/8.3/pkgs/laundry/perf.rkt" +# Unable to init server: Could not connect: Connection refused +# Gtk initialization failed for display ":0" + +# Full freeze of Guix channels: +# guix time-machine --channels=./channels-lock.scm -- shell \ +# --container --network REST-OF-ARGS-OF-GUIX-SHELL + +# xtrace: Print commands and their arguments as they are executed +set -x + +guix shell \ + --container --network --no-cwd \ + racket bash grep coreutils which openssl nss-certs \ + --preserve='^DISPLAY$' --preserve='^XAUTHORITY$' --expose=$XAUTHORITY \ + --share=$WD/.bash_profile=$HOME/.bash_profile \ + --share=$WD/.bashrc=$HOME/.bashrc \ + --share=$WD/etc=/usr/etc \ + --share=/etc/ssl/certs \ + --share=$WD \ + -- bash From e6d6e72f59bb3dc2dfa7b88069e272a83960b4ef Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Tue, 8 Feb 2022 12:05:15 +0100 Subject: [PATCH 2/4] [rde] Reorganize the Guix RDE-relevant files --- README.org | 2 +- .bash_profile => guix-rde/.bash_profile | 0 .bashrc => guix-rde/.bashrc | 0 channels-lock.scm => guix-rde/channels-lock.scm | 0 {etc => guix-rde/etc}/profile | 0 run.sh => guix-rde/run-rde.sh | 6 +++--- 6 files changed, 4 insertions(+), 4 deletions(-) rename .bash_profile => guix-rde/.bash_profile (100%) rename .bashrc => guix-rde/.bashrc (100%) rename channels-lock.scm => guix-rde/channels-lock.scm (100%) rename {etc => guix-rde/etc}/profile (100%) rename run.sh => guix-rde/run-rde.sh (90%) diff --git a/README.org b/README.org index cc8524e..ec51a2d 100644 --- a/README.org +++ b/README.org @@ -39,7 +39,7 @@ laundry/cli.rkt docs/thoughts.org laundry/test.org * Reproducible Development Environment To have a (GNU Guix) fully Reproducible Development Environment run #+begin_src bash :results drawer -./run.sh +./guix-rde/run-rde.sh #+end_src * Status diff --git a/.bash_profile b/guix-rde/.bash_profile similarity index 100% rename from .bash_profile rename to guix-rde/.bash_profile diff --git a/.bashrc b/guix-rde/.bashrc similarity index 100% rename from .bashrc rename to guix-rde/.bashrc diff --git a/channels-lock.scm b/guix-rde/channels-lock.scm similarity index 100% rename from channels-lock.scm rename to guix-rde/channels-lock.scm diff --git a/etc/profile b/guix-rde/etc/profile similarity index 100% rename from etc/profile rename to guix-rde/etc/profile diff --git a/run.sh b/guix-rde/run-rde.sh similarity index 90% rename from run.sh rename to guix-rde/run-rde.sh index 6c39d45..ab137e6 100755 --- a/run.sh +++ b/guix-rde/run-rde.sh @@ -30,9 +30,9 @@ guix shell \ --container --network --no-cwd \ racket bash grep coreutils which openssl nss-certs \ --preserve='^DISPLAY$' --preserve='^XAUTHORITY$' --expose=$XAUTHORITY \ - --share=$WD/.bash_profile=$HOME/.bash_profile \ - --share=$WD/.bashrc=$HOME/.bashrc \ - --share=$WD/etc=/usr/etc \ + --share=$WD/guix-rde/.bash_profile=$HOME/.bash_profile \ + --share=$WD/guix-rde/.bashrc=$HOME/.bashrc \ + --share=$WD/guix-rde/etc=/usr/etc \ --share=/etc/ssl/certs \ --share=$WD \ -- bash From ac09902064e8832cf087006bbcfd4d5b00258a90 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Tue, 8 Feb 2022 12:31:20 +0100 Subject: [PATCH 3/4] [rde] Better function names, cleanup, share working directory --- guix-rde/etc/profile | 18 +++++++++--------- guix-rde/run-rde.sh | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/guix-rde/etc/profile b/guix-rde/etc/profile index 9816c04..4374d6a 100755 --- a/guix-rde/etc/profile +++ b/guix-rde/etc/profile @@ -1,23 +1,23 @@ # /etc/profile -ri () { +inst () { set -x raco pkg install --deps search-auto laundry - { retval="$?"; } 2>/dev/null - { set +x; } 2>/dev/null + { retval="$?"; + set +x; } 2>/dev/null return $retval } -rt () { +test () { set -x raco test --package laundry - { retval="$?"; } 2>/dev/null - { set +x; } 2>/dev/null + { retval="$?"; + set +x; } 2>/dev/null return $retval } -go () { - ri && rt +inst_test () { + inst && test } cat << EOF @@ -28,6 +28,6 @@ cat << EOF | |_| | |\ | |_| | | |_| | |_| | |> < \____|_| \_|\___/ \____|\__,_|_/_/\_\\ -Available commands: ri rt go +Available commands: inst, test, inst_test ========================================= EOF diff --git a/guix-rde/run-rde.sh b/guix-rde/run-rde.sh index ab137e6..4690b4e 100755 --- a/guix-rde/run-rde.sh +++ b/guix-rde/run-rde.sh @@ -6,7 +6,6 @@ WD=$(pwd) # WD=$(dirname "$0") # i.e. path to this file # --container run command within an isolated container # --network allow containers to access the network -# --no-cwd don't share current working directory with an isolated container # --preserve preserve environment variables that match the REGEXP # --expose expose read-only host file system according to SPEC # The --preserve and --expose parameters are needed so that `raco test laundry` @@ -27,7 +26,7 @@ WD=$(pwd) # WD=$(dirname "$0") # i.e. path to this file set -x guix shell \ - --container --network --no-cwd \ + --container --network \ racket bash grep coreutils which openssl nss-certs \ --preserve='^DISPLAY$' --preserve='^XAUTHORITY$' --expose=$XAUTHORITY \ --share=$WD/guix-rde/.bash_profile=$HOME/.bash_profile \ From 0b354a305eb5f3085b5aa4d1270c569e19913e37 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 14 Feb 2022 14:29:23 +0100 Subject: [PATCH 4/4] [rde] Bring down the number of script files --- guix-rde/.bashrc | 38 ++++++++++++++++++++++++++++++++++++-- guix-rde/channels-lock.scm | 11 ----------- guix-rde/etc/profile | 33 --------------------------------- guix-rde/run-rde.sh | 18 +++++++++++++++--- 4 files changed, 51 insertions(+), 49 deletions(-) delete mode 100644 guix-rde/channels-lock.scm delete mode 100755 guix-rde/etc/profile diff --git a/guix-rde/.bashrc b/guix-rde/.bashrc index cc9a472..fb9d5ef 100644 --- a/guix-rde/.bashrc +++ b/guix-rde/.bashrc @@ -5,12 +5,46 @@ # honor it and otherwise use /bin/sh. export SHELL +inst () { + set -x + raco pkg install --deps search-auto laundry + { retval="$?"; + set +x; } 2>/dev/null + return $retval +} + +test () { + set -x + raco test --package laundry + { retval="$?"; + set +x; } 2>/dev/null + return $retval +} + +inst_test () { + inst && test +} + +guix_prompt () { + cat << EOF +========================================= + ____ _ _ _ _ ____ _ + / ___| \ | | | | | / ___|_ _(_)_ __ +| | _| \| | | | | | | _| | | | \ \/ / +| |_| | |\ | |_| | | |_| | |_| | |> < + \____|_| \_|\___/ \____|\__,_|_/_/\_\\ + +Available commands: inst, test, inst_test +========================================= +EOF +} + if [[ $- != *i* ]] then # We are being invoked from a non-interactive shell. If this # is an SSH session (as in "ssh host command"), source # /etc/profile so we get PATH and other essential variables. - [[ -n "$SSH_CLIENT" ]] && source /etc/profile + [[ -n "$SSH_CLIENT" ]] && guix_prompt # Don't do anything else. return @@ -19,7 +53,7 @@ fi # Source the system-wide file. # source /etc/bashrc -source /usr/etc/profile +guix_prompt # Adjust the prompt depending on whether we're in 'guix environment'. if [ -n "$GUIX_ENVIRONMENT" ] diff --git a/guix-rde/channels-lock.scm b/guix-rde/channels-lock.scm deleted file mode 100644 index e75140f..0000000 --- a/guix-rde/channels-lock.scm +++ /dev/null @@ -1,11 +0,0 @@ -(list (channel - (name 'guix) - (url "https://git.savannah.gnu.org/git/guix.git") - (branch "master") - (commit - "67817299808a03e2750cfb630dc09fe8eb99c468") - (introduction - (make-channel-introduction - "9edb3f66fd807b096b48283debdcddccfea34bad" - (openpgp-fingerprint - "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA"))))) diff --git a/guix-rde/etc/profile b/guix-rde/etc/profile deleted file mode 100755 index 4374d6a..0000000 --- a/guix-rde/etc/profile +++ /dev/null @@ -1,33 +0,0 @@ -# /etc/profile - -inst () { - set -x - raco pkg install --deps search-auto laundry - { retval="$?"; - set +x; } 2>/dev/null - return $retval -} - -test () { - set -x - raco test --package laundry - { retval="$?"; - set +x; } 2>/dev/null - return $retval -} - -inst_test () { - inst && test -} - -cat << EOF -========================================= - ____ _ _ _ _ ____ _ - / ___| \ | | | | | / ___|_ _(_)_ __ -| | _| \| | | | | | | _| | | | \ \/ / -| |_| | |\ | |_| | | |_| | |_| | |> < - \____|_| \_|\___/ \____|\__,_|_/_/\_\\ - -Available commands: inst, test, inst_test -========================================= -EOF diff --git a/guix-rde/run-rde.sh b/guix-rde/run-rde.sh index 4690b4e..ab930c5 100755 --- a/guix-rde/run-rde.sh +++ b/guix-rde/run-rde.sh @@ -18,8 +18,21 @@ WD=$(pwd) # WD=$(dirname "$0") # i.e. path to this file # Unable to init server: Could not connect: Connection refused # Gtk initialization failed for display ":0" -# Full freeze of Guix channels: -# guix time-machine --channels=./channels-lock.scm -- shell \ +## Full freeze of Guix channels: +# cat << EOF >> /tmp/channels-lock.scm +# (list (channel +# (name 'guix) +# (url "https://git.savannah.gnu.org/git/guix.git") +# (branch "master") +# (commit +# "67817299808a03e2750cfb630dc09fe8eb99c468") +# (introduction +# (make-channel-introduction +# "9edb3f66fd807b096b48283debdcddccfea34bad" +# (openpgp-fingerprint +# "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA"))))) +# EOF +# guix time-machine --channels=/tmp/channels-lock.scm -- shell \ # --container --network REST-OF-ARGS-OF-GUIX-SHELL # xtrace: Print commands and their arguments as they are executed @@ -31,7 +44,6 @@ guix shell \ --preserve='^DISPLAY$' --preserve='^XAUTHORITY$' --expose=$XAUTHORITY \ --share=$WD/guix-rde/.bash_profile=$HOME/.bash_profile \ --share=$WD/guix-rde/.bashrc=$HOME/.bashrc \ - --share=$WD/guix-rde/etc=/usr/etc \ --share=/etc/ssl/certs \ --share=$WD \ -- bash