This is one way of managing your user profile declaratively.
Alternatives include:
- an attrset-based
nix-env
-based environment, installed usingnix-env -ir
rather thannix-env --set
. LnL has an overlay which shows a way of doing this. - home-manager, which provides NixOS-like config for your
$HOME
Note that this is incompatible with regular imperative use of nix-env
, e.g. nix-env -iA nixpkgs.hello
. It has the advantage of allowing the installation of multiple outputs of the same package much better than nix-env
's builtin profile builder does.
I personally currently use home-manager.
- buildEnv ✔️
- buildEnv takes responsibility for the entire user profile, meaning that nix's builtin env builder cannot modify it
- attrset ❌
- the attrset approach leaves building the profile up to
nix-env
, which allows adding packages ad-hoc (though they will be removed on the next profile build) usingnix-env -i
- the attrset approach leaves building the profile up to
- home-manager ❌
- home-manager installs a single
buildEnv
into the user profile, remaining compatible with imperative/impurenix-env
- home-manager installs a single
- buildEnv ❌
- attrset ❌
- home-manager ✔️
- buildEnv ❌
- attrset ❌
- home-manager ✔️
- buildEnv ✔️
- attrset ❌
- home-manager ❓
@rendaw thanks for the hint, I left that
with xfce;
in by accident.Re. just
~
being enough: as documented for the --file option at https://nixos.org/nix/manual/#common-options, if nix is given a directory it will look fordefault.nix
inside. As the comment saying you can put it anywhere says, you need to adjust theupdate-profile
script to pass the new path if you do put it elsewhere.Re.
~
making sense at all: ifdefault.nix
exists, nix will not touch any subdirectories.Re.
.nix-defexpr
: that command is indeed quite pretty! The mechanism is awful though,nix-env
is the only nix command that uses it and the search behaviour can be rather unexpected. This is why things like these profile management tools exist in the first place, because nix-env doesn't do a very good job by itself… Anyway, don't let my opinion that nix-defexpr shouldn't exist stop you from using it ;)