Hi ![]()
The problem to solve:
We need randomness (for example, for key generation), but since it’s fundamentally impure, we handle these tasks “manually”. These impure operations can become tedious and a source of problems, much like the many manual operations in other distributions. It is fundamentally impossible to purely describe a machine that partly needs to be the result of randomness.
A clean generic solution:
The description of machines also includes the description of impure elements (the data to be produced containing randomness) — that’s the “DJ” (Dirty-Job) part. DJ does not produce randomness; it purely produces code that handles this randomness (which is why everything remains pure). The build includes an extra step: before the usual Nix build, the code resulting from DJ is produced and executed. It performs the impure actions if needed, then the build is carried out.
I envision two modes:
• Clean mode:
◇ Two repos
One without randomness (no public or private keys or other files originating from randomness or the “outside”).
One like the first, but also containing the result of DJ execution.
◇ The “DJ” phase consists of producing the dirty repo (the 2nd) from the clean repo.
◇ The classic build phase.
• In-place mode: Same thing, but everything in the same repo.
Drawbacks
One extra step.
Advantages
• Everything can be automated; we only have to produce Nix code.
• No risk of forgetting to generate keys, to renew them, no secrets.nix to manage — we can replace agenix-rekey with a cleaner solution.
• Automated collection and management of public keys for different machines.
• Permanence management: if a key is no longer needed, it isn’t automatically deleted; we can configure how long before the key is destroyed.
• Distribution of DJ modules: administrators no longer need to know how to generate keys; they just need to know how to configure them. This allow to always use the state of the art practices just by updating DJ modules.
• Distribution (in clean mode) of sources with or without the randomness parts, depending on the use case (with them internally, without them for sharing knowledge).
• No need to produce a manual of the “outer part of the job” because everything is in the nix files.
• Later, possible integration into Nix to make the DJ process natural.
• DJ is not limited to keys but to any manual part of the repo. For example, generating automatic documentation, using an additional code analyzer.
Example:
config.dj."${name}".httpd.key.enable=true
...
sslServerKey=if devMode then config.dj."${name}".httpd.key.path else <ECMA things>;
That’s it, the rest (key pair creation, rekeying, determining which machines use these keys) is handled by DJ.
--
I’m an enthusiastic beginner on NixOS, unfortunately completely swamped with other things, but maybe this idea could be beneficial and might interest some developers.
-----BEGIN SSH SIGNATURE-----
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgE3auYztV18qug7NHVal89ZH0U5
jnKZKonRNR5Y5cndkAAAAEZmlsZQAAAAAAAAAGc2hhNTEyAAAAUwAAAAtzc2gtZWQyNTUx
OQAAAEDvw8IDxKvweK+FUKmFZ8aCCpywvgabwQ+OYFjafDekKkpcM6iXeEzl3vNGNsif7R
TXF6cbpmFs7ys74BVOXGkG
-----END SSH SIGNATURE-----