FAQ: Difference between revisions

imported>Jtojnar
avoid deprecated github:NixOS/nixpkgs-channels
imported>Symphorien
mention overlays to change the version of packages used by nixos modules
Line 317: Line 317:


== How can I install a package from unstable while remaining on the stable channel? ==
== How can I install a package from unstable while remaining on the stable channel? ==
''Note: This may temporarily not work because of [https://github.com/NixOS/nix/issues/1865 nix#1865]''


If you simply want to run a ''nix-shell'' with a package from unstable, you can run a command like the following:
If you simply want to run a ''nix-shell'' with a package from unstable, you can run a command like the following:
Line 330: Line 328:


<syntaxhighlight lang="bash">sudo nix-channel --update nixos-unstable</syntaxhighlight>
<syntaxhighlight lang="bash">sudo nix-channel --update nixos-unstable</syntaxhighlight>
queries via <code>nix-env</code> (or <code>nox</code>) will show packages from both ''stable'' and ''unstable''. Use this to install unstable packages into your user environment. The following snippet shows how this can be done in ''configuration.nix''.
queries via <code>nix-env</code> will show packages from both ''stable'' and ''unstable''. Use this to install unstable packages into your user environment. The following snippet shows how this can be done in ''configuration.nix''.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 340: Line 338:
}
}
</syntaxhighlight>
</syntaxhighlight>
This only changes what version of <code>PACKAGE_NAME</code> is available on <code>$PATH</code>. If the package you want to take from unstable is installed through a NixOS module, you must use [[overlays]]:
<syntaxhighlight lang="nix">
{ config, pkgs, ... }:
let
  unstable = import <nixos-unstable> {};
in {
  nixpkgs.overlays = [
    (self: super: {
      PACKAGE_NAME = unstable.PACKAGE_NAME;
    })
  ];
}
</syntaxhighlight>
Note that this will rebuild all packages depending on the overlaid package, which may be a lot. Some modules offer a <code>services.foo.package</code> to change the actual derivation used by the module without and overlay, and without recompiling dependencies ([https://nixos.org/manual/nixos/stable/options.html#opt-services.gvfs.package example]).


If you want to install unfree packages from unstable you need to also set allowUnfree by replacing the import statment above with:
If you want to install unfree packages from unstable you need to also set allowUnfree by replacing the import statment above with: