services: Add network-online-service-type and home-network-online-service-type.

* modules/rosenthal/services/networking.scm (%network-online-shepherd): New
procedure.
(network-online-service-type, home-network-online-service-type): New variables.
* modules/rosenthal/services/desktop.scm (%rosenthal-desktop-services/base)
(%rosenthal-desktop-home-services): Add them.
This commit is contained in:
Hilton Chain 2026-02-19 21:27:34 +08:00
parent 9cb7193827
commit 0dbc71e278
No known key found for this signature in database
GPG Key ID: ACC66D09CA528292
2 changed files with 65 additions and 2 deletions

View File

@ -25,6 +25,7 @@
#:use-module (gnu services sddm)
#:use-module (gnu services xorg)
#:use-module (rosenthal services base)
#:use-module (rosenthal services networking)
;; Guix Home - services
#:use-module (gnu home)
#:use-module (gnu home services)
@ -626,7 +627,9 @@ gtk-key-theme-name = ~a~%"
gdm-service-type
sddm-service-type))
(cons* (service bluetooth-service-type
(cons* (service network-online-service-type)
(service bluetooth-service-type
(bluetooth-configuration
(auto-enable? #t)))
@ -699,6 +702,8 @@ gtk-key-theme-name = ~a~%"
(auto-start? #f)
(daemonize? #f)))
(service home-network-online-service-type)
;; NOTE: The environment variable set by home-dbus-service-type will
;; prevent GNOME from starting when using above Shepherd configuration.
;; Replace home-dbus-service-type, expecting the session bus will be

View File

@ -5,6 +5,7 @@
;; Guile builtins
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
;; Utilities
#:use-module (guix gexp)
#:use-module (guix records)
@ -17,16 +18,73 @@
#:use-module (gnu services configuration)
#:use-module (gnu services dbus)
#:use-module (gnu services shepherd)
;; Guix Home - services
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
;; Guix packages
#:use-module (gnu packages admin)
#:use-module (gnu packages base)
#:use-module (gnu packages bash)
#:use-module (gnu packages linux)
#:use-module (gnu packages networking)
#:use-module (rosenthal packages networking)
#:export (sing-box-service-type
#:export (network-online-service-type
home-network-online-service-type
sing-box-service-type
sing-box-configuration
tailscale-configuration
tailscale-service-type))
;;;
;;; network-online (https://codeberg.org/guix/guix/issues/838#issue-1886438)
;;;
(define* (%network-online-shepherd _ #:key home-service?)
(list (shepherd-service
(requirement (if home-service? '() '(networking)))
(provision '(network-online))
(documentation "Wait for the network to come up.")
(one-shot? #t)
(start
#~(lambda _
(let ((timeout #$(file-append coreutils-minimal "/bin/timeout"))
(sh #$(file-append bash-minimal "/bin/sh"))
(ping (if #$home-service?
"ping"
#$(file-append inetutils "/bin/ping"))))
(zero?
(system* timeout "60" sh "-c"
(format #f "\
until ~a -qc1 -W1 example.org
do
sleep 1
done"
ping)))))))))
(define network-online-service-type
(service-type
(name 'network-online)
(extensions
(list (service-extension shepherd-root-service-type
%network-online-shepherd)))
(default-value #f)
(description "Wait for the network to come up.")))
(define home-network-online-service-type
(service-type
(inherit network-online-service-type)
(name 'home-network-online)
(extensions
(list (service-extension home-shepherd-service-type
(cut %network-online-shepherd <> #:home-service? #t))))))
(define-service-type-mapping
network-online-service-type => home-network-online-service-type)
;;;
;;; sing-box
;;;