RNG and Cosine in Nix
Published on: 2025-04-25 07:30:22
RNG and Cosine in Nix How to implement random number generation and cosine for your NixOS configuration
NixOS is an immutable, atomic Linux distribution with a declarative and reproducible configuration and packaging system using the purely functional, lazily evaluated, dynamically typed Nix programming language.
Kublai: AAAAAAHHH too many buzzwords, what does that all mean???
Glad you asked! Basically, in NixOS, you can configure your entire system using a configuration.nix file and NixOS will magically (using a bunch of Bash scripts) figure out what needs to be installed and how to do it. For instance, if you want to enable Firefox, you’d add programs.firefox.enable = true; to your configuration.nix . Easy as that.
Kublai: Sure that sounds cool, but what if I want to enable Firefox with only 50% probability?
Great question! The easiest solution would be something like randomNumber = 4 (from this xkcd), but what about doing the RNG using the Nix language so that it’s declarative?
... Read full article.