From patchwork Wed Oct 6 22:05:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleg Pykhalov X-Patchwork-Id: 33663 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 6534827BBE3; Wed, 6 Oct 2021 23:13:03 +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_H2, SPF_HELO_PASS,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 ESMTPS id CE84E27BBE1 for ; Wed, 6 Oct 2021 23:13:02 +0100 (BST) Received: from localhost ([::1]:58108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYF9p-0006Oa-P8 for patchwork@mira.cbaines.net; Wed, 06 Oct 2021 18:13:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYF42-0007Yw-Ro for guix-patches@gnu.org; Wed, 06 Oct 2021 18:07:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:34123) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYF42-0006Wp-K3 for guix-patches@gnu.org; Wed, 06 Oct 2021 18:07:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mYF42-0007J8-5J for guix-patches@gnu.org; Wed, 06 Oct 2021 18:07:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50967] [PATCH 3/3] guix: scripts: Make sure profile directory exists. Resent-From: Oleg Pykhalov Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 06 Oct 2021 22:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50967 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 50967@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , zimoun , Xinglu Chen , Andrew Tropin Received: via spool by 50967-submit@debbugs.gnu.org id=B50967.163355796628019 (code B ref 50967); Wed, 06 Oct 2021 22:07:02 +0000 Received: (at 50967) by debbugs.gnu.org; 6 Oct 2021 22:06:06 +0000 Received: from localhost ([127.0.0.1]:45669 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mYF2y-0007HS-Fq for submit@debbugs.gnu.org; Wed, 06 Oct 2021 18:06:06 -0400 Received: from mail-lf1-f53.google.com ([209.85.167.53]:40837) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mYF2t-0007HB-NR for 50967@debbugs.gnu.org; Wed, 06 Oct 2021 18:05:55 -0400 Received: by mail-lf1-f53.google.com with SMTP id y15so16362138lfk.7 for <50967@debbugs.gnu.org>; Wed, 06 Oct 2021 15:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=X7rlIbMlKz6tSv9eg/79WmGG7SLvINHM3n4Jk+JLtJ4=; b=DZL7ZdPBSTswPz5UczHgegvgidZ+ul8Z48dwRT6y3xcbw0I6vnnkwgBLIBA13mkMd9 epJ/v0a2fqn6xyzWphQmPkiedAWIxsY0z2wpHmkdlCnev6bs1BgbpFxUIjgf9Q9/QJKw KSMVG6lJUThDcVdhiQwzLeMpFsTBuLj5NogqLi3jOQuAd7o0r0DVMhZU77vwkhqBYuIA xtl6oACkbw/3+c7W4xvXQBb457R1iPVNPmNvW2G+rGsYS+7b7aXtDbGFfL4pwlCj1uDR vA5zRCb605JE1pkPRxnnOk6SsnhACWBp7kO7mZqbE405QP9L46sknl6Rh+hKUcGU0iOx RleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=X7rlIbMlKz6tSv9eg/79WmGG7SLvINHM3n4Jk+JLtJ4=; b=2tByPrpwUEjj6yTWHFUf9HqIPvFbaR73WywiIVyQwe/2vyZtvf4QaOdVQPbBBDjQAJ DE3BnJFFGk45BIYsdpMYweUR2RrbSQPFDis4Rxd9O7FFgsarLnCZki6FPhp8R5P7vZaM iFypM7Rc2KMEtCzPacKB6LcJevDYym7mfUp5JIB6X3yO5kwuqy7DdMLu2Ibo9rHElRgx O6GA5YcFWTMXgliJn0fxho0fjLu2r+5Z+TJVwTdXdJ+dm4Tm/b05E4azkOPuGqUI+4k4 4NuCR6Mad120lXJJdlrkkis8e2/76B4QuP430i9uii6Xq29urPdFkFJc4q84DGTwTECy 6q8A== X-Gm-Message-State: AOAM533mlOZBAwsIonQwupdZACot6HRPo62lm1iye7ixSshYZ+ro4ceN iUU2v9N3/MaUHKWYSR8hTx0= X-Google-Smtp-Source: ABdhPJx1aMrcWYIpSb0oMxzrjxdzI0I/le6l9Om96KFd2Z1mcHJacaEH6glh0kc7AUPKqGUqcAqRPA== X-Received: by 2002:a05:6512:3bc:: with SMTP id v28mr544830lfp.604.1633557945630; Wed, 06 Oct 2021 15:05:45 -0700 (PDT) Received: from guixsd ([88.201.161.72]) by smtp.gmail.com with ESMTPSA id r9sm16139ljk.101.2021.10.06.15.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 15:05:45 -0700 (PDT) From: Oleg Pykhalov References: <87h7dwq4cb.fsf_-_@gnu.org> <20211004231331.5269-1-go.wigust@gmail.com> <20211004231331.5269-3-go.wigust@gmail.com> Date: Thu, 07 Oct 2021 01:05:41 +0300 In-Reply-To: <20211004231331.5269-3-go.wigust@gmail.com> (Oleg Pykhalov's message of "Tue, 5 Oct 2021 02:13:31 +0300") Message-ID: <878rz54xmy.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 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 This patch fixes user's files corruption. Also, I applied suggestions about commit message, thanks zimoun! From eec2ab5f514ec6e156244898f8a635baf323ab70 Mon Sep 17 00:00:00 2001 From: Oleg Pykhalov 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 | 86 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 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 ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2021 Oleg Pykhalov ;;; ;;; 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..96cbd12857 --- /dev/null +++ b/tests/guix-home.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash + +# GNU Guix --- Functional package management for GNU +# Copyright © 2021 Oleg Pykhalov +# +# 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 . + +# +# 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 -mrf bash -c "run_guix_home_without_home" -- 2.33.0