From 48246191f80b3cfbc5a966689a3b427d7f7c5c70 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Tue, 22 Oct 2024 11:21:28 +0300 Subject: [PATCH] Nix: Add prefetch function. --- home/program/bash/module/Nix.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/home/program/bash/module/Nix.nix b/home/program/bash/module/Nix.nix index e6fa0ec..31424bb 100644 --- a/home/program/bash/module/Nix.nix +++ b/home/program/bash/module/Nix.nix @@ -47,5 +47,18 @@ SHELL_NAME="''${pkg}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure github:NixOS/nixpkgs/''${rev}#''${pkg} -c ''${cmd} } + + # Prefetch to nix store. + # Usage: prefetch + function prefetch() { + local url="''${1}" + + if [[ "''${url}" = "" ]]; then + help prefetch + return 2 + fi + + nix hash to-sri --type sha256 $(nix-prefetch-url "''${url}") + } ''; }