summaryrefslogtreecommitdiff
path: root/nix-turing/loop.nix
blob: 2849d6a81052838e9d0ea0d7e326ab8e0a100f7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# defeats the recursion checks of nix and will cause it to
# loop infinitely. well, almost, anyways.
#
# annoyingly, nix doesn't have tail recursion, so actually
# it'll eventually terminate with a stack overflow.
let
  pkgs = import <nixpkgs> {};
  writeTextVerbose = file: content: pkgs.stdenv.mkDerivation {
    name = file;
    src = pkgs.hello;
    buildPhase = ''
      echo ${pkgs.lib.escapeShellArg content} > $out
    '';
    installPhase = ''
      echo wrote file to $name
    '';
  };
  storefile = v: writeTextVerbose "nixfile" ''
    {
      x = ${toString v};
    }
  '';
  loop = a:
    let file = import (storefile a);
    in if file.x == 1 then loop a else "done";
in loop 1