Hello HN!<p>I had to work with a codebase that was full of magic environment variables and tons of bash scripts, which was and still is a nightmare.<p>I decided to try and make a solution using NIX, which ended being far more easy to work with and I think that brings a lot of value.<p>This is: <a href="https://github.com/Rucadi/nixsh">https://github.com/Rucadi/nixsh</a><p>Some examples can be found on the readme but a more advanced example can be seen here:
<a href="https://github.com/Rucadi/nixsh/blob/master/examples/nixsh/cpp_script/cpp.nixsh">https://github.com/Rucadi/nixsh/blob/master/examples/nixsh/c...</a><p>Here's a glimpse of what the solution offers:<p>- Precise control over environment variables, ensuring only the necessary ones are accessible when executing any script.<p>- Ability to set default values for environment variables<p>- Ability to dynamically manipulate environment variables directly from NIX expressions.<p>- Using nix to eliminate the need for manual installation of dependencies before script execution.<p>- Integration of disparate components like bash scripts and programs in C++, Rust, or Python, facilitating cohesive scripting.<p>- Leveraging NIX as a preprocessor for any file, for example, you can generate code using nix, and compile it before the execution runs automatically.<p>- Compile-Time checking of existence of files and envars<p>- Full interoperability, since you end up executing bash/python in the end, with the benefit that nixsh will already have cleaned your environment :)<p>The current implementation involves parsing NIX code using tools like awk and sed to strategically inject components where needed. While this proof of concept serves its purpose.<p>I think it's a cool program and I think that I will use from now on, I'm 100% open to contributions if you feel like it :)