Skip to content
/ nux Public

a "more declarative" alternative to nix-env

Notifications You must be signed in to change notification settings

timor/nux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

Description

DISCLAIMER: This is an early version with “works for me” status. If something should go wrong, it can be fixed using nix’s supplied commands. The code is adapted from https://gist.github.com/danbst/f07d9760ed15dd844e141177cf7dd478 You might want to keep a copy of your favorite list of packages somewhere…

The main difference compared to nix-env behavior is that packages are identified by their attribute names in the same package set that is available to the NixOS installation (default) This makes package update semantics identical to nixos-rebuild.

Also, depending on how an attribute is specified, it will either refer to a named path from NIX_PATH, or the package set of the NixOS system. The latter enables keeping up with the exact same packages that the OS would install, taking into account any system-wide overlays and other modifications to the package set. Note that currently, the validity of a variable is determined by the presence of a flake.nix file.

Note that the installed package collection is handled by nix-env underneath. This has the following consequences:

  • Calling nux creates a new generation of ~/.nix-profile.
  • nix-env -u will not upgrade packages installed with nux.
  • nix-env --rollback removes the new packages installed by nux from the current user environment, but not from the list of packages handled by nux.
  • Packages that are installed with nix-env -i and nux can collide.

nux builds and keeps track of packages in its own profile, which resides in $NIX_USER_PROFILE_DIR/nux. All nux commands use the package list of the most recent version of this profile as a basis. This profile can of course be rolled back by specifying it as an argument to nix-env -p --rollback..., which effectively resets the base list for the next nux command to that of the rolled-back-to generation.

The packages are always taken from the current channel generations. This has the following consequences:

  • nux install always includes a nux update

This results in semantics that lie somewhere between environment.systemPackages and nix-env. The intention is to make it easier to keep user-wide installed packages defined by the OS up-to-date.

Installation

There are 2 ways to install nux:

  1. Globally in NixOS with environment.systemPackages
  2. Locally per user with nix-shell -p nux --run 'nux install nixpkgs.nux'

Note that the second method ensures that nux itself is not prone to the problems of nix-env. If NIX_PATH does not contain an entry nixpkgs, the command must be adjusted accordingly.

You can also just simply download the nux script here, make it executable and run it.

Usage

Options

-f file
read list of package attributes from file (not affected by -p)
-p nixPath
prefix subsequent attributes with nixPath
-n, --dry-run
don’t actually install anything
--state-file file
(advanced) supply a custom nux-package-list file

Commands

The commands that take a list of package attributes (currently ‘install’ and ‘uninstall’) can be combined with the -p <entry-in-NIX_PATH> and -f path-to-package-list-file command line options. The -p option applies to all following package names, and adds the given argument in front of the dot, i.e. the top-level path entry in NIX_PATH. So the following two lines are equivalent:

nux install nixpkgs.hello nixpkgs.htop nixpkgs.zsh foo.mc

nux install nixpkgs.hello -p nixpkgs htop zsh -p foo mc

Note that this is different from supplying no prefix at all, which will use the package set currently installed by NixOS.

nux install htop zsh foo mc

If supplied to -f, that file is interpreted as one attribute per line (not affected by -p).

Installing packages

nux install <pkg>...

Note that <pkg> takes the same form as the results returned by nix search.

Aliases: add

Showing installed packages

nux list

Removing packages

nux uninstall <pkg>...

Aliases: remove, delete

Updating packages

nux update

Known Issues

  • Can not automatically deal with attributes becoming unavailable in pkgs collection. Does fail loudly though.
  • Can not automatically deal with renamed/missing paths in NIX_PATH, same as above
  • To recover from the above, copy ~/.config/nixpkgs/nux-package-list somewhere else, edit it and run nux update --state-file <edited-file>.
  • No Duplicate detection, as two attributes from different pkgs collections count as different packages. If they differ, they will collide, which is expected, and if they have the same hash, they will only be installed once. But if one of them is removed, the package will still not be uninstalled, since the other attribute remains in the list.
  • running nux update always generates a new generation at the moment, even if no packages have changed

Things to improve

  • Give details about packages being newly installed
  • Provide rollback command
  • add some tests

About

a "more declarative" alternative to nix-env

Resources

Stars

Watchers

Forks

Packages

No packages published