From e7c07009592b1aa6d1c0fbdeaa6d62a95d991803 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 28 Dec 2020 23:08:11 -0700 Subject: [PATCH] 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. --- compat/fetch.nix | 17 +++++++++++++++++ compat/nixpkgs.nix | 5 +++++ nixpkgs-compat.nix | 13 ------------- shell.nix | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 compat/fetch.nix create mode 100644 compat/nixpkgs.nix delete mode 100644 nixpkgs-compat.nix diff --git a/compat/fetch.nix b/compat/fetch.nix new file mode 100644 index 00000000..01f0f02f --- /dev/null +++ b/compat/fetch.nix @@ -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; +} diff --git a/compat/nixpkgs.nix b/compat/nixpkgs.nix new file mode 100644 index 00000000..3dd503a9 --- /dev/null +++ b/compat/nixpkgs.nix @@ -0,0 +1,5 @@ +let + fetch = import ./fetch.nix; + nixpkgs = fetch "nixos"; +in +nixpkgs diff --git a/nixpkgs-compat.nix b/nixpkgs-compat.nix deleted file mode 100644 index 08b07372..00000000 --- a/nixpkgs-compat.nix +++ /dev/null @@ -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 diff --git a/shell.nix b/shell.nix index 5aae2efc..dadb9e7f 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,5 @@ let - nixpkgs' = import ./nixpkgs-compat.nix; + nixpkgs = import ./compat/nixpkgs.nix; in { pkgs ? import nixpkgs { }, nixpkgs ? nixpkgs' }: let