Skip to content

lib: add fromHexString#266705

Closed
lucasew wants to merge 1 commit intoNixOS:masterfrom
lucasew:lib/fromHexString
Closed

lib: add fromHexString#266705
lucasew wants to merge 1 commit intoNixOS:masterfrom
lucasew:lib/fromHexString

Conversation

@lucasew
Copy link
Copy Markdown
Contributor

@lucasew lucasew commented Nov 10, 2023

Description of changes

Add a function that convert an hexadecimal string to it's int representation

Simplification of #258834

How to test:

  • nix-instantiate --eval lib/tests/misc.nix

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Signed-off-by: lucasew <lucas59356@gmail.com>
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Nov 10, 2023
@lucasew lucasew marked this pull request as ready for review November 10, 2023 17:44
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Nov 10, 2023
*/
fromHexString = value:
let
parsed = builtins.fromTOML "v=0x${value}";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure to check for the limits of this approach. I recommend a single builtins.match "^[0-9a-fA-F]{,<maximum>}$" value to validate there's no invalid characters and not too many (fill in ). The current length limit should also be documented as a warning in the docs (see here), with a note that it could get increased in the future.

Comment on lines +167 to +170
testFromHexStringSecondExample = {
expr = fromHexString (builtins.hashString "sha256" "test");
expected = 9223372036854775807;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will run into the length limit, needs some trimming :)

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 20, 2024
@woojiq woojiq mentioned this pull request Jun 10, 2024
3 tasks
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@woojiq
Copy link
Copy Markdown
Contributor

woojiq commented Jul 13, 2024

This PR can be closed since I cherry-picked the commit into #318712

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 13, 2024
@lucasew lucasew closed this Jul 13, 2024
@lucasew lucasew deleted the lib/fromHexString branch July 13, 2024 09:06
emilazy added a commit to emilazy/nixpkgs that referenced this pull request Aug 14, 2025
This was cherry‐picked from
<NixOS#266705> and merged as part of
<NixOS#318712>, despite there being
a blocking review on the former pointing out these kinds of issues.

This documents some of the dodgy behaviour. It also can’t handle
negative literals. It might be worth considering deprecating and
dropping this, by inlining it into `lib.network.ipv6.fromString`,
its only in‐tree user.
@emilazy
Copy link
Copy Markdown
Member

emilazy commented Aug 14, 2025

FWIW, this should really not have been merged in its current state without the review comments being addressed; see #433710.

nixpkgs-ci bot pushed a commit that referenced this pull request Aug 16, 2025
This was cherry‐picked from
<#266705> and merged as part of
<#318712>, despite there being
a blocking review on the former pointing out these kinds of issues.

This documents some of the dodgy behaviour. It also can’t handle
negative literals. It might be worth considering deprecating and
dropping this, by inlining it into `lib.network.ipv6.fromString`,
its only in‐tree user.

(cherry picked from commit 6673e05)
arcnmx pushed a commit to arcnmx/nixpkgs-lib that referenced this pull request Aug 29, 2025
This was cherry‐picked from
<NixOS/nixpkgs#266705> and merged as part of
<NixOS/nixpkgs#318712>, despite there being
a blocking review on the former pointing out these kinds of issues.

This documents some of the dodgy behaviour. It also can’t handle
negative literals. It might be worth considering deprecating and
dropping this, by inlining it into `lib.network.ipv6.fromString`,
its only in‐tree user.

(cherry picked from commit 6673e05ad065b0f2388c94cc3b3445f9f7da780e)
github-actions bot pushed a commit to yunfachi/nixpkgs.lib that referenced this pull request Oct 28, 2025
This was cherry‐picked from
<NixOS/nixpkgs#266705> and merged as part of
<NixOS/nixpkgs#318712>, despite there being
a blocking review on the former pointing out these kinds of issues.

This documents some of the dodgy behaviour. It also can’t handle
negative literals. It might be worth considering deprecating and
dropping this, by inlining it into `lib.network.ipv6.fromString`,
its only in‐tree user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants