Commit Graph

281 Commits

Author SHA1 Message Date
Robert Hensing
acb6191c6e lib: Add splicing utilities (#426889) 2025-10-30 21:22:54 +00:00
Silvan Mosberger
428bd8f1a2 lib.teams: Populate fields from synced GitHub state
The before and after of

    nix-instantiate --eval -A lib.teams --strict --json | jq 'walk(if type == "array" then sort else . end)'

has been ensured to be negligible, only consisting of minor team
shortName and scope differences
2025-10-27 19:36:57 +01:00
Aliaksandr
dc7095a86e treewide: remove deprecated lib functions that had warning for more than 2 years 2025-10-24 06:30:16 +03:00
Philip Taron
3aefc14aca lib.attrsets: remove deprecated names
- `lib.attrsets.cartesianProductOfSets` was deprecated in 228621e42d
- `lib.attrsets.zip` was deprecated in fcbc4fe9ff (2013!)
- `lib.attrsets.zipWithNames` was deprecated in 00127bef3f (2009!)

The time has come.
2025-10-13 09:09:59 -07:00
Philip Taron
db45f2b770 lib: remove mapAttrsFlatten after a year
It was deprecated in b9c51260d0.
2025-10-13 08:55:22 -07:00
dish
92aa5dc190 lib: remove lib.options.mkPackageOptionMD
Removed this, as it was deprecated in 24.11 and was intended to be
removed in 25.05. Better late than never.
2025-10-07 15:53:30 -04:00
Johannes Kirschbauer
b37ac6a920 lib: init strings.join 2025-09-27 09:18:37 +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
misuzu
8d45e68ff1 lib.mkEUI64Suffix: init (#416086) 2025-09-11 15:26:02 +00:00
nukdokplex
2a31d7e083 lib.mkEUI64Suffix: init 2025-09-09 12:23:38 +05:00
Robert Hensing
7ba464154f lib: Introduce Cross Index concept
A Cross Index, short for Cross Platform Pair Index, is the essential
shape of a splice, without the invoking the more mind bending concept
of adding variations of for these 6 pairings to an existing thing so
that it can be switched out for something else.

So the purpose of a Cross Index is to contain the result of `f`\
(which may be reified in code, or just an abstract concept):
 - f "build" "build"
 - f "build" "host"
 - ...

Splicing on the other hand refers not just to these six variants, but
to the idea of tacking them onto one of the variants. (hostTarget,
I believe)

Cross Indexes are a necessity for making cross compilation work, but
splicing is more than necessary.
2025-09-09 04:42:37 +02:00
Robert Hensing
ca4beaaf1c lib: Add splice structure utilities 2025-09-09 04:42:36 +02:00
Wolfgang Walther
399136b3d7 lib/attrsets: add mapAttrsToListRecursive(Cond) function (#395160) 2025-09-08 19:12:59 +00:00
Plume
0477b30ab6 lib.attrsets.genAttrs': init (#436434)
* lib.attrsets.genAttrs': init

* lib.attrsets.genAttrs: rewrite with lib.attrsets.genAttrs'

* lib.attrsets.{genAttrs,genAttrs'}: add tests

* Update lib/attrsets.nix

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>

* Update lib/attrsets.nix

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>

* lib.attrsets.genAttrs': document and test attrName collision

---------

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>
2025-09-01 11:58:28 +02:00
Mikael Voss
e5ac84e29c lib/attrsets: add mapAttrsToListRecursive(Cond) function 2025-08-31 12:11:43 +02:00
Martin Weinelt
4bd0b9c7ab Reapply "Merge remote-tracking branch 'origin/master' into staging-next"
This reverts commit 106b1418bc.

Restores the commits lost during the revert of a merge on staging-next.
2025-08-23 16:06:41 +02:00
Martin Weinelt
106b1418bc Revert "Merge remote-tracking branch 'origin/master' into staging-next"
This reverts commit 28cafe5795, reversing
changes made to 281c9189d4.

Broken merge due to mergiraf removing many newlines from
python-packages.nix.
2025-08-15 13:58:54 +02:00
Johannes Kirschbauer
78ac637056 lib: init lists.uniqueStrings 2025-08-15 11:45:50 +02:00
Jan Malakhovski
7c8a4efb68 lib, treewide: introduce repoRevToName, use it in most fetch* functions
This patch adds `lib.repoRevToName` function that generalizes away most of the
code used for derivation name generation by `fetch*` functions (`fetchzip`,
`fetchFromGitHub`, etc, except those which are delayed until latter commits
for mass-rebuild reasons).

It's first argument controls how the resulting name will look (see below).

Since `lib` has no equivalent of Nixpkgs' `config`, this patch adds
`config.fetchedSourceNameDefault` option to Nixpkgs and then re-exposes
`lib.repoRevToName config.fetchedSourceNameDefault` expression as
`pkgs.repoRevToNameMaybe` which is then used in `fetch*` derivations.

The result is that different values of `config.fetchedSourceNameDefault` now
control how the `src` derivations produced by `fetch*` functions are to be
named, e.g.:

- `fetchedSourceNameDefault = "source"` (the default):

  ```
  $ nix-instantiate -A fuse.src
  /nix/store/<hash>-source.drv
  ```

- `fetchedSourceNameDefault = "versioned"`:

  ```
  $ nix-instantiate -A fuse.src
  /nix/store/<hash>-libfuse-2.9.9-source.drv
  ```

- `fetchedSourceNameDefault = "full"`:

  ```
  $ nix-instantiate -A fuse.src
  /nix/store/<hash>-libfuse-2.9.9-github-source.drv
  ```

See the documentation of `config.fetchedSourceNameDefault` for more info.
2025-05-31 10:01:21 +00: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
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