Commit graph

115 commits

Author SHA1 Message Date
Silvan Mosberger dd72ff27f7 lib.attrsets.foldlAttrs: Make stricter
See the parent commit for the same change to lib.lists.foldl'
2023-09-27 02:43:59 +02:00
Silvan Mosberger 3b6169f87b lib.lists.foldl': Make strict in the initial accumulator
To maintain backwards compatibility, this can't be changed in the Nix language.
We can however ensure that the version Nixpkgs has the more intuitive behavior.
2023-09-27 02:43:59 +02:00
Silvan Mosberger 9893fee947 lib.lists.foldl': Add tests 2023-09-26 18:55:54 +02:00
VwCSXg 147560180c lib.generators.toGitINI: added test
Added basic generators.toGitINI test.
Mostly taken from 958c06303f/tests/modules/programs/git/git.nix.
The ${"\t} escape is used so that the lines aren't recognized as "Wrong
indent style".
2023-08-21 13:12:40 +02:00
Silvan Mosberger 8fab18d4c1 lib.removePrefix: Add tests 2023-08-14 23:29:00 +02:00
Silvan Mosberger 87c5a6a84f
Merge pull request #243511 from tweag/lib.lists.hasPrefix
`lib.lists.{hasPrefix,removePrefix}`: init
2023-08-14 21:15:54 +02:00
Silvan Mosberger bd74cdfb2e
Merge pull request #243520 from tweag/lib.lists.commonPrefix
`lib.lists.{findFirstIndex,commonPrefix}`: init
2023-07-26 23:14:58 +02:00
Silvan Mosberger 7f61b01600 lib.lists.commonPrefix: init 2023-07-20 22:42:01 +02:00
Silvan Mosberger 53dcfd24ad lib.lists.findFirstIndex: init
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-07-19 17:35:28 +02:00
Robert Hensing 0665253b86
Merge pull request #244044 from tweag/lib-readme
Create a Readme in `lib`
2023-07-19 16:34:36 +02:00
Silvan Mosberger fa503f4b92 lib.attrsets.mergeAttrsList: init
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-07-18 20:27:15 +02:00
Silvan Mosberger 581d7c88be lib/tests: Unify documentation of individual testable files 2023-07-18 17:22:45 +02:00
Silvan Mosberger 9fdc0bb2bf lib.lists.removePrefix: init 2023-07-14 19:36:46 +02:00
Silvan Mosberger bc8fbc2572 lib.lists.hasPrefix: init 2023-07-14 19:36:45 +02:00
Silvan Mosberger 9790e70150 lib.list.findFirst: Make lazier
There's no need to evaluate list elements after a matching element
2023-06-06 17:17:32 +02:00
Silvan Mosberger 6996f76885 lib/tests: Add findFirst tests 2023-06-06 17:06:18 +02:00
toonn e31c8b22dd
Merge pull request #223407 from AngryAnt/toplist-path
lib.toPlist: Add support for path values
2023-05-05 21:15:23 +02:00
Mykola Orliuk 7287c0e076 lib.generators.toLua: asBindings option
Allows to generate code block for setting of global variables
2023-04-29 19:26:35 +02:00
Mykola Orliuk e9b416168a lib.generators.toLua: allow disabling multiline 2023-04-23 19:46:14 +02:00
Mykola Orliuk 4ec4c6fda9 lib/generators: add toLua/mkLuaInline
Suitable to simplify Lua-based configurations like neovim-lspconfig that
might need to interpolate Nix package paths.
2023-04-23 01:07:58 +02:00
Emil "AngryAnt" Johansen e932e98437
lib.toPlist: keep test output in external files for their tab indents 2023-03-27 19:25:52 +02:00
Emil "AngryAnt" Johansen 63a8c43d09
lib.toPlist: basic test coverage 2023-03-27 19:25:38 +02:00
hsjobeki 15a8d05ba5 init: lib.foldlAttrs
- provide comprehensive example
- add unit test
2023-03-11 10:42:00 +01:00
Patrick Widmer 7089294f10 strings: add escapeQuery for url encoding 2023-03-03 20:48:55 +01:00
Silvan Mosberger 0a60663e67
Merge pull request #206611 from h7x4/lib-lists-add-repeat
lib.lists: add `replicate`
2023-02-07 06:16:09 +01:00
h7x4 7c4abbf80e
lib.lists: add replicate
`replicate` returns n copies of an element as a list.

Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
2023-02-06 20:40:47 +01:00
Silvan Mosberger 50e4dbf35b
Merge pull request #205557 from ncfavier/concatLines
lib/strings: add `concatLines`
2023-01-31 18:05:53 +01:00
Naïm Favier 0355479715
lib/versions: add pad
Pad a version string with zeros to match a given number of components.
2022-12-21 12:58:21 +01:00
Robert Hensing efa1140e83
Merge pull request #205457 from h7x4/lib-strings-toInt-broken-for-negative-numbers
lib.strings: fix negative number handling for `toInt` and `toIntBase10`
2022-12-11 02:26:42 +01:00
Naïm Favier ed0b8c26f1
lib/strings: add concatLines
Like `unlines` from Haskell.

The aim is to replace the `concatStringsSep "\n"` pattern for generated
files, which doesn't add a final newline.
2022-12-10 15:56:30 +01:00
h7x4 62e863e98c
lib.strings: fix negative number handling for toInt and toIntBase10
The previous version would be unstable due to an input validation regex
not expecting a '-' in front of the number.
2022-12-10 13:16:45 +01:00
Naïm Favier 6a117e2759 nixos/doc: render option values using lib.generators.toPretty
Render un`_type`d defaults and examples as `literalExpression`s using
`lib.generators.toPretty` so that consumers don't have to reinvent Nix
pretty-printing. `renderOptionValue` is kept internal for now intentionally.

Make `toPretty` print floats as valid Nix values (without a tilde).

Get rid of the now-obsolete `substSpecial` function.

Move towards disallowing evaluation of packages in the manual by
raising a warning on `pkgs.foo.{outPath,drvPath}`; later, this should
throw an error. Instead, module authors should use `literalExpression`
and `mkPackageOption`.
2022-12-08 17:52:52 +01:00
Naïm Favier 0b661ce32a lib/generators.toPretty: escape strings properly 2022-12-08 17:52:52 +01:00
Naïm Favier 0fa7b1b004 lib/generators.toPretty: don't evaluate derivations
With the goal of making `toPretty` suitable for rendering option
values, render derivations as `<derivation foo-1.0>` instead of
`<derivation /nix/store/…-foo-1.0.drv>`.

This is to avoid causing sudden evaluation errors for out-of-tree
projects that have options with `default = pkgs.someUnfreePackage;` and
no `defaultText`.
2022-12-08 17:52:52 +01:00
figsoda f993f8a186 lib/attrsets: add concatMapAttrs 2022-11-17 10:41:53 -05:00
Jacob Abel ed71173841
lib/strings: Update docs and restructured code to improve readability of toInt and toIntBase10. 2022-10-23 17:50:24 -04:00
Jacob Abel 39a4ab78a1
lib/strings: Refactor toInt into toInt and toIntBase10 2022-10-23 17:50:24 -04:00
Jacob Abel 3d196a5f2a
lib/strings: Update toInt to handle intermixed ws and zeros. Added tests 2022-10-23 17:50:23 -04:00
Jacob Abel febff1dccd
lib/strings: allow toInt to parse zero-padded strings 2022-10-23 17:50:20 -04:00
Daniel Olsen 23c1754fff lib/tests/misc: Add tests for charToInt, escapeC, and normalizePath 2022-10-20 20:12:15 +02:00
Robert Hensing fce8b018f0 lib: Add lazyDerivation 2022-09-21 10:55:07 +01:00
Robert Hensing 1cbe950384 lib.types: Add parentheses where description is ambiguous 2022-09-17 22:16:39 +01:00
Silvan Mosberger 4b2827e6a1
Merge pull request #168374 from Ma27/special-attrs-in-with-recursion
lib/generators: withRecursion: don't break attr-sets with special attrs
2022-05-23 17:55:18 +02:00
adisbladis 161776ec1e Revert "lib: init flakes.nix"
This reverts commit PR #167947.

Flakes aren't standardised and the `lib` namespace shouldn't be
polluted with utilities that serve only experimental uses.
2022-05-15 22:39:46 +12:00
Naïm Favier 4d2ea62d82
lib/strings/toShellVars: handle derivations as strings 2022-05-07 17:01:51 +02:00
Robert Hensing 761c21a16a
Merge pull request #170090 from danth/has-infix-toString
lib/strings: call toString within hasInfix
2022-05-02 09:47:15 +02:00
Daniel Thwaites 7b5be1a0f8 lib/tests: add tests for hasInfix
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-05-02 09:05:56 +02:00
Artturi a5357d06e4
Merge pull request #167947 from MatthewCroughan/mc/callLocklessFlake
lib: add callLocklessFlake
2022-05-01 23:06:17 +03:00
Naïm Favier 226bc99659
lib/strings: add toShellVars
A straightforward piece of plumbing to safely inject Nix variables into
shell scripts:

''
  ${lib.toShellVars { inherit foo bar; }}
  cmd "$foo" --bar "$bar"
''
2022-04-27 16:04:17 +02:00
matthewcroughan 3f128cc024 lib/tests: evaluate value from subflake with callLocklessFlake 2022-04-12 21:22:36 +01:00