The NixOS cheatsheet describes how to install packages from unstable
in configuration.nix
.
It starts off by saying to add the unstable channel like so:
$ sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ sudo nix-channel --update
Then, it is easy to use this channel in configuration.nix
(since it should now be on NIX_PATH
):
nixpkgs.config = {
allowUnfree = true;
packageOverrides = pkgs: {
unstable = import <nixos-unstable> {
config = config.nixpkgs.config;
};
};
};
environment = {
systemPackages = with pkgs; [
unstable.google-chrome
];
};
I would like to not have to do the manual nix-channel --add
and nix-channel --update
steps.
I would like to be able to install my system from configuration.nix
without first having to run the nix-channel --add
and nix-channel --update
steps.
Is there a way to automate this from configuration.nix
?
Declarative Configuration This configuration file is normally located at /etc/nixos/configuration. nix (although another location may be specified using the environment variable NIX_PATH ); after the configuration file is modified, the new configuration is then made active by running nixos-rebuild switch .
The official channelsStable channels ( nixos-22.05 ) provide conservative updates for fixing bugs and security vulnerabilities, but do not receive major updates after initial release. New stable channels are released every six months.
I was able to get this working with a suggestion by @EmmanuelRosa.
Here are the relevant parts of my /etc/nixos/configuration.nix
:
{ config, pkgs, ... }:
let
unstableTarball =
fetchTarball
https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz;
in
{
imports =
[ # Include the results of the hardware scan.
/etc/nixos/hardware-configuration.nix
];
nixpkgs.config = {
packageOverrides = pkgs: {
unstable = import unstableTarball {
config = config.nixpkgs.config;
};
};
};
...
};
This adds an unstable
derivative that can be used in environment.systemPackages
.
Here is an example of using it to install the htop
package from nixos-unstable:
environment.systemPackages = with pkgs; [
...
unstable.htop
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With