diff mbox

[bug#50967,00/12] Move (gnu home-services XYZ) to (gnu services XYZ)

Message ID 871r4x4x6e.fsf_-_@gmail.com
State Accepted
Headers show

Commit Message

Oleg Pykhalov Oct. 6, 2021, 10:15 p.m. UTC
Oleg Pykhalov <go.wigust@gmail.com> writes:

> This patch fixes user's files corruption.  Also, I applied suggestions
> about commit message, thanks zimoun!

Also, in addion I forget to:

Replace '#!/usr/bin/env bash' with '#!/bin/bash'

Maybe a /bin/sh would be more Guix friendly, but shellcheck warns about
export -f does not exist in posix shell.  Thoughts are welcome ;-)


Remove a unnecessary subshell in run_guix_home_without_home.

Comments

M Oct. 7, 2021, 6:37 a.m. UTC | #1
Oleg Pykhalov schreef op do 07-10-2021 om 01:15 [+0300]:
> Oleg Pykhalov <go.wigust@gmail.com> writes:
> 
> > This patch fixes user's files corruption.  Also, I applied suggestions
> > about commit message, thanks zimoun!
> 
> Also, in addion I forget to:
> 
> Replace '#!/usr/bin/env bash' with '#!/bin/bash'
> 
> Maybe a /bin/sh would be more Guix friendly, but shellcheck warns about
> export -f does not exist in posix shell.  Thoughts are welcome ;-)

/bin/bash doesn't exist on Guix System, so it seems a bit weird to me
to use that in Guix.  Anyway, I think shellcheck should classify
'#!/usr/bin/env bash' as a bash shell instead of a posix shell?

Greetings,
Maxime.
Oleg Pykhalov Oct. 7, 2021, 9:56 a.m. UTC | #2
Maxime Devos <maximedevos@telenet.be> writes:

[…]

>> Replace '#!/usr/bin/env bash' with '#!/bin/bash'
>> 
>> Maybe a /bin/sh would be more Guix friendly, but shellcheck warns about
>> export -f does not exist in posix shell.  Thoughts are welcome ;-)
>
> /bin/bash doesn't exist on Guix System, so it seems a bit weird to me
> to use that in Guix.  Anyway, I think shellcheck should classify
> '#!/usr/bin/env bash' as a bash shell instead of a posix shell?

Yes, also /usr/bin/env does not exist on Guix as well.  So in that sense
both /bin/bash and /usr/bin/env bash are equal.

I see special-files-service-type has an example about creating
/usr/bin/env, so probable should use /usr/bin/env bash in test's
shebang line to make shellcheck happy.
M Oct. 7, 2021, 4:43 p.m. UTC | #3
Oleg Pykhalov schreef op do 07-10-2021 om 12:56 [+0300]:
> Maxime Devos <maximedevos@telenet.be> writes:
> 
> […]
> 
> > > Replace '#!/usr/bin/env bash' with '#!/bin/bash'
> > > 
> > > Maybe a /bin/sh would be more Guix friendly, but shellcheck warns about
> > > export -f does not exist in posix shell.  Thoughts are welcome ;-)
> > 
> > /bin/bash doesn't exist on Guix System, so it seems a bit weird to me
> > to use that in Guix.  Anyway, I think shellcheck should classify
> > '#!/usr/bin/env bash' as a bash shell instead of a posix shell?
> 
> Yes, also /usr/bin/env does not exist on Guix as well.  So in that sense
> both /bin/bash and /usr/bin/env bash are equal.

It does exist:

$ ls /usr/bin/env
/usr/bin/env

It's supposed to be possible to do without on Guix System though, by removing it
from %base-services.

FWIW, the shell scripts in tests/*.sh do not have a shebang.

Greetings,
Maxime.
Ludovic Courtès Oct. 8, 2021, 10:44 p.m. UTC | #4
Maxime Devos <maximedevos@telenet.be> skribis:

> Oleg Pykhalov schreef op do 07-10-2021 om 01:15 [+0300]:
>> Oleg Pykhalov <go.wigust@gmail.com> writes:
>> 
>> > This patch fixes user's files corruption.  Also, I applied suggestions
>> > about commit message, thanks zimoun!
>> 
>> Also, in addion I forget to:
>> 
>> Replace '#!/usr/bin/env bash' with '#!/bin/bash'
>> 
>> Maybe a /bin/sh would be more Guix friendly, but shellcheck warns about
>> export -f does not exist in posix shell.  Thoughts are welcome ;-)
>
> /bin/bash doesn't exist on Guix System,

Also, tests/*.sh are not executable and thus have no shebang; you can do
the same here.

Ludo’.
diff mbox

Patch

From 6351e3f099d3c09143c5f0289216d52ee45664d9 Mon Sep 17 00:00:00 2001
From: Oleg Pykhalov <go.wigust@gmail.com>
Date: Tue, 5 Oct 2021 02:10:25 +0300
Subject: [PATCH] scripts: home: Make sure profile directory exists.

* 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    | 84 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 87 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..b0b85737b0
--- /dev/null
+++ b/tests/guix-home.sh
@@ -0,0 +1,84 @@ 
+#!/bin/bash
+
+# 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
+
+run_guix_home_without_home()
+{
+    # Save current directory (Guix source directory) for later mount
+    test_directory="$(mktemp -d)"
+    trap 'umount $test_directory; rmdir $test_directory' EXIT
+    mount --bind "$PWD" "$test_directory"
+
+    # Make $HOME directory empty to preserve user's files
+    mount --types tmpfs none "$HOME"
+
+    # Mount Guix source directory in a clean environment
+    mkdir -p "$PWD"
+    mount --bind "$test_directory" "$PWD"
+    cd "$PWD" || 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"
+}
+export -f run_guix_home_without_home
+
+unshare --mount --map-root-user --fork sh -c "run_guix_home_without_home"
-- 
2.33.0