I'm new to NixOS and trying to learn its concepts. One of the reasons I'm excited about it is I'm hoping it will be able to give me a reproducible system configuration, similar to using Ansible for localhost. However, I am not sure how to achieve this.
I am aware of environment.systemPackages
in /etc/nixos/configuration.nix
, but these are system-wide packages only. I also know that the nix-env
command can install a package for a user, but I'd rather declare such a package in a file that I can check into source control.
Is there a particular file I can configure (similar to a playbook) where I could declare a set of packages for a user? Or at least specify its "user environment" or "profiles" (not sure which term is correct)?
Ideally I could take a few files, copy them to another computer, run a command, and it's at the same state as the old computer, including multiple users with different sets of packages.
Finally, does my use case mean that I should never use nix-env
to install packages?
So I asked the folks on the Freenode #nixos IRC channel, and they led me to this answer.
I need to create a
~/.nixpkgs/config.nix
file. In that file, I need to create a package collection using the buildEnv function and install it withnix-env
.Installing ad-hoc packages using
nix-env
does not update~/.nixpkgs/config.nix
, so for my use case I would want to avoid doing that. Although, it is worth noting that installing ad-hoc packages usingnix-env
is still useful for experimentation since installing the package collection using the--remove-all
switch would remove everything not in that package collection.