~ruther/guix-config

f690ea8c14f85667881115e139da317da5e4e174 — Rutherther 9 days ago 462b85a
feat: auto-login prompt choosing between ruther and fbw on tty1
2 files changed, 53 insertions(+), 2 deletions(-)

M config.scm
A modules/ruther/services/auto-login.scm
M config.scm => config.scm +4 -2
@@ 25,6 25,7 @@
 (ruther services bind)
 (ruther services nix-gl)
 (ruther services nix)
 (ruther services auto-login)
 (ruther services netbird)
 (ruther packages netbird)
 (ruther bootloader grub)


@@ 394,8 395,9 @@
               (mingetty-service-type config => (if (string=? (mingetty-configuration-tty config) "tty1")
                                                    (mingetty-configuration
                                                     (inherit config)
                                                     (auto-login "ruther")
                                                     (login-pause? #t))
                                                     (auto-login "auto")
                                                     (login-program (make-auto-login-program #:users '("ruther" "fbw")))
                                                     (login-pause? #f))
                                                    config))
               (elogind-service-type config => (elogind-configuration
                                                (handle-lid-switch-external-power 'ignore)))

A modules/ruther/services/auto-login.scm => modules/ruther/services/auto-login.scm +49 -0
@@ 0,0 1,49 @@
(define-module (ruther services auto-login)
  #:use-module (guix gexp)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages base)
  #:export (make-auto-login-program))

(define* (make-auto-login-program #:key (users '()))
  (program-file
   "auto-login"
   #~(begin
       (define users (list #$@users))
       (define marker "/tmp/.auto-login-done")
       (define stty-bin #$(file-append coreutils "/bin/stty"))

       (define (show-menu!)
         (display "\nAuto-login — choose account:\n")
         (let loop ((us users) (i 0))
           (when (pair? us)
             (format #t "  ~a) ~a\n" (integer->char (+ i (char->integer #\a))) (car us))
             (loop (cdr us) (+ i 1))))
         (display "> "))

       (define (read-key)
         (dynamic-wind
           (lambda () (system* stty-bin "-echo" "cbreak"))
           (lambda () (read-char))
           (lambda () (system* stty-bin "echo" "-cbreak"))))

       (define (read-choice)
         (show-menu!)
         (let* ((ch  (read-key))
                (idx (- (char->integer ch) (char->integer #\a))))
           (newline)
           (if (and (>= idx 0) (< idx (length users)))
               (list-ref users idx)
               (begin
                 (display "Invalid choice, try again.\n")
                 (read-choice)))))

       (let ((login-bin #$(file-append shadow "/bin/login"))
             (args       (filter (lambda (a) (not (or (string=? a "-f")
                                                      (string=? a "auto"))))
                                (cdr (command-line)))))  ; strip -f and dummy username injected by mingetty
         (if (file-exists? marker)
             (apply execlp login-bin login-bin args)
             (let ((user (read-choice)))
               (call-with-output-file marker
                 (lambda (p) (display (getpid) p)))
               (apply execlp login-bin login-bin "-f" user args)))))))