bartman's blog

nixos package overlay

bartman
Table of Contents

I’m running NixOS as my desktop, and I want to include a package, that is now newer in git than what’s published with the stable release of NixOS (25.04).

This can be done with overlays.

the setup #

Specifically I want to use my changes to mtr. Changes are available on github bartman/mtr’s master branch.

While this is available in the official upstream also, I decided to use my branch just in case I keep mucking with it.

I already have mtr packages installed in my config…

1  environment.systemPackages = with pkgs; [
2    mtr
3  ];

getting the hash #

Nix wants a SHA-256 hash of the code we want to use for integrity and reproducibility. We can obtain it using nix-prefetch-git

1❯ nix-prefetch-git https://github.com/bartman/mtr.git HEAD

and you’ll see something like:

1  "sha256": "0lr3kq5vma4wjbspbnh2jpcv3vkhdi57023nv46yfz8f3n83l408",

in the output (obviously if you use a different package, your hash will be different).

NOTE: if you don’t have nix-prefetch-git installed, you can also run…

1❯ nix run nixpkgs#nix-prefetch-git -- https://github.com/bartman/mtr.git HEAD

adding the overlay #

The overlay itself looks like this:

 1  nixpkgs.overlays = [
 2    (self: super: {
 3      mtr = super.mtr.overrideAttrs (oldAttrs: {
 4        src = super.fetchFromGitHub {
 5          owner = "bartman";
 6          repo = "mtr";
 7          rev = "master";
 8          sha256 = "0lr3kq5vma4wjbspbnh2jpcv3vkhdi57023nv46yfz8f3n83l408";
 9        };
10        patches = [];
11      });
12    })
13  ];

The key parts are:

Then just nixos-rebuild as usual, and you’re up and running with your overlay.

Tags:
Categories: