feat(package): nix-derivation-hash

This commit is contained in:
2025-07-23 20:15:53 +00:00
parent 6e77853453
commit 52cb6b2410
3 changed files with 19 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
{
writeShellScriptBin,
bash,
}: let
# Use folder name as name of this system
name = builtins.baseNameOf ./.;
in writeShellScriptBin name /* sh */ ''
${bash}/bin/sh ${./${name}.sh} "$@"
''

View File

@@ -0,0 +1,9 @@
path="$1"
base_path_name="$(basename "$path")"
sha256="$(nix-hash --type sha256 "$path")"
temp_dir="$(mktemp -d)"
temp_file="${temp_dir}/${base_path_name}.str"
printf "source:sha256:%s:/nix/store:%s" "$sha256" "$base_path_name" > "$temp_file"
nix-hash --type sha256 --truncate --base32 --flat "$temp_file"
rm -rf "${temp_dir:?}"