Commit graph

259 commits

Author SHA1 Message Date
Johannes Kirschbauer be393db73e
lib.takeEnd: init (#398222) 2025-04-23 14:20:47 +02:00
azahi 9fee9e7371
lib.takeEnd: init 2025-04-13 17:37:35 +03:00
Heitor Augusto bb4be9a474
lib.strings: init splitStringBy 2025-04-07 15:51:18 -03:00
Robert Hensing b42b9e061b
lib.modules: init lib.mkDefinition
Free-floating definitions including file location.
2025-04-03 14:12:07 +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
Matt Sturgeon 7436684102
lib.generators: alias mkLuaInline at the top-level 2025-03-15 10:26:57 +00:00
Johannes Kirschbauer 0d52202380
lib.strings: init toSentenceCase (#381802) 2025-02-20 07:58:44 +07:00
isabel b109863c25 lib.strings: init toSentenceCase 2025-02-19 12:10:39 +00:00
Robert Hensing a7c201020d
lib: Discourage use of extend (#376033) 2025-02-09 21:04:55 +01:00
Robert Hensing 55a11de1b0 lib/default.nix: Update extend doc
Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>
2025-01-29 22:13:16 +01:00
Robert Hensing 0f9034d8b5 lib: Discourage use of extend
It creates interoperability issues that can not be reconciled by
`lib` or maintainers of projects that use the Nixpkgs library.
Occasionally, end users may be able to solve the problems they run
into, but most are not prepared to deal with this set of problems,
nor should they be.

Typical conflict:
- User wants to propagate their own lib, because it has some function
  they like to use throughout their projects
- Project maintainer requires the project's lib to be used

No sane language uses a single namespace for combining all the things.
(Arguably not even C with its extensive use of prefixing)

Meanwhile, in Nix, all symbols are first class variables. We don't even
have the concept of a global top-level namespace to pour everything into.
With `lib` you can try to approximate that, I get the appeal of its
apparent simplicity, but since `lib` can't be global, we just don't even
get that apparent simplicity.

I apologize for not offering concrete solutions to this in the text.
The manuals are limited to reference documentation.
Alternatives - of which we have multiple - are best provided in
task-oriented documentation, e.g. nix.dev.
2025-01-23 08:27:29 +01:00
Yueh-Shun Li 2439ead791 lib.extendMkDerivation: init
Add functions extendMkDerivation to lib.customisation.

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-authored-by: Lin Jian <me@linj.tech>
Co-authored-by: Philip Taron <philip.taron@gmail.com>
2025-01-18 14:20:45 +08:00
Robert Hensing 782a0e6581 lib.dropEnd: init
Naming borrowed from Haskell
- `base`: [`dropWhileEnd`]
- `extra`, `mono-traversable`, ...: [`dropEnd`]

[`dropEnd`]: https://hackage.haskell.org/package/mono-traversable-1.0.21.0/docs/Data-Sequences.html#v:dropEnd
[`dropWhileEnd`]: https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-List.html#v:dropWhileEnd
2025-01-03 12:04:06 +01:00
Silvan Mosberger 944f47455e
lib: add defaultTo (#357681) 2024-12-08 10:24:42 +01:00
Yueh-Shun Li b1371135b5 lib.strings.concatMapAttrsStringSep: init 2024-12-06 11:02:26 +08:00
ash cf9805af62 lib.derivations: add warnOnInstantiate 2024-12-02 19:09:07 +00:00
Simon Žlender 8ba40fdd4f lib: add defaultTo 2024-12-01 10:58:42 +01:00
Wolfgang Walther 73df63f8ef
lib/options: remove mdDoc
Following through on message itself.
2024-11-22 18:30:11 +01: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
Yueh-Shun Li 11c20cd390 lib.toExtension: init
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2024-09-14 20:56:47 +08:00
Silvan Mosberger f55a4b99ef lib.meta: Minor SPDX license function improvements
- Expose `lib.licensesSpdx`
- Create bindings for the needed internal functions
- Mention that some SPDX licenses might be missing (in the future I hope
  we can autogenerate the Nixpkgs license list from some SPDX endpoint
2024-08-25 00:57:44 +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
Silvan Mosberger 7c6692836e
Merge pull request #149990 from ShamrockLee/lib-spdx-license 2024-07-25 22:27:10 +02:00
Someone Serge 98384afab5 lib: add getStatic 2024-07-21 11:38:04 +00:00
Someone Serge 744305bce4 lib: add getOutput', a nix-lang counterpart of _overrideFirst 2024-07-21 11:29:23 +00: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
Robert Hensing fed26baf1e lib: Expose typeOf, unsafeGetAttrPos
All builtins should be in mirrored in lib, for consistency, as well
as control to let the Nixpkgs pin effect *subtle* improvements in
behavior (such as the foldl' accumulator strictness).
2024-07-03 11:16:31 +02:00
Yueh-Shun Li 10d2e6c906 lib.getLicenseFromSpdxIdOr: init
Add lib.meta.getLicenseFromSpdxIdOr as a variant of
lib.meta.getLicenseFromSpdxId that explicitly state the default
(fallback) value if there's no license matching the given SPDX ID.
2024-06-30 02:59:58 +08:00
woojiq d559eed93a lib.network: ipv6 parser from string
Add a library function to parse and validate an IPv6 address from a
string. It can parse the first two versions of an IPv6 address according
to https://datatracker.ietf.org/doc/html/rfc4291#section-2.2. The third
form "xxx:x.d.d.d.d" is not yet implemented. Optionally parser can accept prefix length (128 is default).

Add shell script network.sh to test IPv6 parser functionality.
2024-06-29 10:02:00 +03:00
lucasew 52cc703bba lib: add fromHexString
Co-authored-by: lucasew <lucas59356@gmail.com>
2024-06-28 20:53:53 +03:00
Silvan Mosberger 5d892a8ea5 lib: Add a TODO for builtins not available in sub-libraries 2024-06-20 22:48:55 +02:00
Silvan Mosberger 1e4f04d4d6 lib.replaceStrings: inherit from lib.strings 2024-06-20 22:48:54 +02:00
Silvan Mosberger d3c09b9327 lib.readFile: inherit from lib.trivial 2024-06-20 22:48:54 +02:00
Silvan Mosberger e3b0f46af9 lib.genericClosure: inherit from lib.trivial 2024-06-20 22:48:54 +02:00
Silvan Mosberger e3faf23ba6 lib.pathExists: inherit from lib.trivial 2024-06-20 22:48:54 +02:00
Silvan Mosberger 574611fe0b lib.getAttr: inherit from lib.attrsets 2024-06-20 22:48:53 +02:00
Silvan Mosberger 94a863973a lib.isString: inherit from lib.strings 2024-06-20 22:48:04 +02:00
Silvan Mosberger 6f7324c1f0 lib.isList: inherit from lib.lists 2024-06-20 22:48:04 +02:00
Silvan Mosberger fa82e813f1 lib.isInt: inherit from lib.trivial 2024-06-20 22:48:04 +02:00
Silvan Mosberger 5313a054d3 lib.isBool: inherit from lib.trivial 2024-06-20 22:48:04 +02:00
Silvan Mosberger 53744d55cd lib.isAttrs: inherit from lib.attrsets 2024-06-20 22:48:02 +02:00
Silvan Mosberger c3b87461e7 lib.hasAttr: inherit from lib.attrsets 2024-06-20 22:47:33 +02:00
Silvan Mosberger 4bcc1d3450 lib.elemAt: inherit from lib.lists 2024-06-20 22:47:01 +02:00
Silvan Mosberger 46b7bbb660 lib.elem: inherit from lib.lists 2024-06-20 22:47:01 +02:00
Silvan Mosberger f341dca2a2 lib.deepSeq: inherit from lib.trivial 2024-06-20 22:47:01 +02:00
Silvan Mosberger 8a6941dbef lib.sub: inherit from lib.trivial 2024-06-20 22:47:01 +02:00
Silvan Mosberger a32d38d380 lib.add: inherit from lib.trivial 2024-06-20 22:47:01 +02:00
Silvan Mosberger 74c87fd888 lib.lessThan: inherit from lib.trivial 2024-06-20 22:47:00 +02:00
Silvan Mosberger 64e8494f8a lib.seq: inherit from lib.trivial 2024-06-20 22:47:00 +02:00
Silvan Mosberger 597f62d782 lib.listToAttrs: inherit from lib.attrsets 2024-06-20 22:46:59 +02:00