flake-compat
flake-compat copied to clipboard
readme example: get owner,repo from flake.lock
example formatted with nixfmt
I think it's best to keep default.nix / shell.nix as simple as possible, since it's not updated automatically. For reference, Nix's default.nix is:
(import (fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz") {
src = ./.;
}).defaultNix
Using inherit to shorten the code results in something like this (it still hardcodes github.com, but at least you can fork the flake-compat project and use that fork without any need to adjust default.nix):
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
in
fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
}) {src = ./.;})
.defaultNix
(.defaultNix on a separate line is how Alejandra formats this code).
added to https://github.com/nix-community/flake-compat