vm-image.tmpl 5.5 KB

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