2022-09-17 19:54:28 -06:00
|
|
|
(define-module (system base-system)
|
2022-09-28 14:55:38 -06:00
|
|
|
#:use-module (metznet)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (ice-9 exceptions)
|
|
|
|
#:use-module (nongnu system linux-initrd)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (nongnu packages linux)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (guix gexp)
|
2023-11-26 14:58:54 -07:00
|
|
|
#:use-module (guix utils)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (guix packages)
|
|
|
|
#:use-module (guix download)
|
|
|
|
#:use-module (guix build-system gnu)
|
|
|
|
#:use-module ((guix licenses) #:prefix license:)
|
|
|
|
#:use-module (gnu)
|
|
|
|
#:use-module (gnu system setuid)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu system nss)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (gnu system pam)
|
2023-11-27 18:08:03 -07:00
|
|
|
#:use-module (gnu services)
|
|
|
|
#:use-module (gnu services dbus)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu services pm)
|
2023-11-27 18:08:03 -07:00
|
|
|
#:use-module (gnu services shepherd)
|
2023-11-21 19:05:13 -07:00
|
|
|
#:use-module (gnu services authentication)
|
2023-11-27 18:08:03 -07:00
|
|
|
#:use-module (gnu services configuration)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu services vpn)
|
|
|
|
#:use-module (gnu services networking)
|
|
|
|
#:use-module (gnu services ssh)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (gnu services kerberos)
|
|
|
|
#:use-module (gnu services desktop)
|
|
|
|
#:use-module (gnu services xorg)
|
|
|
|
#:use-module (gnu services base)
|
|
|
|
#:use-module (gnu packages linux)
|
2023-11-26 14:58:54 -07:00
|
|
|
#:use-module (gnu packages ssh)
|
2023-11-27 18:08:03 -07:00
|
|
|
#:use-module (gnu packages sssd)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (gnu packages compression)
|
|
|
|
#:use-module (gnu packages libedit)
|
|
|
|
#:use-module (gnu packages hurd)
|
|
|
|
#:use-module (gnu packages tls)
|
|
|
|
#:use-module (gnu packages xorg)
|
|
|
|
#:use-module (gnu packages pkg-config)
|
|
|
|
#:use-module (gnu packages groff)
|
2023-11-26 14:58:54 -07:00
|
|
|
#:use-module (gnu packages gcc)
|
|
|
|
#:use-module (gnu packages commencement)
|
2023-11-24 11:36:43 -07:00
|
|
|
#:use-module (gnu packages security-token)
|
|
|
|
#:use-module (gnu packages vim)
|
|
|
|
#:use-module (gnu packages certs)
|
|
|
|
#:use-module (gnu packages vpn)
|
|
|
|
#:use-module (gnu packages networking)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu packages dns)
|
2023-11-22 12:26:17 -07:00
|
|
|
#:use-module (gnu packages base)
|
2022-09-17 19:28:48 -06:00
|
|
|
#:use-module (gnu packages openldap)
|
|
|
|
#:use-module (gnu packages kerberos)
|
|
|
|
#:use-module (gnu packages admin)
|
|
|
|
#:use-module (gnu packages shells)
|
|
|
|
#:use-module (gnu packages gnome)
|
|
|
|
#:use-module (gnu packages wm)
|
|
|
|
#:use-module (gnu packages suckless)
|
|
|
|
#:use-module (gnu packages gnuzilla)
|
|
|
|
#:use-module (gnu packages terminals)
|
|
|
|
#:use-module (gnu packages virtualization)
|
|
|
|
#:use-module (gnu packages version-control)
|
2023-11-21 19:05:13 -07:00
|
|
|
#:export (%domain-realm)
|
|
|
|
#:export (%domain-name)
|
|
|
|
#:export (%domain-kadmin)
|
|
|
|
#:export (%domain-kdc)
|
|
|
|
#:export (%metznet-base-user-accounts)
|
|
|
|
#:export (%metznet-base-groups)
|
|
|
|
#:export (%metznet-base-packages)
|
|
|
|
#:export (%metznet-desktop-packages)
|
|
|
|
#:export (%metznet-server-packages)
|
|
|
|
#:export (%metznet-setuid-programs)
|
|
|
|
#:export (%default-keyboard-layout)
|
|
|
|
#:export (%kvm-udev-rule)
|
|
|
|
#:export (%usb-udev-rule)
|
|
|
|
#:export (%tun-udev-rule)
|
|
|
|
#:export (%metznet-desktop-services)
|
|
|
|
#:export (%metznet-server-services)
|
|
|
|
#:export (%metznet-base-server-system)
|
|
|
|
#:export (%metznet-base-desktop-system))
|
|
|
|
|
|
|
|
(define %domain-realm "METZNET.CA")
|
|
|
|
|
|
|
|
(define %domain-name "metznet.ca")
|
|
|
|
|
|
|
|
(define %domain-kadmin (string-append "kerberos." %domain-name))
|
2023-11-21 20:57:51 -07:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %domain-kdc (string-append "kerberos." %domain-name))
|
|
|
|
|
|
|
|
(define %metznet-base-user-accounts (append (list
|
2022-09-17 19:28:48 -06:00
|
|
|
(user-account
|
|
|
|
(name "root")
|
|
|
|
(group "root")
|
|
|
|
(uid 0)
|
|
|
|
(password (crypt "root" "$6$salt"))
|
|
|
|
(shell (file-append zsh "/bin/zsh"))))
|
|
|
|
%base-user-accounts))
|
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-base-groups (append (list
|
2022-09-17 19:28:48 -06:00
|
|
|
(user-group
|
|
|
|
(system? #t)
|
|
|
|
(name "realtime"))
|
|
|
|
(user-group
|
|
|
|
(system? #t)
|
|
|
|
(name "usb")))
|
|
|
|
%base-groups))
|
|
|
|
|
2023-11-27 21:38:26 -07:00
|
|
|
(define %metznet-base-packages (append (list openssh openldap git neovim zsh le-certs nss-certs mit-krb5 openvpn openresolv) %base-packages))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-desktop-packages (append (list i3-wm i3status dmenu kitty icecat) %metznet-base-packages))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-server-packages (append (list isc-dhcp) %metznet-base-packages))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %desktop-setuid-programs (append
|
2022-09-17 19:28:48 -06:00
|
|
|
(list (setuid-program
|
|
|
|
(program #~(string-append #$openvpn "/sbin/openvpn")))
|
|
|
|
(setuid-program
|
|
|
|
(program #~(string-append #$openresolv "/sbin/resolvconf"))))
|
|
|
|
%setuid-programs))
|
|
|
|
|
2023-11-21 20:57:51 -07:00
|
|
|
(define %metznet-krb5-config (krb5-configuration
|
2023-11-21 19:05:13 -07:00
|
|
|
(default-realm %domain-realm)
|
2022-09-17 19:28:48 -06:00
|
|
|
(allow-weak-crypto? #t)
|
|
|
|
(rdns? #f)
|
|
|
|
(realms (list (krb5-realm
|
2023-11-21 19:05:13 -07:00
|
|
|
(name %domain-realm)
|
2023-11-21 20:57:51 -07:00
|
|
|
(admin-server %domain-kadmin)
|
|
|
|
(kdc %domain-kdc))))))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(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
|
2022-09-17 19:28:48 -06:00
|
|
|
(udev-rule
|
|
|
|
"65-kvm.rules"
|
|
|
|
"KERNEL==\"KVM\", GROUP=\"libvirt\", MODE=\"0660\""))
|
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %usb-udev-rule
|
2022-09-17 19:28:48 -06:00
|
|
|
(udev-rule
|
|
|
|
"51-usb.rules"
|
|
|
|
(string-append "SUBSYSTEM==\"usb\", GROUP=\"usb\"\n"
|
|
|
|
"SUBSYSTEM==\"usbmisc\", GROUP=\"usb\"")))
|
|
|
|
|
|
|
|
(define %tun-udev-rule
|
|
|
|
(udev-rule
|
|
|
|
"90-tun.rules"
|
|
|
|
"KERNEL==\"tun\", GROUP=\"netdev\", MODE=\"0660\", OPTIONS+=\"static_node=net/tun\""))
|
|
|
|
|
|
|
|
(define %backlight-udev-rule
|
|
|
|
(udev-rule
|
|
|
|
"55-backlight.rules"
|
|
|
|
"RUN+=\"/bin/chgrp video /sys/class/backlight/intel_backlight/brightness\""))
|
|
|
|
|
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-21 19:05:13 -07:00
|
|
|
(name-service-switch
|
|
|
|
(password services)
|
|
|
|
(shadow services)
|
|
|
|
(group services))))
|
|
|
|
|
2023-11-22 12:26:17 -07:00
|
|
|
|
2023-11-27 21:38:26 -07:00
|
|
|
(define (pam-mkhomedir-service config)
|
2023-11-24 11:36:43 -07:00
|
|
|
(lambda (pam)
|
|
|
|
(if (member (pam-service-name pam) config)
|
2023-11-27 21:38:26 -07:00
|
|
|
(let ((required
|
2023-11-26 14:58:54 -07:00
|
|
|
(pam-entry
|
|
|
|
(control "required")
|
|
|
|
(module "pam_mkhomedir.so"))))
|
2023-11-24 11:36:43 -07:00
|
|
|
(pam-service
|
|
|
|
(inherit pam)
|
2023-11-27 21:38:26 -07:00
|
|
|
(session (cons required (pam-service-account pam)))))
|
2023-11-24 11:36:43 -07:00
|
|
|
pam)))
|
|
|
|
|
2023-11-27 21:38:26 -07:00
|
|
|
(define (pam-mkhomedir-services config)
|
|
|
|
(list (pam-mkhomedir-service config)))
|
2023-11-24 11:36:43 -07:00
|
|
|
|
2023-11-27 18:08:03 -07:00
|
|
|
(define default-sssd-conf-file (plain-file "sssd.conf" (string-join (list
|
|
|
|
"[sssd]"
|
|
|
|
"domains = metznet.ca"
|
|
|
|
"services = nss, sudo, pam, ssh, ifp"
|
|
|
|
""
|
|
|
|
"[domain/metznet.ca]"
|
|
|
|
"id_provider = ldap"
|
|
|
|
"auth_provider = ldap"
|
|
|
|
"cache_credentials = True"
|
|
|
|
"ldap_uri = ldaps://ldap.metznet.ca"
|
|
|
|
"ldap_tls_reqcert = never"
|
|
|
|
"ldap_tls_cacertdir = /etc/ssl/certs"
|
|
|
|
"ldap_search_base = ou=users,ou=accounts,dc=metznet,dc=ca"
|
|
|
|
(string-append "ldap_default_bind_dn = " (getenv "LDAP_BINDDN"))
|
|
|
|
"ldap_default_authtok_type = password"
|
|
|
|
(string-append "ldap_default_authtok = " (getenv "LDAP_BINDPW"))) "\n")))
|
|
|
|
|
2023-11-24 11:36:43 -07:00
|
|
|
(define metznet-service-type
|
|
|
|
(service-type
|
|
|
|
(name 'metznet-service)
|
|
|
|
(description "MetzNet Services")
|
|
|
|
(extensions
|
2023-11-27 21:38:26 -07:00
|
|
|
(list (service-extension pam-root-service-type pam-mkhomedir-services)))
|
2023-11-24 11:36:43 -07:00
|
|
|
(default-value '())))
|
|
|
|
|
2023-11-27 18:08:03 -07:00
|
|
|
(define-configuration sssd-configuration
|
|
|
|
(sssd (file-like sssd) "SSSD Package to use")
|
|
|
|
(config (file-like default-sssd-conf-file) "sssd.conf file"))
|
|
|
|
|
|
|
|
(define (sssd-pam-service config)
|
|
|
|
(define sssd-pam-module
|
|
|
|
(file-append (sssd-configuration-sssd config) "/lib/security/pam_sss.so"))
|
|
|
|
(lambda (pam)
|
|
|
|
(if (member (pam-service-name pam) pam-service-list)
|
|
|
|
(let ((sufficient
|
|
|
|
(pam-entry
|
|
|
|
(control "sufficient")
|
|
|
|
(module sssd-pam-module))))
|
|
|
|
(pam-service
|
|
|
|
(inherit pam)
|
|
|
|
(auth (cons sufficient (pam-service-auth pam)))
|
|
|
|
(account (cons sufficient (pam-service-account pam)))
|
|
|
|
(password (cons sufficient (pam-service-password pam)))
|
|
|
|
(session (cons sufficient (pam-service-session pam)))))
|
|
|
|
pam)))
|
2023-11-27 11:26:54 -07:00
|
|
|
|
2023-11-27 18:08:03 -07:00
|
|
|
|
|
|
|
(define (sssd-pam-services config)
|
|
|
|
(list (sssd-pam-service config)))
|
|
|
|
|
|
|
|
(define (sssd-shepherd-service config)
|
|
|
|
(list (shepherd-service
|
|
|
|
(documentation "")
|
|
|
|
(provision '(sssd))
|
|
|
|
(requirement '(networking user-processes))
|
|
|
|
(start #~(make-forkexec-constructor
|
|
|
|
(list (string-append #$(sssd-configuration-sssd config) "/sbin/sssd") "-i" "-d" "0x77f0")
|
|
|
|
#:user "root"
|
|
|
|
#:group "root"
|
|
|
|
#:environment-variables
|
|
|
|
(list (string-append "LD_LIBRARY_PATH=" #$(sssd-configuration-sssd config) "/lib"))))
|
|
|
|
(stop #~(make-kill-destructor)))))
|
|
|
|
|
|
|
|
(define %sssd-activation
|
|
|
|
#~(begin
|
|
|
|
(let ((dbdir "/var/lib/sss/db")
|
|
|
|
(dbusdir "/var/lib/sss/pipes/private")
|
|
|
|
(user (getpw "root")))
|
|
|
|
(mkdir-p/perms dbusdir user #o755)
|
|
|
|
(mkdir-p/perms dbdir user #o755)
|
|
|
|
(chmod "/etc/sssd/sssd.conf" #o600))))
|
|
|
|
|
|
|
|
(define (sssd-etc-service config)
|
|
|
|
`(("sssd/sssd.conf" ,(sssd-configuration-config config))))
|
|
|
|
|
|
|
|
(define sssd-service-type
|
|
|
|
(service-type
|
|
|
|
(name 'sssd)
|
|
|
|
(description "MetzNet SSSD Service")
|
|
|
|
(extensions
|
|
|
|
(list (service-extension pam-root-service-type sssd-pam-services)
|
|
|
|
(service-extension dbus-root-service-type
|
|
|
|
(compose
|
|
|
|
list
|
|
|
|
sssd-configuration-sssd))
|
|
|
|
(service-extension etc-service-type sssd-etc-service)
|
|
|
|
(service-extension activation-service-type (const %sssd-activation))
|
|
|
|
(service-extension nscd-service-type (const (list sssd)))
|
|
|
|
(service-extension shepherd-root-service-type sssd-shepherd-service)))
|
|
|
|
(default-value (sssd-configuration))))
|
|
|
|
|
|
|
|
(define pam-service-list (list "su" "gdm-password" "login" "sshd" "passwd"))
|
2023-11-22 12:30:06 -07:00
|
|
|
|
2023-11-24 11:36:43 -07:00
|
|
|
(define %metznet-services
|
|
|
|
(list
|
|
|
|
(simple-service 'metznet-ln-service activation-service-type #~(symlink "/run/current-system/profile/bin/zsh" "/bin/zsh"))
|
|
|
|
(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-11-27 18:08:03 -07:00
|
|
|
(service sssd-service-type)
|
2023-11-27 11:26:54 -07:00
|
|
|
(service metznet-service-type pam-service-list)))
|
2023-11-26 14:58:54 -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)
|
2023-11-27 18:08:03 -07:00
|
|
|
(persistent? #t)))
|
2023-11-26 14:58:54 -07:00
|
|
|
%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-27 11:26:54 -07:00
|
|
|
(append
|
|
|
|
%metznet-services
|
|
|
|
(modify-services %desktop-services
|
|
|
|
(nscd-service-type config => %metznet-nscd-configuration)
|
|
|
|
(elogind-service-type config =>
|
|
|
|
(elogind-configuration (inherit config)
|
|
|
|
(handle-lid-switch-external-power 'suspend)))
|
|
|
|
(guix-service-type config => (guix-configuration
|
|
|
|
(inherit config)
|
|
|
|
(substitute-urls
|
|
|
|
(append (list "https://substitutes.nonguix.org")
|
|
|
|
%default-substitute-urls))
|
|
|
|
(authorized-keys
|
|
|
|
(append (list (plain-file "nonguix.pub"
|
|
|
|
"(public-key
|
|
|
|
(ecc
|
|
|
|
(curve Ed25519)
|
|
|
|
(q #C1FD53E5D4CE971933EC50C9F307AE2171A2D3B52C804642A7A35F84F3A4EA98#)))"))
|
|
|
|
%default-authorized-guix-keys))))
|
|
|
|
(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-11-27 11:26:54 -07:00
|
|
|
(define %metznet-server-services
|
|
|
|
(append %metznet-services
|
|
|
|
(list
|
2023-11-27 18:08:03 -07:00
|
|
|
(dbus-service)
|
2023-11-27 11:26:54 -07:00
|
|
|
(service dhcp-client-service-type)
|
|
|
|
(openvpn-client-service
|
|
|
|
#:config (openvpn-client-configuration
|
|
|
|
(openvpn openvpn)
|
|
|
|
(pid-file "/var/run/openvpn/client.pid")
|
|
|
|
(persist-key? #f)
|
|
|
|
(tls-auth "/etc/openvpn/ta.key"))))
|
|
|
|
(modify-services %base-services
|
|
|
|
(nscd-service-type config => %metznet-nscd-configuration))))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-base-operating-system
|
2022-09-17 19:28:48 -06:00
|
|
|
(operating-system
|
|
|
|
;; Hostname and localization information
|
|
|
|
(host-name "base")
|
|
|
|
(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 and firmware definitions
|
|
|
|
(kernel linux)
|
|
|
|
(kernel-arguments (append '("console=ttyS0") %default-kernel-arguments))
|
|
|
|
(firmware (list linux-firmware))
|
|
|
|
(initrd microcode-initrd)
|
|
|
|
;; Grub UEFI Bootloader installed to /boot/efi
|
|
|
|
(bootloader
|
|
|
|
(bootloader-configuration
|
|
|
|
(bootloader grub-efi-bootloader)
|
|
|
|
(targets '("/boot/efi"))
|
|
|
|
(keyboard-layout keyboard-layout)))
|
|
|
|
(file-systems (cons*
|
|
|
|
(file-system
|
|
|
|
(mount-point "/boot/efi")
|
|
|
|
(device "/dev/vda1")
|
|
|
|
(type "vfat")
|
|
|
|
(check? #f))
|
|
|
|
(file-system
|
|
|
|
(mount-point "/")
|
|
|
|
(device "/dev/vda3")
|
|
|
|
(type "xfs")
|
|
|
|
(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-24 11:36:43 -07:00
|
|
|
(services (append %metznet-services %base-services))))
|
2022-09-17 19:28:48 -06:00
|
|
|
|
2023-11-21 19:05:13 -07:00
|
|
|
(define %metznet-base-server-system
|
2022-09-17 19:28:48 -06:00
|
|
|
(operating-system
|
2023-11-21 19:05:13 -07:00
|
|
|
(inherit %metznet-base-operating-system)
|
|
|
|
(host-name "metznet-base-server")
|
2022-09-28 15:40:15 -06:00
|
|
|
(packages %metznet-server-packages)
|
|
|
|
(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
|
2022-09-17 19:28:48 -06:00
|
|
|
(operating-system
|
2023-11-21 19:05:13 -07:00
|
|
|
(inherit %metznet-base-operating-system)
|
|
|
|
(host-name "metznet-base-desktop")
|
2022-09-17 19:28:48 -06:00
|
|
|
(setuid-programs %desktop-setuid-programs)
|
2022-09-28 15:40:15 -06:00
|
|
|
(packages %metznet-desktop-packages)
|
|
|
|
(services %metznet-desktop-services)))
|