📜 ⬆️ ⬇️

Guix - the most advanced operating system

Operating systems (OS) is an extensive topic. For decades, one approach has dominated here: Unix. Indeed, most modern systems, including most GNU / Linux distributions, * BSD and macOS, adhere to the Unix architecture. (Windows is not, but there is almost nothing interesting on this topic).

In 2000, Rob Pike made a presentation on why system software research is not relevant . Due to pessimism or neglect of the community, he seems to have completely ignored the complaints collected by many Unix-users in The Unix-Haters Handbook (1994). The book is intentionally sarcastic, but it points to some critical problems of Unix systems — and they have not been solved yet.

In 2006, Elko Dositra published his thesis “A fully functional model of software deployment,” which describes the functional package manager Nix. In 2008, the author published NixOS: a fully functional distribution of Linux . While NixOS reuses a lot of free software for Unix systems, it is so far away from the design and philosophy of Unix that it can hardly be called a "Unix system."

Nix - a giant step forward in system development. This OS not only solved many Unix problems (including criticism from the aforementioned collection), but also opened the way for many other functions and research that can play a very important role in our time, when reliability and security have become the main theme of many scientific, public and political debates.

Pike was wrong. And this proves another more general point: it is probably wiser to refrain from declaring the irrelevance of any research if you cannot prove the impossibility of further development. And the mentioned report can hardly be considered a mathematical proof. He only reinforced the idea that Unix is ​​“good enough” and that one should come to terms with its features and problems.

Fortunately, this unnecessary pessimism was short-sighted and did not survive for long: just a couple of years later, the Nix system proved him wrong.

Guix appearance


Guix is the package manager on Nix, and GuixSD is the operating system, the equivalent of NixOS, which aims to be a “fully programmable OS.” Indeed, almost everything here is written and configured in Guile Scheme : from Guix package management to the GNU shepherd initialization system.

Guix is ​​significantly different from Unix operating systems. You can view the documentation and assess the degree of change:


Guix Benefits


The advantages of Guix are revolutionary to such an extent that the rest of the operating systems look outdated compared to it.

My personal favorite features:


Guix compared to competitors


Debian, Arch Linux, and most other GNU / Linux distributions


GNU / Linux distributions usually lack the above-mentioned Guix benefits. The most critical shortcomings:


Gentoo, * BSD


Gentoo and other distributions with Portage's package manager have a famous feature: USE flags to activate features throughout the system (for example, mute, enable GUI support, etc.).

USE flags make it trivial to enable and disable features from the package author (and the advantage is that they are tested). Portage, on the other hand, does not allow functions that are not thought out in advance. For example, if the package has an additional sound, but the author has not set the corresponding flag, the user will not be able to do anything about it (except for creating a new package definition).

By comparison, Guix allows full customization of everything, albeit with a little more Scheme code. In pseudocode, it looks like this:

 (loop-over (TARGET-PACKAGES) (package (inherit TARGET) (changes-here... including patches, build options, etc.)) 

This code batch sets the definitions for TARGET-PACKAGES with your changes. None of the changes need to be made to the package definition. At any time, the user retains full control over the changes that can be made to the packages.

I loved Gentoo, but after switching to Guix, the limitations of Portage became apparent.


In addition, Portage suffers from the same problem with the lack of proper support for multiple versions, and the flags significantly increase the scale of the problem (a frequent complaint about Portage): when incompatible USE flags are applied to some dependencies, the user has to manually search for a solution. Sometimes this means that the required function is not applicable (at least without substantial work on package definitions).

In practice, Guix provides precompiled packages - a huge time saving compared to Gentoo (although Portage supports the distribution of binary packages).

* BSD systems (for example, FreeBSD) suffer from similar problems in make config .

Nix


Nix was a historic breakthrough in operating system research, and Guix borrowed almost all of its ideas from there. Today, Nix is ​​still one of the best active OSes. Probably, Guix would not exist if it were not for one drawback.

In my opinion, Guix solves the basic problem of Nix: instead of its own domain-specific language (DSL), the full-fledged Lisp -based programming language is used here.

“Implementing your own programming language” is a very common misconception in software development. This hit hard on many projects where the configuration or programming language suffered from the following flaws:


There are a huge number of projects in homegrown or too limited languages:


Reinventing a wheel is usually not a good idea. When it comes to such important tools as programming languages, this has very dramatic consequences. Requires unnecessary extra effort, errors occur. The community is dissipating. More consolidated communities are more efficient and use their time better if they improve existing, well-developed programming languages.

Not just for the desktop


Guix supports several architectures (i686, x86_64, ARMv7, and AArch64 as of January 2019), and plans to support more kernels outside the Linux ecosystem (say, * BSD, GNU Hurd, or maybe your own system!).

This makes Guix a great tool for deploying (reproducible) servers and other specialized systems. I think that in embedded systems Guix can compete very well with OpenWRT (although it will take some work on porting to embedded systems).

Self-reproducible live USB


Above, I mentioned the guix system disk-image : for example, it allows you to recreate the current system on a USB flash drive.

Thus, a clone of the current system is easy to connect anywhere and replicate the exact current environment (minus the hardware). There you can include user data: PGP keys, email. Everything is available immediately after the download.

Obviously, the cloning works further with the machine on which the clone is installed: instead of the “naked” Guix, a full-fledged OS is deployed, ready for work.

Replacing other package managers


Emacs, Python, Ruby ... and the power of the guix environment


Guix can replace any package manager, including programming language package managers. It has several advantages:


At this point, you should mention the guix environment . This command only sets up a temporary environment with a specific set of packages, like virtualenv . Killer feature is that it is universal for all languages ​​and their combinations.

Texlive


(Disclaimer: as of January 2019, the TeXlive assembly system for Guix is ​​being modified).

TeXlive received a special mention, because it is especially awful :), which once again confirms the saving role of Guix!

Most Unix-based operating systems typically distribute TeXlive as part of a set of packages. For example, in Arch Linux there are a dozen of these. If you need some TeX packages from different sets, then Arch Linux leaves no choice but to install thousands (possibly unnecessary) packages, and TeXlive takes up a lot of space: hundreds of megabytes.

Alternatively, you can install TeXlive manually, but let's face it: tlmgr is just a bad batch manager, and it requires tedious additional work.

Using Guix, TeXlive packages are installed separately, like everything else that helps you keep your own set of TeXlive packages or even create virtual environment specifications for compiling specific documents.

Core


Many operating systems offer only limited support for non-standard kernels. If users want to move away from the default kernel, the non-standard kernel has to be manually maintained.

Gentoo is known to "require" a custom kernel as a recommended (required?) Installation step. However, this is hardly a mandatory requirement, and users themselves must support the configuration of the kernel.

In Guix, the kernel is a fully customizable regular package, just like any other. You can customize everything and transfer the kernel configuration file to the package definition.

For example, the following are the definitions of a non-free Linux kernel with the iwlwifi driver (warning: I strongly advise against using proprietary drivers, as they pose a serious threat to your privacy and freedom):

 (define-module (ambrevar linux-custom) #:use-module (guix gexp) #:use-module (guix packages) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix build-system trivial) #:use-module ((guix licenses) #:prefix license:) #:use-module (gnu packages linux) #:use-module (srfi srfi-1)) (define-public linux-nonfree (package (inherit linux-libre) (name "linux-nonfree") (version (package-version linux-libre)) (source (origin (method url-fetch) (uri (string-append "https://www.kernel.org/pub/linux/kernel/v4.x/" "linux-" version ".tar.xz")) (sha256 (base32 "1lm2s9yhzyqra1f16jrjwd66m3jl43n5k7av2r9hns8hdr1smmw4")))) (native-inputs `(("kconfig" ,(local-file "./linux-custom.conf")) ,@(alist-delete "kconfig" (package-native-inputs linux-libre)))))) (define (linux-firmware-version) "9d40a17beaf271e6ad47a5e714a296100eef4692") (define (linux-firmware-source version) (origin (method git-fetch) (uri (git-reference (url (string-append "https://git.kernel.org/pub/scm/linux/kernel" "/git/firmware/linux-firmware.git")) (commit version))) (file-name (string-append "linux-firmware-" version "-checkout")) (sha256 (base32 "099kll2n1zvps5qawnbm6c75khgn81j8ns0widiw0lnwm8s9q6ch")))) (define-public linux-firmware-iwlwifi (package (name "linux-firmware-iwlwifi") (version (linux-firmware-version)) (source (linux-firmware-source version)) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((source (assoc-ref %build-inputs "source")) (fw-dir (string-append %output "/lib/firmware/"))) (mkdir-p fw-dir) (for-each (lambda (file) (copy-file file (string-append fw-dir (basename file)))) (find-files source "iwlwifi-.*\\.ucode$|LICENSE\\.iwlwifi_firmware$")) #t)))) (home-page "https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi") (synopsis "Non-free firmware for Intel wifi chips") (description "Non-free iwlwifi firmware") (license (license:non-copyleft "https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/LICENCE.iwlwifi_firmware?id=HEAD")))) 

Custom kernel and firmware can be conditionally included in the current system configuration (some file config.scm ):

 (define *lspci* (let* ((port (open-pipe* OPEN_READ "lspci")) (str (get-string-all port))) (close-pipe port) str)) (operating-system (host-name "...") ;;... (kernel (cond ((string-match "Network controller: Intel Corporation Wireless 8888" *lspci*) linux-nonfree) (#t linux-libre))) (firmware (append (list linux-firmware-iwlwifi) %base-firmware)) 

Then follow these steps to install the new system configuration:

 sudo -E guix system reconfigure config.scm 

Without even installing a new kernel, you can directly create an image ready for booting from a USB drive.

Games


Since Guix packages use advanced technologies (for example, the latest versions of Mesa) and allow full kernel tuning, this is an ideal platform for games and, in particular, for packaging games!

Unfortunately, the game industry is still far from the free software philosophy, and very few games are packaged as part of the official Guix project.

Although Guix stands for free software and doesn’t accept any proprietary rights in its repository, ironically, many advanced features make Guix an ideal package manager for non-free software.

Some of the benefits are:


For these reasons, Guix is ​​the perfect tool for packaging and distributing closed source games.

However, this is a large separate topic, which is best left for another article.

Tips and Tips


Emacs-guix


One of the amazing benefits of Guix is ​​the Emacs-Guix interface , which allows you to install and remove packages, selectively update, search, go to package definition, manage generations, print "differences" between them, and much more.

It has design modes for assembly and programming, as well as a special interactive environment Scheme REPL . This is a unique user interface for the operating system.

There is also the Helm System Packages interface, which partially overlaps with Emacs-Guix, but it seems to me more pleasant for quick package searching and quick operations.

Data storage


Since Guix saves several generations of system configurations (including the entire package history), it requires more disk space than other operating systems.

In my experience, in 2018, section 25 GB had to be cleaned about once a month (taking into account that I have large requests for the number of packages), and the section 50 GB can not be touched for a whole year.

It is convenient to use the command to clear the storage guix gc, but it can remove “too many packages”, that is, packages that will be needed immediately upon the next update.

Emacs-Guix has a command mx guix-store-dead-itemthat sorts dead packets by size and allows you to delete them individually.

If you need to analyze dependencies, look at guix gc --referencesand guix gc --requisites. This can be combined with the output result guix build ...to see the different elements of the dependency graph.

For example, to view the code for one of the build scripts, open the file returned by the following command:

 $ guix gc --references $(guix build -d coreutils) | grep builder /gnu/store/v02xky6f5rvjywd7ficzi5pyibbmk6cq-coreutils-8.29-guile-builder 

Manifest generation


It is often useful to generate a manifest of all packages installed in a profile.

This can be done using the following Guile script:

 (use-modules (guix profiles) (ice-9 match) (ice-9 pretty-print)) (match (command-line) ((_ where) (pretty-print `(specifications->manifest ',(map manifest-entry-name (manifest-entries (profile-manifest where)))))) (_ (error "Please provide the path to a Guix profile."))) 

For example, run it on the profile ~/.guix-profile:

 $ guile -s manifest-to-manifest.scm ~/.guix-profile 

My dotfiles track the history of installed packages. Since I also save the Guix version, I can return to the exact state of my system at any time in the past.

Links


Some web interfaces:


Documents:


Informal packages:

Source: https://habr.com/ru/post/436938/