summaryrefslogtreecommitdiff
path: root/nix-turing/loop.nix
diff options
context:
space:
mode:
authorstuebinm2021-06-08 16:04:23 +0200
committerstuebinm2021-06-08 16:08:07 +0200
commit41cc0560362ad402a91e1eb006935865b7c42d97 (patch)
treeded65d7758cb2cf60522a3a6b3fcea03ae7a6720 /nix-turing/loop.nix
parent4cba21106d13aa021b2757a3a550244a884cfccf (diff)
turing machine in nix
Diffstat (limited to 'nix-turing/loop.nix')
-rw-r--r--nix-turing/loop.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/nix-turing/loop.nix b/nix-turing/loop.nix
new file mode 100644
index 0000000..2849d6a
--- /dev/null
+++ b/nix-turing/loop.nix
@@ -0,0 +1,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