edolstra / flake-compat

MIT License
254 stars 71 forks source link

readme example: get owner,repo from flake.lock #38

Closed Artturin closed 1 week ago

Artturin commented 2 years ago

example formatted with nixfmt

edolstra commented 2 years ago

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
sigprof commented 2 years ago

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

zimbatm commented 1 year ago

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