Commit graph

55 commits

Author SHA1 Message Date
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
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
Ben Siraphob
b63a54f81c
Merge pull request #110742 from siraben/deprecate-fold 2021-07-27 15:13:31 +07:00
Erlend Pedersen
3452a739d1
nixpkgs-manual: lib.attrsets.mapAttrsToList returns a list (#122179) 2021-05-08 13:55:11 +02:00
Jacek Galowicz
123045a570 lib/attrsets: add cartesianProductOfSets function 2021-01-28 23:08:59 +01:00
Ben Siraphob
1c2a2b0a08 treewide: fold -> foldr 2021-01-26 10:57:07 +07:00
rnhmjoj
986079275b
lib/attrsets: add getMan function 2020-06-18 10:16:57 +02:00
Pierre Allix
106be3f6fe lib/attrsets: fix typo in the comment of mapAttrsRecursiveCond 2020-06-16 13:48:57 +02:00
Silvan Mosberger
f75c11cfdf
Merge pull request #83241 from Infinisil/valid-drv-name
lib/strings: Add `sanitizeDerivationName` function
2020-04-02 05:58:13 +02:00
Silvan Mosberger
4b206ac83b
lib/strings: Add sanitizeDerivationName function 2020-03-30 01:15:30 +02:00
Robert Hensing
e38a01db5d
Merge pull request #68491 from roberth/fix-dontRecurseIntoAttrs
Fix dontRecurseIntoAttrs + add to lib + doc
2020-03-01 11:05:34 +01:00
Silvan Mosberger
74775d1d72
lib/attrsets: Fix error in comment for getAttrFromPath 2020-01-20 22:42:38 +01:00
Peter Simons
c82b347947 lib: fix typo in 'zipAttrsWith' documentation 2019-09-11 19:54:36 +02:00
Robert Hensing
a96f37db10 Document attrsets.recurseIntoAttrs 2019-09-11 14:55:23 +02:00
Robert Hensing
fc64cf65ab top-level: Fix dontRecurseIntoAttrs and include in lib
dontRecurseIntoAttrs was a noop (x: x), causing the expression
dontRecurseIntoAttrs (recurseIntoAttrs a) to have the wrong effect.
2019-09-11 13:12:06 +02:00
Robert Hensing
8935bfb4ac lib: Add recurseIntoAttrs
This makes the function available without having to evaluate the
Nixpkgs fix-point, making it available in a more natural way for
code that deals with multiple Nixpkgs invocations.

Its definition is coupled to Nix rather than Nixpkgs, so it will
feel right at home in lib.
2019-09-11 13:12:06 +02:00
Alyssa Ross
67b1265fb3
bundlerEnv: ensure dependencies always included
Suppose I have a Gemfile like this:

    source "https://rubygems.org"
    gem "actioncable"
    gem "websocket-driver", group: :test

The gemset.nix generated by Bundix 2.4.1 will set ActionCable's groups
to [ "default" ], and websocket-driver's to [ "test" ]. This means that
the generated bundlerEnv wouldn't include websocket-driver unless the
test group was included, even though it's required by the default group.

This is arguably a bug in Bundix (websocket-driver's groups should
probably be [ "default" "test" ] or just [ "default" ]), but there's no
reason bundlerEnv should omit dependencies even given such an input --
it won't necessarily come from Bundix, and it would be good for
bundlerEnv to do the right thing.

To fix this, filterGemset is now a recursive function, that adds
dependencies of gems in the group to the filtered gemset until it
stabilises on the gems that match the required groups, and all of their
recursive dependencies.
2018-12-11 21:26:07 +00:00
Silvan Mosberger
c7104d97c8
lib.overrideExisting: Better example 2018-09-17 23:28:47 +02:00
Silvan Mosberger
5cfdec6e94
lib: Improve overrideExisting implementation 2018-09-07 21:00:14 +02:00
Silvan Mosberger
9113696051
Merge pull request #45038 from symphorien/optopt
module system: rework module merging
2018-08-30 20:08:45 +02:00
Symphorien Gibol
526d604670 module system: rework module merging
The asymptotic complexity is now much lower.
2018-08-27 17:11:58 +02:00
Mathijs Kwik
b63ec64521 lib/recursiveUpdateUntil: fix code to match documentation
$ nix repl lib
Welcome to Nix version 2.0.2. Type :? for help.

Loading 'lib'...
Added 350 variables.

-- this is the exact example from the function's documentation:
nix-repl> recursiveUpdateUntil (path: l: r: path == ["foo"]) {
                   # first attribute set
                   foo.bar = 1;
                   foo.baz = 2;
                   bar = 3;
                 } {
                   #second attribute set
                   foo.bar = 1;
                   foo.quz = 2;
                   baz = 4;
                 }
{ bar = 3; baz = 4; foo = { bar = 1; baz = 2; quz = 2; }; }

-- although the documentation says:
{
    foo.bar = 1; # 'foo.*' from the second set
    foo.quz = 2; #
    bar = 3;     # 'bar' from the first set
    baz = 4;     # 'baz' from the second set
}
2018-08-15 17:16:56 +02:00
volth
6d2857a311 [bot] treewide: remove unused 'inherit' in let blocks 2018-07-20 19:38:19 +00:00
volth
e9a6c7cebb lib.concatMap and lib.mapAttrs to be builtins 2018-07-05 03:08:00 +00:00
Graham Christensen
152c63c9ff
Convert libs to a fixed-point
This does break the API of being able to import any lib file and get
its libs, however I'm not sure people did this.

I made this while exploring being able to swap out docFn with a stub
in #2305, to avoid functor performance problems. I don't know if that
is going to move forward (or if it is a problem or not,) but after
doing all this work figured I'd put it up anyway :)

Two notable advantages to this approach:

1. when a lib inherits another lib's functions, it doesn't
   automatically get put in to the scope of lib
2. when a lib implements a new obscure functions, it doesn't
   automatically get put in to the scope of lib

Using the test script (later in this commit) I got the following diff
on the API:

  + diff master fixed-lib
  11764a11765,11766
  > .types.defaultFunctor
  > .types.defaultTypeMerge
  11774a11777,11778
  > .types.isOptionType
  > .types.isType
  11781a11786
  > .types.mkOptionType
  11788a11794
  > .types.setType
  11795a11802
  > .types.types

This means that this commit _adds_ to the API, however I can't find a
way to fix these last remaining discrepancies. At least none are
_removed_.

Test script (run with nix-repl in the PATH):

  #!/bin/sh

  set -eux

  repl() {
      suff=${1:-}
      echo "(import ./lib)$suff" \
          | nix-repl 2>&1
  }

  attrs_to_check() {
      repl "${1:-}" \
          | tr ';'  $'\n' \
          | grep "\.\.\." \
          | cut -d' ' -f2 \
          | sed -e "s/^/${1:-}./" \
          | sort
  }

  summ() {
      repl "${1:-}" \
          | tr ' ' $'\n' \
          | sort \
          | uniq
  }

  deep_summ() {
      suff="${1:-}"
      depth="${2:-4}"
      depth=$((depth - 1))
      summ "$suff"

      for attr in $(attrs_to_check "$suff" | grep -v "types.types"); do
          if [ $depth -eq 0 ]; then
              summ "$attr" | sed -e "s/^/$attr./"
          else
              deep_summ "$attr" "$depth" | sed -e "s/^/$attr./"
          fi
      done
  }

  (
      cd nixpkgs

      #git add .
      #git commit -m "Auto-commit, sorry" || true
      git checkout fixed-lib
      deep_summ > ../fixed-lib
      git checkout master
      deep_summ > ../master
  )

  if diff master fixed-lib; then
      echo "SHALLOW MATCH!"
  fi

  (
      cd nixpkgs
      git checkout fixed-lib
      repl .types
  )
2017-09-16 21:36:43 -04:00
Tom Saeger
5989515b94 lib: trivial spelling fixes 2017-04-19 19:37:55 -05:00
John Ericson
fffcee35f9 lib: Fix matchAttrs 2017-04-17 17:13:01 -04:00
John Ericson
4c0d7da183 Get rid of all with { inherit... } and just used let inherit...
The old forms presumably predates, or were made in ignorance of,
`let inherit`. This way is better style as the scoping as more lexical,
something which Nix can (or might already!) take advantage of.
2017-03-30 03:05:05 -04:00
Franz Pletz
67332d4e4c
lib: fix typo 2016-12-04 01:39:51 +01:00
Eelco Dolstra
1c043e0749 toDerivation: Provide "out" and "outputName" attributes 2016-09-19 20:02:07 +02:00
Tuomas Tynkkynen
e0b5eef4e7 lib.chooseDevOutputs: Use lib.getDev
Reduces duplication, plus is actually needed for Go packages (at least
go-repo-root).
2016-09-12 00:18:18 +03:00
Tuomas Tynkkynen
5326e85f3d stdenv.mkDerivation: Use chooseDevOutputs 2016-08-29 14:49:51 +03:00
Eelco Dolstra
532211c68d Really remove library functions
Throwing a message like "removed 2016-02-29 because unused and broken"
is unhelpful because it doesn't show what function was removed.
2016-07-11 16:34:46 +02:00
Nikolay Amiantov
5ff40ddedf add get* helper functions and mass-replace manual outputs search with them 2016-04-25 13:24:39 +03:00
Nikolay Amiantov
7d3e75827b getOutput function: init 2016-04-25 13:22:41 +03:00
Nikolay Amiantov
5f3987f44f Revert "tryAttrs: init function"
This reverts commit 338340f993.
2016-04-25 13:22:41 +03:00
Nikolay Amiantov
338340f993 tryAttrs: init function 2016-04-13 22:05:45 +03:00
zimbatm
523e328318 lib/attrsets: document all the functions 2016-03-09 19:59:57 +00:00
zimbatm
a086858ef5 Remove lib.deepSeqList and lib.deepSeqAttrs
Both functions are broken and unused in the repo.
2016-03-09 19:59:57 +00:00
Vladimír Čunát
889351af8b Revert "Merge #12357: nixos docs: show references to packages"
The PR wasn't good enough yet.
This reverts commit b2a37ceeea, reversing
changes made to 7fa9a1abce.
2016-02-03 12:16:33 +01:00
Vladimír Čunát
b9f6dfe8c5 nixos manuals: allow displaying package references
The manuals are now evaluated with each derivation in `pkgs` (recursively)
replaced by a fake with path "\${pkgs.path.to.the.attribute}".
It isn't perfect, but it seems to cover a vast majority of use cases.
Caveat: even if the package is reached by a different means,
the path above will be shown and not e.g. `${config.services.foo.package}`.

As before, defaults created by `mkDefault` aren't displayed,
but documentation shouldn't (mostly) be a reason to use that anymore.

Note: t wouldn't be enough to just use `lib.mapAttrsRecursive`,
because derivations are also (special) attribute sets.
2016-01-13 12:03:18 +01:00
Christian Zagrodnick
ce96057588 add helper to lib/attrsets: hasAttrByPath 2015-12-07 11:04:14 +01:00
Eelco Dolstra
45c7dd7d98 Add stdenv bootstrap tools generation to release.nix 2015-10-23 13:05:36 +02:00
Jaka Hudoklin
341ac85644 Add lib.filterAttrsRecursive function 2015-09-19 00:33:44 +02:00
Eelco Dolstra
214d4fb73c Allow options with type "package" to be store paths
For example, this allows writing

  nix.package = /nix/store/786mlvhd17xvcp2r4jmmay6jj4wj6b7f-nix-1.10pre4206_896428c;

Also, document types.package in the manual.
2015-08-07 03:09:57 +02:00
Eelco Dolstra
0ae8b365b3 Rename misc.nix -> deprecated.nix 2015-07-23 18:31:54 +02:00
Eelco Dolstra
3cd5fd8bb3 More efficient version of filterAttrs 2015-07-23 16:49:13 +02:00
Benjamin Staffin
4dd93dbf25 lib: Fix matchAttrs by importing builtins.length
Before:

    nix-repl> :l <nixpkgs>
    nix-repl> lib.matchAttrs { foo = "bar"; } { bar = "bas"; }
    error: undefined variable ‘length’ at "/home/benley/nix/nixpkgs/lib/attrsets.nix":317:10

After:

    nix-repl> :l <nixpkgs>
    nix-repl> lib.matchAttrs { foo = "bar"; } { bar = "bas"; }
    false

Change-Id: I548d69d50cffe1c63a6f39f76fd09d1835d8d9a2
2014-12-30 15:07:29 -08:00
Eelco Dolstra
97220c973f Replace hasAttr/getAttr calls with the ? and . operators
For NixOS evaluation, this gives a ~21% reduction in the number of
values allocated and a ~4% speedup. It's also more readable.
2014-10-05 01:11:06 +02:00
Eelco Dolstra
0e120dc68f Use new primops 2014-10-05 01:10:52 +02:00