this post was submitted on 19 Jun 2023
38 points (95.2% liked)

Linux

47232 readers
796 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Hi everyone!

I saw that NixOS is getting popularity recently. I really have no idea why and how this OS works. Can you guys help me understanding all of this ?

Thanks !

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 1 year ago (1 children)

A simple bash script is not reproducible or deterministic. Also a filesystem rollback is not the same as NixOS's generation based rollback.

Also, NixOS doesn't just install packages, all system configuration is done declaratively, which would be a very bad idea to do via a bash script.

[–] [email protected] 0 points 1 year ago* (last edited 1 year ago) (1 children)

I have to check a little harder on what it does since I saw in a vid that you still needed to add your own if statement to get it working I assumed a simple

pacman -Qk xorg-xrtrop 2> /dev/null && sudo pacman --noconfirm -S package1 package2 package3 || echo 'I aint got no x, idiot'

would do the job as well

[–] [email protected] 1 points 1 year ago

I'd recommend reading some more; especially w.r.t. imperative vs. declarative.

In NixOS, you'd do something like this:

{ config, ... }:

{
  environment.systemPackages = if config.services.xserver.enabled then [
    package1
    package2
    package3
  ] else [
    # You could optionally make headless packages available here
  ];
}

You don't need to understand the exact semantics here but you can look at it like JSON but with functions. This is not a "program", the end-result is just data. You're not modifying some stateful system state with new state from an uncontrolled source (i.e. the Arch repos) but rather just "outputting" a different dataset.
NixOS then builds a concrete system out of this pure data specification. In this concrete system, those packages' executables are available in the "global" PATH.

You say "I want a system where x y z are installed" and it does it for you in a standardised manner. With the bash script, you explicitly tell it each step ("install x; install y; install z"). This pure data nature is what's meant by declarative.
This distinction rules out whole classes of issues you simply cannot run into with NixOS.

Another aspect is that, as long as you use the same revision of Nixpkgs and the same config file, you can re-create the exact same system (almost bit-for-bit). If you were to run your bash script in a year's time however, you'd get an entirely different system with totally different revisions of software and therefore possibly entirely different behaviour.
This is what's meant by reproducibility.

You can achieve some of the same things NixOS does using imperative tools but nowhere near the same quality.