vm-image.tmpl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ;; This is an operating system configuration for a VM image.
  2. ;; Modify it as you see fit and instantiate the changes by running:
  3. ;;
  4. ;; guix system reconfigure /etc/config.scm
  5. ;;
  6. (use-modules (gnu) (guix) (srfi srfi-1))
  7. (use-service-modules desktop mcron networking spice ssh xorg sddm)
  8. (use-package-modules bootloaders certs fonts nvi
  9. package-management wget xorg)
  10. (define vm-image-motd (plain-file "motd" "
  11. \x1b[1;37mThis is the GNU system. Welcome!\x1b[0m
  12. This instance of Guix is a template for virtualized environments.
  13. You can reconfigure the whole system by adjusting /etc/config.scm
  14. and running:
  15. guix system reconfigure /etc/config.scm
  16. Run '\x1b[1;37minfo guix\x1b[0m' to browse documentation.
  17. \x1b[1;33mConsider setting a password for the 'root' and 'guest' \
  18. accounts.\x1b[0m
  19. "))
  20. ;;; XXX: Xfce does not implement what is needed for the SPICE dynamic
  21. ;;; resolution to work (see:
  22. ;;; https://gitlab.xfce.org/xfce/xfce4-settings/-/issues/142). Workaround it
  23. ;;; by manually invoking xrandr every second.
  24. (define auto-update-resolution-crutch
  25. #~(job '(next-second)
  26. (lambda ()
  27. (setenv "DISPLAY" ":0.0")
  28. (setenv "XAUTHORITY" "/home/guest/.Xauthority")
  29. (execl (string-append #$xrandr "/bin/xrandr") "xrandr" "-s" "0"))
  30. #:user "guest"))
  31. (operating-system
  32. (host-name "gnu")
  33. (timezone "Etc/UTC")
  34. (locale "en_US.utf8")
  35. (keyboard-layout (keyboard-layout "us" "altgr-intl"))
  36. ;; Label for the GRUB boot menu.
  37. (label (string-append "GNU Guix " (package-version guix)))
  38. (firmware '())
  39. ;; Below we assume /dev/vda is the VM's hard disk.
  40. ;; Adjust as needed.
  41. (bootloader (bootloader-configuration
  42. (bootloader grub-bootloader)
  43. (targets '("/dev/vda"))
  44. (terminal-outputs '(console))))
  45. (file-systems (cons (file-system
  46. (mount-point "/")
  47. (device "/dev/vda1")
  48. (type "ext4"))
  49. %base-file-systems))
  50. (users (cons (user-account
  51. (name "guest")
  52. (comment "GNU Guix Live")
  53. (password "") ;no password
  54. (group "users")
  55. (supplementary-groups '("wheel" "netdev"
  56. "audio" "video")))
  57. %base-user-accounts))
  58. ;; Our /etc/sudoers file. Since 'guest' initially has an empty password,
  59. ;; allow for password-less sudo.
  60. (sudoers-file (plain-file "sudoers" "\
  61. root ALL=(ALL) ALL
  62. %wheel ALL=NOPASSWD: ALL\n"))
  63. (packages (append (list font-bitstream-vera nss-certs nvi wget)
  64. %base-packages))
  65. (services
  66. (append (list (service xfce-desktop-service-type)
  67. ;; Choose SLiM, which is lighter than the default GDM.
  68. (service slim-service-type
  69. (slim-configuration
  70. (auto-login? #t)
  71. (default-user "guest")
  72. (xorg-configuration
  73. (xorg-configuration
  74. ;; The QXL virtual GPU driver is added to provide
  75. ;; a better SPICE experience.
  76. (modules (cons xf86-video-qxl
  77. %default-xorg-modules))
  78. (keyboard-layout keyboard-layout)))))
  79. ;; Uncomment the line below to add an SSH server.
  80. ;;(service openssh-service-type)
  81. ;; Add support for the SPICE protocol, which enables dynamic
  82. ;; resizing of the guest screen resolution, clipboard
  83. ;; integration with the host, etc.
  84. (service spice-vdagent-service-type)
  85. (simple-service 'cron-jobs mcron-service-type
  86. (list auto-update-resolution-crutch))
  87. ;; Use the DHCP client service rather than NetworkManager.
  88. (service dhcp-client-service-type))
  89. ;; Remove some services that don't make sense in a VM.
  90. (remove (lambda (service)
  91. (let ((type (service-kind service)))
  92. (or (memq type
  93. (list gdm-service-type
  94. sddm-service-type
  95. wpa-supplicant-service-type
  96. cups-pk-helper-service-type
  97. network-manager-service-type
  98. modem-manager-service-type))
  99. (eq? 'network-manager-applet
  100. (service-type-name type)))))
  101. (modify-services %desktop-services
  102. (login-service-type config =>
  103. (login-configuration
  104. (inherit config)
  105. (motd vm-image-motd)))))))
  106. ;; Allow resolution of '.local' host names with mDNS.
  107. (name-service-switch %mdns-host-lookup-nss))