How to create an overlay to modify failed sources with working ones

Hello, Nixers!

I reinstalled my NixOS two weeks ago, more or less. Now it is 19.03.172392.6d7ed964296 (Koi).

Today I modified some parameters, in order to add gparted to system packages. And now it complains with some sources not being found anymore:

exporting https://svn.unix-ag.uni-kl.de/vpnc (r550) into /nix/store/0x4jdm1dhb593bpgazqclg7np5mb9yp2-vpnc-r550

svn: E170013: Unable to connect to a repository at URL 'https://svn.unix-ag.uni-kl.de/vpnc'
svn: E000110: Error running context: Connection timed out

I have found a working (?) source at Github: GitHub - streambinder/vpnc: IPsec (Cisco/Juniper) VPN concentrator client (it is recommended at ArchLinux, btw).

So, I ask: how can I create an overlay to be read by nixos-rebuild switch in order to fix that issue?

(Of course, I know that the best way is a patch to Nixpkgs source tree, but for now I just want a quick&dirty fixup…)

Do you need help to define an overlay, or to use the said overlay system-wide ?

As an example, here is an overlay that I use for factorio, to get the exact version needed (it also changes the version and the name).

self: super:
{
  factorio = super.factorio.overrideAttrs (oldAttrs: rec {
    version = "0.17.4";
    name = "factorio-${version}";
    src = super.fetchurl {
      url = null;
      name = "factorio_alpha_x64_0.17.4.tar.xz";
      sha256 = "408a8fff6a87bfb48da4a4054cba10a868ee3339938c4a6ac3aca13a1545d93f";
    };
  });

}

Now, to make nixos-rebuild use your overlay, the simplest way is to put it in the nixpkgs.overlays config option. There is a literal example in the linked option documentation, but you can also import it from a standalone file like this

nixpkgs.overlays = [ (import /path/to/your/overlay.nix) ];

Hope this helps,

– Layus

4 Likes

Just the thing I needed! Thanks!

(Well, my use case is a bit worse, because I need to change the full recipe, but your skeleton is perfect nonetheless!)

EDIT: Here is my solution!

# File configuration.nix
nixpkgs.overlays = [
  (import ./overlays/source-fixups)
];

# File overlays/source-fixups/default.nix
self: super:
{
  neo = super.callPackage ./neo { };
}

# File overlays/source-fixups/neo/default.nix
{ stdenv, fetchurl }:

stdenv.mkDerivation rec {
  name = "neo-${version}";
  version = "unstable-2018-09-04";

  src = fetchurl {
    name = "neo.map";
    url = "https://raw.githubusercontent.com/neo-layout/neo-layout/"
          + "fdb34f295eefc788ab61b613681339c8aaa8b30a"
            + "/linux/console/neo.map";
    sha256 = "19mfrd31vzpsjiwc7pshxm0b0sz5dd17xrz6k079cy4im1vf0r4g";
  };

  phases = [ installPhase ];

  installPhase = ''
    install -D $src $out/share/keymaps/i386/neo/neo.map
  '';
}
1 Like