Skip to content
IT related

Overlays

Updated 1 min read

On this page 2 sections
  1. Nix Overlays
  2. Flake.nix

Nix Overlays

Nix overlays allow you to patch software, when Nix builds it.
i.e tell Nix to use a specific version of the software bundles with something that is maybe using an older verion and is no longer compatable.

I use Overlays to allow my NixOs 24.11 based system install packages from the unstable branch.

Flake.nix

In your flake.nix you will need to specify you default inputs for nixpkgs and the unstable version or even an older version of the nixpkgs.

inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
  nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  pkgs21.url = "github:NixOS/nixpkgs/nixos-21.11";
}

Then add them to your outputs as normal, in the let binding section of the outputs you add this:

unstable-packages = final: _prev: {
  unstable = import nixpkgs-unstable {
  system = final.system;
  config.allowUnfree = true;
  };
};
packages-21 = final: _prev: {
  pkgs-21 = import pkgs21 {
  system = final.system;
  config.allowUnfree = true;
  };
};

This tells Nix when its building that these are overlays, and they should overide the pkgs of your default nixpkgs but we have to enable them in the configuration.nix.

  # Enabling NIX Overlays.
  nixpkgs.overlays = [
    unstable-packages
    packages-21
  ];

Now that we have specified them as overlays to your current nixpkgs you can access them anywhere you install packages.

environment.systemPackages = with pkgs; [
   wget
   rsync
   unstable.docker
   pkgs-21.vlc
]

For example by prepending unstable I get the newest version of docker, and by using pkgs-21 I get an older version.
The is alot more complicated stuff you can do with Overlays, like patching other softwares when you build them from source but I'm not going into that.

IT related RSS feed Published with Oblish

Keyboard shortcuts

/
Search
[
Previous page
]
Next page
?
Show this list
Esc
Close