Skip to content

Latest commit

 

History

History
108 lines (75 loc) · 2.19 KB

53-overrides.org

File metadata and controls

108 lines (75 loc) · 2.19 KB

Override & OverrideAttr

Problem


How to change a package without having to re-write it yourself?

Solution


Overrides!

Basic idea


  • override and overrideAttr are special functions implemented around derivations
  • An example from day 1: pkgs.wine.override { ... }
  • What’s their difference?

Override


  • Specific to each package
  • Acts on the derivation output
with import <nixpkgs> {};
{
  my-git = pkgs.git.override {
    svnSupport = true;
    sendEmailSupport = true;
  };
}

 ❤ (theia) ~> nix-build ./override.nix
this derivation will be built:
  /nix/store/rn2qbgzkc4b8h7zsflhdyn9rhsjy0mp1-git-with-svn-2.38.1.drv
building '/nix/store/rn2qbgzkc4b8h7zsflhdyn9rhsjy0mp1-git-with-svn-2.38.1.drv'...
...

overrideAttrs


  • Generic for all* derivations
  • Acts on the inputs to mkDerivation
    • It therefore allows much more generic overrides

*any derivation which is wrapped in ‘makeOverridable’

overrideAttrs takes a function which takes an attribute set and returns an attribute set. Only changed keys should be returned.


some-package.overrideAttrs { ... }: { /* ... */  }

htop.overrideAttrs ({ patches ? [], nativeBuildInputs ? [], postConfigure ? "", ... }: {
  patches = patches ++ [ ./0001-htop-untruncated-username.patch ];
})

stdenv.mkDerivation (finalAttrs: {
  pname = "memtest86+";
  version = "6.00";

  src = fetchFromGitHub {
    owner = "memtest86plus";
    repo = "memtest86plus";
    rev = "v${finalAttrs.version}";
    hash = "sha256-m9oGLXTCaE5CgA4o8MGdjQTQSz/j8kC9BJ84RVcBZjs=";
  };

  # ...
}

overrideDerivation


  • Extremely special function which is very rarely useful
  • Override attributes that mkDerivation passes to derivation
  • You might see this in some places but you probably don’t need/ want to use it!