Commit graph

141 commits

Author SHA1 Message Date
Johannes Kirschbauer bb9da33c62
lib/*: fix docs to use "returns" instead of "return" (#442388) 2025-10-06 08:09:54 +00:00
NAHO 6177c4ad72
lib: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd --type file . lib --exec-batch sed --in-place --regexp-extended "
      s/\<builtins\.($(
        printf '%s\n' "${builtins[@]}" |
          paste --delimiter '|' --serial -
      ))\>/\1/g
    "

    nix fmt
2025-09-30 09:02:59 +02:00
Felix Buehler 06ac3fbebd lib/*: fix docs to use "returns" instead of "return" 2025-09-12 16:16:41 +02:00
Johannes Kirschbauer 0047f9de6c
lib/trivial: add boolToYesNo (#413036) 2025-09-12 13:05:31 +00:00
Felix Buehler c1ad4464c6 lib/trivial: add boolToYesNo 2025-09-11 21:48:47 +02:00
Emily 3c7d67da23 lib: deprecate fromHexString on dodgy inputs
See <https://github.com/NixOS/nixpkgs/pull/433710>.
2025-08-16 13:36:05 +01:00
Emily 449ad44f16 lib: fix overflowing fromHexString tests and example
`fromHexString` is backed by `builtins.fromTOML`. Per [the TOML
v1.0.0 specification]:

> Arbitrary 64-bit signed integers (from −2^63 to 2^63−1) should be
> accepted and handled losslessly. If an integer cannot be represented
> losslessly, an error must be thrown.

[the TOML v1.0.0 specification]: <https://toml.io/en/v1.0.0#integer>

The saturating behaviour of the toml11 version currently used
by Nix is not lossless, and is therefore a violation of the TOML
specification. We should not be relying on it. This blocks the update
of toml11, as it became stricter about reporting this condition.

This, yes, is arguably an evaluation compatibility break. However,
integer overflow was recently explicitly defined as an error by
both Nix and Lix, as opposed to the C++ undefined behaviour it was
previously implemented as:

* <https://nix.dev/manual/nix/stable/release-notes/rl-2.25>
* <https://docs.lix.systems/manual/lix/stable/release-notes/rl-2.91.html#fixes>

This included changing `builtins.fromJSON` to explicitly
reject overflowing integer literals. I believe that the case for
`builtins.fromTOML` is comparable, and that we are effectively testing
undefined behaviour in TOML and the Nix language here, in the same way
that we would have been if we had tests relying on overflowing integer
arithmetic. I am not aware of any use of this behaviour outside of
these tests; the reverted toml11 bump in Nix did not break the 23.11
evaluation regression test, for example.

C++ undefined behaviour is not involved here, as toml11 used the C++
formatted input functions that are specified to saturate on invalid
values. But it’s still a violation of the TOML specification caused
by insufficient error checking in the old version of the library,
and inconsistent with the handling of overflowing literals in the
rest of Nix.

Let’s fix this so that Nix implementations can correctly flag up
this error and we can unblock the toml11 update.
2025-08-14 21:02:11 +01:00
Leona Maroni c62f186127
lib/trivial: update oldestSupportedRelease to 2505
24.11 is deprecated now
2025-08-01 16:05:51 +02:00
Leona Maroni e56e0beed4
25.11 is Xantusia 2025-05-16 19:21:55 +02:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Weijia Wang 2927d4b6ba lib/trivial: update oldestSupportedRelease 2024-12-31 22:15:23 +01:00
Simon Žlender 8ba40fdd4f lib: add defaultTo 2024-12-01 10:58:42 +01:00
Tristan Ross 90fcf3aa7e
25.05 is Warbler 2024-11-14 09:10:54 -08:00
Robert Hensing c2b411e674 lib.oldestSupportedReleaseIsAtLeast: rename from bad name and deprecate after 24.11
It seems impossible to describe this condition more concisely without making
it incomprehensible.
2024-10-08 11:04:29 +02:00
Robert Hensing db77328e33
Merge pull request #306481 from hercules-ci/lib-builtins-warn
lib.warn: Use or behave like builtins.warn
2024-07-23 13:41:03 +02:00
Robert Hensing bc556c5686 lib.warn: Update docs
- Bring up to date
- Give meaning to the metavariables
- Use italics for metavariables (just like the Nix manual)
- Don't abbreviate
  - No hard feelings, Val.
2024-07-23 12:48:01 +02:00
Robert Hensing 7d4a9a5772 lib.warn: Remove color from the message itself
This aligns with Nix and makes it more readable.
The prefix still stands out.
2024-07-16 15:56:01 +02:00
Robert Hensing f621ab9204 lib.warn: Fix color
Co-authored-by: Aleksana <alexander.huang.y@gmail.com>
2024-07-16 15:54:12 +02:00
Janik c20399ea2e
Merge pull request #318712 from woojiq/lib-network-ipv6-parser
lib.network: add ipv6 parser
2024-07-11 20:57:53 +02:00
Weijia Wang f136ad9609 lib/trivial: update oldestSupportedRelease 2024-07-01 08:49:45 +02:00
lucasew 52cc703bba lib: add fromHexString
Co-authored-by: lucasew <lucas59356@gmail.com>
2024-06-28 20:53:53 +03:00
Jörg Thalheim b17538d34d
Merge pull request #318511 from sg-qwt/master
24.11 rename codeName to Vicuna
2024-06-13 13:04:22 +02:00
Samuel Shuert cfc6c9b6e4 lib.trivial.importJSON: add example
Add parity with importTOML.
2024-06-13 03:12:03 +02:00
Samuel Shuert 64f0f7a448 lib.trivial.importTOML: add example
Friend came to me with misunderstanding of how this function works.
After discussion we came to the conclusion having an example would have
prevented this.
2024-06-13 03:11:56 +02:00
無名氏 0ea93461ed 24.11 rename codeName to Vicuna 2024-06-09 19:31:01 +08:00
Lorenz Leutgeb 4584ea0767 lib.warn: Say _evaluation_ warning, like builtins.warn 2024-06-06 01:15:38 +02:00
Weijia Wang 4a817d2083 24.05 is Vicuña 2024-05-22 18:15:34 +02:00
Robert Hensing f7250f372a lib.warn: Use or behave like builtins.warn 2024-04-24 11:14:47 +02:00
edef 725bb4e48c lib: add xor
This gets clumsily reimplemented in various places, to no useful end.
2024-04-04 19:46:58 +00:00
Johannes Kirschbauer 956fff0825
doc: migrate lib.trivial to use doc-comments (#297270)
* doc: migrate lib.trivial to use doc-comments

* Apply suggestions from code review

---------

Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>
2024-03-19 19:04:14 -07:00
Robert Hensing 39327e4cf2
Merge pull request #288812 from hercules-ci/lib-flake-version
`lib/` flake: fix `lib.version`
2024-03-03 18:19:00 +01:00
Robert Hensing 17117cf565 lib flake: Fix version
Manually tested with

nix-repl> :lf path:lib
nix-repl> lib.version
2024-02-26 22:32:58 +01:00
Silvan Mosberger 27488b861c lib.trivial: Remove unneeded polyfills
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-09 05:45:31 +01:00
Alois Wohlschlager d33127863e
lib: make deprecation warnings consistent
The deprecation warnings in lib were wildly inconsistent. Different
formulations were used in different places for the same meaning. Some warnings
used builtins.trace instead of lib.warn, which prevents silencing; one even
only had a comment instead. Make everything more uniform.
2024-02-03 19:01:39 +01:00
figsoda e08ce8d1d1 lib/trivial: bump oldestSupportedRelease to 23.11 2024-01-29 12:08:59 -05:00
Silvan Mosberger 6d8c22272a
Merge pull request #273470 from adisbladis/lib-tohexstring-static-values
lib.toHexString: Statically compute hexDigits attrset
2023-12-11 17:46:23 +01:00
Silvan Mosberger 581adae822
Merge pull request #273467 from adisbladis/lib-pipe-no-let
lib.pipe: Avoid creating a scope
2023-12-11 17:16:05 +01:00
adisbladis ad647985cf lib.toHexString: Statically compute hexDigits attrset 2023-12-11 16:36:29 +13:00
adisbladis c8c2ae638a lib.pipe: Avoid creating scopes 2023-12-11 16:25:21 +13:00
Maximilian Bosch 78f5ed053a
lib/trivial: drop rec in favor of lib fixpoint
That way each expression uses the final version of other lib.trivial
declarations.

For instance, when replacing `versionSuffix` with the string `"fnord"`
in a lib overlay, `trivial.version` uses `"fnord"` as suffix now rather
than `pre-git`.
2023-12-10 13:25:24 +01:00
figsoda 87cc06983c
24.05 is Uakari 2023-11-21 14:34:30 -05:00
Yueh-Shun Li a16319908e lib.mirrorFunctionArgs: init
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2023-11-07 01:58:04 +00:00
Silvan Mosberger 59b08b7ee8
Merge pull request #235625 from ShamrockLee/lib-doc-tidy 2023-08-10 12:00:36 +02:00
Martin Weinelt c31bda504c
lib/trivial: Bump oldestSupportedReleaseto to 23.05 2023-07-04 14:17:58 +02:00
Yueh-Shun Li 96cccdd56f lib: fix nix-doc variable "Type" in comment
Fix documentation of lib.trivial.importJSON and lib.trivial.importTOML
2023-06-03 00:48:45 +08:00
Raito Bezarius 2c28f1de7c 23.11 is Tapir 2023-05-22 21:16:04 +02:00
Martin Weinelt 192f844477
lib/trival: Bump oldestSupportedRelease to 2211 2023-01-01 14:57:25 +01:00
Artturi 761a5ba7d8
Merge pull request #202370 from Artturin/revertpartof1
Revert "lib/trivial: fix 'error: cannot decode virtual path '/nix/sto…
2022-11-22 19:49:35 +02:00
Artturin f0e298c002 Revert "lib/trivial: fix 'error: cannot decode virtual path '/nix/store/virtual0000000000000000000000005-source''"
This reverts commit b67ee6e861.

https://github.com/NixOS/nixpkgs/issues/202244

error: a string that refers to a store path cannot be appended to a path, at /etc/nixos/nix/nixos-unstable/lib/sources.nix:193:30

appears to happen when there's a nixpkgs git submodule

> So one of the things that is different for a git submodule is that the .git folder isn't a folder, it's a textfile that contains (in my case) this:

> $ cat nix/nixos-unstable/.git
> gitdir: ../../.git/modules/nixpkgs
2022-11-22 18:33:09 +02:00
Martin Weinelt b68bd2ee52 23.05 is Stoat 2022-11-21 21:22:27 +01:00