From 41cc0560362ad402a91e1eb006935865b7c42d97 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 8 Jun 2021 16:04:23 +0200 Subject: turing machine in nix --- nix-turing/loop.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 nix-turing/loop.nix (limited to 'nix-turing/loop.nix') 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 {}; + 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 -- cgit v1.2.3