lainchan / Ω
Awesome NixOS thread!
Dozer · 2023-09-27 14:39
This will be a thread dedicated to NixOS. Anything about Nix and the NixOS goes.
Q - What is NixOS?
A - NixOS is a Linux distro that is based on Nix. Nix is a package manager, a build system, and a domain-specific language.
Using Nix and NixOS gives you benefits over traditional Linux distributions:
1. Your builds are reproducible. This means that you will receive the same output from building a package as the person who released the package.
2. Binaries are cached. They are located within a unique store, and that store can be shared, eliminating the need for other machines to build the package from source.
3. Dependency hell is eliminated. Multiple versions of the same package live alongside each other, since all of their dependencies are contained to their own stores. You can install a Python2 package and unlike other distributions this won't break your system.
4. Nix store is immutable and upgrades are atomic. You update your system by making changes to the configuration file. Upgrades do not apply until you rebuild your system and create a new generation. NixOS also keeps track of old generations and old packages are not removed as long as they are referenced in the system. That means that you will be able to rollback the state of your system to any of your previous configurations, making almost impossible to break it.
5. Nix is flexible. You can have multiple profiles and environments that will each use their own set of dependencies that do not affect your system. You can set up an environment using flakes and link it to arbitrary profile (that is just a file). To remove all of the dependencies from your system it is enough to remove the profile and run the garbage collector.
6. Because your system configuration is contained to .nix files, you can save and manage your machines from a git repository, hosted anywhere. Just dropping the configuration.nix file to a new install will bring you the system to the same state as you have configured it. You can manage not only your system, but home directories too!
7. Nixpkgs is the largest repository of packages. It is larger than AUR. You can create your own packages and introduce changes to the existing ones by cloning the nixpkgs repo.
At the same time, Nix is complex and has a steep learning curve. To understand NixOS you have to understand Nix first, even though it is not necessary to understand them - you can simply pick your configuration from templates.
Relevant links:
Nix manual: https://nixos.org/manual/nix/stable/
NixOS manual: https://nixos.org/manual/nixos/stable/
Unofficial wiki: https://nixos.wiki/wiki/Main_Page
Telegram groups: @nix_org @nixos_en
Ivan Horvat · 2023-09-27 21:36
I use Linux because I like the ability to integrate my own programs with the system and Nix feels extremely awkward for doing this, when I tried it, I ended up bloating my $HOME/bin because it just felt ridiculous to write a package definition for everything I want to try that is not on nixpkgs.
>Nix is complex and has a steep learning curve.
It is not that complex, it is just hard to get used to, I probably never will. The only way I don't feel uncomfortable running a functional packaging distro is using it as a kiosk with only one main program, so it is a bretty good Emacs bootloader, 10 out of 10 in that respect.
Chan Siu Ming · 2023-09-28 05:07
>>73116
obviously it requires some work to adapt your packages to nix environment, otherwise your binary does not know where to find /usr/bin or /usr/lib. But pretty much anything can be run with the use of nix-shell or buildFHSEnv.
Neuromancer · 2023-09-28 13:11
Is there any purpose to this OS if you're not a programmer? I would consider myself a general purpose power user. At most I do some scripting.
Yu-ichi · 2023-09-28 14:08
>>73122
if you need to set up and forget, yes. If you need a desktop where you constantly change something, you won't be able to go far without learning the basics.
Koos van der Merwe · 2023-09-29 02:36
I have a difficulty running my old node projects because in new node versions they changed hashing algorithm in OpenSSL, breaking compatibility with webpack (and subsequently old modules). So you have to downgrade to last node 16 version and pass an environment variable to enable legacy OpenSSL support. I made a flake to manage my specific project without affecting my main system.
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
inputs.systems.url = "github:nix-systems/default";
outputs = {
self,
nixpkgs,
flake-utils,
systems,
}:
flake-utils.lib.eachSystem (import systems)
(system: let
pkgs = import nixpkgs {
inherit system;
};
in {
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.nodejs_16
yarn
];
};
});
}
By default, Nix will not allow me to use that flake because pkgs.nodejs_16 is insecure, so I have to explicitly declare that Nix is allowed to use that package. To do that you need to edit nixpkgs config, but instead of changing it system-wide you can simply override it for this specific flake.
pkgs = import nixpkgs {
inherit system;
config = {
permittedInsecurePackages = [ "nodejs-16.20.2" ];
};
};
Now flake works but my project will not build because yarn, as a package, declares default node as its dependency. So running yarn install will always fail as it will use node 18 to compile modules that have node 16 as their last supported version. Resolving this is fairly simple, I can override yarn package definition and force it use my own node version as its dependency.
pkgs = import nixpkgs { ... };
yarn = pkgs.yarn.overrideAttrs { buildInputs = [ pkgs.nodejs_16 ]; };
Finally, I need to add the environment variable to enable legacy OpenSSL support. In pkgs.mkShell I add:
shellHook = ''
export NODE_OPTIONS=--openssl-legacy-provider
'';
Now I run nix flake check . To drop into my custom environment I run nix develop --profile ./nix.profile . Passing --profile will record my environment into specified profile and create a symlink to the store, preventing the environment from being removed by garbage collector. When I'm done with my project and don't have to work on it anymore, I simply remove the symlink and garbage collector will remove everything associated with flake from my system. Yay :D
Tequila · 2023-09-29 07:06
>>73129
And you couldn't update webpack?
The Phantom Phreak · 2023-09-29 08:42
>>73136
no, because it breaks my project.
fsociety · 2023-10-02 12:00
>>73113
Thanks, but devs are kind of assholes that deliberately cut compability to other init systems other than sysd because "we dont have the bandwith to maintain these" (real answer to a merge request for runit&openrc support). Also isolation is reasonably unsecure and averall package quality is just one head above aur (which is not great).
For now i'm sticking with appimage & guix. Guix does not have a lot of packages, but the amount of work put into perfecting the system is heaven and earth compared to nix.
Debbie Charteris · 2023-10-02 13:25
>>73217
I have both guix and nix as foreign installs on my raspberry pi. I prefer to use nix because guix starts to compile stuff without warning, and seemingly without reason even though I have the substitutes set up. My system is slow and doesn't have excessive amounts of ram an disk space to be compiling stuff all the time. In general, I find the idea of guix better (no systemd, etc), but either I'm not using it right or it's got some things that it needs to be fixed.
Hong, Guil Dong · 2023-10-03 06:46
I've just ordered a new OVH instance and overwrote the default Ubuntu install with nixos-anywhere kexec script (github.com/nix-community/nixos-anywhere). Since configuration is defined in flakes, changes to server are made remotely. I was thinking about staying with Ubuntu, but they did something retarded again that made /etc/ssh configuration to be ignored. NixOS is awesome in that regard, since usually spinning up a new VPS requires me to enter a lot of commands in a unique order relative to distro (e.g setting up nginx, docker, configuring services, spinning up postgresql and so on), and here I can replicate the entire setup with a single command.
Mitnick · 2023-10-03 21:30
>>73122
I'd say so. Personally I use NixOS because to me the most important part of a Linux distribution is its package manager, and I didn't like how every other package manager seemed to have either ancient or bleeding-edge packages with no in-between. The replication and ability to easily rollback to previous system states is also a plus.
I will warn you though that system management on NixOS is very different from a traditional Linux system. Pretty much everything has to be done through the package manager and configuration.nix if you want the full strengths of the system, and a lot of standard instructions for how to go about installing or configuring things do not apply when using NixOS. I've had to rely mainly on the reference manual, wiki, and MyNixOS to figure out how to use the system. I am overall happy with it though; I've been capable of doing everything that I would with a normal distribution on NixOS.
Dujour · 2023-10-04 14:17
Why would you use nixOS when Guix OS exists?
John Rain · 2023-10-08 06:30
>>73276
Guix does not have even nearly the same amount of packages. Even if the distro itself is way ahead over Nix, at the end of the day most people abandon Nix because it's either too hard to do simple tasks, or they have issues with packaging/security.
SHODAN · 2023-10-08 17:42
>>73217
>Also isolation is reasonably unsecure and averall package quality is just one head above aur (which is not great).
I was going to ask itt about using Nix as a aur replacement on another distro like Tumbleweed or Debian and isolate all my gaming in a environment. Are you implying I shouldn't? Otherwise I feel like Nix and Guix immensely complicate package management with little to offer the average user. Although I do like the ieda of configuring my OS the same way as Emacs.