From 152c63c9ff82276e225ac4a4fa71c791d33e443d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Fri, 28 Jul 2017 20:05:35 -0400 Subject: 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 ) --- lib/default.nix | 173 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 121 insertions(+), 52 deletions(-) (limited to 'lib/default.nix') diff --git a/lib/default.nix b/lib/default.nix index 3893e349db3..3e30ec515fc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,58 +5,127 @@ */ let - # often used, or depending on very little - trivial = import ./trivial.nix; - fixedPoints = import ./fixed-points.nix; - - # datatypes - attrsets = import ./attrsets.nix; - lists = import ./lists.nix; - strings = import ./strings.nix; - stringsWithDeps = import ./strings-with-deps.nix; - - # packaging - customisation = import ./customisation.nix; - maintainers = import ./maintainers.nix; - meta = import ./meta.nix; - sources = import ./sources.nix; - - # module system - modules = import ./modules.nix; - options = import ./options.nix; - types = import ./types.nix; - - # constants - licenses = import ./licenses.nix; - systems = import ./systems; - - # misc - debug = import ./debug.nix; - generators = import ./generators.nix; - misc = import ./deprecated.nix; - - # domain-specific - sandbox = import ./sandbox.nix; - fetchers = import ./fetchers.nix; - - # Eval-time filesystem handling - filesystem = import ./filesystem.nix; - -in - { inherit trivial fixedPoints - attrsets lists strings stringsWithDeps - customisation maintainers meta sources - modules options types - licenses systems - debug generators misc - sandbox fetchers filesystem; + callLibs = file: import file { inherit lib; }; + + lib = rec { + + # often used, or depending on very little + trivial = callLibs ./trivial.nix; + fixedPoints = callLibs ./fixed-points.nix; + + # datatypes + attrsets = callLibs ./attrsets.nix; + lists = callLibs ./lists.nix; + strings = callLibs ./strings.nix; + stringsWithDeps = callLibs ./strings-with-deps.nix; + + # packaging + customisation = callLibs ./customisation.nix; + maintainers = callLibs ./maintainers.nix; + meta = callLibs ./meta.nix; + sources = callLibs ./sources.nix; + + + # module system + modules = callLibs ./modules.nix; + options = callLibs ./options.nix; + types = callLibs ./types.nix; + + # constants + licenses = callLibs ./licenses.nix; + systems = callLibs ./systems; + + # misc + debug = callLibs ./debug.nix; + + generators = callLibs ./generators.nix; + misc = callLibs ./deprecated.nix; + # domain-specific + sandbox = callLibs ./sandbox.nix; + fetchers = callLibs ./fetchers.nix; + + # Eval-time filesystem handling + filesystem = callLibs ./filesystem.nix; # back-compat aliases platforms = systems.doubles; - } - # !!! don't include everything at top-level; perhaps only the most - # commonly used functions. - // trivial // fixedPoints - // lists // strings // stringsWithDeps // attrsets // sources - // options // types // meta // debug // misc // modules - // customisation + + inherit (builtins) add addErrorContext attrNames + concatLists deepSeq elem elemAt filter genericClosure genList + getAttr hasAttr head isAttrs isBool isFunction isInt isList + isString length lessThan listToAttrs pathExists readFile + replaceStrings seq stringLength sub substring tail; + inherit (trivial) id const concat or and boolToString mergeAttrs + flip mapNullable inNixShell min max importJSON warn info + nixpkgsVersion mod; + + inherit (fixedPoints) fix fix' extends composeExtensions + makeExtensible makeExtensibleWithCustomName; + inherit (attrsets) attrByPath hasAttrByPath setAttrByPath + getAttrFromPath attrVals attrValues catAttrs filterAttrs + filterAttrsRecursive foldAttrs collect nameValuePair mapAttrs + mapAttrs' mapAttrsToList mapAttrsRecursive mapAttrsRecursiveCond + genAttrs isDerivation toDerivation optionalAttrs + zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil + recursiveUpdate matchAttrs overrideExisting getOutput getBin + getLib getDev chooseDevOutputs zipWithNames zip; + inherit (lists) singleton foldr fold foldl foldl' imap0 imap1 + concatMap flatten remove findSingle findFirst any all count + optional optionals toList range partition zipListsWith zipLists + reverseList listDfs toposort sort take drop sublist last init + crossLists unique intersectLists subtractLists + mutuallyExclusive; + inherit (strings) concatStrings concatMapStrings concatImapStrings + intersperse concatStringsSep concatMapStringsSep + concatImapStringsSep makeSearchPath makeSearchPathOutput + makeLibraryPath makeBinPath makePerlPath optionalString + hasPrefix hasSuffix stringToCharacters stringAsChars escape + escapeShellArg escapeShellArgs replaceChars lowerChars upperChars + toLower toUpper addContextFrom splitString removePrefix + removeSuffix versionOlder versionAtLeast getVersion nameFromURL + enableFeature fixedWidthString fixedWidthNumber isStorePath + toInt readPathsFromFile fileContents; + inherit (stringsWithDeps) textClosureList textClosureMap + noDepEntry fullDepEntry packEntry stringAfter; + inherit (customisation) overrideDerivation makeOverridable + callPackageWith callPackagesWith addPassthru hydraJob makeScope; + inherit (meta) addMetaAttrs dontDistribute setName updateName + appendToName mapDerivationAttrset lowPrio lowPrioSet hiPrio + hiPrioSet; + inherit (sources) pathType pathIsDirectory cleanSourceFilter + cleanSource sourceByRegex sourceFilesBySuffices + commitIdFromGitRepo; + inherit (modules) evalModules closeModules unifyModuleSyntax + applyIfFunction unpackSubmodule packSubmodule mergeModules + mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions + pushDownProperties dischargeProperties filterOverrides + sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride + mkOptionDefault mkDefault mkForce mkVMOverride mkStrict + mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions + mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule + mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule + mkAliasOptionModule doRename filterModules; + inherit (options) isOption mkEnableOption mkSinkUndeclaredOptions + mergeDefaultOption mergeOneOption mergeEqualOption getValues + getFiles optionAttrSetToDocList optionAttrSetToDocList' + scrubOptionValue literalExample showOption showFiles + unknownModule mkOption; + inherit (types) isType setType defaultTypeMerge defaultFunctor + isOptionType mkOptionType; + inherit (debug) addErrorContextToAttrs traceIf traceVal + traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq + traceValSeqN traceShowVal traceShowValMarked + showVal traceCall traceCall2 traceCall3 traceValIfNot runTests + testAllTrue strict traceCallXml attrNamesToStr; + inherit (misc) maybeEnv defaultMergeArg defaultMerge foldArgs + defaultOverridableDelayableArgs composedArgsAndFun + maybeAttrNullable maybeAttr ifEnable checkFlag getValue + checkReqs uniqList uniqListExt condConcat lazyGenericClosure + innerModifySumArgs modifySumArgs innerClosePropagation + closePropagation mapAttrsFlatten nvs setAttr setAttrMerge + mergeAttrsWithFunc mergeAttrsConcatenateValues + mergeAttrsNoOverride mergeAttrByFunc mergeAttrsByFuncDefaults + mergeAttrsByFuncDefaultsClean mergeAttrBy + prepareDerivationArgs nixType imap overridableDelayableArgs; + }; +in lib -- cgit 1.4.1