How to import remote nix file importing other files?


I am trying to build custom cpython derivation with unmerged changes. I found this really hard to do, because cpython derivation has extra attributes generated by private passthruFun function.
The function is not available from my default.nix.

I tried to copy the function but it imports files across nixpkgs tree structure, which also import some other files - long dependency chain resulting in the need to basically copy the whole nixpkgs repo!

I know how to get content of individual nix file and then import it,
but I cannot import such nix file if it imports some other nix files locally.

nix-repl> xx = builtins.fetchurl { url = “” ; }
xx = builtins.fetchurl { url = “” ; }

nix-repl> xx
nix-repl> import xx {}
import xx {}
error: anonymous function at /nix/store/n69jaiphiwmf2l8nw0wwpfhqwchkw2pc-default.nix:1:1 called without required argument ‘pk
gs’, at (string):1:1

nix-repl> pkgs = import {}
pkgs = import {}

nix-repl> import xx { inherit pkgs; }
import xx { inherit pkgs; }
{ graalpython37 = error: getting status of ‘/nix/store/graalpython/default.nix’: No such file or directory

If you only fetch individual files from nixpkgs, the evaluation will likely fail, because the file references other files in parent directories which are not present. Better import the whole nixpkgs and then reference a specific attribute of it.

In your case (it sounds like you want to replace the src of cpython), you might want to use:

mySpecialPython = pkgs.python3.overrideAttrs (old: {
  src = fetchTarball ...;

Thanks. I was able to build python3.11 just from github, though with some effort because of tuning patches and postInstall scripts.
Then I tried new python. It is working, but I have no clue how to use with packages.

My following trick is not working - get old python:

myPkgsPy311 = pkgs.extend (self: super: {
python3 = myPatchedPython;
python38 = myPatchedPython;
python39 = myPatchedPython;

pp = myPkgsPy311.python39Packages;

pyobjc-core = pp.buildPythonPackage rec {
pname = “pyobjc-core”;
version = “7.3”;
name = “${pname}-${version}”;
src = pp.fetchPypi {
pname = “pyobjc-core”;
inherit version;
sha256 = “0x3msrzvcszlmladdpl64s48l52fwk4xlnnri8daq2mliggsx0ah”;

in pyobjc-core;

Running nix shell

$ nix-shell
$ python3
Python 3.9.5 (default, Jul 18 2021, 14:31:15)
[Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

Python is old 3.9 and not 3.11.