salt.modules.nix

Work with Nix packages

New in version 2017.7.0.

Does not require the machine to be Nixos, just have Nix installed and available to use for the user running this command. Their profile must be located in their home, under $HOME/.nix-profile/, and the nix store, unless specially set up, should be in /nix. To easily use this with multiple users or a root user, set up the nix-daemon.

This module exposes most of the common nix operations. Currently not meant to be run as a pkg module, but explicitly as nix.*.

For more information on nix, see the nix documentation.

salt.modules.nix.collect_garbage()

Completely removed all currently 'uninstalled' packages in the nix store.

Tells the user how many store paths were removed and how much space was freed.

Returns:

How much space was freed and how many derivations were removed

Return type:

str

Warning

This is a destructive action on the nix store.

salt '*' nix.collect_garbage
salt.modules.nix.install(*pkgs, **kwargs)

Installs a single or multiple packages via nix

Parameters:
  • pkgs (list(str)) -- packages to update

  • attributes (bool) -- Pass the list of packages or single package as attribues, not package names. default: False

Returns:

Installed packages. Example element: gcc-3.3.2

Return type:

list(str)

salt '*' nix.install package [package2 ...]
salt '*' nix.install attributes=True attr.name [attr.name2 ...]
salt.modules.nix.list_pkgs(installed=True, attributes=True)

Lists installed packages. Due to how nix works, it defaults to just doing a nix-env -q.

Parameters:
  • installed (bool) -- list only installed packages. This can be a very long list (12,000+ elements), so caution is advised. Default: True

  • attributes (bool) -- show the attributes of the packages when listing all packages. Default: True

Returns:

Packages installed or available, along with their attributes.

Return type:

list(list(str))

salt '*' nix.list_pkgs
salt '*' nix.list_pkgs installed=False
salt.modules.nix.uninstall(*pkgs)

Erases a package from the current nix profile. Nix uninstalls work differently than other package managers, and the symlinks in the profile are removed, while the actual package remains. There is also a nix.purge function, to clear the package cache of unused packages.

Parameters:

pkgs (list(str)) -- List, single package to uninstall

Returns:

Packages that have been uninstalled

Return type:

list(str)

salt '*' nix.uninstall pkg1 [pkg2 ...]
salt.modules.nix.upgrade(*pkgs)

Runs an update operation on the specified packages, or all packages if none is specified.

Parameters:

pkgs (list(str)) -- List of packages to update

Returns:

The upgraded packages. Example element: ['libxslt-1.1.0', 'libxslt-1.1.10']

Return type:

list(tuple(str, str))

salt '*' nix.update
salt '*' nix.update pkgs=one,two