Spool - Differences between Guix and NixOS & Why I ditched NixOS

Introduction

I'm an active user declarative systems: NixOS and GNU Guix System. I wanted to tell you about my experience from Guix and NixOS, also disassemble why I ditched NixOS in favor of Guix.

I acctivly worked to NixOS already 9 months, it is my first declarative distribution. I liked the idea of a declarative deterministic distribution, because very comfortable have system configuration in which there will be full behavior system and all packages. Approximately 1.5 year ago I started used declarative systems how a main OS.

After NixOS I changed it a GNU Guix System, why? I'm big fan and user of GNU Emacs, where I met a dialect Lisp - ELisp. I really liked this programming language, it was very unusual and it was the freedom to expand the environment and add my own macros, so I can program the language while writing the code, thus is awesome. And when I found for Guix, where full system built on GNU Guile Scheme, that next the right step was a transition to Guix. But after the transition, I learned even more advantages of GNU Guix System compared to NixOS.

Nix DSL vs. GNU Guile Scheme

First of all, Guix is based on Nix, but doesn't use Nixpkgs or the Nix language itself. It is fully rewritten in Guile, that is, in dialect Lisp. Guix only takes a piece of code in C++ from nix-daemon to make /gnu/store/.

Nix itself is a DSL, it is written only under narrowly focused tasks, such as declarative descriptions of configurations and packages. The main problem is that you spend time learning a whole separate language, which is completely useless outside of NixOS - just dead weight in your head. And as soon as you need real logic inside your configuration, the Nix DSL hits a wall, and you still have to drag in Bash, Python, or other programing languages. Also Nix is written in other programing languages, for example: С++, C, Nix, Python, Bash and other. Moreover, under the hood in Nix, when rebuilding the system, everything ultimately comes down to the fact that Nix glues together huge sheets of Bash scripts and runs them through the shell as a builder for derivations. In my view this pulls many garbage and problems. Another huge difference is how they handle errors. In Nix, because of lazy evaluation and glued-together Bash scripts, a single mistake dumps a huge wall of unreadable stack traces from inside nixpkgs - or points to a line in a generated Bash script where you have no idea what actually broke. But in Guix, this is implemented much simpler and more elegant.

In turn, GNU Guile Scheme is a full programming language. With it, you can expand your configs as you wish, using the same language in which you write your config and describe packages. For example, if you want to write your service or script for Nix, then you will have to write a Bash script, wrapping it '' ... '', there is no syntax highlighting or syntax checking, and this is just an ugly hack. And on Guix you just write everything in Guile - it is really simple. In Guix, even the sandbox builder itself is Guile: there are no ugly hacks with generating Bash scripts - pure Scheme runs everywhere, from high-level configs down to the lowest level of building. In Guix, since everything runs on pure Guile Scheme, you immediately get a clean backtrace showing the exact file, line number, and cause of the error - just like in any normal programming language. Also, Guix is 98.4% written in Guile Scheme, this makes it architecturally cleaner.

Nix - Nix + Bash
      
pkgs.writeShellScriptBin "start-river" ''
  unset DISPLAY
  USER_ID=$(id -u)
  export XDG_RUNTIME_DIR="/run/user/$USER_ID"
  if [ ! -d "$XDG_RUNTIME_DIR" ]; then
    export XDG_RUNTIME_DIR="/tmp/run-$USER_ID"
    mkdir -p "$XDG_RUNTIME_DIR"
    chmod 700 "$XDG_RUNTIME_DIR"
  fi

  export XDG_SESSION_TYPE=wayland
  export XDG_CURRENT_DESKTOP=river

  exec ${pkgs.dbus}/bin/dbus-run-session \
    ${pkgs.river}/bin/river
''
      
Guix - GNU Guile Scheme
      
(program-file "start-river"
  #~(begin
      (unsetenv "DISPLAY")
      (let* ((uid (number->string (getuid)))
             (run-dir (string-append "/run/user/" uid))
             (tmp-dir (string-append "/tmp/run-" uid)))
        (if (file-exists? run-dir)
            (setenv "XDG_RUNTIME_DIR" run-dir)
            (begin
              (mkdir tmp-dir #o700)
              (chmod tmp-dir #o700)
              (setenv "XDG_RUNTIME_DIR" tmp-dir))))

      (for-each
       (lambda (var)
         (setenv (car var) (cdr var)))
       '(("XDG_SESSION_TYPE" . "wayland")
         ("XDG_CURRENT_DESKTOP" . "river")))

      (execl #$(file-append dbus "/bin/dbus-run-session")
             "dbus-run-session"
             #$(file-append river "/bin/river"))))
      

Systemd vs. GNU Shepherd

NixOS uses systemd as its init system. It is a plus that it is used in many distros and systemd has become the standard init system for Linux. Of course, many people are ready to argue with this, including me, but let's face it. Yeah, you can tune systemd through Nix options - systemd.services.(name), but under the hood Nix generates ordinary INI .service files. If you want to write your custom service, then you'll have to build its configuration in bash scripts, and for this you'll also need to know a separate unit-file syntax. Also, systemd itself is a huge monolithic piece of C code, which in turn pulls in a bunch of garbage that you won't use.

Guix uses GNU Shepherd - it runs as PID 1 on Guix System and manages user services for Guix Home. GNU Shepherd is written in Guile and can be extended in the same language, just like the rest of Guix. That's it, just write in GNU Guile Scheme and don't worry about 100 other languages.

Flakes vs. Channels & Time-Machine & Packages

Nix doesn't have a single approach to package and system management. Classic configuration.nix is considered a base, but without it the meaning of the declarative approach is lost. And Flakes, which fixes its problems, has been under the experimental-features flag for many years. Because of this, it is unclear what is happening in the ecosystem. Some have one approach, others have another - I personally think this is a big problem.

Flakes themselves are tightly tied to Git. When your local configuration lives in a Git repository, Nix copies your entire repository folder into /nix/store on every single rebuild - including images, docs, wallpapers, and any other unrelated clutter sitting next to your flake.nix. Even worse, if you create a new file in your config directory and forget to run git add, Flakes simply pretend it doesn't exist and fail with an error.

In Guix, there is no split between "classic" and "experimental" - there is just one unified, stable approach right out of the box. External package repositories are defined in a single channels.scm file written in standard Guile Scheme, and you can pin the exact commits of all your channels for full reproducibility with a single command guix describe -f channels. Meanwhile, your local configs config.scm and home-configuration.scm stay ordinary files on disk: Guix doesn't force you to track them in Git, run git add before every check, or dump your entire directory clutter into /gnu/store on every rebuild. And if you ever need to roll back or run packages from an older state, Guix has guix time-machine built straight in - letting you jump to any commit in history and build a package or an entire system from that exact point in time without ugly workarounds.

What I thinks about packages on Guix/Nix

I really like that Guix uses only Free Software by default. Even when I needed proprietary packages, I could simply add nonguix or other third-party channels(for example myself - mpupgg) and install the necessary packages. What I appreciate even more is that Guix maintainers actively patch packages to strip out binary blobs and make them fully free. Also, Guix uses a rolling-release model, which really appeals to me. You always get the freshest packages - you just run guix pull and update everything globally without waiting for big versioned releases.

Of course, in NixOS you can use the unstable branch of the repository and get new packages, but this is not the same as rolling-release. The branches themselves updated in unstable are not added one at a time, but are released in batches of many packages at a time. And in this unstable branch they are checked only by the system - Hydra. It allows a package into the unstable branch if it's just built, but it can't test whether it works, which makes the unstable branch in NixOS quite unstable. Guix is much stricter in this regard; before updating, members of Guix meticulously check everything in the package assembly, run it through Cuirass and install the package themselves in the system and test it. I myself have encountered this experience; they even pay attention to. at the end of the sentence, or a link to the repository, if there is .git there, they say to remove it.

What have we come to?

Thus, I analyzed the disadvantages of NixOS because of which I chose Guix. Of course, Nix has a great advantage in the form of a huge database of packages and a large community. But in all other respects, Guix is ahead of Nix.

Pheeeeew, to be honest, I'm tired of writing this post. But while writing it, I definitely learned more about Guix and Nix, because before writing it I didn’t even know about half of it. I also improved my English very well, which I am incredibly happy about. Thank you very much for reading to the end, this is my 5 anniversary post, more to come. Bye! :)