From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +FYnG5dSU2FtXgEAgWs5BA (envelope-from ) for ; Tue, 28 Sep 2021 19:36:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QFfAFpdSU2HAbAAAbx9fmQ (envelope-from ) for ; Tue, 28 Sep 2021 17:36:23 +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 D7C624F6 for ; Tue, 28 Sep 2021 19:36:22 +0200 (CEST) Received: from localhost ([::1]:43920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVH1i-00049s-2V for larch@yhetil.org; Tue, 28 Sep 2021 13:36:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVH1P-00049I-85 for guix-patches@gnu.org; Tue, 28 Sep 2021 13:36:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35379) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVH1O-0005rt-JK; Tue, 28 Sep 2021 13:36:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mVH1O-0001Cs-FE; Tue, 28 Sep 2021 13:36:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50873] [PATCH 1/5] guix home: import: Make the user to specify a destination directory. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, andrew@trop.in, guix-patches@gnu.org Resent-Date: Tue, 28 Sep 2021 17:36:02 +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: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Andrew Tropin X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Andrew Tropin Received: via spool by 50873-submit@debbugs.gnu.org id=B50873.16328505444601 (code B ref 50873); Tue, 28 Sep 2021 17:36:02 +0000 Received: (at 50873) by debbugs.gnu.org; 28 Sep 2021 17:35:44 +0000 Received: from localhost ([127.0.0.1]:46920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVH16-0001C8-55 for submit@debbugs.gnu.org; Tue, 28 Sep 2021 13:35:44 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:33258 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVH14-0001Bs-3S for 50873@debbugs.gnu.org; Tue, 28 Sep 2021 13:35:42 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1632850536; bh=8204i1p8k/yCcQOFyl3weMDTCmOJgLPRH+CH29SV5KQ=; h=From:To:Subject:In-Reply-To:References:Date; b=OCHgu16TLyGwFG+Kz75jJVa6BrBoqz6DDjo9xJq9ATAhFzv84z23luGe2UA1Uskfe AYDaMgxftsW7PPhwb/UoPGOCqKj7P89zQ7RrvYVhBSPl15Stb7zHZcyQpGCmszBd+O Bpi6V7P9o34aBpAvnwR6sN3OmcNPuppYo5IJEztc= In-Reply-To: References: Message-Id: <649c8f3218460dea0ec6cca46064150224374f89.1632849969.git.public@yoctocell.xyz> Date: Tue, 28 Sep 2021 19:35:35 +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=1632850583; 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=gApnVtJxeDGl6QKZ3H/Jcv+hJDTN36J2fEkuxsfR574=; b=HRrA8+Y4ToE3xUH74Ic6mwyshgjC/eEAvINNgj/oJDkSvFAfYhmWFUNJC1VXradW2GyQDD gUlcGwZUmWpxn49Rrx7C9TXVEB2g9ROQtCh3qWUtKf0zd/wSQ+ocWMBJeHrLCMZMH0AnVj AlVPlBEwqUCdq4twzOjixLDFgrbZQLD4VABQqCtR2B5sUbDxbCTo3wvYQnLNOIzAq100kb 8PyR4NK4tJ1IAiG/zhrxEDvVkosE28MSx2y6AYQLyyCailfuNbMPKvwRZwBUfvYhiEMRIm mgNMNkTiTacw1xthwd5HOGeU+F8GRj1zDPQVc5YTMDNtbWHeoqdHTXQ7nGrR1g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1632850583; a=rsa-sha256; cv=none; b=Z4nzqY0ySpzgPaUFfVTZztht0dfawiRsG2Hespjyu6kYbe3QA/Zuc80ZZjcoT+VTRJ6L70 L6S5aFa1jgMZdfDXNdvFCib2XI7/DSbMOasRKaJLuLyPMai69l9jPQmr8wQaAtce1KgY5G dySQFbviGBaQkU48nzKuVZiInDfGO1IZSMXLV2h619cle5wwvgqkqKlyvVy2fiknmzHd2t WUGHtLgwE4gGmVT0rgDboNoKgu+C5oEDA2Kx29ulKeGAmuc3yzbOGPXZToT92jJWMM8N4a +5jbbRwpqdVxVdBwtClB6qtdrBruGbbWNju3Lk+xZxd97ZPcthLeyWfgnqX0tA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=OCHgu16T; 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: -0.70 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=OCHgu16T; 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: D7C624F6 X-Spam-Score: -0.70 X-Migadu-Scanner: scn1.migadu.com X-TUID: gAiVSHFCjHxp 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, 60 insertions(+), 40 deletions(-) diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm index 75df6d707d..0f638b643e 100644 --- a/guix/scripts/home.scm +++ b/guix/scripts/home.scm @@ -38,6 +38,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) @@ -248,15 +249,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 79fb23a2fd..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,29 +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"))) + (define (destination-append path) + (string-append (%destination-directory) "/" path)) + + (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))))) - '())))))) - + (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) @@ -66,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