diff options
| author | muradm <mail@muradm.net> | 2022-06-15 12:17:39 +0300 |
|---|---|---|
| committer | Lars-Dominik Braun <ldb@leibniz-psychology.org> | 2022-06-17 10:30:41 +0200 |
| commit | 530e0f02606a0e04818bdd792bb5239f7ee9e637 (patch) | |
| tree | ce4cea7ae572f568dacbcb5e7f8986e5da28c4f8 /gnu/services | |
| parent | 32ca068cb9f98698bd1c29b980ecd4ae36caf795 (diff) | |
gnu: base: Add greetd-service-type.
* gnu/services/base.scm (greetd-service-type): New variable
* gnu/services/base.scm (greetd-configuration): New data type
* gnu/services/base.scm (greetd-terminal-configuration): New data type
* gnu/services/base.scm (greetd-agreety-session): New data type
* gnu/services/base.scm (pam-limits-service-type): Should be aware of
greetd PAM service
* gnu/services/pam-mount.scm (pam-mount-pam-service): Should be aware
of greetd PAM service
Signed-off-by: Lars-Dominik Braun <ldb@leibniz-psychology.org>
Diffstat (limited to 'gnu/services')
| -rw-r--r-- | gnu/services/base.scm | 223 | ||||
| -rw-r--r-- | gnu/services/pam-mount.scm | 2 |
2 files changed, 223 insertions, 2 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index ebbe4e128dd..d58afb27e3a 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | ;;; Copyright © 2021 qblade <qblade@protonmail.com> | 16 | ;;; Copyright © 2021 qblade <qblade@protonmail.com> |
| 17 | ;;; Copyright © 2021 Hui Lu <luhuins@163.com> | 17 | ;;; Copyright © 2021 Hui Lu <luhuins@163.com> |
| 18 | ;;; Copyright © 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> | 18 | ;;; Copyright © 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
| 19 | ;;; Copyright © 2021 muradm <mail@muradm.net> | ||
| 19 | ;;; Copyright © 2022 Guillaume Le Vaillant <glv@posteo.net> | 20 | ;;; Copyright © 2022 Guillaume Le Vaillant <glv@posteo.net> |
| 20 | ;;; Copyright © 2022 Justin Veilleux <terramorpha@cock.li> | 21 | ;;; Copyright © 2022 Justin Veilleux <terramorpha@cock.li> |
| 21 | ;;; | 22 | ;;; |
| @@ -226,6 +227,11 @@ | |||
| 226 | pam-limits-service-type | 227 | pam-limits-service-type |
| 227 | pam-limits-service | 228 | pam-limits-service |
| 228 | 229 | ||
| 230 | greetd-service-type | ||
| 231 | greetd-configuration | ||
| 232 | greetd-terminal-configuration | ||
| 233 | greetd-agreety-session | ||
| 234 | |||
| 229 | %base-services)) | 235 | %base-services)) |
| 230 | 236 | ||
| 231 | ;;; Commentary: | 237 | ;;; Commentary: |
| @@ -1446,7 +1452,7 @@ information on the configuration file syntax." | |||
| 1446 | (module "pam_limits.so") | 1452 | (module "pam_limits.so") |
| 1447 | (arguments '("conf=/etc/security/limits.conf"))))) | 1453 | (arguments '("conf=/etc/security/limits.conf"))))) |
| 1448 | (if (member (pam-service-name pam) | 1454 | (if (member (pam-service-name pam) |
| 1449 | '("login" "su" "slim" "gdm-password" "sddm" | 1455 | '("login" "greetd" "su" "slim" "gdm-password" "sddm" |
| 1450 | "sudo" "sshd")) | 1456 | "sudo" "sshd")) |
| 1451 | (pam-service | 1457 | (pam-service |
| 1452 | (inherit pam) | 1458 | (inherit pam) |
| @@ -2807,6 +2813,221 @@ to handle." | |||
| 2807 | (name-servers '("10.0.2.3")))) | 2813 | (name-servers '("10.0.2.3")))) |
| 2808 | 2814 | ||
| 2809 | 2815 | ||
| 2816 | ;;; | ||
| 2817 | ;;; greetd-service-type -- minimal and flexible login manager daemon | ||
| 2818 | ;;; | ||
| 2819 | |||
| 2820 | (define-record-type* <greetd-agreety-session> | ||
| 2821 | greetd-agreety-session make-greetd-agreety-session | ||
| 2822 | greetd-agreety-session? | ||
| 2823 | (agreety greetd-agreety (default greetd)) | ||
| 2824 | (command greetd-agreety-command (default (file-append bash "/bin/bash"))) | ||
| 2825 | (command-args greetd-agreety-command-args (default '("-l"))) | ||
| 2826 | (extra-env greetd-agreety-extra-env (default '())) | ||
| 2827 | (xdg-env? greetd-agreety-xdg-env? (default #t))) | ||
| 2828 | |||
| 2829 | (define greetd-agreety-tty-session-command | ||
| 2830 | (match-lambda | ||
| 2831 | (($ <greetd-agreety-session> _ command args extra-env) | ||
| 2832 | (program-file | ||
| 2833 | "agreety-tty-session-command" | ||
| 2834 | #~(begin | ||
| 2835 | (use-modules (ice-9 match)) | ||
| 2836 | (for-each (match-lambda ((var . val) (setenv var val))) | ||
| 2837 | (quote (#$@extra-env))) | ||
| 2838 | (apply execl #$command #$command (list #$@args))))))) | ||
| 2839 | |||
| 2840 | (define greetd-agreety-tty-xdg-session-command | ||
| 2841 | (match-lambda | ||
| 2842 | (($ <greetd-agreety-session> _ command args extra-env) | ||
| 2843 | (program-file | ||
| 2844 | "agreety-tty-xdg-session-command" | ||
| 2845 | #~(begin | ||
| 2846 | (use-modules (ice-9 match)) | ||
| 2847 | (let* | ||
| 2848 | ((username (getenv "USER")) | ||
| 2849 | (useruid (passwd:uid (getpwuid username))) | ||
| 2850 | (useruid (number->string useruid))) | ||
| 2851 | (setenv "XDG_SESSION_TYPE" "tty") | ||
| 2852 | (setenv "XDG_RUNTIME_DIR" (string-append "/run/user/" useruid))) | ||
| 2853 | (for-each (match-lambda ((var . val) (setenv var val))) | ||
| 2854 | (quote (#$@extra-env))) | ||
| 2855 | (apply execl #$command #$command (list #$@args))))))) | ||
| 2856 | |||
| 2857 | (define (make-greetd-agreety-session-command config command) | ||
| 2858 | (let ((agreety (file-append (greetd-agreety config) "/bin/agreety"))) | ||
| 2859 | (program-file | ||
| 2860 | "agreety-command" | ||
| 2861 | #~(execl #$agreety #$agreety "-c" #$command)))) | ||
| 2862 | |||
| 2863 | (define (make-greetd-default-session-command config-or-command) | ||
| 2864 | (cond ((greetd-agreety-session? config-or-command) | ||
| 2865 | (cond ((greetd-agreety-xdg-env? config-or-command) | ||
| 2866 | (make-greetd-agreety-session-command | ||
| 2867 | config-or-command | ||
| 2868 | (greetd-agreety-tty-xdg-session-command config-or-command))) | ||
| 2869 | (#t | ||
| 2870 | (make-greetd-agreety-session-command | ||
| 2871 | config-or-command | ||
| 2872 | (greetd-agreety-tty-session-command config-or-command))))) | ||
| 2873 | (#t config-or-command))) | ||
| 2874 | |||
| 2875 | (define-record-type* <greetd-terminal-configuration> | ||
| 2876 | greetd-terminal-configuration make-greetd-terminal-configuration | ||
| 2877 | greetd-terminal-configuration? | ||
| 2878 | (greetd greetd-package (default greetd)) | ||
| 2879 | (config-file-name greetd-config-file-name (thunked) | ||
| 2880 | (default (default-config-file-name this-record))) | ||
| 2881 | (log-file-name greetd-log-file-name (thunked) | ||
| 2882 | (default (default-log-file-name this-record))) | ||
| 2883 | (terminal-vt greetd-terminal-vt (default "7")) | ||
| 2884 | (terminal-switch greetd-terminal-switch (default #f)) | ||
| 2885 | (default-session-user greetd-default-session-user (default "greeter")) | ||
| 2886 | (default-session-command greetd-default-session-command | ||
| 2887 | (default (greetd-agreety-session)) | ||
| 2888 | (sanitize make-greetd-default-session-command))) | ||
| 2889 | |||
| 2890 | (define (default-config-file-name config) | ||
| 2891 | (string-join (list "config-" (greetd-terminal-vt config) ".toml") "")) | ||
| 2892 | |||
| 2893 | (define (default-log-file-name config) | ||
| 2894 | (string-join (list "/var/log/greetd-" (greetd-terminal-vt config) ".log") "")) | ||
| 2895 | |||
| 2896 | (define (make-greetd-terminal-configuration-file config) | ||
| 2897 | (let* | ||
| 2898 | ((config-file-name (greetd-config-file-name config)) | ||
| 2899 | (terminal-vt (greetd-terminal-vt config)) | ||
| 2900 | (terminal-switch (greetd-terminal-switch config)) | ||
| 2901 | (default-session-user (greetd-default-session-user config)) | ||
| 2902 | (default-session-command (greetd-default-session-command config))) | ||
| 2903 | (mixed-text-file | ||
| 2904 | config-file-name | ||
| 2905 | "[terminal]\n" | ||
| 2906 | "vt = " terminal-vt "\n" | ||
| 2907 | "switch = " (if terminal-switch "true" "false") "\n" | ||
| 2908 | "[default_session]\n" | ||
| 2909 | "user = " default-session-user "\n" | ||
| 2910 | "command = " default-session-command "\n"))) | ||
| 2911 | |||
| 2912 | (define %greetd-accounts | ||
| 2913 | (list (user-account | ||
| 2914 | (name "greeter") | ||
| 2915 | (group "wheel") | ||
| 2916 | (supplementary-groups '("users" "tty" "input" "video" "audio")) | ||
| 2917 | (system? #t)))) | ||
| 2918 | |||
| 2919 | (define %greetd-file-systems | ||
| 2920 | (list (file-system | ||
| 2921 | (device "none") | ||
| 2922 | (mount-point "/run/greetd/pam_mount") | ||
| 2923 | (type "tmpfs") | ||
| 2924 | (check? #f) | ||
| 2925 | (flags '(no-suid no-dev no-exec)) | ||
| 2926 | (options "mode=0755") | ||
| 2927 | (create-mount-point? #t)))) | ||
| 2928 | |||
| 2929 | (define %greetd-pam-mount-rules | ||
| 2930 | `((debug (@ (enable "0"))) | ||
| 2931 | (volume (@ (sgrp "users") | ||
| 2932 | (fstype "tmpfs") | ||
| 2933 | (mountpoint "/run/user/%(USERUID)") | ||
| 2934 | (options "noexec,nosuid,nodev,size=1g,mode=0700,uid=%(USERUID),gid=%(USERGID)"))) | ||
| 2935 | (logout (@ (wait "0") | ||
| 2936 | (hup "0") | ||
| 2937 | (term "yes") | ||
| 2938 | (kill "no"))) | ||
| 2939 | (mkmountpoint (@ (enable "1") (remove "true"))))) | ||
| 2940 | |||
| 2941 | (define-record-type* <greetd-configuration> | ||
| 2942 | greetd-configuration make-greetd-configuration | ||
| 2943 | greetd-configuration? | ||
| 2944 | (motd greetd-motd (default %default-motd)) | ||
| 2945 | (allow-empty-passwords? greetd-allow-empty-passwords? (default #t)) | ||
| 2946 | (terminals greetd-terminals (default '()))) | ||
| 2947 | |||
| 2948 | (define (make-greetd-pam-mount-conf-file config) | ||
| 2949 | (computed-file | ||
| 2950 | "greetd_pam_mount.conf.xml" | ||
| 2951 | #~(begin | ||
| 2952 | (use-modules (sxml simple)) | ||
| 2953 | (call-with-output-file #$output | ||
| 2954 | (lambda (port) | ||
| 2955 | (sxml->xml | ||
| 2956 | '(*TOP* | ||
| 2957 | (*PI* xml "version='1.0' encoding='utf-8'") | ||
| 2958 | (pam_mount | ||
| 2959 | #$@%greetd-pam-mount-rules | ||
| 2960 | (pmvarrun | ||
| 2961 | #$(file-append greetd-pam-mount | ||
| 2962 | "/sbin/pmvarrun -u '%(USER)' -o '%(OPERATION)'")))) | ||
| 2963 | port)))))) | ||
| 2964 | |||
| 2965 | (define (greetd-etc-service config) | ||
| 2966 | `(("security/greetd_pam_mount.conf.xml" | ||
| 2967 | ,(make-greetd-pam-mount-conf-file config)))) | ||
| 2968 | |||
| 2969 | (define (greetd-pam-service config) | ||
| 2970 | (define optional-pam-mount | ||
| 2971 | (pam-entry | ||
| 2972 | (control "optional") | ||
| 2973 | (module #~(string-append #$greetd-pam-mount "/lib/security/pam_mount.so")) | ||
| 2974 | (arguments '("disable_interactive")))) | ||
| 2975 | |||
| 2976 | (list | ||
| 2977 | (unix-pam-service "greetd" | ||
| 2978 | #:login-uid? #t | ||
| 2979 | #:allow-empty-passwords? | ||
| 2980 | (greetd-allow-empty-passwords? config) | ||
| 2981 | #:motd | ||
| 2982 | (greetd-motd config)) | ||
| 2983 | (lambda (pam) | ||
| 2984 | (if (member (pam-service-name pam) | ||
| 2985 | '("login" "greetd" "su" "slim" "gdm-password")) | ||
| 2986 | (pam-service | ||
| 2987 | (inherit pam) | ||
| 2988 | (auth (append (pam-service-auth pam) | ||
| 2989 | (list optional-pam-mount))) | ||
| 2990 | (session (append (pam-service-session pam) | ||
| 2991 | (list optional-pam-mount)))) | ||
| 2992 | pam)))) | ||
| 2993 | |||
| 2994 | (define (greetd-shepherd-services config) | ||
| 2995 | (map | ||
| 2996 | (lambda (tc) | ||
| 2997 | (let* | ||
| 2998 | ((greetd-bin (file-append (greetd-package tc) "/sbin/greetd")) | ||
| 2999 | (greetd-conf (make-greetd-terminal-configuration-file tc)) | ||
| 3000 | (greetd-log (greetd-log-file-name tc)) | ||
| 3001 | (greetd-vt (greetd-terminal-vt tc))) | ||
| 3002 | (shepherd-service | ||
| 3003 | (documentation "Minimal and flexible login manager daemon") | ||
| 3004 | (requirement '(user-processes host-name udev virtual-terminal)) | ||
| 3005 | (provision (list (symbol-append | ||
| 3006 | 'term-tty | ||
| 3007 | (string->symbol (greetd-terminal-vt tc))))) | ||
| 3008 | (start #~(make-forkexec-constructor | ||
| 3009 | (list #$greetd-bin "-c" #$greetd-conf) | ||
| 3010 | #:log-file #$greetd-log)) | ||
| 3011 | (stop #~(make-kill-destructor))))) | ||
| 3012 | (greetd-terminals config))) | ||
| 3013 | |||
| 3014 | (define greetd-service-type | ||
| 3015 | (service-type | ||
| 3016 | (name 'greetd) | ||
| 3017 | (description "Provides necessary infrastructure for logging into the | ||
| 3018 | system including @code{greetd} PAM service, @code{pam-mount} module to | ||
| 3019 | mount/unmount /run/user/<uid> directory for user and @code{greetd} | ||
| 3020 | login manager daemon.") | ||
| 3021 | (extensions | ||
| 3022 | (list | ||
| 3023 | (service-extension account-service-type (const %greetd-accounts)) | ||
| 3024 | (service-extension file-system-service-type (const %greetd-file-systems)) | ||
| 3025 | (service-extension etc-service-type greetd-etc-service) | ||
| 3026 | (service-extension pam-root-service-type greetd-pam-service) | ||
| 3027 | (service-extension shepherd-root-service-type greetd-shepherd-services))) | ||
| 3028 | (default-value (greetd-configuration)))) | ||
| 3029 | |||
| 3030 | |||
| 2810 | (define %base-services | 3031 | (define %base-services |
| 2811 | ;; Convenience variable holding the basic services. | 3032 | ;; Convenience variable holding the basic services. |
| 2812 | (list (service login-service-type) | 3033 | (list (service login-service-type) |
diff --git a/gnu/services/pam-mount.scm b/gnu/services/pam-mount.scm index 33649b0f7c6..e60781d05bb 100644 --- a/gnu/services/pam-mount.scm +++ b/gnu/services/pam-mount.scm | |||
| @@ -90,7 +90,7 @@ | |||
| 90 | (module #~(string-append #$pam-mount "/lib/security/pam_mount.so")))) | 90 | (module #~(string-append #$pam-mount "/lib/security/pam_mount.so")))) |
| 91 | (list (lambda (pam) | 91 | (list (lambda (pam) |
| 92 | (if (member (pam-service-name pam) | 92 | (if (member (pam-service-name pam) |
| 93 | '("login" "su" "slim" "gdm-password" "sddm")) | 93 | '("login" "greetd" "su" "slim" "gdm-password" "sddm")) |
| 94 | (pam-service | 94 | (pam-service |
| 95 | (inherit pam) | 95 | (inherit pam) |
| 96 | (auth (append (pam-service-auth pam) | 96 | (auth (append (pam-service-auth pam) |
