Cursed-nix: collection of nix hacks nobody should've come up with

Since I’m hacking on nix random things I come up with while I’m trying to fall asleep or because I saw something somewhere and I think to myself if I can do it in nix, I decided to start collecting and (maybe sometimes) documenting them. The collection is modest for now, but I promise to keep updating it.

One of the current “projects” - htmnix - is what the tvix people talked about doing in the Nix Developer Dialogues (https://www.youtube.com/live/ZYG3T4l8RU8) but instead of having to fork nix or write your own interpreter I did it in pure nix, just as eelco intended :slight_smile:

<html> { lang = "en"; } [
  (<head> { } [ ])
  (<body> { } [ (<h1> { } [ "hello nixers" ]) ])
]

after running nix eval --raw -f impl.nix returns:

<html lang="en">
  <head >

</head>

<body >
  <h1 >
  hello nixers
</h1>

</body>

</html>
9 Likes

What Vincent mentions in the stream is independent of Tvix (I wrote it before the first version of the Tvix evaluator was committed to depot) and actually wouldn’t work with Tvix, since it doesn’t support shadowing __findFile (yet or maybe ever).

You can find the implementation with an explanation and docs in my user directory (as shown in the Developer Dialogues).

3 Likes

Oh so you also overwrote __findFile, I must’ve misunderstood then because I thought they said you changed how the tvix interpreter evaluates the <path> syntax. My bad and I’ll credit you properly since your implementation is way more „mature” than what I did in a couple of minutes, haha

2 Likes

I added operator-fun which will contain different unique ways I or someone willing to contribute found to change the behavior of operators in nix. The first one I added - glob.nix - makes it so that whenever you multiply a path with a string you’ll get a list of paths back. So something like ./foo*".md" will return all the markdown files in directory foo :smile:

2 Likes