Skip to content

Instantly share code, notes, and snippets.

@AmineChikhaoui
Created April 22, 2019 13:12
Show Gist options
  • Save AmineChikhaoui/65c93cb4c6934f186c0afc818b88b7c6 to your computer and use it in GitHub Desktop.
Save AmineChikhaoui/65c93cb4c6934f186c0afc818b88b7c6 to your computer and use it in GitHub Desktop.

Using https://github.com/NixOS/nixops/compare/master...AmineChikhaoui:amine/nixops-outputs, the following network would trigger an infinite recursion:

{
  resources.output.foo =
    {
      script =
      ''
        echo foo
      '';
    };
}
[nix-shell:~/src/nixops]$ nixops deploy -d out
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)
error: evaluation of the deployment specification failed

If I create a regular NixOS module with the resource definition module and evaluate/build it, it works just fine:

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

    script = mkOption {
      default = null;
      type = types.nullOr types.str;
      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: nix-instantiate --eval --strict --json 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment