Hi. One of the first things that amazes me about Nixos is how convenient it is to manage packages from a .nix file. But this is restricted only to the super user. To install my personal packages, packages that would not make sense to be available in the whole system, I have to use nix-env in the terminal, and itβs a pain in the ass when there are many packages.
It would be great to have something like enviroment.userPackages; with pkgs; [];
It would also be great to have something nixos-rebuild for normal users.
It replaces nix-env with a thing, that supports 3 commands: install, uninstall and list.
$ nix-env list
nixpkgs.htop
$ nix-env uninstall calibre
Not installed
$ nix-env install calibre
scheduled install'n'update
error: undefined variable 'calibre' at /home/danbst/.config/nixpkgs/declarative-env.nix:7:1
$ nix-env install nixpkgs.calibre
scheduled install'n'update
replacing old 'declarative-collection'
installing 'declarative-collection'
building '/nix/store/2cnhxqwxl79qj81mfkrqpl7xr361i3z1-user-environment.drv'...
created 5054 symlinks in user environment
Success
$ nix-env install '(nixpkgs.htop.overrideAttrs (_: { name = "my-override"; }))'
scheduled install'n'update
replacing old 'declarative-collection'
installing 'declarative-collection'
these derivations will be built:
/nix/store/fbggzpbs91ryysmdzc131vvkg8vm14yz-declarative-collection.drv
building '/nix/store/fbggzpbs91ryysmdzc131vvkg8vm14yz-declarative-collection.drv'...
building '/nix/store/wpb2w7vj3cq4lsl1syac7lhndahqc64r-user-environment.drv'...
created 5054 symlinks in user environment
Success
$ nix-env list
nixpkgs.calibre
(nixpkgs.htop.overrideAttrs (_: { name = "my-override"; }))
# Original nix-env is available as \nix-env
There are 3 distinctions from nix-env here (besides completely new CLI):
packages are identified by their attribute, instead of βnameβ. Just like in nix 2.0
it saves itβs installed packages state in simple format: line per package (original nix-env builds a maniphest.nix with lots of metadata, but most importantly, it doesnβt save attribute name in maniphest)
as a buildEnv wrapper, it maintains consistency among all installed pacakges (can upgrade/downgrade some unrelated package). Same behavior as for nixos-rebuild
In fact, nix-env list is an alias to cat ~/.config/nixpkgs/declarative. This list is used to build env:
Thanks for the info, but the ways you show me are from third parties. They are not official. I imagined that there would be a way similar to how some packages can be configured in .nixpkgs / conf.nix.
I think the best thing will be that or report as a suggestion on Github.
I use the -f and -r flags of nix-env , along with a custom configuration file, for this purpose.
I have a file, ~/.config/nixpkgs/packages.nix, with contents like the following:
{ pkgs ? import <nixos> {}}:
with pkgs;
{
# Packages go here
}
I then run nix-env -irf ~/.config/nixpkgs/packages.nix to make my profile match what is declared in that file. I leave it to you decide which set of tradeoffs you think are worthwhile.
Thanks for the info, but the ways you show me are from third parties. They are not official.
Welcome to Nix.
The βthird partiesβ are often the same people who make NixOS, and a lot of tools that are integral to Nixpkgs donβt live in the NixOS organisation. Itβs just the way things are. Often thereβs no βofficialβ way because thereβs no point β somebody else has already addressed the need.
Overlays are similar to other methods for customizing Nixpkgs, in particular the packageOverrides attribute described in Section 6.5, βModify packages via packageOverrides β. Indeed, packageOverrides acts as an overlay with only the super argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute.
Would love to hear similar insights into the Nix flakes proposal; Iβve seen a lot of activity on Github around it, but most are over my head yet.