Commit Graph

401 Commits

Author SHA1 Message Date
Anselm Schüler
55ab538abf
lib/tests: add test for pkgsText parameter and package set selection of mkPackageOption 2023-10-10 13:13:38 +02:00
Anselm Schüler
d27d38c13a
lib/tests: add more tests for mkPackageOption 2023-10-06 14:08:46 +02:00
linsui
a50cea84be lib.gvariant: make the tests really work 2023-09-28 16:30:05 +02:00
Silvan Mosberger
dd72ff27f7 lib.attrsets.foldlAttrs: Make stricter
See the parent commit for the same change to lib.lists.foldl'
2023-09-27 02:43:59 +02:00
Silvan Mosberger
3b6169f87b lib.lists.foldl': Make strict in the initial accumulator
To maintain backwards compatibility, this can't be changed in the Nix language.
We can however ensure that the version Nixpkgs has the more intuitive behavior.
2023-09-27 02:43:59 +02:00
Silvan Mosberger
9893fee947 lib.lists.foldl': Add tests 2023-09-26 18:55:54 +02:00
Robert Hensing
00e5487906
Merge pull request #249243 from lf-/jade/declarationsWithLocations
nixos/modules: Add declarationPositions
2023-09-17 19:43:07 +02:00
Robert Helgesson
54bc9b45a3
Merge pull request #250220
lib.generators.toGitINI: escape string values in configuration
2023-09-11 23:44:42 +02:00
Jade Lovelace
a1d3882307 nixos/modules: Add declarationPositions
What it does: line and column level *declaration* position information:

$ nix repl .
nix-repl> :p nixosConfigurations.micro.options.environment.systemPackages.declarationPositions
[ { column = 7; file = "/nix/store/24aj3k7fgqv3ly7qkbf98qvphasrw9nb-source/nixos/modules/config/system-path.nix"; line = 63; } ]

Use cases:
- ctags over NixOS options, as will be presented at NixCon 2023 ;)
- improving the documentation pages to go to the exact line of the
  declarations.

Related work:
- https://github.com/NixOS/nixpkgs/pull/65024

  This one does it for all *definitions* rather than declarations, and
  it was not followed through with due to performance worries.
- https://github.com/NixOS/nixpkgs/pull/208173

  The basis for this change. This change is just a rebase of that one.
  I split it out to add the capability before adding users of it, in
  order to simplify review. However, the ctags script in there is a
  sample user of this feature.

Benchmarks: conducted by evaluating my own reasonably complex NixOS
configuration with the command:
`hyperfine -S none -w 1 -- "nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath"`

```
Benchmark 1: nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath
  Time (mean ± σ):      8.971 s ±  0.254 s    [User: 5.872 s, System: 1.388 s]
  Range (min … max):    8.574 s …  9.327 s    10 runs

Benchmark 1: nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath
  Time (mean ± σ):      8.766 s ±  0.160 s    [User: 5.873 s, System: 1.346 s]
  Range (min … max):    8.496 s …  9.033 s    10 runs
```

Summary of results: it seems to be in the noise, this does not cause any
visible regression in times.
2023-09-08 11:48:40 +02:00
Silvan Mosberger
d66929b7b1
Merge pull request #245623 from tweag/fileset.toSource
File set combinators base: `lib.fileset.toSource`
2023-09-02 04:07:02 +02:00
Silvan Mosberger
465e05c0c5 lib.fileset.toSource: init 2023-09-01 15:46:04 +02:00
Jan Tojnar
434d160d7c
Merge pull request #234615 from linsui/dconf
nixos/dconf: support generating from attrs
2023-08-28 18:31:52 +02:00
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