- Nix 93.7%
- Shell 6.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| examples | ||
| lib | ||
| src | ||
| .gitignore | ||
| default.nix | ||
| README.md | ||
httpnix
Yet another HTTP Server... In Nix...
...well... almost. It is ~90% Nix and 10% Shell Script. The actual socket is implemented using netcat in a Shell Script but apart from that, everything is handled inside of Nix
How it works
The flag --allow-unsafe-native-code-during-evaluation to the nix command gives you access to builtins.exec. Given an array of command + arguments, it will parse stdout of that command into a nix expression. This essentially allows you to run commands during the evaluation phase, including netcat.
Goals
- No
nix buildornix run, everything runs during the evaluation phase - Parse the TCP-Messages in Nix
- Do not use nixpkgs, just the language builtins
Limitations
- This is extremely insecure! I can already think of at least two ways a hacker might get RCE using this software! DO NOT USE IN PRODUCTION
- This is HTTP/1.1 only. Contributions for HTTP/2 and HTTP/3 are appreciated but HTTPS is out of scope
- This can only proccess 1 Request at a time, which breaks html files with a lot of assets
Using it
Head over to the examples to find out, how to use this. You can run them using the following command:
nix eval --file ./default.nix --allow-unsafe-native-code-during-evaluation.
Ensure that the nc, env, sh, cat, rm and mkfifo commands are available in your PATH.
The default port is 8080.
LLM Usage
No "AI" was used while developing this. Any Contributions created with or by LLMs is prohibited
License
All code is licensed under CC0-1.0. The JSON-List of HTTP Status codes was taken from phpjsnerd's Github Gist and the JSON-List of Mimetypes from micnic's Github Repository