guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#50967] [PATCH 3/3] guix: scripts: Make sure profile directory exist


From: Oleg Pykhalov
Subject: [bug#50967] [PATCH 3/3] guix: scripts: Make sure profile directory exists.
Date: Tue, 5 Oct 2021 02:13:31 +0300

* guix/scripts/home.scm (process-action): Make sure profile directory exists.
* tests/guix-home.sh: New file.
* Makefile.am (SH_TESTS): Add this.
---
 Makefile.am           |  1 +
 guix/scripts/home.scm |  2 ++
 tests/guix-home.sh    | 73 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 tests/guix-home.sh

diff --git a/Makefile.am b/Makefile.am
index b66789fa0b..5bf2567dc8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -546,6 +546,7 @@ SH_TESTS =                                  \
   tests/guix-package-aliases.sh                        \
   tests/guix-package-net.sh                    \
   tests/guix-system.sh                         \
+  tests/guix-home.sh                           \
   tests/guix-archive.sh                                \
   tests/guix-authenticate.sh                   \
   tests/guix-environment.sh                    \
diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index 75df6d707d..115dfadb57 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -179,6 +180,7 @@ ACTION must be one of the sub-commands that takes a home 
environment
 declaration as an argument (a file name.)  OPTS is the raw alist of options
 resulting from command-line parsing."
   (define (ensure-home-environment file-or-exp obj)
+    (ensure-profile-directory)
     (unless (home-environment? obj)
       (leave (G_ "'~a' does not return a home environment ~%")
              file-or-exp))
diff --git a/tests/guix-home.sh b/tests/guix-home.sh
new file mode 100644
index 0000000000..e79982b7f7
--- /dev/null
+++ b/tests/guix-home.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+# GNU Guix --- Functional package management for GNU
+# Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
+#
+# This file is part of GNU Guix.
+#
+# GNU Guix is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GNU Guix is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+#
+# Test the 'guix home' using the external store, if any.
+#
+
+guix home --version
+
+NIX_STORE_DIR="$(guile -c '(use-modules (guix config))(display %storedir)')"
+localstatedir="$(guile -c '(use-modules (guix config))(display 
%localstatedir)')"
+GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
+export NIX_STORE_DIR GUIX_DAEMON_SOCKET
+
+# Run tests only when a "real" daemon is available.
+if ! guile -c '(use-modules (guix)) (exit (false-if-exception 
(open-connection)))'
+then
+    exit 77
+fi
+
+STORE_PARENT="$(dirname "$NIX_STORE_DIR")"
+export STORE_PARENT
+if test "$STORE_PARENT" = "/"; then exit 77; fi
+
+test_directory="$(mktemp -d)"
+export test_directory
+trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
+
+(
+    cd "$test_directory" || exit 77
+
+    cat > "dot-bashrc" <<'EOF'
+# dot-bashrc test file for guix home
+EOF
+
+    cat > "home.scm" <<'EOF'
+(use-modules (gnu home)
+             (gnu home-services)
+             (gnu home services shells)
+             (gnu services)
+             (guix gexp))
+
+(home-environment
+ (services
+  (list
+   (service home-bash-service-type
+            (home-bash-configuration
+             (guix-defaults? #t)
+             (bashrc
+              (list
+               (local-file (string-append (dirname (current-filename))
+                                          "/dot-bashrc")))))))))
+EOF
+)
+
+guix home reconfigure "${test_directory}/home.scm"
-- 
2.33.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]