FetchFromGithub in configuration.nix

Hey Guys and Girls,

I am new to NixOs and really like the concepts that go into it.

So yesterday I read up on the whole Nix Languaged and feel confident to do some advanced stuff now, conviently there is this one package (redshift) which does not support wayland on 19.09 stable (on 20.03 there is a variation that does) my idea was to use pkgs.redshift.overrideAttrs to override the src attribute with a call to fetchFromGithub but with a set which points to the wayland fork of the project.

Now to the core of the question? How do I make use of fetchFromGithub here, do I have to import it or something?

And the alternative would be to fetch the fork manually and set the src attribute to the path of the local repo, right?

Thanks Everyone!

2 Likes

So yesterday I read up on the whole Nix Languaged and feel confident to do some advanced stuff now, conviently there is this one package (redshift) which does not support wayland on 19.09 stable (on 20.03 there is a variation that does) my idea was to use pkgs.redshift.overrideAttrs to override the src attribute with a call to fetchFromGithub but with a set which points to the wayland fork of the project.

Now to the core of the question? How do I make use of fetchFromGithub here, do I have to import it or something?

It depends on how and where you are overriding the attributes of
redshift. If you are using an overlay for that you can just access
fetchFromGithub by using super.fetchFromGithub.

If you are just overriding in place (e.g. as part of your
environment.systemPackages you can probably just use
pkgs.fetchFromGithub for that.

And the alternative would be to fetch the fork manually and set the src attribute to the path of the local repo, right?

That would also work but always requires you to keep that checkout
around. I’d prefer using a different src as described above.

2 Likes

Okay, thank you very much I read up on overlays and overriding and got this:

  # Overlays for nixpkgs
  nixpkgs.overlays = [
    (self: super:
    {
      redshift = super.redshift.overrideAttrs (oldAttrs: rec {
        src = super.fetchFromGithub {
          owner = "minus7";
          repo = "redshift";
          rev = "eecbfedac48f827e96ad5e151de8f41f6cd3af66";
          sha256 = "0rs9bxxrw4wscf4a8yl776a8g880m5gcm75q06yx2cn3lw2b7v22";
        };
      });
    })
  ];

but I still get this error:

error: attribute 'fetchFromGithub' missing, at /etc/nixos/configuration.nix:18:15

Alas, it’s fetchFromGitHub, not fetchFromGithub. I just tried your overlay on my NixOS system and it appears to be working otherwise.

It’d be really nice if we had “did you mean similar variable X” compiler suggestions on the error msg, but another way to check is with nix repl, which has tab completion:

1 Like

Wow that was simple, thank you very much! :smile:

No problem. As another tip, you may want to consider overriding version as well (and possibly pname if it’s a fork and not just a newer version). This is just cosmetic, but it makes it easier to tell that it worked and separate your updated redshift package from the default one.

I’ve made this mistake enough that I wonder if we should add something like

fetchFromGithub = abort "fetchFromGithub doesn't exist; perhaps you meant fetchFromGitHub";

but the problem with this is now things like nix repl will show fetchFromGithub as a viable completion option.

Extending Nix to emit “did you mean X” suggestions would of course be the better long-term fix.

I’m always wondering why some functions live in pkgs.lib and others in pkgs directly…

1 Like

everything in lib doesn’t result in a derivation, generally these are helper functions, metadata, and other generically useful utilities. Functions and helpers which exist in pkgs generally operate on derivations. (E.g. buildPythonPackage)

1 Like

https://github.com/NixOS/nixpkgs/pull/79877

1 Like

Functions that don’t depend on pkgs generally go in lib, which can be imported independently with import <nixpkgs/lib>. Note that it needs no arguments: it does not depend on system, config, overlays, etc.

So as a rule of thumb:

Function creates or uses derivations → pkgs.*
Function does not use derivations → lib.*

2 Likes