by Rucadi on 3/31/24, 7:33 PM with 0 comments
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.
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.
This is: https://github.com/Rucadi/nixsh
Some examples can be found on the readme but a more advanced example can be seen here: https://github.com/Rucadi/nixsh/blob/master/examples/nixsh/c...
Here's a glimpse of what the solution offers:
- Precise control over environment variables, ensuring only the necessary ones are accessible when executing any script.
- Ability to set default values for environment variables
- Ability to dynamically manipulate environment variables directly from NIX expressions.
- Using nix to eliminate the need for manual installation of dependencies before script execution.
- Integration of disparate components like bash scripts and programs in C++, Rust, or Python, facilitating cohesive scripting.
- Leveraging NIX as a preprocessor for any file, for example, you can generate code using nix, and compile it before the execution runs automatically.
- Compile-Time checking of existence of files and envars
- Full interoperability, since you end up executing bash/python in the end, with the benefit that nixsh will already have cleaned your environment :)
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.
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 :)