* gnu/home-services/state.scm (state-hg): New procedure.
* gnu/home-services/version-control.scm: Export ‘serialize-hg-config’.
---
The state services probably need a refactor, I think you mentioned that
specific state services should be put into other modules, e.g. (gnu
home-services version-control) for ‘state-git’ and ‘state-hg’.
gnu/home-services/state.scm | 23 +++++++++++++++++++++++
gnu/home-services/version-control.scm | 1 +
2 files changed, 24 insertions(+)
diff --git a/gnu/home-services/state.scm b/gnu/home-services/state.scm
index 1c3b901..6c1a762 100644
--- a/gnu/home-services/state.scm
+++ b/gnu/home-services/state.scm
@@ -17,9 +17,32 @@
#:export (home-state-service-type
state-generic
state-git
+ state-hg
state-rsync))
(use-modules (gnu packages version-control))
+(define* (state-hg path remote #:key (config #f))
+ (state-generic
+ path
+ #:init-gexp
+ #~(lambda* (_ self)
+ (let* ((meta (car (action self 'metadata)))
+ (path (assoc-ref meta 'path))
+ (remote (assoc-ref meta 'remote)))
+ (format #t "Initializing ~a.\n" self)
+ (let* ((port ((@@ (guix build utils) open-pipe-with-stderr)
+ #$(file-append mercurial "/bin/hg") "clone" remote path)))
+ (waitpid WAIT_ANY)
+ (display ((@@ (ice-9 rdelim) read-delimited) "" port))
+ (close-port port))
+
+ (when '#$config
+ (call-with-output-file (string-append path "/.hg/hgrc")
+ (lambda (port) (display (string-append
+ #$@(serialize-hg-config config)) port))))))
+ #:additional-metadata `((remote . ,remote)
+ (general-sync? . #f))))
+
(define* (state-git path remote #:key (config #f))
(state-generic
path
diff --git a/gnu/home-services/version-control.scm b/gnu/home-services/version-control.scm
index 2c2aa7a..335afd1 100644
--- a/gnu/home-services/version-control.scm
+++ b/gnu/home-services/version-control.scm
@@ -21,6 +21,7 @@
home-hg-configuration
home-hg-extension
+ serialize-hg-config
home-hg-service-type))
;;; Commentary:
base-commit: 262c7fb2db7454fdf4f67bbc53ec0c0306a8fbaf
--
2.32.0
Xinglu Chen <public@yoctocell.xyz> writes:
> * gnu/home-services/state.scm (state-hg): New procedure.
> * gnu/home-services/version-control.scm: Export ‘serialize-hg-config’.
> ---
> The state services probably need a refactor, I think you mentioned that
> specific state services should be put into other modules, e.g. (gnu
> home-services version-control) for ‘state-git’ and ‘state-hg’.
Yes, it requires a refactoring, I would like to make those state-*
functions return a state record, which has a few different fields and
the home-state-service will create shepherd services from those records.
It will allow to pass these state records to other services or any other
places, where the values of fields are needed. Also, it will make it
easier to swap underlying state initialization and/or syncronization
mechanism in case in the future we decide it's necessary to do it
outside of shepherd or something else.
After refactoring we can move non-generic states to respective modules,
I still find this to be a good idea.
Applied the patch.
>
> gnu/home-services/state.scm | 23 +++++++++++++++++++++++
> gnu/home-services/version-control.scm | 1 +
> 2 files changed, 24 insertions(+)
>
> diff --git a/gnu/home-services/state.scm b/gnu/home-services/state.scm
> index 1c3b901..6c1a762 100644
> --- a/gnu/home-services/state.scm
> +++ b/gnu/home-services/state.scm
> @@ -17,9 +17,32 @@
> #:export (home-state-service-type
> state-generic
> state-git
> + state-hg
> state-rsync))
>
> (use-modules (gnu packages version-control))
> +(define* (state-hg path remote #:key (config #f))
> + (state-generic
> + path
> + #:init-gexp
> + #~(lambda* (_ self)
> + (let* ((meta (car (action self 'metadata)))
> + (path (assoc-ref meta 'path))
> + (remote (assoc-ref meta 'remote)))
> + (format #t "Initializing ~a.\n" self)
> + (let* ((port ((@@ (guix build utils) open-pipe-with-stderr)
> + #$(file-append mercurial "/bin/hg") "clone" remote path)))
> + (waitpid WAIT_ANY)
> + (display ((@@ (ice-9 rdelim) read-delimited) "" port))
> + (close-port port))
> +
> + (when '#$config
> + (call-with-output-file (string-append path "/.hg/hgrc")
> + (lambda (port) (display (string-append
> + #$@(serialize-hg-config config)) port))))))
> + #:additional-metadata `((remote . ,remote)
> + (general-sync? . #f))))
> +
> (define* (state-git path remote #:key (config #f))
> (state-generic
> path
> diff --git a/gnu/home-services/version-control.scm b/gnu/home-services/version-control.scm
> index 2c2aa7a..335afd1 100644
> --- a/gnu/home-services/version-control.scm
> +++ b/gnu/home-services/version-control.scm
> @@ -21,6 +21,7 @@
>
> home-hg-configuration
> home-hg-extension
> + serialize-hg-config
> home-hg-service-type))
>
> ;;; Commentary:
>
> base-commit: 262c7fb2db7454fdf4f67bbc53ec0c0306a8fbaf