From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qNBVDqa+YmEmDQAAgWs5BA (envelope-from ) for ; Sun, 10 Oct 2021 12:21:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id CLQHCqa+YmF1ZwAA1q6Kng (envelope-from ) for ; Sun, 10 Oct 2021 10:21:26 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E2D7F21EDB for ; Sun, 10 Oct 2021 12:21:25 +0200 (CEST) Received: from localhost ([::1]:33700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZVxN-0003cS-24 for larch@yhetil.org; Sun, 10 Oct 2021 06:21:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZVx1-0003ai-VE for guix-patches@gnu.org; Sun, 10 Oct 2021 06:21:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42963) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mZVx0-00050F-5W for guix-patches@gnu.org; Sun, 10 Oct 2021 06:21:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mZVx0-0003Ov-1Z for guix-patches@gnu.org; Sun, 10 Oct 2021 06:21:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50873] [PATCH 1/7] guix home: import: Make the user to specify a destination directory. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 10 Oct 2021 10:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50873 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50873@debbugs.gnu.org Cc: Oleg Pykhalov , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Andrew Tropin Received: via spool by 50873-submit@debbugs.gnu.org id=B50873.163386121912920 (code B ref 50873); Sun, 10 Oct 2021 10:21:01 +0000 Received: (at 50873) by debbugs.gnu.org; 10 Oct 2021 10:20:19 +0000 Received: from localhost ([127.0.0.1]:54490 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZVwJ-0003MJ-7R for submit@debbugs.gnu.org; Sun, 10 Oct 2021 06:20:19 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:39716 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZVwG-0003Lt-Vo for 50873@debbugs.gnu.org; Sun, 10 Oct 2021 06:20:17 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1633861211; bh=GjCDFBVPzoLpomEwylpSfTEdA589GFIwlMJCLptPUyo=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=VgYbwohlQkJZE7h1HrQrGwiOAsFdvYiQq/EcAV9we8BMRNHmS9o5tQVoSZ6ELA5Ds jdM9ZRHTWR7Z8+eaI1BJ2tej3iPnVgZtnKtI9RVkLCdTM7+oSKBCwwiTCdIUKMp5jU znIYvy/GFCqsHf5RJ9CedidWYw9u7sC+oT/RWkys= In-Reply-To: References: Message-Id: <9db0424f9494d3d15e534eb75773ae9bd3f33cb3.1633861021.git.public@yoctocell.xyz> Date: Sun, 10 Oct 2021 12:20:11 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633861286; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=nulK+eKsIhqy39ZbVdglfqrKTZdeBjr7Nx3G7qHkub8=; b=RJVNtSiMegIJF2AfgV7egNS3szaxEkRp6zquQoVZabrb9XqkGSfNtWoIs8ytz4RzH0wKCp Yf4tcVQvIfgvxC/a7W5AlxoiO7BqTROiGt7A0q5NZXMnaGub3j+HtnY5cDQGLo//mFAiVS NNiia6N20ivy9m5+iSN5gMJ+4EnNNS2Blnw9ueAtiEwfc0N/5FHcfq6URV88f37Qq2VlYl hMw7asRa8/SZ4689inLUJG9vhdbNvRnfR0pRRwnYYkfC+fQi7JpN2z7nbVWUcd6v3T8733 3a2ACcR8ZKnoKgyABVDC2bGF5HM9NSSIWI4kfY8BNZgT0SFtpnpZOYQZe08SzA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633861286; a=rsa-sha256; cv=none; b=oVsxtTf9dGNVg4E5NSfNWwdQirBwYnHnR/5F1/edvUyroqV4KEnWAsCLFd/8ihtGbnJ2tQ juQd3+PzrvY6pKgvT4FGCV4/DSNwms53/tz2doQRfWCDtJ5tJXR8U/Pwg54ZfUt6y8IaLJ mqXSEvatTwPFJwl1Pk2syJggeKxVqLvuTrA9VU+oQU/2qIJ0XwLjSzIdksg7ckWl2+RoqU ZZDANCOF9KUNVP5hmP0WpayEBwO6ve2lkdU1SZYmXlJNMGN0SFpymxG36zTvMwdQgsvUi/ W2HqQNKUfPTZg83GXDr6QBSYOXyD2AMAw+Zkt64DsiglJZ4VtO3MWbpy4pOrGg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=VgYbwohl; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 1.19 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=VgYbwohl; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: E2D7F21EDB X-Spam-Score: 1.19 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9ugnnTrjbsm6 Copy the appropriate the relevant configuration files to the destination directory, and call =E2=80=98local-file=E2=80=99 on them. Without this, =E2=80=98guix home import=E2=80=99 will generate a service de= claration like this (service home-bash-service-type (home-bash-configuration (bashrc (list (slurp-file-gexp (local-file "/home/yoctocell/.bashrc")))))) but when running =E2=80=98guix home reconfigure=E2=80=99, the ~/.bashrc fil= e would be moved, so when running =E2=80=98guix home reconfigure=E2=80=99 for the second time, i= t would read the ~/.bashrc which is itself a symlink to a file the store. * guix/scripts/home/import.scm (%destination-directory): New parameter. (generate-bash-module+configuration): Adjust accordingly. (modules+configurations): Copy the user=E2=80=99s configuration file to =E2=80=98%destination-directory=E2=80=99. * guix/scripts/home.scm (process-command): Adjust accordingly; create =E2=80=98%destination-directory=E2=80=99 if it doesn=E2=80=99t exist. --- guix/scripts/home.scm | 25 +++++++----- guix/scripts/home/import.scm | 75 +++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm index 55e7b436c1..520360e14a 100644 --- a/guix/scripts/home.scm +++ b/guix/scripts/home.scm @@ -40,6 +40,7 @@ (define-module (guix scripts home) #:autoload (guix scripts pull) (channel-commit-hyperlink) #:use-module (guix scripts home import) #:use-module ((guix status) #:select (with-status-verbosity)) + #:use-module ((guix build utils) #:select (mkdir-p)) #:use-module (guix gexp) #:use-module (guix monads) #:use-module (srfi srfi-1) @@ -260,15 +261,21 @@ (define-syntax-rule (with-store* store exp ...) (apply search args)) ((import) (let* ((profiles (delete-duplicates - (match (filter-map (match-lambda - (('profile . p) p) - (_ #f)) - opts) - (() (list %current-profile)) - (lst (reverse lst))))) - (manifest (concatenate-manifests - (map profile-manifest profiles)))) - (import-manifest manifest (current-output-port)))) + (match (filter-map (match-lambda + (('profile . p) p) + (_ #f)) + opts) + (() (list %current-profile)) + (lst (reverse lst))))) + (manifest (concatenate-manifests + (map profile-manifest profiles))) + (destination (match args + ((destination) destination) + (_ (leave (G_ "wrong number of arguments~%"))))= )) + (unless (file-exists? destination) + (mkdir-p destination)) + (parameterize ((%destination-directory destination)) + (import-manifest manifest (current-output-port))))) ((describe) (match (generation-number %guix-home) (0 diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm index 611f580e85..a6ab68a32c 100644 --- a/guix/scripts/home/import.scm +++ b/guix/scripts/home/import.scm @@ -27,7 +27,8 @@ (define-module (guix scripts home import) #:use-module (ice-9 pretty-print) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) - #:export (import-manifest)) + #:export (import-manifest + %destination-directory)) =20 ;;; Commentary: ;;; @@ -36,27 +37,34 @@ (define-module (guix scripts home import) ;;; ;;; Code: =20 +(define %destination-directory + (make-parameter (string-append (getenv "HOME") "/src/guix-config"))) =20 (define (generate-bash-module+configuration) - (let ((rc (string-append (getenv "HOME") "/.bashrc")) - (profile (string-append (getenv "HOME") "/.bash_profile")) - (logout (string-append (getenv "HOME") "/.bash_logout"))) - `((gnu home services bash) - (service home-bash-service-type - (home-bash-configuration - ,@(if (file-exists? rc) - `((bashrc - (list (local-file ,rc)))) - '()) - ,@(if (file-exists? profile) - `((bash-profile - (list (local-file ,profile)))) - '()) - ,@(if (file-exists? logout) - `((bash-logout - (list (local-file ,logout)))) - '())))))) + (define (destination-append path) + (string-append (%destination-directory) "/" path)) =20 + (let ((rc (destination-append ".bashrc")) + (profile (destination-append ".bash_profile")) + (logout (destination-append ".bash_logout"))) + `((gnu home-services bash) + (service home-bash-service-type + (home-bash-configuration + ,@(if (file-exists? rc) + `((bashrc + (list (slurp-file-gexp + (local-file ,rc))))) + '()) + ,@(if (file-exists? profile) + `((bash-profile + (list (slurp-file-gexp + (local-file ,profile))))) + '()) + ,@(if (file-exists? logout) + `((bash-logout + (list (slurp-file-gexp + (local-file ,logout))))) + '())))))) =20 (define %files-configurations-alist `((".bashrc" . ,generate-bash-module+configuration) @@ -64,17 +72,24 @@ (define %files-configurations-alist (".bash_logout" . ,generate-bash-module+configuration))) =20 (define (modules+configurations) - (let ((configurations (delete-duplicates - (filter-map (match-lambda - ((file . proc) - (if (file-exists? - (string-append (getenv "HOME") "/" f= ile)) - proc - #f))) - %files-configurations-alist) - (lambda (x y) - (equal? (procedure-name x) (procedure-name y)))= ))) - (map (lambda (proc) (proc)) configurations))) + (define configurations + (delete-duplicates + (filter-map (match-lambda + ((file . proc) + (let ((absolute-path (string-append (getenv "HOME") + "/" file))) + (if (file-exists? absolute-path) + (begin + (copy-file absolute-path + (string-append + (%destination-directory) "/" file)) + proc) + #f)))) + %files-configurations-alist) + (lambda (x y) + (equal? (procedure-name x) (procedure-name y))))) +=20=20 + (map (lambda (proc) (proc)) configurations)) =20 ;; Based on `manifest->code' from (guix profiles) ;; MAYBE: Upstream it? --=20 2.33.0