Skip to main content


Making GNU Guix VM (the hackish way)


GNU Guix can take a system definition (in .scm file) and make a VM out of it for you. Cool! But that's a "thin" VM — it shares part of the filesystem (the /gnu/store stuff) with the host. If you want a full VM with Guix in it, the official way is to boot the installation .iso inside a VM and use it to perform a usual install.

If you're like me, you probably feel this desire to avoid booting a .iso and building/downloading stuff in a VM ;)

Here's a solution ^^ First, make sure you have qemu and parted available (e.g. with `guix shell qemu parted`). Then, do


qemu-img create -f qcow2 vm.qcow2 100G
sudo modprobe nbd max_part=63
sudo qemu-nbd -n -c /dev/nbd0 vm.qcow2
sudo parted /dev/nbd0 mktable msdos
sudo parted /dev/nbd0 mkpart primary 0% 100%
sudo mkfs.ext4 -L my-vm-root /dev/nbd0p1
sudo mount /dev/nbd0p1 /mnt


Now, we can do `guix system init` to /mnt. But wait! Guix is going to check if the bootloader partition specified in your OS definition (assume it is in ./vm.scm, ok?) really exists (and, by default, it'll try to install the bootloader to it). So if your ./vm.scm has sth like this


(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(targets (list "/dev/sda"))))


It might cause you trouble… My solution is to pick the target depending on an environment variable 💡️ In your ./vm.scm, before the operating-system record is instantiated, put


(define bootloader-target
(or (getenv "SYSTEM_INIT_DISK_DEV") "/dev/sda"))


and make the bootloader part look like


(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(targets (list bootloader-target))))


Now, you can finish the installation :)


sudo sh -c 'SYSTEM_INIT_DISK_DEV=/dev/nbd0 guix system init vm.scm /mnt/'
sudo umount /mnt
sudo qemu-nbd -d /dev/nbd0


That should do. You can start the VM with sth like


sudo qemu-system-x86_64 -net nic,model=rtl8139 \
-net user,hostfwd=tcp::22-:22 \
-m 2G -hda vm.qcow2 -nographic -enable-kvm


The hostfwd part is to expose VM's SSH port on localhost (since you're going to play with it this way, aren't you?). sudo is purely to have permissions to do this forwarding and -nographic is to… If you're still reading, you surely understand this stuff, anyway ;)

In case you're wondering — the environment-controlled bootloader target now allows you to reuse the same system definition file for reconfiguring the running VM (otherwise, there's no reason not to just have /dev/nbd0 hardcoded in OS definition).

While doing this (as part of a more complex project for university classes, btw) I was also (un)lucky enough to stumble upon and fix one bug[1] that broke `guix init` 🦸

[1] https://issues.guix.gnu.org/70245

EDIT 27.04.2024: More or less the same can be achieved using an existing Guix command: `guix system init`. I'm not sure why I overlooked it here (I've been using it before).

This post is licensed CC0 v1.0.

This entry was edited (1 week ago)


Markdown → PDF bez pojedynczych literek na końcach lini


Zawsze mam wrażenie, że jeśli mam sierotki na końcach lini, to mój dokument wygląda nieprofesjonalnie… Dzisiaj skleciłem komendę pandoca, która załatwia ten problem przynajmniej w przypadku .md → .pdf. Może komuś też się przyda?

pandoc -H <(printf %s '\usepackage[nosingleletter]{impnattypo}') \
    --pdf-engine=lualatex -o artykul.pdf artykul.md
This entry was edited (2 months ago)


Jak obejrzeć Mszę online używając wolnego oprogramowania?


Za pomocą niektórych stron można łatwo znaleźć transmicje Mszy św. o prawie każdej godzinie. Przydatne. Ale... takie transmisje z reguły wymagają włączenia w przeglądarce JavaScriptu, zazwyczaj JavaScriptu od YouTube'a.

Może kiedyś będzie lepiej i niektóre transmisje przeniosą się np. na etycznego PeerTube'a, dla którego istnieją oficjalne aplikacje na wolnej licencji. A jak poradzić sobie teraz?

Transmisję-stream z YT da się pobierać znanym skryptem youtube-dl (i kompatybilnymi forkami) i odtwarzać w odpowiednim desktopowym playerze (ja używam mpv).

Na początek trzeba znaleźć kod filmu. W przypadku msze.info wystarczy wejść w kod strony z transmisją (dodając "view-source:" na początku adresu) i znaleźć element z kodem filmu na YT (w tym przypadku "71phvw-OIFk").

Dla kodu konstruujemy URL filmu, w tym przypadku "https://youtube.com/watch?v=71phvw-OIFk". Upewniamy się, że zainstalowane są mpv oraz aktualny youtube-dl i włączamy transmisję komendą

mpv 'https://youtube.com/watch?v=71phvw-OIFk'

Co, jeśli nasza dystrybucja nie oferuje aktualnej wersji youtube-dl'a? Możemy oczywiście zainstalować youtube-dl z gita. A możemy też uruchomić mpv z GNU Guix'a. Guix to distro, którego aplikacji da się używać też pod innymi GNU+Linux'ami. Po zainstalowaniu Guix'a lub zaktualizowaniu go (komenda `guix pull`), możemy np. odpalić dany program ad hoc, w jednym kroku i bez permanentnej instalacji. W naszym przypadku — komenda

guix shell mpv -- mpv 'https://youtube.com/watch?v=71phvw-OIFk'

Zaletą jest to, że wersja mpv z Guix'a z automatu pociąga za sobą yt-dlp (jeden z zamienników dla youtube-dl) i używa go. Na + jest też to, że Guix jest dystrybucją rolling-release i można się spodziewać, że yt-dlp będzie często aktualizowany.

Niestety, ten sposób wciąż daje Google'owi poznać nasz adres IP. Można spróbować ukryć się za VPN'em (bo Tor tu raczej nie zda egzaminu).

This entry was edited (2 months ago)