From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 10 06:20:19 2021 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= To: 50873@debbugs.gnu.org Subject: [PATCH 1/7] guix home: import: Make the user to specify a destination directory. 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-Spam-Score: 2.9 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Copy the appropriate the relevant configuration files to the destination directory, and call ‘local-file’ on them. Without this, ‘guix home import’ will generate a service declaration like this Content analysis details: (2.9 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: yoctocell.xyz (xyz)] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS 0.0 PDS_RDNS_DYNAMIC_FP RDNS_DYNAMIC with FP steps X-Debbugs-Envelope-To: 50873 Cc: Oleg Pykhalov , Ludovic =?utf-8?Q?Court=C3=A8s?= , Andrew Tropin X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.9 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Copy the appropriate the relevant configuration files to the destination directory, and call ‘local-file’ on them. Without this, ‘guix home import’ will generate a service declaration like this Content analysis details: (1.9 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: yoctocell.xyz (xyz)] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager 0.0 PDS_RDNS_DYNAMIC_FP RDNS_DYNAMIC with FP steps 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