Commit Graph

2751 Commits

Author SHA1 Message Date
Jonathan Ringer
dbe6e96d0a
lib/systems: add x86_64-darwin hostPlatform 2021-11-10 11:37:34 -08:00
Bernardo Meurer
90c1cdd93f
lib/tests/sources: update to Nix 2.4 cli syntax 2021-11-09 10:47:20 -08:00
Bernardo Meurer
fd4390146e
lib/tests/modules.sh: update to Nix 2.4 syntax 2021-11-09 10:47:19 -08:00
Robert Helgesson
c7678aff1b
lib: fix escapeXML example in documentation
The previous example output was forgotten copy-paste from some other
function.
2021-11-02 22:43:25 +01:00
Ben Siraphob
481afad265
Merge pull request #144072 from polykernel/lib-lists-mutuallyexclusive-optimization 2021-11-02 02:46:27 -05:00
polykernel
cd6397519f lib/lists: mutuallyExclusive function optimization
The current implementation of `mutuallyExclusive` builds a new list with
length subtracted by one on every recursive call which is expensive. When
b is empty, the function still traverses a in its entirety before returning
a result.

The new implementation uses `any` to check if each element of list b is in
list a using `elem`. This maintains short circuiting when list a or b is empty
and has a worst case time complexity of O(nm).
2021-11-01 16:29:01 -04:00
Robert Hensing
86f5136baf modules: Update evalModules doc 2021-11-01 09:38:51 +01:00
Robert Hensing
64dfd983df modules: Add visible = "shallow" to hide only sub-options 2021-11-01 09:34:07 +01:00
Robert Hensing
27644a82a9 modules: Add extendModules to module args 2021-11-01 09:34:07 +01:00
Robert Hensing
dece37b83a lib.evalModules: Add extendModules and type to result
Allows the simultaneous construction of top-level invocations and
submodule types.

This helps structure configuration systems integration code.
2021-11-01 09:34:07 +01:00
Ryan Burns
81ee86a2c6
Merge pull request #139284 from r-burns/powernv-kernel-config
lib/systems: update powernv kernel config
2021-10-28 13:53:16 -07:00
Silvan Mosberger
98f82e9c35
Merge pull request #141789 from pennae/eval-opt
lib: make extendDerivation lighter on eval
2021-10-21 20:17:32 +02:00
Markus S. Wamser
8e394b8533 licenses: add CAPEC 2021-10-15 23:10:34 +02:00
pennae
dc895fb281 lib: make extendDerivation lighter on eval
the fix to extendDerivation in #140051 unwittingly worsened eval performance by
quite a bit. set elements alone needed over 1GB extra after the change, which
seems disproportionate to how small it was. if we flip the logic used to
determine which outputs to install around and keep a "this one exactly" flag in
the specific outputs instead of a "all of them" in the root we can avoid most
of that cost.
2021-10-15 16:39:10 +02:00
Robert Hensing
a541ce1fe7
Merge pull request #140763 from hercules-ci/abort-on-warn
lib.warn: Add NIX_ABORT_ON_WARN for call traces
2021-10-13 22:43:39 +02:00
Robert Hensing
c9b7cc79e6 lib.warn: Add NIX_ABORT_ON_WARN for call traces 2021-10-13 22:43:06 +02:00
zimbatm
60d3ef0484
lib.systems.supported.tier3: add aarch64-darwin
aarch64-darwin is getting built by hydra
2021-10-06 17:27:32 +02:00
Silvan Mosberger
d193e632bc
Merge pull request #140284 from Infinisil/types-anything-lambdas
lib/types: Make types.anything merge functions
2021-10-05 13:50:42 +02:00
Jonas Chevalier
8377a7bca9
lib: add list of supported systems (#140428)
Adds the first 3 tiers of RFC0046 that are being used in flake.nix.
2021-10-05 11:14:47 +02:00
Robert Hensing
0699530f08
Merge pull request #136909 from ncfavier/cleanup-defaults-examples
nixos/doc: clean up defaults and examples
2021-10-04 20:37:42 +02:00
Michele Guerini Rocco
dd7cbf0c59
Merge pull request #140136 from rnhmjoj/matrix-ids
maintainers/maintainers-list: add Matrix IDs
2021-10-03 23:40:49 +02:00
Naïm Favier
52a2e4136e
lib/options: add literalExpression and literalDocBook, deprecate literalExample 2021-10-03 17:19:19 +02:00
Robert Helgesson
e75f346aa3
lib: add function escapeXML
Given a string, this function returns a string that can be inserted
verbatim in an XML document.
2021-10-03 11:28:03 +02:00
Silvan Mosberger
243a61e183
Merge pull request #140051 from pennae/extend-derivation
fix nested calls to extendDerivation
2021-10-02 17:03:24 +02:00
Silvan Mosberger
48293bd6b6 lib/types: Make types.anything merge functions
Previously it would give an error if there were multiple function
definitions.
2021-10-02 16:37:22 +02:00
rnhmjoj
35841653e1
lib/tests/maintainers: add matrix option 2021-10-01 21:27:00 +02:00
Delta
48eba3e35c ocamlPackages.lustre-v6: init at 6.103.3 2021-09-30 21:38:06 +02:00
pennae
9b3b8f74bb fix nested calls to extendDerivation
if extendDerivation is called on something that already had extendDerivation
called on it (eg a mkDerivation result) the second call will set
outputUnspecified=true on every output by way of propagating attributes of the
full derivation to the individual outputs. this in turn causes buildEnv--and
thus nix-shell and environment.systemPackages--to install every output of such a
derivation even when only a specific output was requested, which renders the
point of multiple outputs moot. this happens in python modules (see #139756),
though it seems that tcl and possibly others should also be affected.
2021-09-30 17:34:07 +02:00
Linus Heckemann
a3df3d05e5
Merge pull request #131205 from Ma27/showdefs-overflow
lib/modules: improve errors for `options`/`config`-mixups
2021-09-29 11:03:31 +02:00
Ryan Burns
288cc2007b lib/systems: update powernv kernel config
PowerNV was looking for a nonexisting zImage file.
Remove unnecessary .file / .installTarget.

Also add config options needed for default minimal
NixOS config and QEMU VirtIO/VirtFS devices.
2021-09-28 17:41:13 -07:00
Maximilian Bosch
681758d415
lib/generators: fix error message 2021-09-28 22:26:51 +02:00
Alyssa Ross
f446318916
lib.cleanSource: ignore sockets
I'm working on a project that involves running a virtual machine
monitor program, which creates a control socket in the project
directory (because it doesn't make sense to put it anywhere else).
This obviously isn't part of the source of my program, so I think
cleanSource should filter it out.
2021-09-17 10:03:00 +00:00
zimbatm
f882fbcee0
lib.generators.toINI: serialize derivations to string
This is the common case when passing a derivation, we want to access the
store path.
2021-09-12 06:26:21 +02:00
zimbatm
9e90a400a5
lib.generators.toGitINI: don't traverse derivations
Consider a derivation a value to be serialized.

    nix-repl> lib.generators.toGitINI { hello = { drv = pkgs.hello; }; }
    error: evaluation aborted with the following error message: 'generators.mkValueStringDefault: attrsets not supported: <derivation /nix/store/533q15q67sl6dl0272dyi7m7w5pwkkjh-hello-2.10.drv>'

Fixes #137390
2021-09-12 06:26:20 +02:00
Sergei Trofimovich
34e468dc42 lib/systems: add minimal s390x-linux cross-compile support
Tested basic functionality as:

    $ nix-build --arg crossSystem '{ config = "s390x-unknown-linux-gnu"; }' -A re2c
    $ file ./result/bin/re2c
    $ ./result/bin/re2c: ELF 64-bit MSB executable, IBM S/390, version 1 (SYSV),
    dynamically linked, interpreter ...-gnu-2.33-50/lib/ld64.so.1, for GNU/Linux 2.6.32, not stripped
    $ qemu-s390x ./result/bin/re2c --version
    re2c 2.2
2021-09-09 10:58:47 +00:00
polykernel
de81edf6ef lib/strings: fix infinite recursion on concatStringsSep fallback
The current implementation of the concatStringsSep fallback references
concatStrings whcih is just a partial application of concatStringsSep,
forming a circular dependency. Although this will almost never be
encountered as (assuming the user does not explicitly trigger it):
  1. the or operator will short circuit both in lazy and strict
     evaluation
  2. this can only occur in Nix versions prior to 1.10
     which is not compatible with various nix operations as of 2.3.15

However it is still important if scopedImport is used or the builtins
have been overwritten. lib.foldl' is used instead of builtins.foldl'
as the foldl' primops was introduced in the same release as concatStringsSep.
2021-08-26 20:08:05 -04:00
Robert Hensing
cdf0aa2907
Merge pull request #135794 from shlevy/composeManyFlakeCompat
lib.compose{Many,}Extensions: Make compatible with nix flake check
2021-08-26 16:37:09 +02:00
Paul-Nicolas Madelaine
fa61f7635d replace dead links 2021-08-26 23:14:50 +09:00
Shea Levy
d09222e48f
lib.compose{Many,}Extensions: Make compatible with nix flake check 2021-08-26 09:12:17 -04:00
Maximilian Bosch
b96101a35f
lib/modules: grammar fix in error msg 2021-08-26 00:37:33 +02:00
Maximilian Bosch
5773ae93f7
lib/generators: move limit detection into withRecursion
As suggested in #131205.

Now it's possible to pretty-print a value with `lib.generators` like
this:

    with lib.generators;
    toPretty { }
      (withRecursion { depthLimit = 10; } /* arbitrarily complex value */)

Also, this can be used for any other pretty-printer now if needed.
2021-08-26 00:28:49 +02:00
Maximilian Bosch
b6d3c9f821
lib/modules: fix error-message when declaring an option inside `config'
The message I originally implemented here was to catch a mixup of
`config' and `options' in a `types.submodule'[1]. However it looks
rather weird for a wrongly declared top-level option.

So I decided to throw

    error: The option `foo' does not exist. Definition values:
           - In `<unknown-file>':
               {
                 bar = {
                   _type = "option";
                   type = {
                     _type = "option-type";
               ...

           It seems as you're trying to declare an option by placing it into `config' rather than `options'!

for an expression like

    with import ./lib;

    evalModules {
      modules = [
        {
          foo.bar = mkOption {
            type = types.str;
          };
        }
      ];
    }

[1]  fa30c9abed
2021-08-25 23:18:27 +02:00
Maximilian Bosch
fbc9084c39
lib/options: use depthLimit for toPretty when showing a definition
When having a bogus declaration such as

    { lib, ... }:
    {
      foo.bar = mkOption {
        type = types.str;
      };
    }

the evaluation will terminate with a not-so helpful

    error: stack overflow (possible infinite recursion)

To make sure a useful error is still provided, I added a `depthLimit` of
`10` which should be perfectly sufficient to `toPretty` when it's used
in an error-case for `showDefs`.
2021-08-25 23:18:27 +02:00
Maximilian Bosch
55ea29fd8c
lib/generators/toPretty: add evaluation-limit
When having e.g. recursive attr-set, it cannot be printed which is
solved by Nix itself like this:

    $ nix-instantiate --eval -E 'let a.b = 1; a.c = a; in builtins.trace a 1'
    trace: { b = 1; c = <CYCLE>; }
    1

However, `generators.toPretty` tries to evaluate something until it's
done which can result in a spurious `stack-overflow`-error:

    $ nix-instantiate --eval -E 'with import <nixpkgs/lib>; generators.toPretty {  } (mkOption { type = types.str; })'
    error: stack overflow (possible infinite recursion)

Those attr-sets are in fact rather common, one example is shown above, a
`types.<type>`-declaration is such an example. By adding an optional
`depthLimit`-argument, `toPretty` will stop evaluating as soon as the
limit is reached:

    $ nix-instantiate --eval -E 'with import ./Projects/nixpkgs-update-int/lib; generators.toPretty { depthLimit = 2; } (mkOption { type = types.str; })' |xargs -0 echo -e
    "{
      _type = \"option\";
      type = {
        _type = \"option-type\";
        check = <function>;
        deprecationMessage = null;
        description = \"string\";
        emptyValue = { };
        functor = {
          binOp = <unevaluated>;
          name = <unevaluated>;
          payload = <unevaluated>;
          type = <unevaluated>;
          wrapped = <unevaluated>;
        };
        getSubModules = null;
        getSubOptions = <function>;
        merge = <function>;
        name = \"str\";
        nestedTypes = { };
        substSubModules = <function>;
        typeMerge = <function>;
      };
    }"

Optionally, it's also possible to let `toPretty` throw an error if the
limit is exceeded.
2021-08-25 23:18:26 +02:00
polykernel
3f4ce46a47 lib: optimize setAttrByPath and cleaup imports
- Remove inheritance of `lists.fold` as it isn't used anywhere.
- Inherit `foldl'` for consistency as only `cartesianProductOfSets` explicitly
  reference lib.
- Inline `foldr` to generate nested attrs instead of using `listToAttrs` and `tail`.
2021-08-23 18:04:47 -04:00
Harrison Houghton
9d71711aec lib: export strings/escapeRegex
I see no reason why I should be disallowed from using it.
2021-08-22 00:01:38 -04:00
Luke Granger-Brown
5ab1ce6734
Merge pull request #134763 from r-burns/fix-scaleway
lib/systems: fix scaleway-c1 platform
2021-08-21 03:40:30 +01:00
Alyssa Ross
273bab6bb6
lib.systems.inspect.patterns.isGnu: init
This allows checking e.g. stdenv.hostPlatform.isGnu, just like isMusl
or isUClibc.  It was already possible to check for glibc with
stdenv.hostPlatform.libc == "glibc", but when that doesn't line up
with how every other platform check works, this is apparently
sufficiently non-obvious that we've ended up with stuff like adding
glibc.static if !isMusl, which is obviously wrong.
2021-08-19 13:03:53 +00:00
Ryan Burns
525c69e724 lib/systems: fix scaleway-c1 platform
This regressed in 9c213398b3

The recursiveUpdate gave the platform both gcc.cpu and gcc.arch attrs
instead of only gcc.cpu. This is invalid; gcc configuration fails with:

```
Switch "--with-arch" may not be used with switch "--with-cpu"
```

So we revert to using `//` to retain only gcc.cpu
(which is more specific than the processor arch).
2021-08-18 21:52:14 -07:00
lassulus
229ff549e6 lib: inherit mkImageMediaOverride 2021-08-18 14:21:16 +02:00