Commit graph

389 commits

Author SHA1 Message Date
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
Robert Hensing
5ad01f1b6f lib/modules: Report a better error when option tree has bare type
Improves on 0d472a6201
- https://github.com/NixOS/nixpkgs/pull/242339

We actually do have the file name.

Thanks Shawn8901 for the [feedback]!

feedback: https://github.com/NixOS/nixpkgs/pull/242339#issuecomment-1683107055
2023-08-18 11:36:51 +02:00
linsui
da614d98e9 lib/gvariant: init 2023-08-15 19:20:39 +08: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
Robert Hensing
0d472a6201 lib/modules: Report a good error when option tree has bare type
Note that this removes the possibility of declaring an option
named `_type`.
2023-08-14 10:44:56 +02:00
Robert Hensing
53b289836b
Merge pull request #243139 from hercules-ci/modules-test-default-argument
lib/tests/modules: Test that _module.args works when a default argume…
2023-08-02 20:12:37 +02:00
Robert Hensing
19f1d7da06
Merge pull request #245271 from sternenseemann/module-system-merge-no-type
lib/modules: handle typeless options in mergeModules
2023-07-27 10:55:08 +02:00
sternenseemann
9c35f44999 lib/modules: handle typeless options in mergeModules
mkOption does not require a `type` argument and does not set the
resulting attribute if it is not given. Consequently, we need to be
prepared to merge options that have no type information.
2023-07-26 23:58:04 +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
Robert Hensing
72f2c8d6c6 lib/tests/modules: Test that _module.args works when a default argument is set 2023-07-12 21:54:57 +02:00
Robert Hensing
8014460c4d lib.mergeModules: Add context to error message 2023-07-11 13:03:52 +02:00
Ryan Burns
2964b720de
Merge pull request #240825 from r-burns/mips-embedded
lib.platforms.mips{,64}-embedded: init
2023-07-05 21:26:47 -07:00
Naïm Favier
f66b401fa3
lib/tests: invalidate hashes
Having the current bash hash present in the nixpkgs tree makes Nix
detect bash as a runtime dependency of nixpkgs, which in turns messes up
`fetchFromGitHub` due to https://github.com/NixOS/nix/issues/6660
2023-07-05 11:31:58 +02:00
Ryan Burns
c8ae88d97b lib.platforms.mips{,64}-embedded: init 2023-06-30 18:19:00 -07:00
Naïm Favier
4bdff8cbbb
lib/tests: remove experimental-features
Now that the lib is tested with Nix 2.3, this isn't needed any more and
causes warnings.
2023-06-27 11:48:53 +02:00
Robert Hensing
18111335ed
lib/tests/modules.sh: Test types.pathInStore
Add missing test cases. I think the .links case should be rejected
even though it's technically a path in the store.
2023-06-27 11:48:53 +02:00
Robert Hensing
b1ad9cd27d
Merge pull request #238136 from hercules-ci/nixos-nixpkgs-dont-check-when-_module.args.pkgs-is-set
`nixos/nixpkgs`: Don't check when `_module.args.pkgs` is set
2023-06-23 19:17:36 +02:00
Adam Joseph
00a749a3a6 lib/system: move toLosslessStringMaybe into lib/tests
toLosslessStringMaybe is not used by anything other than lib/tests,
so it can be private to that file.

I don't think this function was terribly well thought-through.  If
people start using it, we will become permanently dependent on the
ability to test platforms for equality.  It also makes the
elaboration process more fragile, because it encourages code outside
of nixpkgs to become sensitive to the minute details of how
elaboration happens.
2023-06-22 00:18:33 -07:00
Robert Hensing
36ea2bbfe8 lib.modules: Add mergeAttrDefinitionsWithPrio
This will let us make assertions involving _module.args.pkgs, which
is not an option but a value attribute, and therefore doesn't have
its own highestPrio to inspect. The new function gives us that info.
2023-06-16 22:08:16 +02:00
Robert Hensing
3150f25faa lib/tests/release.nix: Run systems tests on OfBorg 2023-06-13 10:43:12 +02:00
Robert Hensing
144018541b lib.systems.equals: Ignore all function attributes reflectively
Co-authored-by: Artturi <Artturin@artturin.com>
2023-06-13 10:22:06 +02:00
Robert Hensing
18c7f6237f lib.systems.{equals,toLosslessStringMaybe}: init 2023-06-13 10:17:02 +02:00
Robert Hensing
6b078d2f5a
Merge pull request #235267 from tweag/lazier-findFirst
`lib.findFirst`: Add tests and make lazier
2023-06-06 19:09:56 +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
Robert Hensing
fb21e6d7dd
Merge pull request #234070 from tweag/pathType-tests
Init `nixVersions.minimum` and fix `lib` tests for all Nix versions
2023-06-01 20:00:36 +02:00
Silvan Mosberger
013acf2396 lib/tests: Also run with nixVersions.minimum and nixVersions.unstable
The previous commits ensure that the tests also succeed with those
versions
2023-06-01 18:07:33 +02:00
Silvan Mosberger
0b6021ee53 lib/tests: Fix when run with Nix 2.3 2023-06-01 18:07:33 +02:00
Silvan Mosberger
de0c11241f lib/tests/filesystem.sh: Check success and failure separately 2023-06-01 18:07:33 +02:00
Alyssa Ross
4e80f80864 lib.systems.doubles: add big-endian MIPS linux doubles
We already have examples for these, but since we didn't actually
recognise the doubles, it wasn't possible to build any packages for
them without setting allowUnsupportedSystem.
2023-06-01 10:42:27 +00:00
Silvan Mosberger
04db3589a8 lib.filesystem.pathType: Fix tests for Nix >= 2.14 2023-05-25 22:39:28 +02:00
Robert Hensing
a344acdc7f
Merge pull request #224834 from tweag/pathType-and-co
Improvements to pathType, pathIsDirectory and pathIsRegularFile
2023-05-23 09:32:01 +02:00
Silvan Mosberger
d064d972f0 lib.filesystem.pathType: Improve error for non-existent paths
Previously it would fail with

  error: attribute 'nonexistent' missing

         at nixpkgs/lib/filesystem.nix:29:10:

             28|     if dirOf path == path then "directory"
             29|     else (readDir (dirOf path)).${baseNameOf path};
               |          ^
             30|
2023-05-22 14:13:57 +02:00
Silvan Mosberger
bb6eab0bdb lib.filesystem.pathType: Fix for filesystem root argument
Previously this function couldn't handle / being passed, it would throw
an error:

error: attribute '' missing

       at nixpkgs/lib/filesystem.nix:24:20:

           23|   */
           24|   pathType = path: (readDir (dirOf path)).${baseNameOf path};
             |                    ^
           25|

Consequently this also fixes the
lib.filesystem.{pathIsDirectory,pathIsRegularFile} functions.
2023-05-22 14:13:57 +02:00
Silvan Mosberger
a1dedc908d lib.filesystem.pathType and co.: Add tests
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2023-05-22 14:13:45 +02:00
Naïm Favier
ac9915b1ea
lib/tests: add mkPackageOption tests 2023-05-20 18:23:41 +02:00
Robert Hensing
eab660d91e lib.modules: configurationClass -> class
This simplifies the documentation. `configuration` is implied by `_type`.
2023-05-06 18:32:59 +02:00
Robert Hensing
89491bef8d lib.modules: in evalModules return move _module.class -> configurationClass 2023-05-06 18:32:59 +02:00
Robert Hensing
fd88c79418 lib.modules: Change class declaration in module to _class 2023-05-06 18:32:59 +02:00
Robert Hensing
7459c02495 lib/tests/modules.sh: Add submodule + class tests 2023-05-06 18:32:59 +02:00
Robert Hensing
8054785157 lib/modules: Move class out of specialArgs 2023-05-06 18:32:58 +02:00
Robert Hensing
84b1b01702 lib/modules: Only interpret class declaration in non-shorthand mode
This is to avoid stealing keys from submodules. `class` might be
common enough that reinterpreting existing `class` attributes in
configurations as a declaration leads to fairly widespread problems.
2023-05-06 18:29:04 +02:00
Robert Hensing
9714487f74 lib/modules: Explain that a configuration can't be loaded as a module 2023-05-06 18:29:04 +02:00
Robert Hensing
2e689d58cb lib/modules: Improve error when a configuration is imported
This is appears to be a fairly common mistake for beginners who want
to build larger things from the system configurations, such as NixOps
networks, etc. Further explanation seems appropriate.
2023-05-06 18:29:03 +02:00
Robert Hensing
58f385f680 lib/modules: Check against importing things with a _type 2023-05-06 18:29:03 +02:00
Robert Hensing
b8ff2807a2 lib/modules: Add class concept to check imports
This improves the error message when an incompatible module is
imported.
2023-05-06 18:29:03 +02:00
Robert Hensing
e7e64233c9 lib/tests/modules.sh: Unload implicit modules
I had some trouble understanding this. Let's try to keep new tests
a bit more stateless and explicit.
2023-05-06 18:22:50 +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
Matthieu Coudron
8670e496ff
Merge pull request #227714 from ony/feature/generateLuarocksConfig-toLua
lua.lib: use toLua in generateLuarocksConfig
2023-05-01 18:53:22 +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
Weijia Wang
b2ef7956b6
Merge pull request #227560 from jackyliu16/loongnix-commit
lib.platforms.loongarch64: init
2023-04-28 13:21:42 +03:00
jackyliu16
edcad332d9 lib.platforms.loongarch64: init 2023-04-27 20:04:30 +03: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
Naïm Favier
8751764236
lib/modules: better error for invalid option declarations
Make `byName` aware of whether it's processing options or config to give
slightly more accurate error messages.
2023-03-22 12:37:28 +01:00
hsjobeki
15a8d05ba5 init: lib.foldlAttrs
- provide comprehensive example
- add unit test
2023-03-11 10:42:00 +01:00
Robert Hensing
6b79fe8cdc
Merge pull request #211855 from hercules-ci/lib-modules-disabledModules-module-with-key
lib/modules: Allow an "anonymous" module with key in disabledModules
2023-03-09 16:16:37 +01:00
Patrick Widmer
7089294f10 strings: add escapeQuery for url encoding 2023-03-03 20:48:55 +01:00
Robert Hensing
118bdf25a6 lib/modules: Allow an "anonymous" module with key in disabledModules
This makes the following work

    disabledModules = [ foo.nixosModules.bar ];

even if `bar` is not a path, but rather a module such as

    { key = "/path/to/foo#nixosModules.bar"; config = ...; }

By supporting this, the user will often be able to use the same syntax
for both importing and disabling a module. This is becoming more relevant
because flakes promote the use of attributes to reference modules. Not
all of these modules in flake attributes will be identifiable, but with
the help of a framework such as flake-parts, these attributes can be
guaranteed to be identifiable (by outPath + attribute path).
2023-03-01 15:03:44 +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
0288ee587f
maintainers: clarify what fields are required 2023-01-27 18:05:28 +01:00
Naïm Favier
93dc2de29a
maintainers: disallow noreply.github.com emails 2023-01-27 18:05:28 +01:00
Naïm Favier
4e39849611
maintainers: make email optional
Not giving an email address is fine as long as the maintainer is
reachable through other means, such as GitHub or Matrix.
2023-01-27 18:04:20 +01:00
John Ericson
c1071e7804
Merge pull request #211622 from alyssais/valgrind-platforms
valgrind: make meta.platforms more accurate
2023-01-19 15:43:22 -05:00
Alyssa Ross
6d165a9474
lib.platforms.s390x: init 2023-01-19 17:43:50 +00:00
Alyssa Ross
541a2a5e91
lib.platforms.power: init 2023-01-19 17:43:49 +00:00
Alyssa Ross
48f3fd2d49
lib.platforms.armv7: init 2023-01-19 17:43:41 +00:00
Robert Hensing
415504e867 lib/tests/release.nix: Make nix a parameter + strictDeps
This makes bisecting nix a bit easier.

Example reproducer, invoked from nix directory:

```bash
nix-build ../nixpkgs/lib/tests/release.nix --arg nix '(builtins.getFlake "git+file://${toString ./.}").packages.x86_64-linux.default'
```
2023-01-18 01:39:38 +01:00
Robert Hensing
f61d4d346b
Merge pull request #205190 from NixOS/lib.path.relativeNormalise
lib.path.subpath.{isValid,normalise}: init
2023-01-03 13:46:11 +01:00
Silvan Mosberger
98fbcf1788 lib.path.subpath.isValid: init
The first path library function
2023-01-03 13:20:36 +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
figsoda
695d4bc76b lib: fix typos 2022-12-17 18:59:29 -05: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
Robert Hensing
6110a6009f lib/modules: Add context to the "option does not exist" error
Add trace items that provide context for a failed definition that
can not be caught within the Nix language.

This also adds a test for the `tryEval` behavior of `showDefs`.
2022-12-02 11:06:53 +00:00
figsoda
f993f8a186 lib/attrsets: add concatMapAttrs 2022-11-17 10:41:53 -05:00
John Ericson
66aa02f190 lib/systems: Support FreeBSD
A tricky thing about FreeBSD is that there is no stable ABI across
versions. That means that putting in the version as part of the config
string is paramount.

We have a parsed represenation that separates name versus version to
accomplish this. We include FreeBSD versions 12 and 13 to demonstrate
how it works.
2022-11-04 16:49:28 -04:00
Robert Hensing
1b6e5ac952 lib/tests/modules: Test doRename 2022-11-03 13:12:58 +01: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
Maximilian Bosch
ac48f07282
lib/types: always use <function body> instead of [function body] to indicate a function inside an option structure
The motivation is to have a single identifier for that. Useful for the
next commit where I'll try to escape option-parts correctly (options can
be any kind of strings, but unless these are Nix identifiers, they must
be quoted).

Since `<function body>` (or `<name>`/`*`) are special identifiers in
error messages and the manual, we need a unique way to mark an option
part as function call because these are not to be quoted.
2022-10-07 10:01:44 +02:00