NixOS - Add Unstable Channel Packages and Services to Configuration


Some packages are lagging behind within the default channel of NixOS. Then it is nice to have the option to use a newer package from the unstable channel.

Below is an excellent solution describing how to add the unstable channel declaratively to the configuration. For example, I used this solution for Cockpit.

I also described how you can use the unstable channel for services. That way, for example, you could make use of options that were only available via the unstable channel. As an example, I’ll use the Ollama service.

Configuration (Unstable Channel Packages)

Open configuration.nix:

sudo nano /etc/nixos/configuration.nix

Adjust the configuration like this:

{ config, pkgs, ... }:

let
# add unstable channel declaratively
  unstableTarball =
    fetchTarball
      https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz;
in
{
  imports =
  [ # include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  nixpkgs.config = {
    packageOverrides = pkgs: {
      unstable = import unstableTarball {
        config = config.nixpkgs.config;
      };
    };
  };

  # use unstable if you want to use the package from the unstable channel
  environment.systemPackages = with pkgs; [
     wget
     htop
     curl
     # examples from the unstable channel
     unstable.cockpit
     unstable.quickemu
     unstable.quickgui
  ];

  # add the rest of the configuration here

}

Save the changes to configuration.nix.

Configuration (Unstable Channel Packages and Services)

If you also want to be able to use services via the unstable channel, you can add the following to the configuration. The unstableTarball is used again.

Open configuration.nix:

sudo nano /etc/nixos/configuration.nix

Adjust the configuration like this:

{ config, pkgs, ... }:

let
# add unstable channel declaratively
  unstableTarball =
    fetchTarball
      https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz;
in
{
  disabledModules = [ "services/misc/ollama.nix" ]; # disable the stable channel version
   # you can find the path to the service and nix file here: https://github.com/NixOS/nixpkgs/tree/656a024f9187fcfc8e5ca81a9c3f370af52e0776/nixos/modules/services 

  imports =
  [ # include the results of the hardware scan.
    ./hardware-configuration.nix
    (unstableTarball + "/nixos/modules/services/misc/ollama.nix")
  ];

  nixpkgs.config = {
    packageOverrides = pkgs: {
      unstable = import unstableTarball {
        config = config.nixpkgs.config;
      };
    };
  };

  # use unstable if you want to use the package from the unstable channel
  environment.systemPackages = with pkgs; [
     wget
     htop
     curl
     # examples from the unstable channel
     unstable.cockpit
     unstable.quickemu
     unstable.quickgui
  ];

  # add the service with options from the unstable channel
  services = {
    ollama = {
      enable = true;
      acceleration = "cuda"; # Or rocm
      package = pkgs.unstable.ollama; # also use the package from the unstable channel!
    };
  };
  
  # add the rest of the configuration here

}

Save the changes to configuration.nix.

Switch Configuration

Now you can switch to the new configuration:

sudo nix-collect-garbage # optional: clean up
sudo nixos-rebuild switch

Here you can find more information about updating and upgrading NixOS. You can view my server configuration.nix here.


Read other notes

Comments

    No comments found for this note.

    Join the discussion for this note on this ticket. Comments appear on this page instantly.

    Tags


    Notes mentioning this note

    • NixOS - Cockpit Setup
      Cockpit is a modern web-based graphical interface for servers. You can use it to administer servers and it has a...

    Notes Graph