diff mbox series

[bug#61483,1/5] DRAFT gnu: home: services: Add home-git-daemon-service-type.

Message ID 20230213165057.24518-1-janneke@gnu.org
State New
Headers show
Series Some basic Home Shepherd Services | expand

Commit Message

Janneke Nieuwenhuizen Feb. 13, 2023, 4:50 p.m. UTC
From: "Janneke Nieuwenhuizen" <janneke@gnu.org>

* gnu/home/services/shepherd-xyz.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
---
 gnu/home/services/shepherd-xyz.scm | 102 +++++++++++++++++++++++++++++
 gnu/local.mk                       |   3 +-
 2 files changed, 104 insertions(+), 1 deletion(-)
 create mode 100644 gnu/home/services/shepherd-xyz.scm

Comments

Bruno Victal Feb. 14, 2023, 1:45 p.m. UTC | #1
Hi,

Have you tried using (non-home) git-daemon-service-type as a home service?
I think it should work.


Cheers,
Bruno
Janneke Nieuwenhuizen Feb. 14, 2023, 3:17 p.m. UTC | #2
Bruno Victal writes:

> Have you tried using (non-home) git-daemon-service-type as a home service?

Yeah, I tried

--8<---------------cut here---------------start------------->8---
(use-modules (gnu services version-control))
;; [..]
,@(let ((root (string-append (getenv "HOME") "/git-daemon")))
    (if (not (file-exists? root)) '()
        `(,(service
            git-daemon-service-type
            (git-daemon-configuration
             (base-path root)
             (export-all? #t))))))
--8<---------------cut here---------------end--------------->8---

and upon guix home reconfigure I got

    guix home: error: no target of type 'account' for service 'git-daemon'

> I think it should work.

It might, and that would be nice, but I would need some more guidance as
to handle the account setup thing?

Greetings,
Janneke
diff mbox series

Patch

diff --git a/gnu/home/services/shepherd-xyz.scm b/gnu/home/services/shepherd-xyz.scm
new file mode 100644
index 0000000000..1bf857b591
--- /dev/null
+++ b/gnu/home/services/shepherd-xyz.scm
@@ -0,0 +1,102 @@ 
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2023 Janneke Nieuwenhuizen <janneke@gnu.org>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(define-module (gnu home services shepherd-xyz)
+  #:use-module (ice-9 match)
+  #:use-module (shepherd support)
+
+  #:use-module (gnu home services)
+  #:use-module (gnu home services shepherd)
+  #:use-module (gnu packages version-control)
+  #:use-module (gnu services configuration)
+  #:use-module (gnu services shepherd)
+  #:use-module (guix records)
+  #:use-module (guix gexp)
+
+  #:export (home-git-daemon-configuration
+            home-git-daemon-service-type))
+
+;;; Commentary:
+;;
+;; Home Services for the Shepherd.
+;;
+;; Example configurations.
+;;
+;; Git daemon: use $HOME/src as the base directory.
+;;
+;; (service home-git-service-type
+;;          (home-git-configuration
+;;           (root (string-append (getenv "HOME") "/src"))))
+;;
+;;; Code:
+
+;;;
+;;; Directories.
+;;;
+(define %user-data-home
+  ;; Default cache directory if shepherd is run as a normal user.
+  (string-append (or (getenv "XDG_DATA_HOME")
+                     (string-append user-homedir "/.local/share"))))
+
+(define %user-log-dir
+  ;; Default log directory if shepherd is run as a normal user.
+  (string-append (or (getenv "XDG_DATA_HOME")
+                     (string-append user-homedir "/.local/share"))
+                 "/shepherd"))
+
+
+;;;
+;;; Git daemon.
+;;;
+(define-record-type* <home-git-daemon-configuration>
+  home-git-daemon-configuration make-home-git-daemon-configuration
+  home-git-daemon-configuration?
+  (git home-git-daemon-git              ;string
+       (default #~(string-append #$git "/bin/git")))
+  (root home-git-daemon-root            ;string
+    (default (string-append %user-data-home "/git-daemon")))
+  (log-dir home-git-daemon-log-dir      ;string
+           (default %user-log-dir)))
+
+(define (home-git-daemon-services config)
+  "Return a <shepherd-service> for a git daemon with CONFIG."
+  (match config
+    (($ <home-git-daemon-configuration> git root log-dir)
+     (list (shepherd-service
+            (documentation "Run the git daemon.")
+            (provision '(git-daemon))
+            (start #~(lambda _
+                       (unless (file-exists? #$log-dir)
+                         (mkdir-p #$log-dir))
+                       (fork+exec-command
+                        (list #$git
+                              "daemon"
+                              (string-append "--base-path=" #$root)
+                              "--export-all")
+                        #:log-file (string-append #$log-dir "/git-daemon.log"))))
+            (stop #~(make-kill-destructor)))))))
+
+(define home-git-daemon-service-type
+  (service-type
+   (name 'home-git-daemon)
+   (default-value (home-git-daemon-configuration))
+   (extensions
+    (list (service-extension home-shepherd-service-type
+                             home-git-daemon-services)))
+   (description
+    "Install and configure the git-daemon as a shepherd service.")))
diff --git a/gnu/local.mk b/gnu/local.mk
index 7278c50e4f..134b81f24f 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -11,7 +11,7 @@ 
 # Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
 # Copyright © 2016, 2017, 2018, 2019 Alex Vong <alexvong1995@gmail.com>
 # Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
-# Copyright © 2016, 2017, 2018, 2019, 2020, 2021, 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+# Copyright © 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 # Copyright © 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
 # Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
 # Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
@@ -94,6 +94,7 @@  GNU_SYSTEM_MODULES =				\
   %D%/home/services/pm.scm			\
   %D%/home/services/shells.scm			\
   %D%/home/services/shepherd.scm		\
+  %D%/home/services/shepherd-xyz.scm		\
   %D%/home/services/ssh.scm			\
   %D%/home/services/mcron.scm			\
   %D%/home/services/utils.scm			\