about summary refs log tree commit diff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2022-02-06Merge pull request #126769 from ncfavier/nixosSystem-libRobert Hensing2-7/+9
nixos: move default module location logic to `eval-config.nix`
2022-01-30lib.sources: Improve docsJan Tojnar1-48/+67
Change comment type so than nixdoc picks them up into Nixpkgs manual. Also improve phrasing a bit and move stuff around so that it is formatted better.
2022-01-30lib.trivial: Change comment type before concat functionJan Tojnar1-5/+5
C-style comment was being picked up by nixdoc as a documentation comment for the function.
2022-01-27lib/modules: introduce setDefaultModuleLocationNaïm Favier2-7/+9
Wraps a module with a default location for reporting errors.
2022-01-25Merge pull request #156503 from hercules-ci/nixos-add-system.build-optionsRobert Hensing3-8/+24
nixos: Add `system.build.`{`toplevel`,`installBootLoader`}, improve error message
2022-01-24lib/meta: fix typo in platformMatch commentThiago Kenji Okada1-1/+1
2022-01-24lib.modules: Define mergeOneOption in terms of mergeUniqueOptionRobert Hensing1-5/+1
2022-01-24lib.types: Add unique like uniq, but custom errorsRobert Hensing3-3/+23
Couldn't extend types.uniq and it had a silly name anyway. Now we can have better error messages.
2022-01-24Merge pull request #155669 from schuelermine/patch-mkPackageOptionpennae1-0/+44
lib/options: Add mkPackageOption
2022-01-24Merge pull request #156215 from Atemu/update/svt-av1Martin Weinelt1-0/+5
2022-01-23nixos/docs/option-declarations: Document mkEnableOption and mkPackageOptionAnselm Schüler1-15/+40
This is a squashed commit. These are the original commit messages: lib/option: Improve comment better comment Update documentation Updated nixos/doc/manual/development/options-declarations.md with info on mkEnableOption and mkPackageOption. Updated the comment on mkEnableOption in lib/options.nix remove trailing whitespace nixos/doc/option-declarations: Update IDs & formatting nixos/docs/option-declarations: Escape angle brackets Build DB from MD (Amended) Fix typo Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> (Amended) Build DB from MD (again)
2022-01-23lib/options: Add mkPackageOptionAnselm Schüler1-0/+19
This is a squashed commit. These are the original commit messages: lib/options: Add mkPackageOption lib/options: Add missing semicolon lib/options.nix: Make mkPackageOption more complicated lib/options: Fix indent. & spacing lib/options.nix: Remove example and align comment lib/options: ravenous overuse of arguments lib/options: Format better lib/options: Add default examplePath decl lib/options: Make better mkPackageOption function lib/options: Remove trailing whitespace lib/options: Improve mkPackageOptions lib/options: Remove pkgs prefixing Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> lib/options: Slim down mkPackageOption further lib/options: mkPackageOption: Add "pkgs." to example lib/options: mkPackageOption: Make name & pkgs single arguments lib/options: mkPackageOption: Swap name & pkgs lib/options: Remove unnecessary import Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-01-22licenses: add Alliance for Open Media Patent License 1.0Atemu1-0/+5
2022-01-21Merge pull request #155522 from Julow/single_line_strRobert Hensing1-0/+13
types.singleLineStr: strings that don't contain '\n'
2022-01-21types.singleLineStr: Improve descriptionJules Aguillon1-1/+1
Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-01-20types.singleLineStr: Allow and trim trailing \nJules Aguillon1-5/+12
Allow a \n character at the end of the string and remove it during the merge function. An option of this type will resolve to the value "foo" whether it is set to "foo" or "foo\n". This is useful when using 'builtins.readFile' or ''-strings, which might add an unintended newline (for example, bash trim the final newline from a subshell).
2022-01-19lib/asserts: use throw to display message for assertMsgsternenseemann1-12/+10
`assert` has the annoying property that it dumps a lot of code at the user without the built in capability to display a nicer message. We have worked around this using `assertMsg` which would *additionally* display a nice message. We can do even better: By using `throw` we can make evaluation fail before assert draws its conclusions and prevent it from displaying the code making up the assert condition, so we get the nicer message of `throw` and the syntactical convenience of `assert`. Before: nix-repl> python.override { reproducibleBuild = true; stripBytecode = false; } trace: Deterministic builds require stripping bytecode. error: assertion (((lib).assertMsg (reproducibleBuild -> stripBytecode)) "Deterministic builds require stripping bytecode.") failed at /home/lukas/src/nix/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix:45:1 After: nix-repl> python.override { reproducibleBuild = true; stripBytecode = false; } error: Deterministic builds require stripping bytecode.
2022-01-18types.singleLineStr: Disallow \rJules Aguillon1-3/+2
2022-01-18types.singleLineStr: strings that don't contain '\n'Jules Aguillon1-0/+7
Add a new type, inheriting 'types.str' but checking whether the value doesn't contain any newline characters. The motivation comes from a problem with the 'users.users.${u}.openssh.authorizedKeys' option. It is easy to unintentionally insert a newline character at the end of a string, or even in the middle, for example: restricted_ssh_keys = command: keys: let prefix = '' command="${command}",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ''; in map (key: "${prefix} ${key}") keys; The 'prefix' string ends with a newline, which ends up in the middle of a key entry after a few manipulations. This is problematic because the key file is built by concatenating all the keys with 'concatStringsSep "\n"', with result in two entries for the faulty key: '' command="...",options... MY_KEY '' This is hard to debug and might be dangerous. This is now caught at build time.
2022-01-11Merge pull request #152392 from polykernel/attrset-optimizations-patch-1pennae1-17/+14
lib/attrset: various function optimizations
2022-01-10Merge pull request #152046 from pennae/optimize-modules-byNameRobert Hensing2-9/+9
lib/modules: optimize byName
2022-01-09lib.checkListOfEnum: initJosé Romildo2-1/+18
2022-01-05Merge pull request #151748 from hercules-ci/check-nixpkgs-overlays-typeRobert Hensing2-1/+24
Check nixpkgs overlays argument types
2022-01-02nixos/documentation: split options doc buildpennae1-1/+1
most modules can be evaluated for their documentation in a very restricted environment that doesn't include all of nixpkgs. this evaluation can then be cached and reused for subsequent builds, merging only documentation that has changed into the cached set. since nixos ships with a large number of modules of which only a few are used in any given config this can save evaluation a huge percentage of nixos options available in any given config. in tests of this caching, despite having to copy most of nixos/, saves about 80% of the time needed to build the system manual, or about two second on the machine used for testing. build time for a full system config shrank from 9.4s to 7.4s, while turning documentation off entirely shortened the build to 7.1s.
2021-12-28lib/modules: extract multiply-used value in byNamepennae1-4/+4
module.${attr} is used at least twice, so it must be evaluated at least twice (and since it's a function argument, be turned into a thunk twice).
2021-12-27lib/attrset: miscellaneous optimizationspolykernel1-10/+10
- Eta reduce `mapAttrsRecursiveCond`, `foldAttrs`, `getAttrFromPath`. - Modify `matchAttrs` to use `elemAt` instead of `head (tail xs)` to access elements. - Modify `matchAttrs` to use `any id` instead of `foldr and true`.
2021-12-27lib/attrset: optimize element access in recursiveUpdateUntilpolykernel1-7/+4
- Eta reduce formal arguments of `recursiveUpdate'. - Access elements in `recursiveUpdateUntil` using `elemAt` and `head` directly instead of `head (tail xs)` which copies a singleton unnecessarily. (`elemAt` is used instead of `last` to save a primitive call to `length`, this is possible because the 2-tuple structure is guranteed) - Use `length` instead of comparison to empty list to save a copy.
2021-12-25lib/attrsets: use builtins.zipAttrsWith if availablepennae1-1/+2
2021-12-25lib/modules: optimize byNamepennae1-6/+5
the foldl is equivalent to a zip with concat. list concatenation in nix is an O(n) operation, which makes this operation extremely inefficient when large numbers of modules are involved. this change reduces the number of list elements by 7 million on the system used to write this, total memory spent on lists by 58MB, and total memory allocated on the GC heap by almost 100MB (with a similar reduction in GC heap size). it's also slightly faster.
2021-12-22lib.throwIfNot: initRobert Hensing2-1/+24
2021-12-17Merge pull request #148785 from pennae/more-option-doc-staticizingGraham Christensen1-0/+2
treewide: more defaultText for options
2021-12-16lib.systems.supported: remove aarch64-darwin from Tier 3 liststernenseemann1-2/+3
While it is a fact of life that aarch64-darwin is built on Hydra, it has never formally been elevated from the Tier 7 state it was originally assigned in RFC 0046. Since platform Tier status is not only descriptive, but also normative, a consensus to commit to supporting aarch64-darwin would need to be reached.
2021-12-13lib: fix flake checkzimbatm1-1/+1
`builtins.currentSystem` is not available in pure eval. For this particular test, we don't really care since it's all about generating .drv files. Fixes the following error: $ nix flake check warning: unknown flake output 'lib' error: attribute 'currentSystem' missing at /nix/store/8wvnlbjxlr90kq2qa6d9zjpj8rqkilr5-source/lib/tests/misc.nix:499:73: 498| let 499| deriv = derivation { name = "test"; builder = "/bin/sh"; system = builtins.currentSystem; }; | ^ 500| in { (use '--show-trace' to show detailed location informat
2021-12-09Merge pull request #149924 from Mic92/aarch64be-embeddedJörg Thalheim1-2/+2
pkgsCross.aarch64be-embedded: fix eval
2021-12-09pkgsCross.x86_64-netbsd-llvm: mark as brokenJörg Thalheim1-0/+1
2021-12-09pkgsCross.ppcle-embedded: fix evalJörg Thalheim1-1/+1
2021-12-09pkgsCross.aarch64be-embedded: fix evalJörg Thalheim1-1/+1
2021-12-08nixos/modules: Allow options to be coerced to a string for convenienceSilvan Mosberger1-0/+2
2021-12-07Merge pull request #144022 from hercules-ci/lib-modules-optimize-unmatchedDefnsSilvan Mosberger3-15/+34
lib/modules: Short-circuit unmatchedDefns when configs is empty
2021-12-07Merge pull request #141856 from ShamrockLee/lib-spdx-licenseSilvan Mosberger2-1/+28
lib/meta: add getLicenseFromSpdxId function (resumed)
2021-12-02lib/modules: Deprecate args and checkRobert Hensing1-1/+6
2021-12-02lib/modules: Pass legacy args argument along through extendModulesRobert Hensing1-4/+21
2021-12-02lib/meta: add getLicenseFromSpdxId functionShamrock Lee2-1/+28
Move function spdxLicense, internally used in yarn2nix to lib/meta.nix, and rename to getLicenseFromSpdxId A similar function is implemented in poetry2nix, but the one originally in yarn2nix seems beter. since it falls back to an license-like attrset for mismatched case instead of a plain string
2021-11-26lib/tests: Use standard test syntaxVictor Engmark1-1/+1
For consistency.
2021-11-26lib/tests: Anchor config output regexesVictor Engmark1-98/+98
Strengthens the tests by making sure the whole line is matched.
2021-11-26lib/tests: Set hardening pragmasVictor Engmark2-4/+8
Makes any programming errors more likely to show up early. Non-obvious changes because of this: - Ignore the `evalConfig` result in `reportFailure`; we're not checking it at that point. - Pre-increment `$fail` and `$pass` to make sure the arithmetic doesn't result in a zero, which would result in a non-zero exit code for the expression.
2021-11-26lib/tests: Don't return non-zero values from checksVictor Engmark1-5/+0
The exit codes aren't used for anything.
2021-11-26lib/tests: Avoid assigning an array to a stringVictor Engmark1-2/+2
As per <https://github.com/koalaman/shellcheck/wiki/SC2124>.
2021-11-26lib/tests: Remove redundant semicolonsVictor Engmark1-6/+6
2021-11-26lib/tests: Clarify assignmentVictor Engmark1-1/+1
The extra equal sign was confusing, and doesn't seem to be relevant.