about summary refs log tree commit diff
path: root/tvix/nix-compat/src/nixhash/mod.rs (follow)
AgeCommit message (Collapse)AuthorFilesLines
13 days r/7972 chore(nix-compat/nixhash): migrate from test_case to rstestFlorian Klink1-12/+14
Change-Id: I053f2c7fc9fdf59de5d8697eab32644b860e40be Reviewed-on: https://cl.tvl.fyi/c/depot/+/11471 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: Connor Brewster <cbrewster@hey.com> Tested-by: BuildkiteCI
2024-04-13 r/7890 feat(tvix/nix-compat): implement Serialize, Deserialize for NixHashFlorian Klink1-7/+48
We use the (slightly more tolerant) from_str to deserialize, and serialize out as SRI. Change-Id: If76b0ed2d4e243904f02df34f6c90b976c0bab8c Reviewed-on: https://cl.tvl.fyi/c/depot/+/11393 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
2024-03-23 r/7763 fix(nix-compat/nixhash): fix SRI string parsing with superfluous suffixFlorian Klink1-41/+38
We tried to be more strict than Nix, actually detecting if multiple hashes were specified, or other garbage at the end. However, Nix seems to just chop off at the end, so happily accepts anything afterwards. Example: https://github.com/NixOS/nixpkgs/pull/298041 Example: https://github.com/NixOS/nixpkgs/pull/298052 Change-Id: I2c1a49f51c8f8589a84df2fbf148e67e7380b550 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11234 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
2024-03-03 r/7634 feat(tvix/nix-compat): add HashMode and CAHash::mode()Florian Klink1-0/+1
This allows peeking at the mode without matching on all enum kinds of CAHash directly. Change-Id: Icca147a876f7f4cff0bbaa067ac4dae40d05bee9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11069 Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: Brian Olsen <me@griff.name> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
2024-02-21 r/7582 feat(tvix/nix-compat): generalize aterm writing for derivationPeter Kolloch1-0/+30
...so that we can also use `StorePath`s in derivation.input_derivations. Towards https://b.tvl.fyi/issues/264 Change-Id: I71d296ca273979c70f277a7f4f88a5f76de3d8be Reviewed-on: https://cl.tvl.fyi/c/depot/+/10973 Reviewed-by: Peter Kolloch <info@eigenvalue.net> Autosubmit: Peter Kolloch <info@eigenvalue.net> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
2024-02-19 r/7560 feat(tvix/nix-compat): Extract to_plain_hex_stringPeter Kolloch1-5/+6
Towards https://b.tvl.fyi/issues/264 Change-Id: Ibde971bfb6baa97b5c678d84ce1941189bc59f6f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10969 Reviewed-by: flokli <flokli@flokli.de> Autosubmit: Peter Kolloch <info@eigenvalue.net> Tested-by: BuildkiteCI
2024-01-20 r/7429 fix(nix-compat): accept SRI hashes of invalid lengthRyan Lahfa1-2/+36
In cl/10468, we accepted SRI hashes of invalid padding while checking their trailing bits. In this commit, we accept SRI hashes of invalid padding and invalid length, as Nix does. Real world example: `pkgs.javaPackages.openjfx11.deps` <https://github.com/NixOS/nixpkgs/blob/849e4dc5ff0ae70fb7a0df19dbbf633e408c0f32/pkgs/development/compilers/openjdk/openjfx/11.nix#L71> in nixpkgs. Change-Id: I834437e7b94dab9fbb030163f7a2741f52bbf03a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10668 Autosubmit: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
2024-01-03 r/7309 fix(nix-compat/nix-hash): relax padding requirementsFlorian Klink1-22/+29
Nix is quite tolerant when it comes to parsing SRI hashes and their padding (and only for SRI hashes, it funnily is strict about that in the non-SRI-hash case). Nix essentially accepts any number of padding characters, no matter if it's too much or too little. So we do the only sane thing - simply strip all padding characters, and parse it with BASE64_NOPAD and the length the algo uses. Change-Id: I6a721aa289b06cc36741589792b9dd4c4f930b86 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10468 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
2023-12-21 r/7243 docs(nix-compat/nixhash): fix referenceFlorian Klink1-1/+1
Change-Id: I95c35a1405601c6f79cbc03462ab7c7cd6f08f2a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10397 Tested-by: BuildkiteCI Reviewed-by: edef <edef@edef.eu> Autosubmit: flokli <flokli@flokli.de>
2023-11-22 r/7045 refactor(tvix/nix-compat): cleanup parse_{ca,hash} and fmt structsFlorian Klink1-1/+28
These were used to format to and parse from strings. Move this to the CAHash and NixHash structs directly, and be explicit in the name about which encoding for digests is used. For output path calculation, nix encodes the nixpaths in hex, but for writing out NARInfos, it's using nixbase32. Change-Id: Ia585a76a3811b2609e7ce259fda66a29403b7e07 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10079 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
2023-11-10 r/6983 feat(nix-compat/nixbase32): use data_encoding::DecodeErroredef1-1/+1
Rather than having our own error type, just make decoding errors use the same common error type. Change-Id: Ie2c86972f3745c695253adc3214444ac0ab8db6e Reviewed-on: https://cl.tvl.fyi/c/depot/+/9995 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
2023-10-27 r/6883 refactor(tvix): condense long bytestringsedef1-33/+10
Change-Id: I3bea0827ec2c8db835334ce378a7bf3a39e9b1a3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9849 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
2023-10-23 r/6871 refactor(tvix/nix-compat): rename NixHashWithMode -> CAHashFlorian Klink1-2/+2
This specific struct is only used to represent content-addressed paths (in case a Derivation has a fixed-output hash, for example). Rename `Output`'s `hash_with_mode` to `ca_hash`. We now also include `CAHash::Text`, and update the `validate` function of the `Output` struct to reject text hashes there. This allows cleaning up the various output path calculation functions inside nix-compat/src/store_path/utils.rs, as they can now match on the type. `make_type` is renamed to `make_references_string`, `build_regular_ca_path` is renamed to `build_ca_path`, and `build_text_path` has a disclaimer added, because you might not actually want to use it. Change-Id: I674d065f2ed5c804012ddfed56e161ac49d23931 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9814 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
2023-10-16 r/6831 feat(nix-compat/{aterm,derivation}): init parserFlorian Klink1-1/+1
This provides a nom-based parser for Nix derivations in ATerm format, which can be reached via `Derivation::from_aterm_bytes`. Some of the lower-level ATerm primitives are moved into a (new) aterm module, and some more higher-level ones that construct derivation- specific types. Also, move the escape_bytes function into there, this is a generic ATerm thing. Change-Id: I2b03b8a1461c7ea2fcb8640c2fc3d1fa3ea719fb Reviewed-on: https://cl.tvl.fyi/c/depot/+/9730 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
2023-10-15 r/6813 feat(tvix/nix-compat/nixhash/NixHashWithMode): from_algo_mode_hashFlorian Klink1-2/+2
Change-Id: Ieae628fab1926a498ae5c3eb27df1b722e6151d7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9728 Reviewed-by: edef <edef@edef.eu> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
2023-10-15 r/6812 refactor(nix-compat/nixhash): add Result type aliasFlorian Klink1-6/+9
Change-Id: Id0248047e9642d38afc106629957a2e7608f8c78 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9727 Reviewed-by: Connor Brewster <cbrewster@hey.com> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
2023-10-15 r/6811 refactor(nix-compat/nixhash): box sha512Florian Klink1-4/+4
Limit the amount of memory consumed on the stack for NixHash. Sha512 isn't used that often, so it's fine if we heap-allocate it. Change-Id: I4a9eecd20c6184610124dc130c41bfa5d0dc04c5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9726 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: Connor Brewster <cbrewster@hey.com>
2023-10-14 r/6807 refactor(tvix/nix-compat): make NixHash an enum with fixed-len bytesFlorian Klink1-131/+147
Less Vec<u8> passed around. Change-Id: Ie153a6bfaa084d7490ffa38634efdf5f3c31a768 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9722 Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
2023-08-20 r/6513 docs(tvix/nix-compat/nixhash): update commentsFlorian Klink1-4/+6
Change-Id: I46660da84065fd6938f581e14d67e231dca3c3ea Reviewed-on: https://cl.tvl.fyi/c/depot/+/9112 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
2023-08-20 r/6512 refactor(tvix/nix-compat/nixhash): validate digest lengthsFlorian Klink1-7/+17
There was a NixHash::new() before, which didn't perform any validation of the digest length. We had some length validation when parsing nix hashes or SRI hashes, but some places didn't perform validation and/or constructed the struct directly. Replace NixHash::new() with a `impl TryFrom<(HashAlgo, Vec<u8>)> for NixHash`, which does do this validation, and update constructing code to use that, rather than populating structs directly. In some rare cases where we're sure the digest length is correct we still populate the struct manually. Fixes b/291. Change-Id: I7a323c5b18d94de0ec15e391b3e7586df42f4229 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9109 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
2023-08-19 r/6489 refactor(tvix/nix-compat/nixhash): use shorthand struct initFlorian Klink1-1/+1
Change-Id: I1e52b752408a70fdb27e3e5c6f3bef5417b3e922 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9085 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de>
2023-07-31 r/6446 chore(tvix/nix-compat): drop useless cloneFlorian Klink1-1/+1
HashAlgo implements Copy, no need to clone here. Change-Id: Ief11d2cfbd4fd0cd44224c7ddd575f518edbbd55 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8989 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: flokli <flokli@flokli.de>
2023-03-31 r/6068 refactor(nix-compat) Make `nixhash_*` mods hierarchicalJohn Ericson1-0/+454
They can go under `nixhash` Change-Id: Ia15835c57130b66d58f5df80ae9595dceee00941 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8408 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI