2023-12-02 17:19:54 -07:00
|
|
|
(define-module (metznet system base-system)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (guix gexp)
|
|
|
|
|
|
|
|
#:use-module (gnu bootloader)
|
|
|
|
#:use-module (gnu bootloader grub)
|
|
|
|
#:use-module (gnu system accounts)
|
|
|
|
#:use-module (gnu system shadow)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (gnu system setuid)
|
2023-11-30 13:52:13 -07:00
|
|
|
#:use-module (gnu services configuration)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu system file-systems)
|
|
|
|
#:use-module (gnu system)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu system nss)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu services kerberos)
|
|
|
|
#:use-module (gnu services sssd)
|
|
|
|
#:use-module (gnu services base)
|
2023-11-27 18:08:03 -07:00
|
|
|
#:use-module (gnu services)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu services desktop)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu services networking)
|
|
|
|
#:use-module (gnu services ssh)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu services vpn)
|
|
|
|
#:use-module (gnu system pam)
|
|
|
|
#:use-module (gnu services dbus)
|
|
|
|
#:use-module (gnu system keyboard)
|
|
|
|
#:use-module (gnu packages admin)
|
2023-11-30 13:52:13 -07:00
|
|
|
|
|
|
|
#:use-module (gnu packages slapd)
|
|
|
|
#:use-module (gnu packages linux)
|
|
|
|
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu packages shells)
|
|
|
|
#:use-module (gnu packages gnome)
|
2023-11-26 14:58:54 -07:00
|
|
|
#:use-module (gnu packages ssh)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu packages dns)
|
|
|
|
#:use-module (gnu packages version-control)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (gnu packages vim)
|
|
|
|
#:use-module (gnu packages certs)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu packages kerberos)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu packages vpn)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu packages wm)
|
|
|
|
#:use-module (gnu packages suckless)
|
|
|
|
#:use-module (gnu packages terminals)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:use-module (gnu packages gnuzilla)
|
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
#:export (%metznet-base-user-accounts)
|
|
|
|
#:export (%metznet-base-groups)
|
2023-11-29 17:52:49 -07:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
#:export (%metznet-desktop-packages)
|
2023-11-29 17:52:49 -07:00
|
|
|
#:export (%metznet-base-packages)
|
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
#:export (%kvm-udev-rule)
|
|
|
|
#:export (%usb-udev-rule)
|
|
|
|
#:export (%tun-udev-rule)
|
2023-11-29 17:52:49 -07:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
#:export (%metznet-desktop-services)
|
|
|
|
#:export (%metznet-server-services)
|
2023-11-29 17:52:49 -07:00
|
|
|
|
2023-12-02 11:12:38 -07:00
|
|
|
#:export (metznet-service-type)
|
|
|
|
#:export (metznet-system-configuration)
|
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
#:export (%metznet-base-server-system)
|
|
|
|
#:export (%metznet-base-desktop-system))
|
|
|
|
|
2023-11-29 17:52:49 -07:00
|
|
|
(define %domain-realm
|
|
|
|
"METZNET.CA")
|
|
|
|
|
|
|
|
(define %domain-name
|
|
|
|
"metznet.ca")
|
|
|
|
|
|
|
|
(define %domain-kadmin
|
|
|
|
(string-append "kerberos." %domain-name))
|
|
|
|
|
|
|
|
(define %domain-kdc
|
|
|
|
(string-append "kerberos." %domain-name))
|
|
|
|
|
|
|
|
(define %metznet-base-user-accounts
|
|
|
|
(append (list (user-account
|
|
|
|
(name "root")
|
|
|
|
(group "root")
|
|
|
|
(uid 0)
|
2023-11-30 18:26:00 -07:00
|
|
|
(password (crypt (or (getenv "GUIX_ROOT_PW") "root")
|
|
|
|
"$6$salt"))
|
2023-11-29 17:52:49 -07:00
|
|
|
(shell (file-append zsh "/bin/zsh")))) %base-user-accounts))
|
|
|
|
|
|
|
|
(define %metznet-base-groups
|
|
|
|
(append (list (user-group
|
|
|
|
(system? #t)
|
|
|
|
(name "realtime"))
|
|
|
|
(user-group
|
|
|
|
(system? #t)
|
|
|
|
(name "usb"))) %base-groups))
|
|
|
|
|
|
|
|
(define %metznet-base-packages
|
|
|
|
(append (list openssh
|
2023-11-30 13:52:13 -07:00
|
|
|
|
|
|
|
openldap-slapd
|
|
|
|
strace
|
|
|
|
|
2023-11-29 17:52:49 -07:00
|
|
|
git
|
|
|
|
neovim
|
|
|
|
zsh
|
|
|
|
le-certs
|
|
|
|
nss-certs
|
|
|
|
mit-krb5) %base-packages))
|
|
|
|
|
|
|
|
(define %metznet-desktop-packages
|
|
|
|
(append (list i3-wm i3status dmenu kitty icecat) %metznet-base-packages))
|
|
|
|
|
|
|
|
(define %desktop-setuid-programs
|
|
|
|
(append (list (setuid-program
|
|
|
|
(program #~(string-append #$openvpn "/sbin/openvpn")))
|
|
|
|
(setuid-program
|
|
|
|
(program #~(string-append #$openresolv "/sbin/resolvconf"))))
|
|
|
|
%setuid-programs))
|
|
|
|
|
|
|
|
(define %metznet-krb5-config
|
|
|
|
(krb5-configuration (default-realm %domain-realm)
|
|
|
|
(allow-weak-crypto? #t)
|
|
|
|
(rdns? #f)
|
|
|
|
(realms (list (krb5-realm (name %domain-realm)
|
|
|
|
(admin-server %domain-kadmin)
|
|
|
|
(kdc %domain-kdc))))))
|
|
|
|
|
|
|
|
(define %default-keyboard-layout
|
|
|
|
(keyboard-layout "us"))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %kvm-udev-rule
|
2023-11-29 17:52:49 -07:00
|
|
|
(udev-rule "65-kvm.rules"
|
|
|
|
"KERNEL==\"KVM\", GROUP=\"libvirt\", MODE=\"0660\""))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %usb-udev-rule
|
2023-11-29 17:52:49 -07:00
|
|
|
(udev-rule "51-usb.rules"
|
|
|
|
(string-append "SUBSYSTEM==\"usb\", GROUP=\"usb\"\n"
|
|
|
|
"SUBSYSTEM==\"usbmisc\", GROUP=\"usb\"")))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
|
|
|
(define %tun-udev-rule
|
2023-11-29 17:52:49 -07:00
|
|
|
(udev-rule "90-tun.rules"
|
|
|
|
"KERNEL==\"tun\", GROUP=\"netdev\", MODE=\"0660\", OPTIONS+=\"static_node=net/tun\""))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
|
|
|
(define %backlight-udev-rule
|
2023-11-29 17:52:49 -07:00
|
|
|
(udev-rule "55-backlight.rules"
|
|
|
|
"RUN+=\"/bin/chgrp video /sys/class/backlight/intel_backlight/brightness\""))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-name-service-switch
|
2023-11-27 18:08:03 -07:00
|
|
|
(let ((services (list (name-service (name "sss"))
|
2023-11-24 11:36:43 -07:00
|
|
|
(name-service (name "files")))))
|
2023-11-29 17:52:49 -07:00
|
|
|
(name-service-switch (password services)
|
|
|
|
(shadow services)
|
|
|
|
(group services))))
|
2023-11-22 12:26:17 -07:00
|
|
|
|
2023-11-30 18:26:00 -07:00
|
|
|
(define list-of-strings?
|
|
|
|
(list-of string?))
|
2023-11-30 13:52:13 -07:00
|
|
|
|
2023-12-01 01:27:39 -07:00
|
|
|
(define-maybe/no-serialization string)
|
|
|
|
|
|
|
|
(define (file-like-pair? val)
|
|
|
|
(let ((name (car val))
|
|
|
|
(file (cdr val)))
|
2023-12-01 17:17:15 -07:00
|
|
|
(and (string? name)
|
|
|
|
(file-like? file))))
|
2023-12-01 01:27:39 -07:00
|
|
|
|
2023-12-01 17:17:15 -07:00
|
|
|
(define alist-of-file-like?
|
|
|
|
(list-of file-like-pair?))
|
2023-12-01 01:27:39 -07:00
|
|
|
|
2023-12-02 11:12:38 -07:00
|
|
|
(define-maybe file-like)
|
|
|
|
|
2023-11-30 18:26:00 -07:00
|
|
|
(define-configuration/no-serialization metznet-system-configuration
|
|
|
|
(certs (file-like le-certs)
|
|
|
|
"certificate package")
|
2023-12-01 17:17:15 -07:00
|
|
|
(user-shells (alist-of-file-like (list (cons
|
|
|
|
"/bin/zsh"
|
|
|
|
zsh)))
|
|
|
|
"user shells to link")
|
2023-11-30 19:56:49 -07:00
|
|
|
(pam-services (list-of-strings (list
|
|
|
|
"su"
|
|
|
|
"gdm-password"
|
|
|
|
"login"
|
|
|
|
"sshd"
|
|
|
|
"passwd"))
|
|
|
|
"list of pam services to configure"))
|
2023-11-30 13:52:13 -07:00
|
|
|
|
|
|
|
(define (pam-mkhomedir-service configuration)
|
2023-11-29 17:52:49 -07:00
|
|
|
(lambda (pam)
|
2023-11-30 18:26:00 -07:00
|
|
|
(if (member (pam-service-name pam)
|
|
|
|
(metznet-system-configuration-pam-services configuration))
|
2023-11-29 17:52:49 -07:00
|
|
|
(let ((required (pam-entry (control "required")
|
|
|
|
(module "pam_mkhomedir.so"))))
|
|
|
|
(pam-service (inherit pam)
|
|
|
|
(session (cons required
|
|
|
|
(pam-service-account pam))))) pam)))
|
2023-11-24 11:36:43 -07:00
|
|
|
|
2023-11-30 13:52:13 -07:00
|
|
|
(define (pam-mkhomedir-services configuration)
|
|
|
|
(list (pam-mkhomedir-service configuration)))
|
2023-11-24 11:36:43 -07:00
|
|
|
|
2023-12-01 01:27:39 -07:00
|
|
|
(define (shell-paths configuration)
|
2023-12-01 17:17:15 -07:00
|
|
|
(map car
|
|
|
|
(metznet-system-configuration-user-shells configuration)))
|
2023-12-01 01:27:39 -07:00
|
|
|
|
|
|
|
(define (shell-packages configuration)
|
2023-12-01 17:17:15 -07:00
|
|
|
(map cdr
|
|
|
|
(metznet-system-configuration-user-shells configuration)))
|
2023-12-01 01:27:39 -07:00
|
|
|
|
2023-11-30 13:52:13 -07:00
|
|
|
(define (metznet-activation configuration)
|
2023-12-02 21:02:28 -07:00
|
|
|
#~(begin
|
|
|
|
(let ((root (getpw "root")))
|
|
|
|
(mkdir-p/perms "/var/lib/openvpn" root 448))
|
|
|
|
(for-each (lambda (path package)
|
2023-12-01 17:17:15 -07:00
|
|
|
(unless (access? path F_OK)
|
2023-12-02 21:02:28 -07:00
|
|
|
(symlink (string-append package path) path)))
|
|
|
|
(list #$@(shell-paths configuration))
|
|
|
|
(list #$@(shell-packages configuration)))))
|
2023-12-02 11:12:38 -07:00
|
|
|
|
|
|
|
(define-public metznet-service-type
|
2023-11-29 17:52:49 -07:00
|
|
|
(service-type (name 'metznet-service)
|
|
|
|
(description "MetzNet Services")
|
|
|
|
(extensions (list (service-extension activation-service-type
|
|
|
|
metznet-activation)
|
2023-11-30 13:52:13 -07:00
|
|
|
(service-extension profile-service-type
|
2023-11-30 18:26:00 -07:00
|
|
|
(compose list
|
|
|
|
metznet-system-configuration-certs))
|
2023-11-29 17:52:49 -07:00
|
|
|
(service-extension pam-root-service-type
|
|
|
|
pam-mkhomedir-services)))
|
2023-11-30 13:52:13 -07:00
|
|
|
(default-value (metznet-system-configuration))))
|
2023-11-22 12:30:06 -07:00
|
|
|
|
2023-11-24 11:36:43 -07:00
|
|
|
(define %metznet-services
|
2023-11-29 17:52:49 -07:00
|
|
|
(list (service openssh-service-type
|
|
|
|
(openssh-configuration (extra-content
|
|
|
|
"KerberosAuthentication yes")))
|
|
|
|
(service krb5-service-type %metznet-krb5-config)
|
|
|
|
(service pam-krb5-service-type
|
|
|
|
(pam-krb5-configuration (pam-krb5 pam-krb5)
|
|
|
|
(minimum-uid 1000)))
|
2023-12-02 19:12:12 -07:00
|
|
|
(service sssd-service-type)
|
2023-11-30 13:52:13 -07:00
|
|
|
(service metznet-service-type)))
|
2023-11-29 17:52:49 -07:00
|
|
|
|
|
|
|
(define %metznet-nscd-configuration
|
|
|
|
(nscd-configuration (caches (append (list (nscd-cache (database 'passwd)
|
|
|
|
(positive-time-to-live
|
|
|
|
(* 3600 12))
|
|
|
|
(negative-time-to-live
|
|
|
|
20)
|
|
|
|
(persistent? #t))
|
|
|
|
(nscd-cache (database 'group)
|
|
|
|
(positive-time-to-live
|
|
|
|
(* 3600 12))
|
|
|
|
(negative-time-to-live
|
|
|
|
20)
|
|
|
|
(persistent? #t)))
|
|
|
|
%nscd-default-caches))))
|
2023-11-24 11:36:43 -07:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-desktop-services
|
2023-11-29 17:52:49 -07:00
|
|
|
(append %metznet-services
|
|
|
|
(modify-services %desktop-services
|
|
|
|
(nscd-service-type config => %metznet-nscd-configuration)
|
|
|
|
(udev-service-type config =>
|
|
|
|
(udev-configuration (inherit config)
|
|
|
|
(rules (append (list
|
|
|
|
%tun-udev-rule
|
|
|
|
%backlight-udev-rule)
|
|
|
|
(udev-configuration-rules
|
|
|
|
config)))))
|
|
|
|
(network-manager-service-type config =>
|
|
|
|
(network-manager-configuration (inherit
|
|
|
|
config)
|
|
|
|
(vpn-plugins
|
|
|
|
(list
|
|
|
|
network-manager-openvpn)))))))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-12-02 11:12:38 -07:00
|
|
|
(define %base-services-nscd
|
|
|
|
(modify-services %base-services
|
|
|
|
(nscd-service-type config => %metznet-nscd-configuration)))
|
|
|
|
|
|
|
|
(define %server-services
|
2023-11-27 11:26:54 -07:00
|
|
|
(append %metznet-services
|
2023-12-02 02:49:54 -07:00
|
|
|
(list (service dbus-root-service-type)
|
2023-11-29 17:52:49 -07:00
|
|
|
(service dhcp-client-service-type)
|
2023-12-02 11:12:38 -07:00
|
|
|
(service openvpn-client-service-type
|
2023-12-02 21:02:28 -07:00
|
|
|
(openvpn-client-configuration (ca
|
|
|
|
"/var/lib/openvpn/ca.crt")
|
|
|
|
(cert
|
|
|
|
"/var/lib/openvpn/client.crt")
|
|
|
|
(key
|
|
|
|
"/var/lib/openvpn/client.key")
|
|
|
|
(tls-auth
|
|
|
|
"/var/lib/openvpn/ta.key")
|
2023-12-02 11:12:38 -07:00
|
|
|
(persist-key? #f)
|
|
|
|
(remote (list (openvpn-remote-configuration
|
|
|
|
(name
|
2023-12-02 21:02:28 -07:00
|
|
|
"vpn.metznet.ca")))))))))
|
2023-12-02 11:12:38 -07:00
|
|
|
|
|
|
|
(define %metznet-server-services
|
|
|
|
(append %server-services %base-services-nscd))
|
|
|
|
|
|
|
|
(define %metznet-base-server-system
|
2022-09-17 19:28:48 -06:00
|
|
|
(operating-system
|
2023-12-02 11:12:38 -07:00
|
|
|
(host-name "metznet-base-server")
|
2022-09-17 19:28:48 -06:00
|
|
|
(timezone "America/Edmonton")
|
|
|
|
(locale "en_CA.utf8")
|
|
|
|
(keyboard-layout %default-keyboard-layout)
|
2023-11-21 19:05:13 -07:00
|
|
|
(name-service-switch %metznet-name-service-switch)
|
2022-09-17 19:28:48 -06:00
|
|
|
(kernel-arguments (append '("console=ttyS0") %default-kernel-arguments))
|
2023-11-29 17:52:49 -07:00
|
|
|
(bootloader (bootloader-configuration
|
2023-12-01 15:10:16 -07:00
|
|
|
(bootloader grub-efi-bootloader)
|
2023-11-29 17:52:49 -07:00
|
|
|
(targets '("/boot/efi"))
|
|
|
|
(keyboard-layout keyboard-layout)))
|
|
|
|
(file-systems (cons* (file-system
|
|
|
|
(mount-point "/")
|
2023-11-30 17:52:15 -07:00
|
|
|
(device (file-system-label "guix-data"))
|
2023-11-30 18:19:49 -07:00
|
|
|
(type "ext4")
|
2023-11-30 17:52:15 -07:00
|
|
|
(check? #f))
|
2023-11-30 18:26:00 -07:00
|
|
|
(file-system
|
2023-11-30 17:52:15 -07:00
|
|
|
(mount-point "/boot/efi")
|
|
|
|
(device (file-system-label "guix-boot"))
|
|
|
|
(type "fat32")
|
2023-11-30 18:26:00 -07:00
|
|
|
(check? #f)) %base-file-systems))
|
2023-11-21 19:05:13 -07:00
|
|
|
(users %metznet-base-user-accounts)
|
|
|
|
(groups %metznet-base-groups)
|
|
|
|
(packages %metznet-base-packages)
|
2023-11-29 17:52:49 -07:00
|
|
|
(services
|
|
|
|
%metznet-server-services)))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-base-desktop-system
|
2023-11-29 17:52:49 -07:00
|
|
|
(operating-system
|
2023-12-02 11:12:38 -07:00
|
|
|
(inherit %metznet-base-server-system)
|
2023-11-29 17:52:49 -07:00
|
|
|
(host-name "metznet-base-desktop")
|
|
|
|
(setuid-programs %desktop-setuid-programs)
|
|
|
|
(packages %metznet-desktop-packages)
|
|
|
|
(services
|
|
|
|
%metznet-desktop-services)))
|