NixOS for the confused – Part √2
Previously, on NixOS for the confused: We created a basic flake.nix
file, did some home-manager
things, and tweaked the configuration.nix
a little. This part is a very brief intro to nixpkgs
.
No better place to start than the NixOS package search. The Nix packages repository contains more than 80 fucking thousand packages, and, chances are you will find what you need there. The same page will let you search for options (more on this in a bit), and, to a certain extent, Flakes. Let’s focus on the packages, though.
Little sidebar: If you user DuckDuckGo as your search engine, you might want to get acquainted with the !Bangs shortcuts. There’s one for NixOS Packages. Let us give it a spin! In your search box, type
!nixpkgs neofetch
and see what happens.
Assuming you either DuckDuckGo’d your way to the Nix Packages search or just went to the page and searched there, you should see something like this:
This tells you that, yes, neofetch
is available as a Nix package. Not only that, it shows you what comes out of the package (the neofetch
binary, as shown under “Programs provided”), what kind of platforms you can run this particular package on (ARM64 Linux, ARM64 Mac, x86 Linux, x86 Mac, and i686 Linux). Yes, you can Nixify your macOS, too. That’s a story for another time, though.
More importantly, it tells you how to install it via nix-env
, NixOS Configuration, and nix-shell
. In other words: you can install it “by hand” via nix-env
(we don’t like that), by adding neofetch
to your configuration.nix
(better), or by spawning a nix-shell with neofetch (good for stuff you only need to run a couple of times), respectively.
Crucially, though, it doesn’t mention the more “modern” way of spawning a shell with neofetch
via nix shell
(yes, without the –) , nor does it tell us how to install neofetch
via home-manager
. Let’s try the former. Go to your terminal, and just nix shell nixpkgs\#neofetch
. You should be able to run neofetch
now. Functionally, using nix-shell -p neofetch
will do about the same thing, but the non-hyphenated variant is a Flakes-fied version of the hyphenated one. If you don’t have experimental-features = "nix-command flakes";
in your configuration.nix
, you won’t have the option to use nix shell
unless you enable it temporarily with export NIX_CONFIG="experimental-features = nix-command flakes"
. So, to recap: if you have Flakes enabled, use nix shell
. If you don’t, use nix-shell
.
This way of “installing” software is good in some occasions. Maybe you just want to run neofetch
and htop
to take a screenshot and submit to /r/unixporn. Maybe you just need to test something. This temporary shells are good because the package will be gone the second you Ctrl+D
out of the shell.
What if we want neofetch
to stick around, though? We can go the chaotic evil route and nix-env -iA nixos.neofetch
, which will get the job done, but will do so by breaking every rule we're trying to follow here: adding shit by hand like this will kill our reproducibility, making you no better than the average barbarian Ubuntu user. We can do better. Be best! We can:
- Add it to our
configuration.nix
Simply open our flakies/nixos/configuration.nix
file and add neofetch
to the environment.systemPackages
list, thusly:
environment.systemPackages = with pkgs; [
neofetch
];
This environment.systemPackages
line should be there already. Just add whatever packages you want, and those will be installed across the board, system-wide, for everyone.
After you add neofetch
to the list, simply sudo nixos-rebuild switch --flake .#luffy
and you'll have neofetch
installed.
- You can also get home-manager to install that for you.
Go to the flakies/home-manager/home.nix
file, add neofetch
to that line with fzf
, bat
, ripgrep
, etc, like so:
home.packages = with pkgs; [
neofetch
bat
fzf
ripgrep
jq
tree
exa
];
Rebuild with home-manager switch --flake .#monkeyd@luffy
, and you're off to the races.
As a matter of personal hygiene, run nix-collect-garbage
to get rid of the trash you've accumulated so far.
You may have noticed that home-manager
does not need sudo
, whereas nixos-rebuild
does. That's a pretty good hint to leave the configuration.nix
file the fuck alone unless absolutely necessary.
Next! We'll get our graphic interface going. No Gnome or KDE. We're going tiling window managers.