factor out a generic fetch from nixpkgs-compat

Create fetch function which takes a valid flake input, and calls
fetchTarball with the revision and hash information from the flake.lock.

Useful for pulling the exact revision of flake inputs from not flake
expressions, such as those in shell.nix.
This commit is contained in:
Timothy DeHerrera 2020-12-28 23:08:11 -07:00
parent 828a939470
commit e7c0700959
No known key found for this signature in database
GPG key ID: 8985725DB5B0C122
4 changed files with 23 additions and 14 deletions

17
compat/fetch.nix Normal file
View file

@ -0,0 +1,17 @@
let
inherit (builtins)
fetchTarball
fromJSON
readFile
;
lockfile = fromJSON (readFile ../flake.lock);
in
input:
let
locked = lockfile.nodes."${input}".locked;
inherit (locked) rev narHash owner repo;
in
fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
}

5
compat/nixpkgs.nix Normal file
View file

@ -0,0 +1,5 @@
let
fetch = import ./fetch.nix;
nixpkgs = fetch "nixos";
in
nixpkgs

View file

@ -1,13 +0,0 @@
let
inherit (builtins)
fetchTarball
fromJSON
readFile
;
nixos = (fromJSON (readFile ./flake.lock)).nodes.nixos.locked;
nixpkgs = fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${nixos.rev}.tar.gz";
sha256 = nixos.narHash;
};
in
nixpkgs

View file

@ -1,5 +1,5 @@
let
nixpkgs' = import ./nixpkgs-compat.nix;
nixpkgs = import ./compat/nixpkgs.nix;
in
{ pkgs ? import nixpkgs { }, nixpkgs ? nixpkgs' }:
let