HeadlinesBriefing favicon HeadlinesBriefing.com

একটি Nix Flake যা সবকে শাসন করবে - Omniflake

Hacker News •
×

Flakes undoubtedly here to stay, and I've made my opinion on them well-known: they are "meh". Despite their ever-presence, adding a flake input continues to be a small annoyance that never goes away. It's touted as a positive feature that flakes are federated but the reality is that I want the simplicity of a centralized flake. That was the beauty and power of nixpkgs. The process is: you want disko, so you add a url, then a follows so it stops dragging in its own nixpkgs, and then you do it again for the next one. This has become a meme in the Nix community about how every flake drags in its own flake-utils. I refuse to accept this user experience.

So I wondered: could one flake carry every other flake, and you just reach in for whatever you need? Introducing Omniflake: nearly every Nix flake behind one flake input. `inputs.omniflake.url = "github:fzakaria/omniflake";` `inputs.omniflake.inputs.nixpkgs.follows = "nixpkgs";` Once you have omniflake, you can use it like any other input. A package, in a shell or on a system: `environment.systemPackages = [omniflake.flakes.nh.packages.${system}.default];` An overlay: `nixpkgs.overlays = [ omniflake.flakes.rust-overlay.overlays.default ];` A NixOS module: `imports = [ omniflake.flakes.disko.nixosModules.disko ];` Or nothing in a flake at all, straight from the command line: `$ nix run 'github:fzakaria/omniflake#flakes.nh.packages.x86_64-linux.default' -- --version`

It has an accessible website at https://omniflake.com/ where you can see the list of flakes it carries and some helpful documentation. Once added, you have access to nearly twelve thousand flakes that you can access as needed lazily. You only pay for what you use. This sounds absurd but it works. A flake with thousands of inputs should be unusable but thanks to the laziness of the Nix language and the flake lock mechanism it works perfectly.

How is it possible to contain nearly every flake within this one? A very short primer on flakes: a flake is a directory with a flake.nix that declares two things: inputs (other flakes it depends on) and outputs (a function of those inputs). The flake.lock next to it says exactly which commit that resolved to, so the build is reproducible. A lock file does not just pin your own inputs. It pins the whole transitive graph for every flake. That means if two child flakes both depend on nixpkgs, they will each have their own copy of nixpkgs in the lock file, and they may be different commits. This is the duplication everyone complains about, and it is why follows exists: follows rewrites a dependency to point at a node you already have, instead of fetching another copy.