DavHau / mach-nix

Create highly reproducible python environments
MIT License
869 stars 106 forks source link

Infinite recursion encountered when using an overlay #172

Open shadowrylander opened 4 years ago

shadowrylander commented 4 years ago

Hello!

I'm getting an infinite recursion error when using the following overlay:

{
  pkgs ? (import <nixpkgs> {}),
  lib ? (import <nixpkgs> {}).lib,
  mach-nix ? (import (builtins.fetchGit {
      url = "https://github.com/DavHau/mach-nix/";
      ref = "master";
  }) { inherit pkgs; python = "python38"; }),
  ...
}:

let
  xonshOverlay = {pkgs, lib, ...}:
    let
      # build a mach-nix python env
      machnixPy = mach-nix.mkPython {
        packagesExtra = [
          # "https://github.com/psf/requests/tarball/v2.22.0"

          # "https://gitlab.com/picotech/nanotech/nanite/-/archive/master/nanite-master.tar.gz"
          (mach-nix.buildPythonPackage {
            src = builtins.fetchGit{
              url = "https://gitlab.com/picotech/nanotech/nanite";
              ref = "master";
            };
          })

          "https://files.pythonhosted.org/packages/bc/ab/c49f97516f78c2b0cacb4f45873abc4ca9872942a9c4c19ded8052c8edda/python-wifi-0.6.1.tar.bz2"
        ];
        requirements = ''
          # add requirements here
          # jedi
          borgmatic
          dephell
          ply
          prompt_toolkit
          pygments
          pipx
          yubico-client

          # add xontribs here
          # xonsh-direnv
          # xonsh-docker-tabcomplete
          # xonsh-vox-tabcomplete
          # xontrib-prompt-bar
          # xontrib-ssh-agent
          xonsh-autoxsh
          xontrib-autojump
          xontrib-fzf-widgets
          xontrib-kitty
          xontrib-pipeliner
          xontrib-powerline2
          xontrib-prompt-vi-mode
          xontrib-readable-traceback
          xontrib-schedule
          xontrib-z
        '';
      };

      # get mach-nix modified nixpkgs
      newPkgs = machnixPy.nixpkgs;

      ### modify the xonsh package
      pythonPackages = newPkgs.python38.pkgs;
      # switch xonsh to python 3.8
      xonsh_py_38 = newPkgs.xonsh.override {
        python3Packages = newPkgs.python38Packages;
      };
      # add extra packages to PYTHONPATH of xonsh
      xonsh_with_pkgs = xonsh_py_38.overrideAttrs (oa: rec {
        version = "0.9.23";

        # fetch from github because the pypi package ships incomplete tests
        src = pkgs.fetchFromGitHub {
          owner  = "xonsh";
          repo   = "xonsh";
          rev    = version;
          sha256 = "1by13ryq9ldc9wln3fk5mm6zvjp4aim57ikw49v0dfmz8irnpglp";
        };

        pythonPath =
          (if (builtins.hasAttr "pythonPath" oa) then oa.pythonPath else [])
          ++ machnixPy.selectPkgs pythonPackages
          ++ (with pythonPackages; [
            ply
            prompt_toolkit
            pygments
            pipx
            yubico-client
            nixpkgs
          ]);
      });

      # make a final overlay with the modified xonsh
      finalOverlay = self: super: { xonsh = xonsh_with_pkgs; };
    in
    finalOverlay;
in
  let
    pkgs = import (builtins.fetchGit {
      url = "https://github.com/NixOS/nixpkgs/";
      ref = "master";
    }) { config = {}; overlays = [];};
    overlay = xonshOverlay { inherit pkgs lib; };
  in
    (import pkgs.path { overlays = [ overlay ]; }).xonsh

This is its trace:

building Nix...
building the system configuration...
error: --- EvalError --- nix-build
at: (65:21) in file: /etc/nixos/shared/global/_xonsh.nix

    64|       # switch xonsh to python 3.8
    65|       xonsh_py_38 = newPkgs.xonsh.override {
      |                     ^
    66|         python3Packages = newPkgs.python38Packages;

infinite recursion encountered
---- show-trace ----
trace: while evaluating the attribute 'xonsh.override'
at: (33:32) in file: /etc/nixos/shared/global/_nixpkgs.nix

    32|         # (self: super: { inherit qtile; })
    33|         (self: super: { inherit xonsh; })
      |                                ^
    34|         mozilla

trace: while evaluating the attribute 'xonsh'
at: (94:37) in file: /etc/nixos/shared/global/_xonsh.nix

    93|       # make a final overlay with the modified xonsh
    94|       finalOverlay = self: super: { xonsh = xonsh_with_pkgs; };
      |                                     ^
    95|     in

trace: while evaluating anonymous lambda
at: (1:1) in file: /etc/nixos/shared/global/_xonsh.nix

     1| {
      | ^
     2|   pkgs ? (import <nixpkgs> {}),

trace: from call site
at: (18:13) in file: /etc/nixos/shared/global/_nixpkgs.nix

    17|     base.mach-nix = { inherit pkgs mach-nix lib; };
    18|     xonsh = import /etc/nixos/shared/global/_xonsh.nix base.mach-nix;
      |             ^
    19|     qtile = import /etc/nixos/shared/global/_qtile.nix base.mach-nix;

trace: while evaluating the attribute 'value.content'
at: (695:14) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   694|     { _type = "override";
   695|       inherit priority content;
      |              ^
   696|     };

trace: while evaluating the attribute 'value._type'
at: (635:73) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   634|       highestPrio = foldl' (prio: def: min (getPrio def) prio) 9999 defs;
   635|       strip = def: if def.value._type or "" == "override" then def // { value = def.value.content; } else def;
      |                                                                         ^
   636|     in {

trace: while evaluating anonymous lambda
at: (534:19) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   533|           # Avoid sorting if we don't have to.
   534|           if any (def: def.value._type or "" == "order") defs''.values
      |                   ^
   535|           then sortProperties defs''.values

trace: from call site
at: (534:14) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   533|           # Avoid sorting if we don't have to.
   534|           if any (def: def.value._type or "" == "order") defs''.values
      |              ^
   535|           then sortProperties defs''.values

trace: while evaluating the attribute 'values'
at: (538:9) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   537|       in {
   538|         values = defs''';
      |         ^
   539|         inherit (defs'') highestPrio;

trace: while evaluating the attribute 'mergedValue'
at: (544:5) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   543|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
   544|     mergedValue =
      |     ^
   545|       if isDefined then

trace: while evaluating the option `users.users.root.shell':
trace: while evaluating the attribute 'value'
at: (512:9) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   511|     in warnDeprecation opt //
   512|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
      |         ^
   513|         inherit (res.defsFinal') highestPrio;

trace: while evaluating anonymous lambda
at: (139:72) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix

   138|           # For definitions that have an associated option
   139|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
      |                                                                        ^
   140| 

trace: from call site
at: (279:20) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/attrsets.nix

   278|               then recurse (path ++ [name]) value
   279|               else f (path ++ [name]) value;
      |                    ^
   280|         in mapAttrs g set;

trace: while evaluating 'g'
at: (276:19) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/attrsets.nix

   275|           g =
   276|             name: value:
      |                   ^
   277|             if isAttrs value && cond value

trace: from call site
trace: while evaluating the attribute 'shell'
trace: while evaluating 'isDerivation'
at: (305:18) in file: /nix/store/134s7gyyvly9vri57p716xjkawgqgv9n-nixos/nixos/lib/attrsets.nix

   304|   */
   305|   isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
      |                  ^
   306| 

trace: from call site
at: (333:18) in file: /nix/store/134s7gyyvly9vri57p716xjkawgqgv9n-nixos/nixos/lib/types.nix

   332|       name = "package";
   333|       check = x: isDerivation x || isStorePath x;
      |                  ^
   334|       merge = loc: defs:

trace: while evaluating 'check'
at: (333:15) in file: /nix/store/134s7gyyvly9vri57p716xjkawgqgv9n-nixos/nixos/lib/types.nix

   332|       name = "package";
   333|       check = x: isDerivation x || isStorePath x;
      |               ^
   334|       merge = loc: defs:

trace: from call site
at: (340:19) in file: /nix/store/134s7gyyvly9vri57p716xjkawgqgv9n-nixos/nixos/lib/types.nix

   339|     shellPackage = package // {
   340|       check = x: (package.check x) && (hasAttr "shellPath" x);
      |                   ^
   341|     };

trace: while evaluating 'check'
at: (340:15) in file: /nix/store/134s7gyyvly9vri57p716xjkawgqgv9n-nixos/nixos/lib/types.nix

   339|     shellPackage = package // {
   340|       check = x: (package.check x) && (hasAttr "shellPath" x);
      |               ^
   341|     };

trace: from call site
at: (28:8) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/lib/utils.nix

    27|   toShellPath = shell:
    28|     if types.shellPackage.check shell then
      |        ^
    29|       "/run/current-system/sw${shell.shellPath}"

trace: while evaluating 'toShellPath'
at: (27:17) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/lib/utils.nix

    26|   # Returns a system path for a given shell package
    27|   toShellPath = shell:
      |                 ^
    28|     if types.shellPackage.check shell then

trace: from call site
at: (412:17) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/config/users-groups.nix

   411|           initialPassword initialHashedPassword;
   412|         shell = utils.toShellPath u.shell;
      |                 ^
   413|       }) cfg.users;

trace: while evaluating the attribute 'text' of the derivation 'users-groups.json'
at: (7:7) in file: /nix/store/134s7gyyvly9vri57p716xjkawgqgv9n-nixos/nixos/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while evaluating the attribute 'text'
at: (82:38) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/strings-with-deps.nix

    81| 
    82|   stringAfter = deps: text: { inherit text deps; };
      |                                      ^
    83| 

trace: while evaluating the attribute 'text'
at: (9:5) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/system/activation/activation-script.nix

     8|   addAttributeName = mapAttrs (a: v: v // {
     9|     text = ''
      |     ^
    10|       #### Activation script snippet ${a}:

trace: while evaluating 'id'
at: (14:5) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/trivial.nix

    13|     # The value to return
    14|     x: x;
      |     ^
    15| 

trace: from call site
trace: while evaluating 'textClosureMap'
at: (75:35) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/lib/strings-with-deps.nix

    74| 
    75|   textClosureMap = f: predefined: names:
      |                                   ^
    76|     concatStringsSep "\n" (map f (textClosureList predefined names));

trace: from call site
at: (89:18) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/system/activation/activation-script.nix

    88|                 withHeadlines = addAttributeName set';
    89|               in textClosureMap id (withHeadlines) (attrNames withHeadlines)
      |                  ^
    90|             }

trace: while evaluating the attribute 'system.activationScripts.script'
at: (68:9) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/system/activation/activation-script.nix

    67|       apply = set: {
    68|         script =
      |         ^
    69|           ''

trace: while evaluating the attribute 'activationScript' of the derivation 'nixos-system-siluam-x86-64-linux-21.03pre-git'
at: (95:5) in file: /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/system/activation/top-level.nix

    94|   baseSystem = pkgs.stdenvNoCC.mkDerivation {
    95|     name = "nixos-system-${config.system.name}-${config.system.nixos.label}";
      |     ^
    96|     preferLocalBuild = true;

And this is how the overlay is being called:

{
    stdenv,
    pkgs,
    lib,
    # import (builtins.fetchGit {url = "https://github.com/DavHau/mach-nix/"; ref = "master";}) { pkgs = import <nixpkgs> {}; python = "python38"; }
    mach-nix ? (import (builtins.fetchGit {
        url = "https://github.com/DavHau/mach-nix/";
        ref = "master";
    }) { inherit pkgs; python = "python38"; }),
    extralays ? [],
    ...
}:

let
    mozilla = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
    base.mach-nix = { inherit pkgs mach-nix lib; };
    xonsh = import /etc/nixos/shared/global/_xonsh.nix base.mach-nix;
    qtile = import /etc/nixos/shared/global/_qtile.nix base.mach-nix;
in {
    config = {
        allowUnfree = true;
        allowBroken = true;
        allowUnsupportedSystem = true;
        buildEnv.override = { inherit stdenv; };
        # preBuild = ''
        #     makeFlagsArray+=(CFLAGS="-w")
        #     buildFlagsArray+=(CC=cc)
        # '';
    };
    overlays = extralays ++ [
        # (self: super: { inherit qtile; })
        (self: super: { inherit xonsh; })
        mozilla
    ];
}

Any help would be greatly appreciated!

shadowrylander commented 4 years ago

The issue seems to somehow have resolved itself when used with a Flake. I'll close this issue, then!

shadowrylander commented 4 years ago

Actually, this is preventing me from using the overlay on a new system without flakes.

DavHau commented 4 years ago

Using channel 20.03 it crashes with some patching related error for me. It builds fine on the unstable channel

shadowrylander commented 4 years ago

Last I tried was on nixpkgs master.

shadowrylander commented 3 years ago

I seem to be unable to build anything with mach-nix at the moment, mostly due to the infinite recursion error originally, and it seems your patching error as well.