feat(package): nix-derivation-hash
This commit is contained in:
9
package/nix-derivation-hash/default.nix
Normal file
9
package/nix-derivation-hash/default.nix
Normal 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} "$@"
|
||||
''
|
||||
9
package/nix-derivation-hash/nix-derivation-hash.sh
Normal file
9
package/nix-derivation-hash/nix-derivation-hash.sh
Normal 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:?}"
|
||||
Reference in New Issue
Block a user