Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the builtin hashTo #3151

Closed
nlewo opened this issue Oct 15, 2019 · 12 comments
Closed

Add the builtin hashTo #3151

nlewo opened this issue Oct 15, 2019 · 12 comments

Comments

@nlewo
Copy link
Member

nlewo commented Oct 15, 2019

I would like to add a builtin to convert a hash from one representation to another. Several Nix sub-commands (to-base16, to-sri, ...) already exist to do such conversion but I would like to do that at evaluation time.

Spec

builtins.hashTo <type> <hash-string>
where

  • <type> is the expected representation. <type> could be one of the hash representations supported by Nix, which are currently base16, base32, base64 and sri.
  • <hash-string> is a string representing a hash. The format of this hash can be inferred.

It would return the hash to the expected representation or an error if the input string doesn't represent a hash.

What do you think?

@zimbatm
Copy link
Member

zimbatm commented Oct 17, 2019

@nlewo what is the motivation of doing the transformation at evaluation time?

@veprbl
Copy link
Member

veprbl commented Oct 25, 2019

@zimbatm For example, I needed it for NixOS/nixpkgs#53787

@nlewo
Copy link
Member Author

nlewo commented Oct 25, 2019

Yep, this is in the same kind of contexts.
@zimbatm I want to generate a list of sources with their hashes which could be consumed by an external entity. I then need to export our hash to a more classical format/representation (our base32 hash representation is home made).

@stale
Copy link

stale bot commented Feb 16, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 16, 2021
@L-as
Copy link
Member

L-as commented Mar 10, 2021

This would still be useful.

@tomprince
Copy link

It looks like fetchTree requires SRI format hashes, so if niv were to switch to using it, when it is available, it would need something like hashTo, if it wants to support existing configuration that uses a different format.

@stale
Copy link

stale bot commented Apr 16, 2022

I marked this as stale due to inactivity. → More info

@ShamrockLee
Copy link
Contributor

ShamrockLee commented Jan 25, 2023

It's still important to me.

BTW, is it possible to implement it inside the nixpkgs/lib first?

@stale stale bot removed the stale label Jan 25, 2023
@Atemu
Copy link
Member

Atemu commented Jan 25, 2023

Theoretically, yes. Practically, writing parsers is absolutely not what the Nix language is tailored to.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/the-length-of-integer-in-the-nix-language/24958/1

@ShamrockLee
Copy link
Contributor

ShamrockLee commented Jan 26, 2023

Thu correct synopsis would be

builtins.hashTo algo base hash

so that the hash algorithm would be available to the function. It is similar to the --type *algo* flag in the command line interface.

We could define an additional sriHashTo base hash as builtin or as a wrapper of builtins.hashTo, as the hash algorithm is prefixed in the SRI hash.

@amarshall
Copy link
Member

Now that #7708 is merged, I believe this is resolved and can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants