188 Commits

Author SHA1 Message Date
Matt Sturgeon
986cb78f05 Reapply "lib/strings.concatLines: call concatStringsSep directly"
But also handle empty lists.

This effectively reapplies commit d7e6988c9b
which was reverted by commit 66f4e5d988.

Co-authored-by: Eman Resu <78693624+quatquatt@users.noreply.github.com>
2026-04-28 20:19:04 +01:00
Johannes Kirschbauer
66f4e5d988 Revert "lib/strings.concatLines: call concatStringsSep directly"
This reverts commit d7e6988c9b.
2026-04-28 10:04:39 +02:00
Johannes Kirschbauer
51f38b40cd lib/strings.concatLines: call concatStringsSep directly (#506077) 2026-04-16 19:32:28 +00:00
Eman Resu
d7e6988c9b lib/strings.concatLines: call concatStringsSep directly 2026-04-03 12:54:06 -04:00
İlkecan Bozdoğan
e394a579b0 lib: update type signatures
- concrete types start with uppercase: Int, String, Bool, Derivation,
  etc.
- type variables start with lowercase: a, b, etc.
- list:
  - use `[x]` for homogeneous lists instead of `List x` or `[ x ]`
  - use `List` for heterogeneous lists (not that common in `lib`)
- attr:
  - use `AttrSet` for a generic attribute set type
  - use `{ key1 :: Type1; key2 :: Type2; ... }` for adding signatures
    for known attribute names and types
  - use `{ key1 = value1; key2 = value2; ... }` for adding attributes
    with known literals
  - end with an ellipsis (`...`) if the set can contain unknown
    attributes
  - use `{ [String] :: x }` if all the attributes has the same type `x`
- prefer `Any` over `a` if the latter is not reused
2026-03-04 00:10:00 +03:00
Niclas Overby
7b16ea8b4e lib: re-export missing pure builtins in lib 2026-01-24 11:10:58 +01:00
Mikael Voss
f9fbbe20a5 lib/strings: order documented cmakeOptionType inputs correctly
The function is defined to take type, feature and value, but the
documented order was feature, type, value.
2026-01-14 20:29:20 -05:00
Shelvacu
5018a33b62 lib/strings.escapeNixIdentifier: quote keywords
Previously `lib.strings.escapeNixIdentifier "assert"` would return `"assert"`; This is wrong, `assert` is not a valid identifier unless quoted.\

This also fixes `lib.generators.toPretty`: `toPretty {} { "assert" = false; }` would previously return an invalid expression.
2026-01-02 13:47:32 -08:00
Anton Mosich
23808c75a8 docs/lib: Make links to clickable hyperlinks 2025-11-29 22:14:16 +01:00
Anton Mosich
31692961e7 docs/lib/strings: wrap command line arguments in quotes and backticks 2025-11-29 21:49:38 +01:00
Anton Mosich
367d102c09 docs/lib: use backticks for nix names 2025-11-29 21:46:54 +01:00
Jacob Abel
c137fe9433 lib/strings.nix: Fix cmakeOptionType argument order in docs
Arguments were listed out of order in the documentation. Fixes that.

Signed-off-by: Jacob Abel <jacobabel@nullpo.dev>
2025-11-28 20:17:12 -05:00
Aliaksandr
dc7095a86e treewide: remove deprecated lib functions that had warning for more than 2 years 2025-10-24 06:30:16 +03:00
Johannes Kirschbauer
bb9da33c62 lib/*: fix docs to use "returns" instead of "return" (#442388) 2025-10-06 08:09:54 +00:00
Robert Hensing
6a5f6f1a4e lib: init strings.join (#446278) 2025-10-02 15:34:34 +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
Johannes Kirschbauer
b37ac6a920 lib: init strings.join 2025-09-27 09:18:37 +02:00
Felix Buehler
06ac3fbebd lib/*: fix docs to use "returns" instead of "return" 2025-09-12 16:16:41 +02:00
Gutyina Gergő
b3b0fd266b lib: prefer replaceString over replaceStrings 2025-05-28 00:20:57 +02:00
Gutyina Gergő
b5720e2b3f lib/strings: init replaceString 2025-05-28 00:20:56 +02:00
Heitor Augusto
24e8a790b7 lib.strings: init toCamelCase 2025-05-11 20:24:56 -03:00
Pol Dellaiera
a9320986b3 lib.strings: init splitStringBy (#385643) 2025-04-23 04:51:38 +00:00
Mikael Voss
487a002c63 lib/strings: Zero‐pad hex digits in escapeC
lib.strings.escapeC produces single‐digit hexadecimal strings for
character values ≤ 15, which results in an ambiguity. If the following
character is a hex digit, it will be interpreted as being part of the
escape sequence.

systemd, which also relies on C‐style escape sequences, does not
decode single‐digit sequences at all, even if unambiguous.

Padding the hexadecimal string with "0" avoids this problem.
2025-04-18 13:41:53 +02:00
Heitor Augusto
bb4be9a474 lib.strings: init splitStringBy 2025-04-07 15:51:18 -03:00
Silvan Mosberger
e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +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
Tristan Ross
b26e122b14 lib.cmakeOptionType: support list 2025-03-26 21:12:07 -07:00
Mikael Voss
7a07cc0da9 lib/strings: allow CA paths in isStorePath 2025-03-05 13:08:41 +01:00
isabel
b109863c25 lib.strings: init toSentenceCase 2025-02-19 12:10:39 +00:00
Yueh-Shun Li
b1371135b5 lib.strings.concatMapAttrsStringSep: init 2024-12-06 11:02:26 +08:00
Robert Hensing
729225e355 treewide: lib.isInOldestRelease -> lib.oldestSupportedReleaseIsAtLeast 2024-10-08 11:14:24 +02:00
adisbladis
8a20781579 lib.strings.trimWith: Refactor scoping
I wanted to use this instead of [my ownimplementation](https://github.com/nix-community/pyproject.nix/blob/65d4134/lib/util.nix#L18-L23) and got a small performance regression.
2024-09-03 01:15:51 +12:00
Gabriella Gonzalez
75c122699a lib.cli.escapeShellArg{,s}: Only escape when necessary (#333744)
These utilities will now leave the string undisturbed if it doesn't need to be quoted (because it doesn't have any special characters). This can help generate nicer-looking command lines.

This also transitively improves the output of `lib.toGNUCommandLine` which uses `escapeShellArg` internally
2024-08-16 16:26:08 +02:00
Johannes Kirschbauer
aba0f17b5a Doc: migrate lib.strings to commonmark 2024-07-27 14:39:31 +02:00
Silvan Mosberger
60027e7836 lib.trimWith: Minor doc improvements 2024-07-26 01:16:49 +02:00
Matt Sturgeon
aad87c2aa8 lib.strings: add trim and trimWith
`strings.trim` returns a copy of the string with all leading and trailing
whitespace removed.

`strings.trimWith` does the same thing, but calling code can decide
whether to trim the start and/or end of the string.
2024-07-25 23:43:33 +01:00
Florian Richer
3b883d3cdf lib/strings: Add makeIncludePath (#296237)
* Update strings.nix

* Fix typo in docs

* Update lib/strings.nix

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>

* Update lib/strings.nix

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>

* Add unit test with strings

* Move test to strings

* Add unit test with package structure

* testMakeIncludePathWithPkgs: use real pkgs

* Revert "testMakeIncludePathWithPkgs: use real pkgs"

This reverts commit fb1850c069.

* Update lib/tests/misc.nix

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>

* Update lib/tests/misc.nix

Co-authored-by: Silvan Mosberger <github@infinisil.com>

---------

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2024-04-02 19:01:05 +02:00
adisbladis
b3cc51a20f lib.toInt/toIntBase10: Make more efficient by hoisting up internal strings into higher scope 2024-03-03 16:52:31 +13:00
Silvan Mosberger
f2c837700d lib.strings: Remove unneeded polyfill
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-09 05:46:05 +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
Silvan Mosberger
04efefaa4c Merge pull request #273473 from adisbladis/lib-isConvertibleToString-static-list
lib.isConvertibleToString: Statically compute types list
2023-12-11 17:46:48 +01:00
adisbladis
2d47874820 lib.cmakeOptionType: Statically compute types list 2023-12-11 16:47:22 +13:00
adisbladis
a128a3f234 lib.isConvertibleToString: Statically compute types list 2023-12-11 16:42:13 +13:00
adisbladis
bd817120c4 lib.strings: Dont create scopes for getName/getVersion
We can create the `parse` function in a scope one level up to avoid recomputing it every time.
2023-12-11 14:49:11 +13:00
h7x4
206d20426c lib.strings: add replicate
`strings.replicate` returns n copies of a string, concatenated into a new
string

Co-authored-by: Silvan Mosberger <github@infinisil.com>
2023-10-31 20:25:41 +01:00
Anderson Torres
0de25e25b0 lib: refactor
- rename `(enable|with)Feature(As|)` inputs to more descriptive names
2023-10-09 17:49:02 -03:00
Anderson Torres
cc3383d12b lib: add cmakeOptionType, cmakeBool and cmakeFeature 2023-09-27 20:49:38 -03:00
Silvan Mosberger
150217c1ac lib.removePrefix: Optimise 2023-08-14 23:32:42 +02:00
figsoda
57ca44c0ae lib: simplify stringToCharacters 2023-06-22 18:27:15 -04:00
Silvan Mosberger
592213ad3f lib.path.hasPrefix: init 2023-06-15 22:29:46 +02:00