this post was submitted on 16 Oct 2023
208 points (97.3% liked)
Linux
48397 readers
1017 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
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
NixOS for declarative system configuration.
Nix is definitely gaining popularity quick too
I still have no idea what it actually is and at this point I'm afraid to ask, cause the answers usually contain the words "declarative", "atomic", "Haskell" "build environment" and "/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-118.0/"
It all began with Nix software build system and package manager; they needee a way to build, compile software in a reproducible way. That is, if it builds on my machine, it should build on yours too given some constraints. Then they build a whole package repository for such sofware or package definitions, Nixpkgs, that can be build or retrieved using Nix package manager. Nixpkgs grew to be a repository for enabling runnig an GNU Linux OS on it: NixOS. It is declarative in the sense you write what it should contain like packages and behaves like system services. For example, see https://git.sr.ht/~misterio/nix-config.
Atomic in the sense that when you want to change system's configuration or state, everything should suceed in that update, otherwise fails; it is everything or nothing. This enables storing previous and current system revisions, so can rollback to previous state.
Nix plus things like flakes, nix shell, enables a build inviroment akin to containers, but much better, correct, and flexible.
Haskell is just an ecossytem Nixpkgs support.
Cool, thanks.
Is NixOS a general purpose distro, a specialized tool for developers, a toy for distro-hoppers or an unfinished proof-of-concept?
Can it be run like any other Linux desktop system apart from the package manager?
How do you install packages that aren't in its repo?
NixOS is a general purpose distro (I use it on my router, server and laptop, and plan to install it on my phone, it doesn't get any more general purpose). To run packages that aren't in its repo, you write a package yourself. Note that unlike on traditional Linux systems, there's essentially no concept of "installing" packages. Packages are built and put into /nix/store, then you can optionally add them to your system packages or user packages and they will be symlinked to /run/current-system/sw or ~/.nix-profile, but there's nothing preventing you from just using the package without adding it to system/user packages.
Basically all that. The unfinished part IMO is mostly for use in developer use cases, and that some ecosystems like JVM are not as well supported.
Can run yes, given that you have to spend some time learning Nix and NixOS specifics. I do that myself.
You either package the software if it is easy to do so—take a look a at nix-init which eases the process—or use Flatpack, containers, steam-run...
I like that, I'd describe the documentation as a POC. It fits.
May I ask what does .nix files do? I have joined unixporn community,and when I look into the dotfiles of some nix os user,their config are all written in nix rather than .conf or some other prevalent files. Should I learn nix if I want to use nix os? Or can I config my apps such as waybar in a way just like other systems (such as arch)?
Nix files are Nix [function] expressions to declare and set your system; there are many options you can set for example. You just need to learn a few chapters of https://nixcloud.io/tour/ and https://nixos.org/manual/nix/stable/language/, also modularization using imports.
For user/de configuration, you can either do the usual way or use home-manager.
You should have some understanding of the nix language to use it, but I wouldn't worry too too much.
I would also start by installing nix and home-manager on top of whatever distro you already use. For some config, you need to specify things in nix, but for things in home-manager, for example, you can usually either use nix or point to a toml or conf or whatever file.
I prefer to come at it from an immediate utility level, and I think a good place to start with that is home-manager.
You can install nix and home-manager on any Linux distribution or MacOs. It lets you, in a single place, specify what packages you want, services you want to run at the user level, and what config files you want in your home directory. For a lot of things, home-manager has built-in config options, but you can also specify arbitrary config files.
Then, you can take this one file to a new computer, and with no other config, have everything set-up the way you like it.
NixOs allows you to do this for your whole system.
It also has a bunch of other benefits, which tie-in to the jargon you bring up. But if you want to check it out, I'd worry about that later.
NixOS uses a naming convention for packages that keeps them all separate from each other, that's how you get
/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-118.0/
./usr
isn't used for packages and only contains/usr/bin/env
for compatibility, nothing else.The whole system is held together by nothing more than shell scripts, symlinks and environment variables, standard Unix stuff. Making it very easy to understand if you are already familiar with Linux.
"Declarative" means that you whole configuration happens in one Nix config file. You don't edit files in
/etc/
directly, you write your settings in/etc/nixos/configuration.nix
and all the other files are generated from there. Same is true for package installation, you add your packages to a text file and rebuild.If that sounds a little cumbersome, that's correct, but Nix has some very nice ways around that. Due to everything being nicely isolated from each other, you do not have to install software to use them, you can just run them directly, e.g.:
nix run nixpkgs#emacs
You can even run them directly from a Git repository if that repository contains a
flake.nix
file:nix run github:ggerganov/llama.cpp
All the dependencies will be downloaded and build in the background and garbage collected when they haven't been used in a while. This makes it very easy to switch between versions, run older versions for testing and all that and you don't have to worry about leaving garbage behind or accidentally breaking your distribution.
The downside of all this is that some proprietary third party software can be a problem, as they might expect files to be in
/usr
that aren't there. NixOS has ways around that (BuildFHSEnv
), but it is quite a bit more involved than just running asetup.sh
and hoping for the best.The upside is that you can install the Nix package manager on your current distribution and play around with it. You don't need to use the full NixOS to get started.
Step 1. Write down all the packages you want in a list, configure all of your system with predefined config options Step 2. Rebuild Step 3. Use packages
Step 4. Configure more settings and install more packages Step 5. Realise you broke everything Step 6. Boot previous version of config and continue with your life
Also makes configuring your system far simpler
Installing gnome is as simple as putting
In your config file and then doing nixos-rebuild switch