Commit Graph

435 Commits

Author SHA1 Message Date
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
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
4a014ed92e lib/modules: Use fixed lib instead of args.lib
The practical use for this should be very limited because I don't
think anyone should change `lib`, let alone change `lib.functionArgs`,
but, but it would be even stranger to rely on `args.lib` (or really
`specialArgs.lib` for what's clearly a behavior of the current
`evalModules`, which uses its own ambient lib for basically everything.

The shadowing of `lib` by `args.lib` here seems to be a small mistake,
which is easy to make.
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
Tristan Ross
8bb66a4929
lib/tests/release.nix: fix pkgs.lib error by passing lib 2024-06-09 18:12:39 -07:00
Tristan Ross
013e398b0f
lib/tests/release.nix: make pure 2024-06-06 21:17:05 -07:00
Rob Pilling
9c9c3848d4 cli.nix: permit separators between args -> -a=b, --xyz=abc, etc 2024-05-22 07:58:26 +01:00
John Ericson
c38dd73dec
Merge pull request #308032 from obsidiansystems/freebsd-no-suffix-version
treewide: freebsd13 -> freebsd
2024-05-01 10:03:12 -04:00
John Ericson
266cdd7d37 treewide: freebsd13 -> freebsd
Co-authored-by: Alyssa Ross <hi@alyssa.is>
2024-04-30 18:20:23 -04:00
Maximilian Bosch
2b4e18f3d4
nixVersions.unstable: build from master, re-init at 2.22.0.pre20240321_6fd2f42c
The idea behind that is to enable users and developers of
downstream tools such as home-manager to test Nix master for several
reasons:

* Nix is currently trying to have a `master` branch that's always
  releasable[1]. We're still on Nix 2.18 in nixpkgs due to too many
  notable regressions. Enabling people to test latest master may help on
  that end.

* This uses the most bleeding-edge Nix, but our packaging, so we can
  identify issues with our packaging early.

* From what I've seen, most people are using the packages from nixpkgs
  anyways instead of the upstream flake, this is far more convenient
  anyways.

My plan is to update this once a week. Right now we rely on the
`installCheckPhase` here, but as soon as we have proper regression
testing[2], we may want to add `nixUnstable` there as well (however with
failures being allowed probably).

[1] https://discourse.nixos.org/t/nix-release-schedule-and-roadmap/14204
[2] https://github.com/NixOS/nixpkgs/pull/304332
2024-04-28 21:59:04 +02:00
Silvan Mosberger
6861ef7707 lib.lists.ifilter0: init 2024-04-22 18:33:14 +02:00
Gabriel Volpe
7b687a59cd
lib/tests: apply lints 2024-04-15 19:18:41 +02:00
Gabriel Volpe
fe2bead78b
lib/attrsets: introduce mapCartesianProduct 2024-04-15 19:16:15 +02:00
Gabriel Volpe
10517cf9ab
tree-wide: use cartesianProduct 2024-04-15 19:13:22 +02:00
Silvan Mosberger
4f1d724b82
Merge pull request #284551 from hercules-ci/types-attrTag
Add `types.attrTag`
2024-04-09 20:48:44 +02:00
Silvan Mosberger
a448a21521
Merge pull request #301556 from edef1c/lib-xor
lib: add xor
2024-04-04 22:03:53 +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
c0f5f271d1
doc: migrate trivial files to doc-comment format (#299986)
* doc: migrate trivial files to doc-comment format

* fix: revert some comments

* Apply suggestions from code review

Thanks @danielSidhion

Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>

* Update lib/types.nix

---------

Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2024-04-04 16:36:07 +02:00
Robert Hensing
22d7f146a4 lib.types.attrTag: Fix declarationPositions after merge 2024-04-04 12:56:56 +02:00
Robert Hensing
cf4968a904 lib/tests/modules/types-attrTag.nix: Test other option doc attrs 2024-04-04 12:22:08 +02:00
Robert Hensing
74831d8b38 lib/tests/modules/types-attrTag.nix: Clean up unneeded comment 2024-04-04 12:00:55 +02:00
Robert Hensing
47e4a18d01 types.attrTagWith: remove
Keep it simple for now.
2024-04-04 12:00:54 +02:00
Robert Hensing
1465777b63 lib.types.attrTag: Custom error when passing bare type 2024-04-04 11:54:46 +02:00
Robert Hensing
bcd774606a lib/tests/modules/types-attrTag: Test against unexpected attrs
Thank you lheckemann for pointing this out!
2024-04-04 11:54:46 +02:00
Robert Hensing
475a55b2f0 lib.types.attrTag: Remove tags from description
You can find them in the sub-options now.
2024-04-04 11:54:46 +02:00
Robert Hensing
4c7d990bad lib.types.attrTag: Provide declarations, definitions 2024-04-04 11:54:45 +02:00
Robert Hensing
0bc9783221 lib.types.attrTag: Support type merging 2024-04-04 11:54:45 +02:00
Robert Hensing
42d3b54f0d lib.types.attrTag: Take options instead of types 2024-04-04 11:54:45 +02:00
Robert Hensing
5b49672af4 lib.types.attrTag: Support module docs 2024-04-04 11:54:41 +02: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
Philip Taron
c8a8550c28
Avoid top-level with in lib/tests/misc.nix 2024-03-11 16:30:31 -07:00
Philip Taron
20abffc0dd
Avoid top-level with ...; in lib/tests/modules/extendModules-168767-imports.nix 2024-03-11 08:38:37 -07:00
Philip Taron
0426125c53
Avoid top-level with ...; in lib/tests/modules/alias-with-priority.nix 2024-03-11 08:38:14 -07:00
Philip Taron
dd46445adc
Avoid top-level with ...; in lib/tests/modules/alias-with-priority-can-override.nix 2024-03-11 08:37:31 -07:00
Silvan Mosberger
fc3cc21d2a
Merge pull request #292209 from hercules-ci/lazyDerivation-multi-output
lib.lazyDerivation: Support multi-output derivations
2024-03-06 17:14:33 +01:00
Artturi
961ddd92a1
Merge pull request #177977 from thefloweringash/call-packages-with-function-args
lib/customization: propagate function arguments in callPackagesWith
2024-03-03 21:07:56 +02:00
Robert Hensing
612dcbe11e lib.lazyDerivation: Support multi-output derivations 2024-02-29 12:37:52 +01:00
Andrew Childs
741377b300 lib/customization: propagate function arguments in callPackagesWith
makeOverridable is very careful to ensure the arguments to the
overridden function are the same as the input function. As a result,
the arguments of hello.override are exactly the same as the original
arguments of the hello function that produced the derivation.

However, callPackagesWith calls makeOverridable with a lambda that
does not propagate the arguments. The override function for a package
instantiated with callPackagesWith will not have the original
arguments.

For example:

    nix-repl> lib.functionArgs hello.override
    { callPackage = false; fetchurl = false; hello = false; lib = false; nixos = false; stdenv = false; testers = false; }

    nix-repl> lib.functionArgs openssl.override
    { }

By copying the arguments onto the inner lambda before passing it to
makeOverridable, we can make callPackage and callPackages behave the
same.

    nix-repl> lib.functionArgs openssl.override
    { buildPackages = false; coreutils = false; cryptodev = false; enableSSL2 = true; enableSSL3 = true; fetchurl = false; lib = false; perl = false; removeReferencesTo = false; static = true; stdenv = false; withCryptodev = true; withPerl = true; }
2024-02-28 15:29:08 +02:00
Robert Hensing
bb036f2486 lib/tests/release: Test lib.version in isolation 2024-02-26 22:35:14 +01:00
Robert Hensing
f45844cb55 .version: Make lib/.version source of truth
This way we don't have to make sure they're in sync, and we remove
a small step from the release process.
2024-02-26 22:34:10 +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
Robert Hensing
475ee3a18e lib/tests/test-with-nix.nix: init
See https://github.com/NixOS/nix/pull/9900
2024-02-23 11:07:08 +01:00
Robert Hensing
ca81a89839 lib.types.attrTag: init 2024-02-11 18:44:52 +01:00
Silvan Mosberger
f37ba19765
Merge pull request #284512 from hercules-ci/lib-types-unique-merge
lib.types.unique: Check inner type deeply
2024-02-10 02:52:45 +01:00
Robert Hensing
5d7125e01e
Merge pull request #285612 from hercules-ci/doRename-condition
lib.modules.doRename: Add condition parameter
2024-02-05 19:24:36 +01:00
Silvan Mosberger
27dbf77d62
Merge pull request #285353 from sternenseemann/nix-2.3-syntax
treewide: fix parse errors with Nix 2.3 and related problems
2024-02-05 17:44:28 +01:00
Shea Levy
ca1262a483
lib: Add optionalDrvAttr to conditionally set drv attributes.
This allows for adding new, conditionally set, derivation attributes
to an existing derivation without changing any output paths in the
case where the condition is not met.
2024-02-02 16:27:30 -05:00