GeistHaus
log in · sign up

NixOS is magic

sharphall.org

I’ve been using NixOS recently on my laptop, because I know how great declarative configuration is from my experience deploying software on servers with tools like Kubernetes and Terraform. Along the way, I’ve had a few experiences with it that have left me impressed with how powerful a declarative approach to the configuration of my personal computers can be. Declarative vs imperative If you’ve used any electronic device that you can install software on, you are already aware of the imperative approach to device configuration. If a piece of software doesn’t exist on your machine and you want it to, you run an installer or tell the package manager to install it: apt-get install -y neovim A problem with installing packages this way is that over time you may build a collection of software with incompatible versions of dependencies. You might want to upgrade all the software on your machine, but you don’t have any guarantee that the upgrade will succeed. And if you do break something, the only way to fix it might be to reinstall. You might even want to reinstall every couple years anyways to start fresh. NixOS lets you define the configuration of your system declaratively. The software you want to be installed on your system is listed (or enabled) in a config file — configuration.nix — and after you add new software to this file, you tell NixOS to rebuild your entire system by running nixos-rebuild switch. { config, pkgs, ... }: { # ... programs.thunderbird.enable = true; programs.fish.enable = true; users.defaultUserShell = pkgs.fish; programs.neovim = { enable = true; defaultEditor = true; }; # Allow unfree packages nixpkgs.config.allowUnfree = true; # List packages installed in system profile. To search, run: # $ nix search wget environment.systemPackages = with pkgs; [ # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. wget ]; } Every time you rebuild your system, Nix “evaluates” all the packages you’ve c

0 pages link to this URL

No pages have linked to this URL yet.