Commit Graph

3952 Commits

Author SHA1 Message Date
Silvan Mosberger
727958ee36
Merge pull request #292945 from adisbladis/lib-toint
lib.toInt/toIntBase10: Make more efficient by hoisting up internal strings into higher scope
2024-03-06 19:42:52 +01:00
Silvan Mosberger
012faf046f
Merge pull request #292941 from adisbladis/lib-getattrfrompath-env
lib.getAttrFromPath: Don't use errorMessage variable
2024-03-06 19:41:34 +01:00
Silvan Mosberger
2dc95cded0
Merge pull request #292938 from adisbladis/mapattrsrecursivecond-env
lib.mapAttrsRecursiveCond: Eliminate intermediate one intermediate variable environment
2024-03-06 19:40:52 +01:00
Silvan Mosberger
b180a6af30
Merge pull request #292937 from adisbladis/zipattrs-env
lib.zipAttrs: Remove needless function wrapping
2024-03-06 19:39:48 +01:00
Silvan Mosberger
0d49917ded
Merge pull request #292934 from adisbladis/lib-choosedevoutput
lib.chooseDevOutputs: Remove needless function wrapping
2024-03-06 19:39:30 +01: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
Valentin Gagarin
73c0b48dd6
doc: add details on mapAttrsRecursive[Cond] (#293509)
* doc: add details on `mapAttrsRecursive[Cond]`

from first reading it wasn't clear that `f` also takes the current
attribute path. also the value f receives is tricky due to how the
condition is evaluated.

Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>
2024-03-06 10:21:23 +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
39327e4cf2
Merge pull request #288812 from hercules-ci/lib-flake-version
`lib/` flake: fix `lib.version`
2024-03-03 18:19:00 +01: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
adisbladis
948e5b841d lib.getAttrFromPath: Don't use errorMessage variable
We can just pass the error message on without creating an environment.
2024-03-03 16:30:00 +13:00
adisbladis
34fefe4e16 lib.mapAttrsRecursiveCond: Eliminate intermediate one intermediate variable environment 2024-03-03 16:18:38 +13:00
adisbladis
4338bfde09 lib.zipAttrs: Remove needless function wrapping
Returning the partially applied `zipAttrsWith fn` is the same as `sets: zipAttrsWith fn sets`.
2024-03-03 16:17:49 +13:00
adisbladis
3ee9d185f3 lib.chooseDevOutputs: Remove needless function wrapping
Returning the partially applied `map getDev` is the same as `drvs: map getDev drvs`.
2024-03-03 16:03:01 +13:00
Silvan Mosberger
28256b81a1
Merge pull request #292340 from DanielSidhion/fix-fixed-points-doc
lib.fixedPoints: fix rendering of docs for `extends`
2024-02-29 16:07:03 +01:00
DS
baae71c821 lib.fixedPoints: fix rendering of docs for extends 2024-02-29 06:22:00 -08:00
Robert Hensing
612dcbe11e lib.lazyDerivation: Support multi-output derivations 2024-02-29 12:37:52 +01:00
Silvan Mosberger
d0f7816d14
Merge pull request #287369 from tweag/lib-remove-polyfills
`lib`: Remove unneeded polyfills
2024-02-28 22:56:19 +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
01973b05aa
Merge pull request #291933 from tweag/fileset-tests-posix
lib.fileset: Fix tests on Darwin, more POSIX
2024-02-28 01:57:33 +01:00
Silvan Mosberger
3429594114 lib.fileset: Fix tests on Darwin, more POSIX
This was found when trying to run the fileset tests on Darwin
(https://github.com/NixOS/nix/pull/9546#issuecomment-1967409445), which mysteriously fail on Darwin:

  test case at lib/fileset/tests.sh:342 failed: toSource { root = "/nix/store/foobar"; fileset = ./.; } should have errored with this regex pattern:

  lib.fileset.toSource: `root` \(/nix/store/foobar\) is a string-like value, but it should be a path instead.
  \s*Paths in strings are not supported by `lib.fileset`, use `lib.sources` or derivations instead.

  but this was the actual error:

  error: lib.fileset.toSource: `root` (/nix/store/foobar) is a string-like value, but it should be a path instead.
      Paths in strings are not supported by `lib.fileset`, use `lib.sources` or derivations instead.

After dissecting this, I find out that apparently \s works on Linux, but not on Darwin for some reason!

From the bash source code, it looks like <regex.h> with `REG_EXTENDED` is used for all platforms the same,
so there's nothing odd there.

It's almost impossible to know where <regex.h> comes from,
but it looks to be a POSIX thing.

So after digging through the almost impossible to find POSIX specifications
(https://pubs.opengroup.org/onlinepubs/007908799/xbd/re.html#tag_007_003_005),
I can indeed confirm that there's no mention of \s or the like!

_However_, there is a mention of `[[:blank:]]`, so we'll use that instead.
2024-02-27 23:26:40 +01:00
Ryan Mulligan
78d6e84385
Merge pull request #291909 from cdmistman/lib-meta-available-on-doc-example
lib.meta.availableOn: add example in documentation
2024-02-27 12:44:37 -08:00
Colton Donnelly
e1e3ca54eb lib.meta.platformMatch: expand documentation 2024-02-27 14:51:33 -05:00
Colton Donnelly
3698be4ee6 lib.meta.availableOn: add example in documentation 2024-02-27 14:44:38 -05: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
Silvan Mosberger
4d11de3e80
Merge pull request #288677 from tweag/fileset.toList
lib.fileset.toList: init
2024-02-26 21:28:26 +01:00
Silvan Mosberger
c1cebaeb16
Merge pull request #291583 from SuperSandro2000/mergeAttrsList
lib: export attrsets.mergeAttrsList
2024-02-26 21:00:25 +01:00
Silvan Mosberger
e3a6e38033 lib.fileset.toList: init 2024-02-26 20:21:50 +01:00
Sandro
e426a8f097
lib: export attrsets.mergeAttrsList 2024-02-26 15:49:25 +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
Valentin Gagarin
b4cdc15163
Merge pull request #286544 from hercules-ci/doRename-doc
lib.modules.doRename: Add doc comments
2024-02-22 16:05:10 +01:00
Benoit de Chezelles
eba79c6df4
lib.evalModules: Fix deprecation doc for args parameter 2024-02-18 21:33:31 +01:00
Robert Hensing
fe36252019 lib.modules.doRename: Add doc comments
I don't think these are rendered yet, but this at least provides
the content.

Follow-up to https://github.com/NixOS/nixpkgs/pull/285612
2024-02-14 17:30:51 +01:00
Robert Hensing
ca81a89839 lib.types.attrTag: init 2024-02-11 18:44:52 +01:00
h7x4
8d165ba903
licenses: add mplus 2024-02-10 16:05:30 +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
Ryan Lahfa
dbd22195df
Merge pull request #287124 from RaitoBezarius/is-sparc-64
lib/systems/inspect: add `isSparc64`
2024-02-09 15:07:01 +01:00
Silvan Mosberger
886e85f4f4 lib.versions: 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
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
Silvan Mosberger
46fd25dda9 lib.lists: Remove unneeded polyfills
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
Silvan Mosberger
31d23ba418 lib.attrsets: Remove unneeded polyfills
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-09 05:46:03 +01:00
Silvan Mosberger
27488b861c lib.trivial: Remove unneeded polyfills
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-09 05:45:31 +01:00
Silvan Mosberger
63373eba60
Merge pull request #286117 from alois31/lib-deprecations
lib: make deprecation warnings consistent
2024-02-09 05:03:43 +01:00
Raito Bezarius
b62bc38ac9 lib/systems/inspect: add isSparc64
This is useful to distinguish between SPARC64 and SPARC whatever,
because SPARC64 do support compressed kernels.
2024-02-08 05:07:39 +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
Robert Hensing
542f5d4f4d lib.option.mergeUniqueOption: Simplify and add warning about merge function
The previous code was optimized for the old uniq behavior, which did not
call merge. That's changed, so the legacy path is not a hot path anymore,
and is not worth any tech debt.
2024-02-04 16:02:13 +01:00
Robert Hensing
bd285d2c11 lib.types.uniq: Check inner type
We now reuse the `unique` type, which implements this.
Keeping the duplication around would be bad at this point.
2024-02-04 15:49:55 +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
Shea Levy
43ec00acab
Merge branch 'optionalDrvAttr' 2024-02-02 16:30:17 -05: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
Robert Hensing
29c7665003 lib.modules.doRename: Add condition parameter
This is to support single-to-multi service migrations, so that the
`to` (e.g. `foos.""`) isn't defined unconditionally. See test cases.
2024-02-02 07:31:16 +01:00
Silvan Mosberger
55ae7c58f3
Merge pull request #285301 from ibbem/gitTracked-shallow
lib.fileset.gitTracked: Allow clones of shallow repositories
2024-02-02 03:30:20 +01:00
ibbem
6558e89177 lib.fileset.gitTracked: Allow clones of shallow repositories
The only reason shallow clones are not the default in
`builtins.fetchGit` is that `revCount` can't be provided when cloning a
shallow repository. However, `revCount` isn't used or exposed by
`lib.fileset`. Hence, allowing cloning shallow repositories makes
`gitTracked` more general without any drawbacks.

Co-authored-by: Silvan Mosberger <github@infinisil.com>
2024-02-01 00:01:26 +01:00
sternenseemann
84a4712bcb lib/tests/packages-from-directory: make sure all .nix files parse
It is useful that all (or almost all) .nix files in nixpkgs at least
parse since it allows for checking syntax in the repository
programmatically without evaluating anything.
2024-01-31 20:30:17 +01:00
Robert Hensing
33e2ec81c7
Merge pull request #284829 from deemp/master
types.nix: fix nonEmptyListOf
2024-01-30 20:55:24 +01:00
Danila Danko
7dea495d34 feat: add test for nonEmptyListOf submodule 2024-01-30 21:32:34 +03:00
Danila Danko
ad853c1368 types.nix: fix nonEmptyListOf 2024-01-29 22:29:44 +03:00
figsoda
e08ce8d1d1 lib/trivial: bump oldestSupportedRelease to 23.11 2024-01-29 12:08:59 -05:00
Robert Hensing
b78ba9bc68 lib.types.unique: Check inner type deeply
This doesn't change uniq. Why not?

- In NixOS it seems that uniq is only used with
  simple types that are fully checked by t.check.

- It exists for much longer and is used more widely.

- I believe we should deprecate it, because unique was
  already better.

- unique can be a proving ground.
2024-01-28 14:09:27 +01:00
Vincenzo Mantova
4c6e59f0f8 licenses: add Creative Commons Attribution 2.0 2024-01-27 09:32:21 +00:00
Adam Joseph
9b4c306d98 lib.system.inspect: add wasm32 to isILP32
According to the WebAssembly design doc, wasm32 is an ILP32 ABI like
x32, mips64n32, and aarch64_ilp32 (Apple Watch).  This commits adds
it to the predicate.

  1319968ca5/CAndC%2B%2B.md (L16)
2024-01-18 09:09:29 +00:00
Silvan Mosberger
501963a6df
Merge pull request #248220 from infinisil/document-extends
Improve the documentation of `lib.extends` and how it relates to overlays
2024-01-12 02:25:42 +01:00
Silvan Mosberger
0ed96eed10
Merge pull request #278777 from tweag/fix-evals
`lib.callPackageWith`: Use abort again instead of throw and fix evaluation errors caused by it
2024-01-08 03:50:58 +01:00
Silvan Mosberger
56df668386 lib.callPackageWith: Use abort, not throw
This reverts f8ea911f7c, see also https://github.com/NixOS/nixpkgs/pull/271123#discussion_r1442134594
2024-01-07 23:31:11 +01:00
Ryan Burns
5cbd74e49a lib/systems: add exec format inspection attrs
Most of the time when we do a patchelf conditional on
hostPlatform.isLinux, what we really mean is hostPlatform.isElf.
Now that we are starting to support BSDs, this is becoming more important.
2024-01-02 14:07:20 -08:00
Robert Hensing
9f98c59547
Merge pull request #276271 from hercules-ci/modules-types-description-nonRestrictiveClause
lib.types: Improve descriptions of composed types that have commas
2023-12-30 17:29:16 +01:00
jopejoe1
95f9761fd9 lib/license: add dtoa 2023-12-30 00:40:41 +01:00
jopejoe1
7b7b4967d4 lib/licenses: add missing spdxids 2023-12-26 17:38:49 +01:00
jopejoe1
a302ae8adc lib/licenses: add smlnj 2023-12-23 12:11:14 +01:00
Robert Hensing
6f4d0b5261 lib.types: Improve descriptions of composed types that have commas
Type:   either ints.positive (enum ["auto"])
Before: positive integer, meaning >0 or value "auto" (singular enum)
After:  positive integer, meaning >0, or value "auto" (singular enum)
2023-12-23 11:40:27 +01:00
jopejoe1
d4a1307524 lib/licenses: add xinetd 2023-12-23 10:40:02 +01:00
jopejoe1
3e53f2b569 lib/licenses: add xskat 2023-12-23 10:31:58 +01:00
Silvan Mosberger
0f8d175ebd
Merge pull request #272083 from tweag/lib-contrib
lib: Add contribution guidelines
2023-12-19 22:29:51 +01:00
Silvan Mosberger
1816242f9c
Merge pull request #273893 from tweag/fileset.gitTracked-storeDir
`lib.fileset.gitTracked`: Support out-of-tree builds
2023-12-19 22:14:19 +01:00
Silvan Mosberger
38cf6ff099 Remove --simulate-pure-eval 2023-12-19 22:09:01 +01:00
Silvan Mosberger
4a70c1e4da lib.fileset.gitTracked: Support out-of-tree builds 2023-12-19 22:08:59 +01:00
Silvan Mosberger
cf47b9a5c0
Merge pull request #270537 from 9999years/packagesFromDirectory
lib.packagesFromDirectoryRecursive: init
2023-12-19 22:03:01 +01:00
Rebecca Turner
090b929b8a
lib.packagesFromDirectoryRecursive: init
Co-authored-by: Gabriella Gonzalez <GenuineGabriella@gmail.com>
2023-12-19 09:48:17 -08:00
Rebecca Turner
fa9727cf1e
lib: modules.sh should check JSON output for predictability
Currently, the `lib/tests/modules.sh` test checks the output of
`nix-instantiate --eval` without `--json`, which outputs an unspecified
human-readable format.

This patch modifies `modules.sh` to use the `--json` output instead, to
be robust against future changes to `nix-instantiate` output.
2023-12-19 09:23:09 -08:00
Silvan Mosberger
74f2e49543 lib.fileset.fetchGit: Refactoring 2023-12-19 01:46:15 +01:00
Matthieu Coudron
4ea6c0c58b lib.generators: made toLua accept derivations too
While trying to extend generateLuarocksConfig, I had infinite loops caused by toLua considering derivations as attrSets
2023-12-15 15:05:46 +01:00
Adam Joseph
8f34a10d6a lib/tests/release.nix: temporary reference to pkgs/test/release
This commit temporarily adds pkgs/test/release to the
lib/tests/release.nix test suite, because ofborg already knows about
that entry point.

We should move the list of test entry points out of ofborg and into
a central place in nixpkgs:

  https://github.com/NixOS/nixpkgs/issues/272591

Once we do that we won't need to have this ugly kludge in an
inappropriate place.
2023-12-15 05:13:50 -08:00
Adam Joseph
80472e3754 treewide: add __attrsFailEvaluation and __recurseIntoDerivationForReleaseJobs 2023-12-15 05:13:46 -08:00
Robert Hensing
bef10a5ace
Merge pull request #269551 from tejing1/nixos-stub-ld
nixos/stub-ld: init module
2023-12-13 22:36:30 +01:00
Silvan Mosberger
39948a158c
Merge pull request #273704 from adisbladis/lib-getexe-efficiency
lib.getExe: Make more efficient
2023-12-13 21:30:13 +01:00
Silvan Mosberger
5027eafc33
Merge pull request #274022 from hercules-ci/doc-attrsets-operators
lib/attrsets: Document and link Nix language operators
2023-12-13 21:14:08 +01:00
Robert Hensing
a7aa95db53 lib/attrsets: Document and link Nix language operators 2023-12-13 18:38:41 +01:00
Silvan Mosberger
d4b7b15407 lib.path.hasStorePathPrefix: init
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-12-13 17:12:52 +01:00
Silvan Mosberger
c4e2e52a21
Merge pull request #273664 from tweag/fileset.gitTracked-improvements
`lib.fileset.gitTracked,gitTrackedWith`: Minor improvements
2023-12-13 05:14:20 +01:00
adisbladis
0286e3119e lib.getExe: Make more efficient 2023-12-12 16:44:07 +13:00
Silvan Mosberger
6e3be6ddb0 lib.fileset.gitTracked: Improve error when passing files 2023-12-11 23:05:51 +01:00
Silvan Mosberger
eec765f9e6 lib.fileset: Refactor gitTracked and gitTrackedWith
Introduce an internal function for them to share more behavior.
This makes future changes easier.
2023-12-11 22:57:12 +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
Silvan Mosberger
6d8c22272a
Merge pull request #273470 from adisbladis/lib-tohexstring-static-values
lib.toHexString: Statically compute hexDigits attrset
2023-12-11 17:46:23 +01:00
Silvan Mosberger
5812c533ed
Merge pull request #273474 from adisbladis/lib-cmakeOptionType-static-list
lib.cmakeOptionType: Statically compute types list
2023-12-11 17:45:22 +01:00
Silvan Mosberger
581adae822
Merge pull request #273467 from adisbladis/lib-pipe-no-let
lib.pipe: Avoid creating a scope
2023-12-11 17:16:05 +01:00
Robert Hensing
6c8fb49bfc
Merge pull request #273004 from hercules-ci/attrset-path-longest-prefix
lib.attrsets.longestValidPathPrefix: init
2023-12-11 13:25:45 +01:00
Robert Hensing
067ac02817
Merge pull request #257100 from Ma27/version-info-lib
flake: fix `lib.trivial.version` when used from a flake
2023-12-11 10:30:12 +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
ad647985cf lib.toHexString: Statically compute hexDigits attrset 2023-12-11 16:36:29 +13:00
adisbladis
c8c2ae638a lib.pipe: Avoid creating scopes 2023-12-11 16:25:21 +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
Maximilian Bosch
d56f942e43
Merge pull request #272709 from hercules-ci/module-system-test-pr-131205
lib/modules: Test optionless module errors from #131205
2023-12-10 13:49:02 +01:00
Maximilian Bosch
ede5720a0d
flake/version overlay: review fixes
* Improves the comments of `lib/flake-version-info.nix` and drops the
  `__`-prefix from the filename.
* `lib'` -> `lib0` in `nixpkgs/lib`.
* Drop the declaration of `trivial.version` in the overlay because this
  declaration already uses the final expressions of `versionSuffix` and
  `release` now.
* No need to fall back to `self.lastModified` anymore, this was a
  workaround for pre2.4 Nix.

Co-authored-by: Robert Hensing <robert@roberthensing.nl>
Co-authored-by: Silvan Mosberger <contact@infinisil.com>
2023-12-10 13:25:24 +01:00
Maximilian Bosch
78f5ed053a
lib/trivial: drop rec in favor of lib fixpoint
That way each expression uses the final version of other lib.trivial
declarations.

For instance, when replacing `versionSuffix` with the string `"fnord"`
in a lib overlay, `trivial.version` uses `"fnord"` as suffix now rather
than `pre-git`.
2023-12-10 13:25:24 +01:00
Robert Hensing
8d20c2011e
Merge pull request #272183 from infinisil/nixpkgs-reference
doc: Rename to Nixpkgs reference manual and restate purpose
2023-12-10 07:07:20 +01:00
Robert Hensing
584463c744
Merge pull request #272764 from tweag/anyBool
lib.types.anyBool: init
2023-12-10 06:03:50 +01:00
Robert Hensing
83712164e6 lib/modules: Clarify test assertions 2023-12-09 20:38:29 +01:00
Robert Hensing
afb1a2e376 lib/modules: Test optionless module errors from #131205 2023-12-09 14:15:49 +01:00
Maximilian Bosch
bb7921d1d6
flake: also provide proper version info for lib's flake
This effectively means that

    nixpkgs$ nix eval ./lib#lib.trivial.version
    "23.11.20231020.ee0d6b5"

now gives meaningful results as well.

See https://github.com/NixOS/nixpkgs/pull/257100#discussion_r1352075369
for the discussion around this.
2023-12-09 11:45:45 +01:00
Robert Hensing
7d993b9521 lib.attrsets.hasAttrByPath: Document law and laziness, and test it 2023-12-08 23:19:09 +01:00
Robert Hensing
72bd4bbb58 lib.attrsets.longestValidPathPrefix: init
Allows finding the most specific path that exists.
This is useful for error messages relating to attribute paths.
2023-12-08 23:15:13 +01:00
Robert Hensing
50793752a7 lib.sort: Make doc consistent with sortOn 2023-12-08 22:15:30 +01:00
Robert Hensing
016993237f lib.callPackageWith: Optimize levenshtein sort
Probably not significant because of the limits already applied.
This is mostly cleanup.
2023-12-08 22:15:29 +01:00
Robert Hensing
67cc78643d lib.sortOn: init
A more efficient sort in some cases, and often convenient.

This exposes `lib.lists.sortOn` immediately on `lib`, because it is
a sibling of `sort`, which is already present there.
Omitting it would lead to more confusion, and worse outcomes.
There's no confusion about the types `sort` or `sortOn` operate on.

Haskell agrees about the type for `sortOn`, and it is in its `base`.
2023-12-08 22:15:29 +01:00
Silvan Mosberger
8d3978c149 lib.types.boolByOr: init
This type is necessary to have correct merging behavior for
`allowUnfreePredicate` and `allowInsecurePredicate`

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-12-08 21:50:29 +01:00
Silvan Mosberger
f5dafbfa83 doc: Rename to Nixpkgs reference manual and state purpose
For the time being, we're moving towards https://nix.dev/ containing
all tutorials and guides. The Nixpkgs manual is reinforced to be a
_reference_ manual. While it's not just reference for now, that's what
the docs team is working towards.

This commits rewrites the Nixpkgs manual introduction to reflect that
and point to some more useful links. The contribution docs are updated
similarly so it's not missed.

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-12-08 01:26:31 +01:00
Silvan Mosberger
395fc06431 lib: Add contribution guidelines
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2023-12-05 20:38:28 +01:00
Jeff Huffman
94a3c17582
lib.systems.elaborate: add libDir attribute 2023-12-03 16:23:44 -05:00
Someone Serge
a3006991c3
lib/customisation: fix eval error (attribute "levenshtein" missing) 2023-12-03 03:49:22 +00:00
Alyssa Ross
973120823b
lib.systems.elaborate: fix passing rust (more) (#271707)
An important idea around the rust stuff in lib.systems is that it's
elaborated — this means that it should idempotently add to the values
passed in, if any.  But we missed that the names used for the
parameter and the elaborated value for "rustcTarget"/"config" didn't
line up.  The intention was to use "rustcTarget" everywhere in the new
interface, as a more descriptive name than "config".

This fixes setting the system in NixOS configuration, which results in
an already elaborated system being elaborated again.  Before, this
wouldn't produce the correct result:

% nix-instantiate --eval -A stdenv.hostPlatform.rust.rustcTarget --system armv7l-linux
"armv7-unknown-linux-gnueabihf"
% NIX_PATH= nix-instantiate --eval -E '(import nixos/lib/eval-config.nix { system = "armv7l-linux"; modules = []; }).pkgs.stdenv.hostPlatform.rust.rustcTarget'
"arm-unknown-linux-gnueabihf"

Fixes: e3e57b8f18 ("lib.systems: elaborate Rust metadata")
Fixes: https://github.com/NixOS/nixpkgs/issues/271000
2023-12-03 01:32:01 +01:00
K900
37445f3c5c lib/customisation: fix callPackage error messages 2023-12-03 01:28:17 +03:00
Pierre Bourdon
5b7ae3565d
sudo: fix meta license information (#269788) 2023-12-02 09:45:08 +01:00
Adam Joseph
f8ea911f7c lib.customisation.callPackageWith: use throw, not abort 2023-11-30 07:43:16 +01:00
Silvan Mosberger
fc2b2af15e
Merge pull request #270299 from adisbladis/lib-customisation-allocs
lib.customisation: Refactor nested set access & avoid some allocations
2023-11-27 16:01:05 +01:00
Robert Hensing
51357572f2
Merge pull request #269552 from adisbladis/lib-matchattrs-list-allocs
lib.attrsets.matchAttrs: Avoid some list allocations when walking structure
2023-11-27 14:44:37 +01:00
adisbladis
8d162ec7b8 lib.customisation: Don't allocate intermediate list for missing args 2023-11-27 21:06:42 +13:00
adisbladis
7903613b0b lib.customisation: Inherit lib/builtins into scope
It makes the code more readable if we have less nested attrsets being accessed.
2023-11-27 21:06:41 +13:00
adisbladis
544a1d375b lib.attrsets.attrByPath: Don't allocate one extra list per lookup recursion
Using `tail` in a recursive loop like this needlessly allocates.
This changes the loop to look up by list index instead.
2023-11-27 11:37:57 +13:00
adisbladis
7e07b3ecd5 lib.attrsets.hasAttrByPath: Don't allocate one extra list per lookup recursion
Using `tail` in a recursive loop like this needlessly allocates.
This changes the loop to look up by list index instead.
2023-11-27 11:37:56 +13:00
Silvan Mosberger
627af21e87
Merge pull request #269637 from adisbladis/lib-meta-avoid-alloc-platformmatch
lib.meta: Avoid attrset allocation in platformMatch
2023-11-26 23:28:39 +01:00
adisbladis
013a0a1357 lib.attrsets.matchAttrs: Avoid some list allocations when walking structure
Benchmarks (`nix-instantiate ./. -A python3`):

- Before:
``` json
{
  "cpuTime": 0.29049500823020935,
  "envs": {
    "bytes": 4484216,
    "elements": 221443,
    "number": 169542
  },
  "gc": {
    "heapSize": 402915328,
    "totalBytes": 53086800
  },
  "list": {
    "bytes": 749424,
    "concats": 4242,
    "elements": 93678
  },
  "nrAvoided": 253991,
  "nrFunctionCalls": 149848,
  "nrLookups": 49612,
  "nrOpUpdateValuesCopied": 1587837,
  "nrOpUpdates": 10104,
  "nrPrimOpCalls": 130356,
  "nrThunks": 358981,
  "sets": {
    "bytes": 30423600,
    "elements": 1859999,
    "number": 41476
  },
  "sizes": {
    "Attr": 16,
    "Bindings": 16,
    "Env": 16,
    "Value": 24
  },
  "symbols": {
    "bytes": 236145,
    "number": 24453
  },
  "values": {
    "bytes": 10502520,
    "number": 437605
  }
}
```

- After:
``` json
{
  "cpuTime": 0.2946169972419739,
  "envs": {
    "bytes": 3315224,
    "elements": 172735,
    "number": 120834
  },
  "gc": {
    "heapSize": 402915328,
    "totalBytes": 48718432
  },
  "list": {
    "bytes": 347568,
    "concats": 4242,
    "elements": 43446
  },
  "nrAvoided": 173252,
  "nrFunctionCalls": 101140,
  "nrLookups": 73595,
  "nrOpUpdateValuesCopied": 1587837,
  "nrOpUpdates": 10104,
  "nrPrimOpCalls": 83067,
  "nrThunks": 304216,
  "sets": {
    "bytes": 29704096,
    "elements": 1831673,
    "number": 24833
  },
  "sizes": {
    "Attr": 16,
    "Bindings": 16,
    "Env": 16,
    "Value": 24
  },
  "symbols": {
    "bytes": 236145,
    "number": 24453
  },
  "values": {
    "bytes": 8961552,
    "number": 373398
  }
}
```
2023-11-27 11:20:50 +13:00
Emily Trau
1b38685b49 acc: init at 1.60 2023-11-26 16:56:53 +02:00
adisbladis
4b4d413817 lib.meta: Avoid attrset allocation in platformMatch
Benchmarks (`nix-instantiate ./. -A python3`)

- Before
``` json
{
  "cpuTime": 0.30625399947166443,
  "envs": {
    "bytes": 4484216,
    "elements": 221443,
    "number": 169542
  },
  "gc": {
    "heapSize": 402915328,
    "totalBytes": 53091024
  },
  "list": {
    "bytes": 749424,
    "concats": 4242,
    "elements": 93678
  },
  "nrAvoided": 253991,
  "nrFunctionCalls": 149848,
  "nrLookups": 49614,
  "nrOpUpdateValuesCopied": 1588326,
  "nrOpUpdates": 10106,
  "nrPrimOpCalls": 130356,
  "nrThunks": 359013,
  "sets": {
    "bytes": 30432320,
    "elements": 1860540,
    "number": 41480
  },
  "sizes": {
    "Attr": 16,
    "Bindings": 16,
    "Env": 16,
    "Value": 24
  },
  "symbols": {
    "bytes": 236218,
    "number": 24459
  },
  "values": {
    "bytes": 10504632,
    "number": 437693
  }
}
```

- After
```
{
  "cpuTime": 0.29695799946784973,
  "envs": {
    "bytes": 3296712,
    "elements": 169055,
    "number": 121517
  },
  "gc": {
    "heapSize": 402915328,
    "totalBytes": 49044992
  },
  "list": {
    "bytes": 504928,
    "concats": 4242,
    "elements": 63116
  },
  "nrAvoided": 175403,
  "nrFunctionCalls": 110554,
  "nrLookups": 44907,
  "nrOpUpdateValuesCopied": 1588326,
  "nrOpUpdates": 10106,
  "nrPrimOpCalls": 82330,
  "nrThunks": 306625,
  "sets": {
    "bytes": 29943328,
    "elements": 1843076,
    "number": 28382
  },
  "sizes": {
    "Attr": 16,
    "Bindings": 16,
    "Env": 16,
    "Value": 24
  },
  "symbols": {
    "bytes": 236218,
    "number": 24459
  },
  "values": {
    "bytes": 9037752,
    "number": 376573
  }
}
```
2023-11-25 11:05:23 +13:00
Alyssa Ross
62f7a6dcc1 lib.systems.elaborate: fix passing rust
Usually, attributes passed explicitly to elaborate take precedence
over the elaborated ones, but since we also elaborate the nested
"rust" attrset, we need to push that one level down, so the rest of
"rust" is still filled in if you just pass
{ rust = { config = ... } }.

I've had to drop the assertion that checked that at most one of "rust"
and "rustc" was part of the un-elaborated system, because doing this
broke passing an elaborated system in, which should be idempotent.

For the same reason, I've also had to make it possible for
rust.rustcTargetSpec to be passed in.  Otherwise, on the second call,
since platform was filled in by the first, the custom target file
would be constructed.  The only other way to avoid this would be to
compare the platform attrs to all built in Rust targets to check it
wasn't one of those, and that isn't feasible.

Fixes: e3e57b8f18 ("lib.systems: elaborate Rust metadata")
2023-11-24 12:21:30 +01:00
Silvan Mosberger
7486aee82e
Merge pull request #266362 from tweag/fileset.fileFilter-ext
`lib.fileset.fileFilter`: Predicate attribute for file extension
2023-11-24 00:15:43 +01:00
Silvan Mosberger
6816f28c96 lib.fileset.fileFilter: Predicate attribute for file extension 2023-11-23 21:05:23 +01:00
Silvan Mosberger
f37dd68fe0
Merge pull request #265964 from tweag/fileset.optional
`lib.fileset.maybeMissing`: init
2023-11-22 19:46:26 +01:00
Silvan Mosberger
827232d6dd lib.fileset: Document decision for strict existence checks
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-11-22 18:51:00 +01:00
figsoda
87cc06983c
24.05 is Uakari 2023-11-21 14:34:30 -05:00
Silvan Mosberger
1cc2c2f13d lib.fileset.maybeMissing: init 2023-11-20 19:56:45 +01:00
Silvan Mosberger
ed5e926ec4
Merge pull request #268619 from tweag/lib-descriptions
lib: Take advantage of section descriptions
2023-11-20 17:25:59 +01:00
Silvan Mosberger
055ba65fed lib: Take advantage of section descriptions
See https://github.com/nix-community/nixdoc/releases/tag/v2.6.0
2023-11-20 03:02:11 +01:00
Silvan Mosberger
4164b1c47e lib.fileset: Re-order to match reference overview 2023-11-19 23:52:13 +01:00
Silvan Mosberger
13f0af428e lib.fileset: Add overview section to reference docs 2023-11-19 23:46:23 +01:00
Silvan Mosberger
5a7118da75
Merge pull request #268520 from tweag/fileset-minor-changes
`lib.fileset`: Minor changes
2023-11-19 19:12:29 +01:00