start detangling lib

This commit is contained in:
Jeff Hykin 2024-05-25 12:14:33 -04:00
parent 9cb4ed1ffc
commit a4c9fde3e9
3 changed files with 197 additions and 167 deletions

View file

@ -4,169 +4,175 @@
* for new functions in `./tests.nix`. * for new functions in `./tests.nix`.
*/ */
let let
loadStatic = (folder: foundation = import ./detangled/1_foundation.nix;
{ fixedPoints = import ./detangled/2_fixed-points.nix;
setup = builtins.fromTOML ( builtins.readFile "${folder}/static/setup.toml" ); in
meta = builtins.fromTOML ( builtins.readFile "${folder}/static/meta.toml" ); let
} static = foundation.loadStatic ../.;
); untangledBase = {
static = loadStatic ../.; # constants
untangledLib = { sourceTypes = static.setup.sourceTypes;
# constants licenses = static.setup.licenses;
sourceTypes = static.setup.sourceTypes; maintainers = static.setup.maintainers;
licenses = static.setup.licenses; teams = static.setup.teams;
maintainers = static.setup.maintainers;
teams = static.setup.teams; # just to be overridable
builtins = builtins;
# top level helpers
loadStatic = foundation.loadStatic;
foldr = foundation.foldr;
# namespaces
fixedPoints = fixedPoints;
};
builtins = builtins;# just to be overridable #
loadStatic = loadStatic; # legacy lib
}; #
lib = fixedPoints.makeExtensible (self: let
callLibs = file: import file { lib = self; };
in untangledBase // {
fixedPoints = fixedPoints;
# often used, or depending on very little
trivial = callLibs ./trivial.nix;
inherit (import ./fixed-points.nix { inherit lib; }) makeExtensible; # datatypes
attrsets = callLibs ./attrsets.nix;
lib = makeExtensible (self: let lists = callLibs ./lists.nix;
callLibs = file: import file { lib = self; }; strings = callLibs ./strings.nix;
in untangledLib // { stringsWithDeps = callLibs ./strings-with-deps.nix;
# often used, or depending on very little
trivial = callLibs ./trivial.nix; # packaging
fixedPoints = callLibs ./fixed-points.nix; customisation = callLibs ./customisation.nix;
derivations = callLibs ./derivations.nix;
# datatypes meta = callLibs ./meta.nix;
attrsets = callLibs ./attrsets.nix; versions = callLibs ./versions.nix;
lists = callLibs ./lists.nix;
strings = callLibs ./strings.nix; # module system
stringsWithDeps = callLibs ./strings-with-deps.nix; modules = callLibs ./modules.nix;
options = callLibs ./options.nix;
# packaging types = callLibs ./types.nix;
customisation = callLibs ./customisation.nix;
derivations = callLibs ./derivations.nix; # constants
meta = callLibs ./meta.nix; systems = callLibs ./systems;
versions = callLibs ./versions.nix;
# serialization
# module system cli = callLibs ./cli.nix;
modules = callLibs ./modules.nix; gvariant = callLibs ./gvariant.nix;
options = callLibs ./options.nix; generators = callLibs ./generators.nix;
types = callLibs ./types.nix;
# misc
# constants asserts = callLibs ./asserts.nix;
systems = callLibs ./systems; debug = callLibs ./debug.nix;
# serialization # domain-specific
cli = callLibs ./cli.nix; fetchers = callLibs ./fetchers.nix;
gvariant = callLibs ./gvariant.nix;
generators = callLibs ./generators.nix; # Eval-time filesystem handling
path = callLibs ./path;
# misc filesystem = callLibs ./filesystem.nix;
asserts = callLibs ./asserts.nix; fileset = callLibs ./fileset;
debug = callLibs ./debug.nix; sources = callLibs ./sources.nix;
# domain-specific # TODO: these are not the same as system.platform, we should probably try and unify them
fetchers = callLibs ./fetchers.nix; # back-compat aliases
platforms = self.systems.doubles;
# Eval-time filesystem handling
path = callLibs ./path; # linux kernel configuration
filesystem = callLibs ./filesystem.nix; kernel = callLibs ./kernel.nix;
fileset = callLibs ./fileset;
sources = callLibs ./sources.nix; inherit (builtins) add addErrorContext attrNames concatLists
deepSeq elem elemAt filter genericClosure genList getAttr
# TODO: these are not the same as system.platform, we should probably try and unify them hasAttr head isAttrs isBool isInt isList isPath isString length
# back-compat aliases lessThan listToAttrs pathExists readFile replaceStrings seq
platforms = self.systems.doubles; stringLength sub substring tail trace;
inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor
# linux kernel configuration bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max
kernel = callLibs ./kernel.nix; importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
info showWarnings nixpkgsVersion version isInOldestRelease
inherit (builtins) add addErrorContext attrNames concatLists mod compare splitByAndCompare
deepSeq elem elemAt filter genericClosure genList getAttr functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs
hasAttr head isAttrs isBool isInt isList isPath isString length toHexString toBaseDigits inPureEvalMode;
lessThan listToAttrs pathExists readFile replaceStrings seq inherit (self.fixedPoints) fix fix' converge extends composeExtensions
stringLength sub substring tail trace; composeManyExtensions makeExtensible makeExtensibleWithCustomName;
inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath
bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs
importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum filterAttrsRecursive foldlAttrs foldAttrs collect nameValuePair mapAttrs
info showWarnings nixpkgsVersion version isInOldestRelease mapAttrs' mapAttrsToList attrsToList concatMapAttrs mapAttrsRecursive
mod compare splitByAndCompare mapAttrsRecursiveCond genAttrs isDerivation toDerivation optionalAttrs
functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil
toHexString toBaseDigits inPureEvalMode; recursiveUpdate matchAttrs mergeAttrsList overrideExisting showAttrPath getOutput
inherit (self.fixedPoints) fix fix' converge extends composeExtensions getBin getLib getDev getMan chooseDevOutputs zipWithNames zip
composeManyExtensions makeExtensible makeExtensibleWithCustomName; recurseIntoAttrs dontRecurseIntoAttrs cartesianProduct cartesianProductOfSets
inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath mapCartesianProduct updateManyAttrsByPath;
getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1
filterAttrsRecursive foldlAttrs foldAttrs collect nameValuePair mapAttrs ifilter0 concatMap flatten remove findSingle findFirst any all count
mapAttrs' mapAttrsToList attrsToList concatMapAttrs mapAttrsRecursive optional optionals toList range replicate partition zipListsWith zipLists
mapAttrsRecursiveCond genAttrs isDerivation toDerivation optionalAttrs reverseList listDfs toposort sort sortOn naturalSort compareLists take
zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil drop sublist last init crossLists unique allUnique intersectLists
recursiveUpdate matchAttrs mergeAttrsList overrideExisting showAttrPath getOutput subtractLists mutuallyExclusive groupBy groupBy';
getBin getLib getDev getMan chooseDevOutputs zipWithNames zip inherit (self.strings) concatStrings concatMapStrings concatImapStrings
recurseIntoAttrs dontRecurseIntoAttrs cartesianProduct cartesianProductOfSets intersperse concatStringsSep concatMapStringsSep
mapCartesianProduct updateManyAttrsByPath; concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput
inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1 makeLibraryPath makeIncludePath makeBinPath optionalString
ifilter0 concatMap flatten remove findSingle findFirst any all count hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
optional optionals toList range replicate partition zipListsWith zipLists escapeShellArg escapeShellArgs
reverseList listDfs toposort sort sortOn naturalSort compareLists take isStorePath isStringLike
drop sublist last init crossLists unique allUnique intersectLists isValidPosixName toShellVar toShellVars
subtractLists mutuallyExclusive groupBy groupBy'; escapeRegex escapeURL escapeXML replaceChars lowerChars
inherit (self.strings) concatStrings concatMapStrings concatImapStrings upperChars toLower toUpper addContextFrom splitString
intersperse concatStringsSep concatMapStringsSep removePrefix removeSuffix versionOlder versionAtLeast
concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput getName getVersion
makeLibraryPath makeIncludePath makeBinPath optionalString cmakeOptionType cmakeBool cmakeFeature
hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape mesonOption mesonBool mesonEnable
escapeShellArg escapeShellArgs nameFromURL enableFeature enableFeatureAs withFeature
isStorePath isStringLike withFeatureAs fixedWidthString fixedWidthNumber
isValidPosixName toShellVar toShellVars toInt toIntBase10 readPathsFromFile fileContents;
escapeRegex escapeURL escapeXML replaceChars lowerChars inherit (self.stringsWithDeps) textClosureList textClosureMap
upperChars toLower toUpper addContextFrom splitString noDepEntry fullDepEntry packEntry stringAfter;
removePrefix removeSuffix versionOlder versionAtLeast inherit (self.customisation) overrideDerivation makeOverridable
getName getVersion callPackageWith callPackagesWith extendDerivation hydraJob
cmakeOptionType cmakeBool cmakeFeature makeScope makeScopeWithSplicing makeScopeWithSplicing';
mesonOption mesonBool mesonEnable inherit (self.derivations) lazyDerivation optionalDrvAttr;
nameFromURL enableFeature enableFeatureAs withFeature inherit (self.meta) addMetaAttrs dontDistribute setName updateName
withFeatureAs fixedWidthString fixedWidthNumber appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
toInt toIntBase10 readPathsFromFile fileContents; hiPrioSet getLicenseFromSpdxId getExe getExe';
inherit (self.stringsWithDeps) textClosureList textClosureMap inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile
noDepEntry fullDepEntry packEntry stringAfter; packagesFromDirectoryRecursive;
inherit (self.customisation) overrideDerivation makeOverridable inherit (self.sources) cleanSourceFilter
callPackageWith callPackagesWith extendDerivation hydraJob cleanSource sourceByRegex sourceFilesBySuffices
makeScope makeScopeWithSplicing makeScopeWithSplicing'; commitIdFromGitRepo cleanSourceWith pathHasContext
inherit (self.derivations) lazyDerivation optionalDrvAttr; canCleanSource pathIsGitRepo;
inherit (self.meta) addMetaAttrs dontDistribute setName updateName inherit (self.modules) evalModules setDefaultModuleLocation
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio unifyModuleSyntax applyModuleArgsIfFunction mergeModules
hiPrioSet getLicenseFromSpdxId getExe getExe'; mergeModules' mergeOptionDecls mergeDefinitions
inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile pushDownProperties dischargeProperties filterOverrides
packagesFromDirectoryRecursive; sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride
inherit (self.sources) cleanSourceFilter mkOptionDefault mkDefault mkImageMediaOverride mkForce mkVMOverride
cleanSource sourceByRegex sourceFilesBySuffices mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
commitIdFromGitRepo cleanSourceWith pathHasContext mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
canCleanSource pathIsGitRepo; mkRenamedOptionModule mkRenamedOptionModuleWith
inherit (self.modules) evalModules setDefaultModuleLocation mkMergedOptionModule mkChangedOptionModule
unifyModuleSyntax applyModuleArgsIfFunction mergeModules mkAliasOptionModule mkDerivedConfig doRename
mergeModules' mergeOptionDecls mergeDefinitions mkAliasOptionModuleMD;
pushDownProperties dischargeProperties filterOverrides inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption
mkOptionDefault mkDefault mkImageMediaOverride mkForce mkVMOverride getValues getFiles
mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions optionAttrSetToDocList optionAttrSetToDocList'
mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule scrubOptionValue literalExpression literalExample
mkRenamedOptionModule mkRenamedOptionModuleWith showOption showOptionWithDefLocs showFiles
mkMergedOptionModule mkChangedOptionModule unknownModule mkOption mkPackageOption mkPackageOptionMD
mkAliasOptionModule mkDerivedConfig doRename mdDoc literalMD;
mkAliasOptionModuleMD; inherit (self.types) isType setType defaultTypeMerge defaultFunctor
inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions isOptionType mkOptionType;
mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption inherit (self.asserts)
getValues getFiles assertMsg assertOneOf;
optionAttrSetToDocList optionAttrSetToDocList' inherit (self.debug) traceIf traceVal traceValFn
scrubOptionValue literalExpression literalExample traceSeq traceSeqN traceValSeq
showOption showOptionWithDefLocs showFiles traceValSeqFn traceValSeqN traceValSeqNFn traceFnSeqN
unknownModule mkOption mkPackageOption mkPackageOptionMD runTests testAllTrue;
mdDoc literalMD; inherit (self.versions)
inherit (self.types) isType setType defaultTypeMerge defaultFunctor splitVersion;
isOptionType mkOptionType; });
inherit (self.asserts) in lib
assertMsg assertOneOf;
inherit (self.debug) traceIf traceVal traceValFn
traceSeq traceSeqN traceValSeq
traceValSeqFn traceValSeqN traceValSeqNFn traceFnSeqN
runTests testAllTrue;
inherit (self.versions)
splitVersion;
});
in lib

View file

@ -0,0 +1,22 @@
#
# foundation contains functions that only depend on builtins
#
{
loadStatic = (folder:
{
setup = builtins.fromTOML ( builtins.readFile "${folder}/static/setup.toml" );
meta = builtins.fromTOML ( builtins.readFile "${folder}/static/meta.toml" );
}
);
foldr = (
op: nul: list:
let
len = builtins.length list;
fold' = n:
if n == len
then nul
else op (builtins.elemAt list n) (fold' (n + 1));
in
fold' 0
);
}

View file

@ -1,5 +1,7 @@
{ foldr }: let # internal lib dependencies
let foundation = import ./1_foundation.nix;
in
let
/* /*
`fix f` computes the fixed point of the given function `f`. In other words, the return value is `x` in `x = f x`. `fix f` computes the fixed point of the given function `f`. In other words, the return value is `x` in `x = f x`.
@ -274,7 +276,7 @@
``` ```
*/ */
composeManyExtensions = composeManyExtensions =
foldr (x: y: composeExtensions x y) (final: prev: {}); foundation.foldr (x: y: composeExtensions x y) (final: prev: {});
/* /*
Same as `makeExtensible` but the name of the extending attribute is Same as `makeExtensible` but the name of the extending attribute is