feat(guix): use noweb instead of multiple files

This commit is contained in:
Pavel Korytov 2021-05-30 15:43:43 +03:00
parent d1dd4b8929
commit 762ae0e5bc

128
Guix.org
View file

@ -115,93 +115,91 @@ References:
* Systems * Systems
Configuring systems with Guix. Configuring systems with Guix.
Again, this part is inspired by [[https://github.com/daviwil/dotfiles/blob/master/Systems.org][David Wilson's]] config.
** Base configuration ** Base configuration
The base configuration is shared between all the machines. The base configuration is shared between all the machines.
To use a configuration derived from ~base-operating-system~, invoke =guix system= as follows: While it's possible to make a single =.scm= file with base confguration and load it, I noticed that it produces more cryptic error messages wherever there is an error in the base file, so I opt in for noweb.
=guix system= invocation is as follows:
#+begin_example #+begin_example
sudo -E guix system -L ~/.config/guix/systems reconfigure ~/.config/guix/systems/[system].scm sudo -E guix system reconfigure ~/.config/guix/systems/[system].scm
#+end_example #+end_example
#+begin_src scheme :tangle ~/.config/guix/systems/base-system.scm Common modules:
(define-module (base-system) #+begin_src scheme :tangle no :noweb-ref system-common
#:use-module (gnu) (use-modules (gnu))
#:use-module (gnu system nss) (use-modules (gnu system nss))
#:use-module (gnu packages version-control) (use-modules (gnu packages certs))
#:use-module (gnu packages vim) (use-modules (gnu packages version-control))
#:use-module (gnu packages wm) (use-modules (gnu packages vim))
#:use-module (gnu packages openbox) (use-modules (gnu packages wm))
#:use-module (nongnu packages linux) (use-modules (gnu packages openbox))
#:use-module (nongnu system linux-initrd)) (use-modules (nongnu packages linux))
(use-modules (nongnu system linux-initrd))
(use-service-modules desktop networking ssh xorg) (use-service-modules desktop networking ssh xorg)
(use-package-modules ssh) (use-package-modules ssh)
#+end_src #+end_src
Define the ~base-operating-system~: In principle, we could define a variable called =base-operating-system= and extend it in ancestors. However, then we would have to define mandatory fields like =host-name=, =bootloader= with dummy values. Since I'm already using noweb, there is little point.
#+begin_src scheme :tangle ~/.config/guix/systems/base-system.scm
(define-public base-operating-system
(operating-system
;; Use the full Linux kernel
(kernel linux)
(initrd microcode-initrd)
(firmware (list (linux-firmware)))
(locale "en_US.utf8")
(timezone "Europe/Moscow")
;; US/RU keyboard layout The following code will be inserted in the top of the =operating-system= definition.
(keyboard-layout (keyboard-layout "us,ru" #:options '("grp:alt_shift_toggle"))) #+begin_src scheme :tangle no :noweb-ref system-base
;; Use the full Linux kernel
(kernel linux)
(initrd microcode-initrd)
(firmware (list linux-firmware))
(locale "en_US.utf8")
(timezone "Europe/Moscow")
;; User accounts ;; US/RU keyboard layout
(users (cons* (user-account (keyboard-layout (keyboard-layout "us,ru" #:options '("grp:alt_shift_toggle")))
(name "pavel")
(comment "Pavel")
(group "users")
(home-directory "/home/pavel")
(supplementary-groups
'("wheel" ;; sudo
"netdev" ;; network devices
"audio"
"video"
"input"
"tty"
"docker"
"lp")))
%base-user-accounts))
;; Base packages ;; User accounts
(packages (users (cons* (user-account
(append (name "pavel")
(list nss-certs (comment "Pavel")
git (group "users")
i3-gaps (home-directory "/home/pavel")
openbox (supplementary-groups
vim) '("wheel" ;; sudo
%base-packages)) "netdev" ;; network devices
"audio"
"video"
"input"
"tty"
;; "docker"
"lp")))
%base-user-accounts))
;; Services ;; Base packages
(services (packages
(append (append
(list (service openssh-service-type) (list nss-certs
(set-xorg-configuration git
(xorg-configuration i3-gaps
(keyboard-layout keyboard-layout)))) openbox
%desktop-services)))) vim)
%base-packages))
;; Services
(services
(append
(list (service openssh-service-type)
(set-xorg-configuration
(xorg-configuration
(keyboard-layout keyboard-layout))))
%desktop-services))
#+end_src #+end_src
** blue ** blue
A VM on which I test Guix. Will probably be deleted sooner or later. A VM on which I test Guix. Will probably be deleted sooner or later.
#+begin_src scheme :tangle ~/.config/guix/systems/blue.scm #+begin_src scheme :noweb yes :tangle ~/.config/guix/systems/blue.scm
(define-module (blue) <<system-common>>
#:use-module (base-system)
#:use-module (gnu))
(operating-system (operating-system
(inherit base-operating-system) <<system-base>>
(host-name "blue") (host-name "blue")
(bootloader (bootloader