about summary refs log tree commit diff
path: root/lib/attrsets.nix
AgeCommit message (Collapse)AuthorFilesLines
2022-03-18lib.attrsets: Introduce showAttrPathSilvan Mosberger1-1/+15
2022-03-09lib.isDerivation: SimplifyRobert Hensing1-1/+1
2022-02-10fix: typo in lib/attrsets.nixJohn Rinehart1-1/+1
2022-01-11Merge pull request #152392 from polykernel/attrset-optimizations-patch-1pennae1-17/+14
lib/attrset: various function optimizations
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-10-15lib: make extendDerivation lighter on evalpennae1-1/+1
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-08-23lib: optimize setAttrByPath and cleaup importspolykernel1-6/+9
- 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-07-27Merge pull request #110742 from siraben/deprecate-foldBen Siraphob1-4/+4
2021-05-08nixpkgs-manual: lib.attrsets.mapAttrsToList returns a list (#122179)Erlend Pedersen1-0/+4
2021-01-28lib/attrsets: add cartesianProductOfSets functionJacek Galowicz1-1/+18
2021-01-26treewide: fold -> foldrBen Siraphob1-4/+4
2020-06-18lib/attrsets: add getMan functionrnhmjoj1-0/+1
2020-06-16lib/attrsets: fix typo in the comment of mapAttrsRecursiveCondPierre Allix1-1/+1
2020-04-02Merge pull request #83241 from Infinisil/valid-drv-nameSilvan Mosberger1-2/+2
lib/strings: Add `sanitizeDerivationName` function
2020-03-30lib/strings: Add sanitizeDerivationName functionSilvan Mosberger1-2/+2
2020-03-01Merge pull request #68491 from roberth/fix-dontRecurseIntoAttrsRobert Hensing1-0/+14
Fix dontRecurseIntoAttrs + add to lib + doc
2020-01-20lib/attrsets: Fix error in comment for getAttrFromPathSilvan Mosberger1-1/+1
2019-09-11lib: fix typo in 'zipAttrsWith' documentationPeter Simons1-1/+1
2019-09-11Document attrsets.recurseIntoAttrsRobert Hensing1-0/+3
2019-09-11top-level: Fix dontRecurseIntoAttrs and include in libRobert Hensing1-0/+5
dontRecurseIntoAttrs was a noop (x: x), causing the expression dontRecurseIntoAttrs (recurseIntoAttrs a) to have the wrong effect.
2019-09-11lib: Add recurseIntoAttrsRobert Hensing1-0/+6
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.
2018-12-11bundlerEnv: ensure dependencies always includedAlyssa Ross1-0/+9
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-09-17lib.overrideExisting: Better exampleSilvan Mosberger1-3/+6
2018-09-07lib: Improve overrideExisting implementationSilvan Mosberger1-1/+1
2018-08-30Merge pull request #45038 from symphorien/optoptSilvan Mosberger1-1/+1
module system: rework module merging
2018-08-27module system: rework module mergingSymphorien Gibol1-1/+1
The asymptotic complexity is now much lower.
2018-08-15lib/recursiveUpdateUntil: fix code to match documentationMathijs Kwik1-2/+3
$ 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-07-20[bot] treewide: remove unused 'inherit' in let blocksvolth1-2/+2
2018-07-05lib.concatMap and lib.mapAttrs to be builtinsvolth1-2/+3
2017-09-16Convert libs to a fixed-pointGraham Christensen1-4/+4
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-04-19lib: trivial spelling fixesTom Saeger1-3/+3
2017-04-17lib: Fix `matchAttrs`John Ericson1-8/+5
2017-03-30Get rid of all `with { inherit... }` and just used `let inherit...`John Ericson1-2/+2
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.
2016-12-04lib: fix typoFranz Pletz1-1/+1
2016-09-19toDerivation: Provide "out" and "outputName" attributesEelco Dolstra1-6/+11
2016-09-12lib.chooseDevOutputs: Use lib.getDevTuomas Tynkkynen1-1/+1
Reduces duplication, plus is actually needed for Go packages (at least go-repo-root).
2016-08-29stdenv.mkDerivation: Use chooseDevOutputsTuomas Tynkkynen1-0/+2
2016-07-11Really remove library functionsEelco Dolstra1-1/+0
Throwing a message like "removed 2016-02-29 because unused and broken" is unhelpful because it doesn't show what function was removed.
2016-04-25add get* helper functions and mass-replace manual outputs search with themNikolay Amiantov1-0/+4
2016-04-25getOutput function: initNikolay Amiantov1-0/+12
2016-04-25Revert "tryAttrs: init function"Nikolay Amiantov1-18/+0
This reverts commit 338340f993563551d8cb45941da987408abef65f.
2016-04-13tryAttrs: init functionNikolay Amiantov1-0/+18
2016-03-09lib/attrsets: document all the functionszimbatm1-28/+109
2016-03-09Remove lib.deepSeqList and lib.deepSeqAttrszimbatm1-1/+1
Both functions are broken and unused in the repo.
2016-02-03Revert "Merge #12357: nixos docs: show references to packages"Vladimír Čunát1-1/+1
The PR wasn't good enough yet. This reverts commit b2a37ceeea8c38ec71447f8dae1e6890a8cf982d, reversing changes made to 7fa9a1abce623aaf18b22f5dca3fc8a44a494e8d.
2016-01-13nixos manuals: allow displaying package referencesVladimír Čunát1-1/+1
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.
2015-12-07add helper to lib/attrsets: hasAttrByPathChristian Zagrodnick1-0/+11
2015-10-23Add stdenv bootstrap tools generation to release.nixEelco Dolstra1-1/+1