flake-compat icon indicating copy to clipboard operation
flake-compat copied to clipboard

readme example: get owner,repo from flake.lock

Open Artturin opened this issue 3 years ago • 3 comments

example formatted with nixfmt

Artturin avatar Mar 25 '22 03:03 Artturin

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

edolstra avatar Mar 25 '22 09:03 edolstra

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).

sigprof avatar Jun 29 '22 20:06 sigprof

added to https://github.com/nix-community/flake-compat

zimbatm avatar Apr 03 '23 14:04 zimbatm