NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.69k stars 1.51k forks source link

stack overflow (possible infinite recursion) when evaluating to XML instead of JSON #2783

Open AmineChikhaoui opened 5 years ago

AmineChikhaoui commented 5 years ago

I've hit this in https://github.com/NixOS/nixops/pull/1048. It's reproducible with the following steps:

# output.nix
{ pkgs, config, lib, name ? "default-output", ... }:
with lib;
{
  options = {
    name = mkOption {
      default = name;
      type = types.str;
      description = "Name of the output.";
    };

    script = mkOption {
      default = null;
      type = types.nullOr types.str;
      #type = types.nullOr (types.either types.str types.path);
      description = ''
        Text of a script which will produce a JSON value.
        <warning>Warning: This uses shell features and is potentially dangerous.</warning>
        Environment variables:
        <envar>$out</envar> is a temp directory available for use.
        '';
    };

    executable = mkOption {
      type = types.path;
      description = "Generated executable that runs the script.";
    };

    value = mkOption {
      default = null;
      type = types.nullOr types.str;
      description = "Result of running script.";
    };
  };
  config = {
    _type = "output";
    executable = pkgs.writeScriptBin "nixops-${config.name}"
    ''
    #!${pkgs.stdenv.shell}
    ${config.script}
    '';

  };
}
# mod.nix
let
  pkgs = import <nixpkgs> {};
  resources.outputs =
    with pkgs;
    with lib;
    (evalModules {
      modules = [
        {
          options = {
            _type = mkOption {
              type = types.str;
            };
          };
        }
        { imports = [./output.nix]; }
        {
          config.script =
          ''
          echo foo
          '';
        }
      ];
      args = {inherit pkgs lib; name = "out"; uuid = "1234";};
    }).config;
in
  resources.outputs.executable

Running nix-instantiate with --xml produces

nix-instantiate --eval-only --strict  --xml nix/mod.nix 1>/dev/null
trace: WARNING: `stdenv.isArm` is deprecated after 18.03. Please use `stdenv.isAarch32` instead
trace: lib.zip is deprecated, use lib.zipAttrsWith instead
trace: Warning: `showVal` is deprecated and will be removed in the next release, please use `traceSeqN`
trace: `mkStrict' is obsolete; use `mkOverride 0' instead.
trace: `lib.nixpkgsVersion` is deprecated, use `lib.version` instead!
error: stack overflow (possible infinite recursion)

While with --json:

nix-instantiate --eval-only --strict  --json nix/mod.nix
"/nix/store/435m8qx6hmfrrr8ckxh3wsk122gb4pp8-nixops-out"
stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

stale[bot] commented 2 years ago

I closed this issue due to inactivity. → More info