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

Closed
Artturin wants to merge 1 commit from Artturin/betterreadme into master
Artturin commented 2022-03-25 03:14:40 +00:00 (Migrated from github.com)

example formatted with nixfmt

example formatted with nixfmt
edolstra commented 2022-03-25 09:14:22 +00:00 (Migrated from github.com)

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
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 2022-06-29 20:47:27 +00:00 (Migrated from github.com)

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

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`): ```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 2023-04-03 14:20:25 +00:00 (Migrated from github.com)
added to https://github.com/nix-community/flake-compat
jade closed this pull request 2024-05-03 02:57:55 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.