diff options
| -rw-r--r-- | gnu/home/services/jupyter.scm | 31 | ||||
| -rw-r--r-- | gnu/local.mk | 2 | ||||
| -rw-r--r-- | gnu/services/jupyter.scm | 116 |
3 files changed, 149 insertions, 0 deletions
diff --git a/gnu/home/services/jupyter.scm b/gnu/home/services/jupyter.scm new file mode 100644 index 00000000000..f15fd7eb1ee --- /dev/null +++ b/gnu/home/services/jupyter.scm | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2026 Nicolas Graves <ngraves@ngraves.fr> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu home services jupyter) | ||
| 20 | #:use-module (gnu home services) | ||
| 21 | #:use-module (gnu services) | ||
| 22 | #:use-module (gnu services jupyter) | ||
| 23 | ;; For the 'home-shepherd-service-type' mapping. | ||
| 24 | #:use-module (gnu home services shepherd) | ||
| 25 | #:export (home-jupyter-service-type) | ||
| 26 | #:re-export (jupyter-configuration)) | ||
| 27 | |||
| 28 | (define home-jupyter-service-type | ||
| 29 | (service-type | ||
| 30 | (inherit (system->home-service-type jupyter-service-type)) | ||
| 31 | (default-value (for-home (jupyter-configuration))))) | ||
diff --git a/gnu/local.mk b/gnu/local.mk index 3259d9b8f93..d16c4e4364a 100644 --- a/gnu/local.mk +++ b/gnu/local.mk | |||
| @@ -119,6 +119,7 @@ GNU_SYSTEM_MODULES = \ | |||
| 119 | %D%/home/services/gnome.scm \ | 119 | %D%/home/services/gnome.scm \ |
| 120 | %D%/home/services/gnupg.scm \ | 120 | %D%/home/services/gnupg.scm \ |
| 121 | %D%/home/services/guix.scm \ | 121 | %D%/home/services/guix.scm \ |
| 122 | %D%/home/services/jupyter.scm \ | ||
| 122 | %D%/home/services/mail.scm \ | 123 | %D%/home/services/mail.scm \ |
| 123 | %D%/home/services/media.scm \ | 124 | %D%/home/services/media.scm \ |
| 124 | %D%/home/services/messaging.scm \ | 125 | %D%/home/services/messaging.scm \ |
| @@ -767,6 +768,7 @@ GNU_SYSTEM_MODULES = \ | |||
| 767 | %D%/services/getmail.scm \ | 768 | %D%/services/getmail.scm \ |
| 768 | %D%/services/guix.scm \ | 769 | %D%/services/guix.scm \ |
| 769 | %D%/services/hurd.scm \ | 770 | %D%/services/hurd.scm \ |
| 771 | %D%/services/jupyter.scm \ | ||
| 770 | %D%/services/kerberos.scm \ | 772 | %D%/services/kerberos.scm \ |
| 771 | %D%/services/ldap.scm \ | 773 | %D%/services/ldap.scm \ |
| 772 | %D%/services/lightdm.scm \ | 774 | %D%/services/lightdm.scm \ |
diff --git a/gnu/services/jupyter.scm b/gnu/services/jupyter.scm new file mode 100644 index 00000000000..6b18d20f633 --- /dev/null +++ b/gnu/services/jupyter.scm | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2026 Nicolas Graves <ngraves@ngraves.fr> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu services jupyter) | ||
| 20 | #:use-module (gnu packages guile) | ||
| 21 | #:use-module (gnu packages jupyter) | ||
| 22 | #:use-module (gnu services) | ||
| 23 | #:use-module (gnu services configuration) | ||
| 24 | #:use-module (gnu services shepherd) | ||
| 25 | #:use-module (guix gexp) | ||
| 26 | #:use-module (guix packages) | ||
| 27 | #:use-module (guix records) | ||
| 28 | #:use-module (ice-9 match) | ||
| 29 | #:export (jupyter-service-type | ||
| 30 | jupyter-configuration)) | ||
| 31 | |||
| 32 | (define list-of-file-likes? (list-of file-like?)) | ||
| 33 | |||
| 34 | (define-configuration/no-serialization jupyter-configuration | ||
| 35 | (python-jupyter-core | ||
| 36 | (file-like python-jupyter-core) | ||
| 37 | "Package providing the @command{jupyter} binary.") | ||
| 38 | (extensions | ||
| 39 | (list-of-file-likes (list)) | ||
| 40 | "List of packages providing server extensions to Jupyter.") | ||
| 41 | (kernels | ||
| 42 | (list-of-file-likes (list)) | ||
| 43 | "Kernel packages to add to the profile, e.g. for python @code{python-ipykernel}.") | ||
| 44 | (disable-check-xsrf? | ||
| 45 | (boolean #f) | ||
| 46 | "Whether to disable the XSRF check.") | ||
| 47 | (token | ||
| 48 | (string "MY_TOKEN") | ||
| 49 | "Authentication token for the Jupyter server.")) | ||
| 50 | |||
| 51 | (define (jupyter-profile-service config) | ||
| 52 | (match-record config <jupyter-configuration> | ||
| 53 | (python-jupyter-core extensions kernels) | ||
| 54 | (append (list python-jupyter-core) extensions kernels))) | ||
| 55 | |||
| 56 | (define (jupyter-server-runtime-config-getter-procedure python-jupyter-core | ||
| 57 | field) | ||
| 58 | (with-extensions (list guile-json-4) | ||
| 59 | #~(begin | ||
| 60 | (use-modules (json)) | ||
| 61 | (lambda (process . args) | ||
| 62 | (let* ((pid (process-id process)) | ||
| 63 | (port | ||
| 64 | ((@ (ice-9 popen) open-input-pipe) | ||
| 65 | (string-append #$(file-append python-jupyter-core | ||
| 66 | "/bin/jupyter") | ||
| 67 | " --runtime-dir"))) | ||
| 68 | (dir (read port)) | ||
| 69 | (file (format #f "~a/jpserver-~a.json" dir pid))) | ||
| 70 | ((@ (ice-9 popen) close-pipe) port) | ||
| 71 | (call-with-input-file file | ||
| 72 | (lambda (port) | ||
| 73 | (let ((url (assoc-ref (json->scm port) #$field))) | ||
| 74 | (format #t "~a~%" url))))))))) | ||
| 75 | |||
| 76 | (define (jupyter-shepherd-service config) | ||
| 77 | (match-record config <jupyter-configuration> | ||
| 78 | (python-jupyter-core disable-check-xsrf? token) | ||
| 79 | (list | ||
| 80 | (shepherd-service | ||
| 81 | (provision '(jupyter)) | ||
| 82 | (documentation "Run a Jupyter server.") | ||
| 83 | (start | ||
| 84 | #~(make-forkexec-constructor | ||
| 85 | (list #$(file-append python-jupyter-core "/bin/jupyter") | ||
| 86 | "server" "--no-browser" | ||
| 87 | #$(string-append "--IdentityProvider.token=" token) | ||
| 88 | #$@(if disable-check-xsrf? | ||
| 89 | #~("--ServerApp.disable_check_xsrf=True") | ||
| 90 | #~())) | ||
| 91 | #:log-file "/var/log/jupyter.log")) | ||
| 92 | (stop #~(make-kill-destructor)) | ||
| 93 | (respawn? #f) | ||
| 94 | (actions | ||
| 95 | (list | ||
| 96 | (shepherd-action | ||
| 97 | (name 'get-url) | ||
| 98 | (documentation "Print the Jupyter server URL.") | ||
| 99 | (procedure | ||
| 100 | (jupyter-server-runtime-config-getter-procedure | ||
| 101 | python-jupyter-core "url"))))))))) | ||
| 102 | |||
| 103 | (define jupyter-service-type | ||
| 104 | (service-type | ||
| 105 | (name 'jupyter) | ||
| 106 | (extensions | ||
| 107 | (list | ||
| 108 | (service-extension profile-service-type | ||
| 109 | jupyter-profile-service) | ||
| 110 | (service-extension shepherd-root-service-type | ||
| 111 | jupyter-shepherd-service))) | ||
| 112 | (default-value (jupyter-configuration)) | ||
| 113 | (description | ||
| 114 | "Run a Jupyter server. The runtime file is reliably at | ||
| 115 | @file{$(jupyter --runtime-dir)/jpserver-@var{pid}.json}. Provide the | ||
| 116 | @code{get-url} function to return a valid URL to fetch from."))) | ||
