How to completely override a scope in nixpkgs?

Hi all, this feels like it should be simple, but I’m having no luck.

poetry2nix is currently broken for some use cases. This is fine; there’s a pull request from @Infinisil open to fix it. :slight_smile:

I’d like to use the incoming version, which exists in the forked repo. In the docs about overlays, there’s an example of overriding a package inside a scope, using the overrideScope' utility function. But I haven’t been able to get this to work for overriding the whole scope.

Below is my attempt at an overlay, the local derivation I want to use it in, and the resulting output.

I think I probably misunderstand something related to syntax, or the utility functions involved. What should I try next?

# ./overlays/poetry2nix.nix
self: super:
let
  p2n-fixed = import (super.fetchFromGitHub {
    owner = "Infinisil";
    repo ="poetry2nix";
    rev = "5d7819647d5a93304484341ea547fef327837c79";
    sha256 = "1c8sa291fzwczb60d0lp141j18hs21pklfmq43mn63rlij81gqq8";
  });
in
{
  poetry2nix = super.poetry2nix.overrideScope' (
    selfp: superp: p2n-fixed { inherit (self) pkgs; }
  );
}
# ./default.nix
{
  pkgs ? import <nixpkgs> {
    overlays = [ (import ./overlays/poetry2nix.nix) ];
  },
  ...
}:

pkgs.poetry2nix.mkPoetryApplication {
  projectDir = ./.;
}

Result output:

> nix-build default.nix --show-trace
error: while evaluating the attribute 'drvPath' at /nix/store/4d097mkjdfwikvzs936nmnlclq1xf8fj-nixos-20.09beta1411.95d26c9a9f2/nixos/lib/customisation.nix:163:7:
while evaluating the attribute 'buildInputs' of the derivation 'python3.8-my-new-pkg-0.1.0' at /nix/store/4d097mkjdfwikvzs936nmnlclq1xf8fj-nixos-20.09beta1411.95d26c9a9f2/nixos/pkgs/development/interpreters/python/mk-python-derivation.nix:108:5:
while evaluating 'getOutput' at /nix/store/4d097mkjdfwikvzs936nmnlclq1xf8fj-nixos-20.09beta1411.95d26c9a9f2/nixos/lib/attrsets.nix:464:23, called from undefined position:
while evaluating anonymous function at /nix/store/4d097mkjdfwikvzs936nmnlclq1xf8fj-nixos-20.09beta1411.95d26c9a9f2/nixos/pkgs/stdenv/generic/make-derivation.nix:143:17, called from undefined position:
while evaluating anonymous function at /nix/store/abgzjqjq8dr7zhwgl7f8dqi1zk0vr7n5-source/lib.nix:162:19, called from undefined position:
while evaluating the attribute 'poetry-core' at /nix/store/abgzjqjq8dr7zhwgl7f8dqi1zk0vr7n5-source/overrides.nix:645:3:
while evaluating the attribute 'poetry-core.overridePythonAttrs' at /nix/store/abgzjqjq8dr7zhwgl7f8dqi1zk0vr7n5-source/default.nix:160:19:
value is null while a set was expected, at /nix/store/abgzjqjq8dr7zhwgl7f8dqi1zk0vr7n5-source/default.nix:90:19
1 Like

I made a little progress, at least figuring out I had to actually import the fetched poetry2nix derivation. :slight_smile: Edited the OP to reflect the current state.

Edit #2:

Here is a correct way to completely override a scope using a derivation from GitHub:

# ./overlays/poetry2nix.nix
self: super:
{
  poetry2nix = super.poetry2nix.overrideScope' (
    selfp: superp: super.callPackage (super.fetchFromGitHub {
      owner = "Infinisil";
      repo ="poetry2nix";
      rev = "5d7819647d5a93304484341ea547fef327837c79";
      sha256 = "1c8sa291fzwczb60d0lp141j18hs21pklfmq43mn63rlij81gqq8";
    }) {});
}
# ./default.nix
{ pkgs ? import <nixpkgs> {
  overlays = [ (import ./overlays/poetry2nix.nix) ];
}}:

pkgs.poetry2nix.mkPoetryApplication {
  projectDir = ./.;
}
3 Likes