feat: make utils use modules

This commit is contained in:
Yusuf Bera Ertan 2022-11-16 03:50:13 +03:00
parent 48c92cfd39
commit 15cb50c271
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
18 changed files with 290 additions and 236 deletions

View File

@ -75,7 +75,6 @@ in let
lib
dlib
pkgs
utils
externals
externalSources
dream2nixWithExternals
@ -102,7 +101,6 @@ in let
inherit inputs;
inherit framework;
inherit dream2nixWithExternals;
inherit utils;
inherit nix;
dream2nixInterface = {
inherit
@ -119,7 +117,7 @@ in let
else import f
) (callPackageDreamArgs // fargs);
utils = callPackageDream ./utils {};
inherit (framework) utils;
# updater modules to find newest package versions
updaters = callPackageDream ./updaters {};
@ -265,7 +263,7 @@ in let
sourceOverrides ? oldSources: {},
} @ args: let
# if dream lock is a file, read and parse it
dreamLock' = (utils.readDreamLock {inherit dreamLock;}).lock;
dreamLock' = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock;
fetcher =
if args.fetcher or null == null
@ -308,7 +306,7 @@ in let
# inject dependencies
dreamLock = utils.dreamLock.injectDependencies args.dreamLock inject;
dreamLockInterface = (utils.readDreamLock {inherit dreamLock;}).interface;
dreamLockInterface = (utils.dreamLock.readDreamLock {inherit dreamLock;}).interface;
produceDerivation = name: pkg:
utils.applyOverridesToPackage {
@ -356,7 +354,7 @@ in let
lib.mapAttrs'
(pname: releases: let
latest =
releases."${utils.latestVersion (b.attrNames releases)}";
releases."${dlib.latestVersion (b.attrNames releases)}";
in (lib.nameValuePair
"${pname}"
(latest
@ -390,7 +388,7 @@ in let
packageOverrides ? {},
} @ args: let
# parse dreamLock
dreamLockLoaded = utils.readDreamLock {inherit (args) dreamLock;};
dreamLockLoaded = utils.dreamLock.readDreamLock {inherit (args) dreamLock;};
dreamLock = dreamLockLoaded.lock;
dreamLockInterface = dreamLockLoaded.interface;
@ -483,7 +481,7 @@ in let
project
// rec {
dreamLock =
(utils.readDreamLock {
(utils.dreamLock.readDreamLock {
dreamLock = "${toString config.projectRoot}/${project.dreamLockPath}";
})
.lock;
@ -741,13 +739,13 @@ in {
inherit
callPackageDream
dream2nixWithExternals
dlib
framework
fetchSources
realizeProjects
translateProjects
riseAndShine
updaters
utils
makeOutputsForDreamLock
makeOutputs
;

View File

@ -101,7 +101,6 @@
dream2nixConfig = config;
dream2nixConfigFile = l.toFile "dream2nix-config.json" (l.toJSON config);
pkgs = throw "pkgs is not available before nixpkgs is imported";
utils = throw "utils is not available before nixpkgs is imported";
externals = throw "externals is not available before nixpkgs is imported";
dream2nixWithExternals = throw "not available before nixpkgs is imported";
};

View File

@ -5,7 +5,6 @@
inputs,
lib,
pkgs,
utils,
dream2nixConfig,
dream2nixConfigFile,
dream2nixWithExternals,
@ -25,6 +24,7 @@ in {
./fetchers
./translators
./indexers
./utils
];
options = {
lib = lib.mkOption {
@ -34,22 +34,21 @@ in {
type = t.raw;
};
externals = lib.mkOption {
type = t.raw;
type = t.lazyAttrsOf t.raw;
};
externalSources = lib.mkOption {
type = t.raw;
type = t.lazyAttrsOf t.path;
};
inputs = lib.mkOption {
type = t.raw;
type = t.lazyAttrsOf t.attrs;
};
pkgs = lib.mkOption {
type = t.raw;
};
utils = lib.mkOption {
type = t.raw;
};
dream2nixConfig = lib.mkOption {
type = t.raw;
type = t.submoduleWith {
modules = [./config];
};
};
dream2nixWithExternals = lib.mkOption {
type = t.path;

View File

@ -0,0 +1,6 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -1,18 +1,12 @@
{
lib,
# dream2nix
dlib,
utils,
...
}: let
{config, ...}: let
b = builtins;
l = lib // builtins;
l = config.lib // builtins;
replaceRootSources = {
dreamLock,
newSourceRoot,
} @ args: let
dreamLockLoaded = utils.readDreamLock {dreamLock = args.dreamLock;};
dreamLockLoaded = config.utils.dreamLock.readDreamLock {dreamLock = args.dreamLock;};
iface = dreamLockLoaded.interface;
patchVersion = version: source:
if
@ -44,10 +38,10 @@
subDreamLockNames = dreamLockFile: let
dir = b.dirOf dreamLockFile;
directories = utils.listDirs dir;
directories = config.dlib.listDirs dir;
dreamLockDirs =
lib.filter
l.filter
(d: b.pathExists "${dir}/${d}/dream-lock.json")
directories;
in
@ -57,7 +51,7 @@
isFile =
b.isPath dreamLock
|| b.isString dreamLock
|| lib.isDerivation dreamLock;
|| l.isDerivation dreamLock;
lockMaybeCompressed =
if isFile
@ -75,7 +69,7 @@
else let
dir = b.dirOf dreamLock;
in
lib.genAttrs
l.genAttrs
(subDreamLockNames dreamLock)
(d:
readDreamLock
@ -111,8 +105,8 @@
candidatesList;
allDependants =
lib.mapAttrs
(name: versions: lib.attrNames versions)
l.mapAttrs
(name: versions: l.attrNames versions)
dependencyGraph;
packageVersions =
@ -228,24 +222,24 @@
newDependcyGraph = decompressDependencyGraph inject;
newDependencyGraph =
lib.zipAttrsWith
l.zipAttrsWith
(name: versions:
lib.zipAttrsWith
(version: deps: lib.unique (lib.flatten deps))
l.zipAttrsWith
(version: deps: l.unique (l.flatten deps))
versions)
[
oldDependencyGraph
newDependcyGraph
];
in
lib.recursiveUpdate lock {
l.recursiveUpdate lock {
dependencies = newDependencyGraph;
};
decompressDependencyGraph = compGraph:
lib.mapAttrs
l.mapAttrs
(name: versions:
lib.mapAttrs
l.mapAttrs
(version: deps:
map
(dep: {
@ -257,9 +251,9 @@
compGraph;
compressDependencyGraph = decompGraph:
lib.mapAttrs
l.mapAttrs
(name: versions:
lib.mapAttrs
l.mapAttrs
(version: deps: map (dep: [dep.name dep.version]) deps)
versions)
decompGraph;
@ -272,15 +266,15 @@
decompressDependencyGraph (comp.cyclicDependencies or {});
emptyDependencyGraph =
lib.mapAttrs
l.mapAttrs
(name: versions:
lib.mapAttrs
l.mapAttrs
(version: source: [])
versions)
comp.sources;
dependencyGraph =
lib.recursiveUpdate
l.recursiveUpdate
emptyDependencyGraph
dependencyGraphDecomp;
in
@ -301,11 +295,11 @@
uncomp.cyclicDependencies;
dependencyGraph =
lib.filterAttrs
l.filterAttrs
(name: versions: versions != {})
(lib.mapAttrs
(l.mapAttrs
(name: versions:
lib.filterAttrs
l.filterAttrs
(version: deps: deps != [])
versions)
dependencyGraphComp);
@ -326,16 +320,17 @@
in
json;
in {
inherit
compressDreamLock
decompressDreamLock
decompressDependencyGraph
getMainPackageSource
getSource
getSubDreamLock
readDreamLock
replaceRootSources
injectDependencies
toJSON
;
config.utils.dreamLock = {
inherit
compressDreamLock
decompressDreamLock
getMainPackageSource
getSource
getSubDreamLock
readDreamLock
replaceRootSources
injectDependencies
toJSON
;
};
}

View File

@ -1,79 +1,41 @@
{
bash,
coreutils,
moreutils,
dlib,
fetchzip,
gitMinimal,
jq,
lib,
nix,
pkgs,
python3,
runCommandLocal,
stdenv,
writeScript,
writeScriptBin,
# dream2nix inputs
callPackageDream,
dream2nixWithExternals,
externalSources,
config,
configFile,
framework,
...
}: let
# TODO(yusdacra): separate every util function implementation into it's own file and load them automatically
# for now this will have to suffice
{config, ...}: let
b = builtins;
l = lib // builtins;
l = config.lib // builtins;
dreamLockUtils = callPackageDream ./dream-lock.nix {};
inherit
(config.pkgs)
bash
coreutils
moreutils
gitMinimal
jq
nix
pkgs
python3
runCommandLocal
stdenv
writeScript
writeScriptBin
;
overrideUtils = callPackageDream ./override.nix {};
translatorUtils = callPackageDream ./translator.nix {};
indexUtils = callPackageDream ./index {};
poetry2nixSemver = import "${externalSources.poetry2nix}/semver.nix" {
inherit lib;
poetry2nixSemver = import "${config.externalSources.poetry2nix}/semver.nix" {
inherit (config) lib;
# copied from poetry2nix
ireplace = idx: value: list: (
lib.genList
l.genList
(i:
if i == idx
then value
else (b.elemAt list i))
(b.length list)
else (l.elemAt list i))
(l.length list)
);
};
in
overrideUtils
// translatorUtils
// indexUtils
// rec {
inherit
(dlib)
dirNames
callViaEnv
identifyGitUrl
latestVersion
listDirs
listFiles
nameVersionPair
parseGitUrl
readTextFile
recursiveUpdateUntilDepth
traceJ
;
dreamLock = dreamLockUtils;
inherit (dreamLockUtils) readDreamLock;
impl = rec {
toDrv = path: runCommandLocal "some-drv" {} "cp -r ${path} $out";
toTOML = import ./toTOML.nix {inherit lib;};
# hash the contents of a path via `nix hash path`
hashPath = algo: path: let
hashPath = runCommandLocal "hash-${algo}" {} ''
@ -96,7 +58,7 @@ in
#!${bash}/bin/bash
set -Eeuo pipefail
export PATH="${lib.makeBinPath availablePrograms}"
export PATH="${l.makeBinPath availablePrograms}"
export NIX_PATH=nixpkgs=${pkgs.path}
TMPDIR=$(${coreutils}/bin/mktemp -d)
@ -112,7 +74,7 @@ in
#!${bash}/bin/bash
set -Eeuo pipefail
export PATH="${lib.makeBinPath availablePrograms}"
export PATH="${l.makeBinPath availablePrograms}"
export NIX_PATH=nixpkgs=${pkgs.path}
TMPDIR=$(${coreutils}/bin/mktemp -d)
@ -139,7 +101,7 @@ in
# Some builders like python require the original archive.
passthru.original = source;
unpackCmd =
if lib.hasSuffix ".tgz" (source.name or "${source}")
if l.hasSuffix ".tgz" (source.name or "${source}")
then ''
tar --delay-directory-restore -xf $src
@ -169,7 +131,7 @@ in
source,
project,
invalidationHash ?
dlib.calcInvalidationHash {
config.dlib.calcInvalidationHash {
inherit project source;
# TODO: translatorArgs
translatorArgs = {};
@ -179,7 +141,7 @@ in
aggregate = project.aggregate or false;
translator =
framework.translators."${project.translator}";
config.translators."${project.translator}";
argsJsonFile =
pkgs.writeText "translator-args.json"
@ -189,7 +151,7 @@ in
project = l.removeAttrs args.project ["dreamLock"];
outputFile = project.dreamLockPath;
}
// (framework.functions.translators.makeTranslatorDefaultArgs translator.extraArgs or {})
// (config.functions.translators.makeTranslatorDefaultArgs translator.extraArgs or {})
// args.project.subsystemInfo or {}
));
script =
@ -210,8 +172,8 @@ in
# aggregate source hashes
if [ "${l.toJSON aggregate}" == "true" ]; then
echo "aggregating all sources to one large FOD"
dream2nixWithExternals=${dream2nixWithExternals} \
dream2nixConfig=${configFile} \
dream2nixWithExternals=${config.dream2nixWithExternals} \
dream2nixConfig=${config.dream2nixConfigFile} \
python3 ${./cli}/aggregate-hashes.py $dreamLockPath
fi
@ -240,4 +202,16 @@ in
'';
in
script // {passthru = {inherit project;};};
}
};
in {
imports = [
./dream-lock.nix
./override.nix
./translator.nix
./toTOML.nix
./index
];
config = {
utils = impl;
};
}

View File

@ -1,19 +1,11 @@
{
lib,
dlib,
dream2nixInterface,
pkgs,
callPackageDream,
utils,
framework,
...
}: let
l = lib // builtins;
in rec {
{config, ...}: let
inherit (config) pkgs utils;
l = config.lib // builtins;
generatePackagesFromLocksTree = {
source ? throw "pass source",
builder ? null,
tree ? dlib.prepareSourceTree {inherit source;},
tree ? config.dlib.prepareSourceTree {inherit source;},
inject ? {},
packageOverrides ? {},
sourceOverrides ? {},
@ -39,7 +31,7 @@ in rec {
);
dreamLocks = findDreamLocks tree;
makePackagesForDreamLock = dreamLock:
(dream2nixInterface.makeOutputsForDreamLock {
(config.dream2nixInterface.makeOutputsForDreamLock {
inherit
dreamLock
inject
@ -54,6 +46,7 @@ in rec {
(acc: el: acc // el)
{}
(l.map makePackagesForDreamLock dreamLocks);
makeOutputsForIndexes = {
source,
indexes,
@ -61,8 +54,6 @@ in rec {
packageOverrides ? {},
sourceOverrides ? {},
}: let
l = lib // builtins;
mkApp = script: {
type = "app";
program = toString script;
@ -76,7 +67,7 @@ in rec {
inputJson="$(${pkgs.coreutils}/bin/mktemp)"
echo '${l.toJSON inputFinal}' > $inputJson
mkdir -p $(dirname ${inputFinal.outputFile})
${framework.apps.index}/bin/index ${input.indexer} $inputJson
${config.apps.index}/bin/index ${input.indexer} $inputJson
'';
in
mkApp script;
@ -85,7 +76,7 @@ in rec {
mkApp (
pkgs.writers.writeBash "translate-${name}" ''
set -e
${framework.apps.translate-index}/bin/translate-index \
${config.apps.translate-index}/bin/translate-index \
${name}/index.json ${name}/locks
''
);
@ -163,8 +154,8 @@ in rec {
mkCiAppWith
"pkgs-all"
''
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) indexApps)}
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) translateApps)}
${l.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) indexApps)}
${l.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) translateApps)}
'';
buildAllApp = let
@ -239,4 +230,11 @@ in rec {
};
in
outputs;
in {
config.utils = {
inherit
generatePackagesFromLocksTree
makeOutputsForIndexes
;
};
}

View File

@ -0,0 +1,86 @@
{config, ...}: let
l = config.lib // builtins;
t = l.types;
mkFunction = {type, ...} @ attrs:
l.mkOption (
attrs
// {
type = t.uniq (t.functionTo attrs.type);
}
);
in {
options.utils = {
dreamLock = {
compressDreamLock = mkFunction {
type = t.attrs;
};
decompressDreamLock = mkFunction {
type = t.attrs;
};
getMainPackageSource = mkFunction {
type = t.attrs;
};
getSource = mkFunction {
type = t.functionTo (t.functionTo (t.either t.package t.path));
};
getSubDreamLock = mkFunction {
type = t.functionTo (t.functionTo t.attrs);
};
readDreamLock = mkFunction {
type = t.attrs;
};
replaceRootSources = mkFunction {
type = t.attrs;
};
injectDependencies = mkFunction {
type = t.functionTo t.attrs;
};
toJSON = mkFunction {
type = t.attrs;
};
};
toDrv = mkFunction {
type = t.package;
};
toTOML = mkFunction {
type = t.str;
};
hashPath = mkFunction {
type = t.functionTo t.str;
};
hashFile = mkFunction {
type = t.functionTo t.str;
};
writePureShellScript = mkFunction {
type = t.functionTo t.package;
};
writePureShellScriptBin = mkFunction {
type = t.functionTo (t.functionTo t.package);
};
extractSource = mkFunction {
type = t.package;
};
satisfiesSemver = mkFunction {
type = t.bool;
};
makeTranslateScript = mkFunction {
type = t.package;
};
applyOverridesToPackage = mkFunction {
type = t.attrs;
};
loadOverridesDirs = mkFunction {
type = t.attrs;
};
simpleTranslate = mkFunction {
type = t.functionTo t.attrs;
};
generatePackagesFromLocksTree = mkFunction {
type = t.attrsOf t.package;
};
makeOutputsForIndexes = mkFunction {
type = t.attrs;
};
};
}

View File

@ -1,23 +1,19 @@
{
lib,
# dream2nix
utils,
...
}: let
{config, ...}: let
b = builtins;
l = config.lib // builtins;
loadOverridesDirs = overridesDirs: pkgs: let
loadOverrides = dir:
lib.genAttrs (utils.dirNames dir) (name:
l.genAttrs (config.dlib.dirNames dir) (name:
import (dir + "/${name}") {
inherit lib pkgs;
inherit l pkgs;
satisfiesSemver = constraint: pkg:
utils.satisfiesSemver pkg.version constraint;
config.utils.satisfiesSemver pkg.version constraint;
});
in
b.foldl'
(loaded: nextDir:
utils.recursiveUpdateUntilDepth 3 loaded (loadOverrides nextDir))
config.dlib.recursiveUpdateUntilDepth 3 loaded (loadOverrides nextDir))
{}
overridesDirs;
@ -51,13 +47,13 @@
'';
getOverrideFunctionArgs = function: let
funcArgs = lib.functionArgs function;
funcArgs = l.functionArgs function;
in
if funcArgs != {}
then b.attrNames funcArgs
else
(
function (old: {passthru.funcArgs = lib.attrNames old;})
function (old: {passthru.funcArgs = l.attrNames old;})
)
.funcArgs;
@ -76,9 +72,9 @@
# filter the overrides by the package name and conditions
overridesToApply = let
regexOverrides =
lib.filterAttrs
l.filterAttrs
(name: data:
lib.hasPrefix "^" name
l.hasPrefix "^" name
&& b.match name pname != null)
conditionalOverrides;
@ -86,16 +82,16 @@
b.foldl'
(overrides: new: overrides // new)
conditionalOverrides."${pname}" or {}
(lib.attrValues regexOverrides);
(l.attrValues regexOverrides);
overridesListForPackage =
lib.mapAttrsToList
l.mapAttrsToList
(
_name: data:
data // {inherit _name;}
)
overridesForPackage;
in (lib.filter
in (l.filter
(condOverride: evalCondition condOverride pkg)
overridesListForPackage);
@ -103,7 +99,7 @@
applySingleAttributeOverride = oldVal: functionOrValue:
if b.isFunction functionOrValue
then
if lib.functionArgs functionOrValue == {}
if l.functionArgs functionOrValue == {}
then functionOrValue oldVal
else
functionOrValue {
@ -118,9 +114,9 @@
base_derivation =
if condOverride ? _replace
then
if lib.isFunction condOverride._replace
if l.isFunction condOverride._replace
then condOverride._replace pkg
else if lib.isDerivation condOverride._replace
else if l.isDerivation condOverride._replace
then condOverride._replace
else
throw
@ -129,27 +125,27 @@
else pkg;
overrideFuncs =
lib.mapAttrsToList
l.mapAttrsToList
(funcName: func: {inherit funcName func;})
(lib.filterAttrs (
(l.filterAttrs (
n: v:
lib.hasPrefix "override" n
l.hasPrefix "override" n
&& (! b.elem n ["overrideDerivation" "overridePythonAttrs"])
)
condOverride);
singleArgOverrideFuncs = let
availableFunctions =
lib.mapAttrs
l.mapAttrs
(funcName: func: getOverrideFunctionArgs func)
(lib.filterAttrs
(funcName: func: lib.hasPrefix "override" funcName && funcName != "overrideDerivation" && funcName != "overridePythonAttrs")
(l.filterAttrs
(funcName: func: l.hasPrefix "override" funcName && funcName != "overrideDerivation" && funcName != "overridePythonAttrs")
base_derivation);
getOverrideFuncNameForAttrName = attrName: let
applicableFuncs =
lib.attrNames
(lib.filterAttrs
l.attrNames
(l.filterAttrs
(funcName: args: b.elem attrName args)
availableFunctions);
in
@ -160,11 +156,11 @@
else b.elemAt applicableFuncs 0;
attributeOverrides =
lib.filterAttrs
(n: v: ! lib.hasPrefix "override" n && ! lib.hasPrefix "_" n)
l.filterAttrs
(n: v: ! l.hasPrefix "override" n && ! l.hasPrefix "_" n)
condOverride;
in
lib.mapAttrsToList
l.mapAttrsToList
(attrName: funcOrValue: {
funcName = getOverrideFuncNameForAttrName attrName;
func = oldAttrs: {"${attrName}" = funcOrValue;};
@ -177,7 +173,7 @@
(old: let
updateAttrsFuncs = overrideFunc.func old;
in
lib.mapAttrs
l.mapAttrs
(attrName: functionOrValue:
applySingleAttributeOverride old."${attrName}" functionOrValue)
updateAttrsFuncs))
@ -185,10 +181,12 @@
(overrideFuncs ++ singleArgOverrideFuncs);
in
# apply the overrides to the given pkg
lib.foldl
l.foldl
(pkg: condOverride: applyOneOverride pkg condOverride)
pkg
overridesToApply;
in {
inherit applyOverridesToPackage loadOverridesDirs;
config.utils = {
inherit applyOverridesToPackage loadOverridesDirs;
};
}

View File

@ -1,21 +1,21 @@
{lib}: let
{config, ...}: let
inherit
(lib)
(config.lib)
length
elemAt
concatMap
all
concatLists
concatStringsSep
concatMapStringsSep
mapAttrsToList
foldl
isDerivation
;
inherit
(builtins)
abort
match
toJSON
typeOf
;
@ -103,7 +103,7 @@
then "float"
else if typeOf x == "set"
then
if lib.isDerivation x
if isDerivation x
then "string"
else "set"
else if typeOf x == "list"
@ -122,7 +122,7 @@
toTOML = attrs:
assert (typeOf attrs == "set"); let
byTy =
lib.foldl
foldl
(
acc: x: let
ty = tomlTy x.v;
@ -141,5 +141,8 @@
++ (byTy.list_of_attrs or [])
++ (byTy.set or [])
);
in
toTOML
in {
config.utils = {
inherit toTOML;
};
}

View File

@ -1,18 +1,13 @@
{
lib,
# dream2nix
dlib,
framework,
...
}: let
{config, ...}: let
b = builtins;
l = config.lib // builtins;
overrideWarning = fields: args:
lib.filterAttrs (
l.filterAttrs (
name: _:
if lib.any (field: name == field) fields
if l.any (field: name == field) fields
then
lib.warn ''
l.warn ''
you are trying to pass a "${name}" key from your source
constructor, this will be overridden with a value passed
by dream2nix.
@ -36,7 +31,7 @@
dependenciesByOriginalID =
b.foldl'
(result: pkgData:
lib.recursiveUpdate result {
l.recursiveUpdate result {
"${final.getOriginalID pkgData}" = pkgData;
})
{}
@ -70,7 +65,7 @@
allDependencies =
b.foldl'
(result: pkgData:
lib.recursiveUpdate result {
l.recursiveUpdate result {
"${getName pkgData}" = {
"${getVersion pkgData}" = pkgData;
};
@ -89,7 +84,7 @@
constructedArgsKeep =
overrideWarning ["pname" "version"] constructedArgs;
constructedSource = framework.functions.fetchers.constructSource (
constructedSource = config.functions.fetchers.constructSource (
constructedArgsKeep
// {
inherit type;
@ -100,12 +95,12 @@
skip =
(type == "path")
&& lib.isStorePath (lib.removeSuffix "/" constructedArgs.path);
&& l.isStorePath (l.removeSuffix "/" constructedArgs.path);
in
if skip
then result
else
lib.recursiveUpdate result {
l.recursiveUpdate result {
"${pkgName}" = {
"${pkgVersion}" =
b.removeAttrs constructedSource ["pname" "version"];
@ -116,9 +111,9 @@
dependencyGraph = let
depGraph =
lib.mapAttrs
l.mapAttrs
(name: versions:
lib.mapAttrs
l.mapAttrs
(version: pkgData: getDependencies pkgData)
versions)
allDependencies;
@ -135,17 +130,17 @@
allDependencyKeys = let
depsWithDuplicates =
lib.flatten
(lib.flatten
(lib.mapAttrsToList
(name: versions: lib.attrValues versions)
l.flatten
(l.flatten
(l.mapAttrsToList
(name: versions: l.attrValues versions)
dependencyGraph));
in
lib.unique depsWithDuplicates;
l.unique depsWithDuplicates;
missingDependencies =
lib.flatten
(lib.forEach allDependencyKeys
l.flatten
(l.forEach allDependencyKeys
(dep:
if sources ? "${dep.name}"."${dep.version}"
then []
@ -155,10 +150,10 @@
if missingDependencies == []
then {}
else
lib.listToAttrs
l.listToAttrs
(b.map
(dep:
lib.nameValuePair
l.nameValuePair
"${dep.name}"
{
"${dep.version}" =
@ -167,7 +162,7 @@
missingDependencies);
allSources =
lib.recursiveUpdate sources generatedSources;
l.recursiveUpdate sources generatedSources;
cyclicDependencies =
# TODO: inefficient! Implement some kind of early cutoff
@ -176,12 +171,12 @@
children = dependencyGraph."${node.name}"."${node.version}";
cyclicChildren =
lib.filter
l.filter
(child: prevNodes ? "${child.name}#${child.version}")
children;
nonCyclicChildren =
lib.filter
l.filter
(child: ! prevNodes ? "${child.name}#${child.version}")
children;
@ -201,14 +196,14 @@
if nonCyclicChildren == []
then cycles'
else
lib.flatten
l.flatten
(b.map
(child: findCycles child prevNodes' cycles')
nonCyclicChildren);
cyclesList =
findCycles
(dlib.nameVersionPair defaultPackage packages."${defaultPackage}")
(config.dlib.nameVersionPair defaultPackage packages."${defaultPackage}")
{}
[];
in
@ -229,7 +224,7 @@
|| b.elem cycle.to existing
then cycles
else
lib.recursiveUpdate
l.recursiveUpdate
cycles
{
"${cycle.from.name}"."${cycle.from.version}" =
@ -259,11 +254,13 @@
sources = allSources;
}
// (lib.optionalAttrs
// (l.optionalAttrs
(getDependencies != null)
{dependencies = dependencyGraph;});
in
dreamLockData;
in {
inherit simpleTranslate;
config.utils = {
inherit simpleTranslate;
};
}

View File

@ -7,27 +7,28 @@
writeText,
# dream2nix inputs
callPackageDream,
fetchers,
utils,
framework,
...
}: let
inherit (framework) utils fetchers;
lockUtils = utils.dreamLock;
updaters = callPackageDream ./updaters.nix {};
getUpdaterName = {dreamLock}: let
lock = (utils.readDreamLock {inherit dreamLock;}).lock;
lock = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock;
source = lockUtils.getMainPackageSource lock;
in
lock.updater
or fetchers.fetchers."${source.type}".defaultUpdater
or fetchers."${source.type}".defaultUpdater
or null;
makeUpdateScript = {
dreamLock,
updater ? getUpdaterName {inherit dreamLock;},
}: let
lock = (utils.readDreamLock {inherit dreamLock;}).lock;
lock = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock;
source = lockUtils.getMainPackageSource lock;
updater' = updaters."${updater}";
in

View File

@ -25,7 +25,7 @@ def callNixFunction(function_path, **kwargs):
d2n = (import {dream2nix_src} {{}});
in
builtins.toJSON (
(d2n.utils.callViaEnv d2n.{function_path})
(d2n.dlib.callViaEnv d2n.{function_path})
)
''',
env=env
@ -63,7 +63,7 @@ def eval(attr_path, wrapper_code=None, **kwargs):
d2n = (import {dream2nix_src} {{}});
result' =
if "{is_function_call}" == "True"
then d2n.utils.callViaEnv d2n.{attr_path}
then d2n.dlib.callViaEnv d2n.{attr_path}
else d2n.{attr_path};
result = (d2n.callPackageDream
{wrapper_code_file.name}
@ -101,7 +101,7 @@ def buildNixFunction(function_path, **kwargs):
let
d2n = (import {dream2nix_src} {{}});
in
(d2n.utils.callViaEnv d2n.{function_path})
(d2n.dlib.callViaEnv d2n.{function_path})
''',
env=env
)

View File

@ -5,5 +5,5 @@ import nix_ffi
('3', [ '2', '3', '1' ]),
])
def test_latestVersion(expected, versions):
result = nix_ffi.callNixFunction('utils.latestVersion', versions=versions)
result = nix_ffi.callNixFunction('dlib.latestVersion', versions=versions)
assert result == expected