refactor: separate utils into own modules

This commit is contained in:
Yusuf Bera Ertan 2022-11-16 17:06:53 +03:00
parent f6ddebb846
commit 59870d0878
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
26 changed files with 143 additions and 77 deletions

View File

@ -263,7 +263,7 @@ in let
sourceOverrides ? oldSources: {},
} @ args: let
# if dream lock is a file, read and parse it
dreamLock' = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock;
dreamLock' = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
fetcher =
if args.fetcher or null == null
@ -304,9 +304,9 @@ in let
allOutputs,
} @ args: let
# inject dependencies
dreamLock = utils.dreamLock.injectDependencies args.dreamLock inject;
dreamLock = utils.dream-lock.injectDependencies args.dreamLock inject;
dreamLockInterface = (utils.dreamLock.readDreamLock {inherit dreamLock;}).interface;
dreamLockInterface = (utils.dream-lock.readDreamLock {inherit dreamLock;}).interface;
produceDerivation = name: pkg:
utils.applyOverridesToPackage {
@ -337,7 +337,7 @@ in let
packageVersions
;
getSource = utils.dreamLock.getSource fetchedSources;
getSource = utils.dream-lock.getSource fetchedSources;
});
# Makes the packages tree compatible with flakes schema.
@ -388,7 +388,7 @@ in let
packageOverrides ? {},
} @ args: let
# parse dreamLock
dreamLockLoaded = utils.dreamLock.readDreamLock {inherit (args) dreamLock;};
dreamLockLoaded = utils.dream-lock.readDreamLock {inherit (args) dreamLock;};
dreamLock = dreamLockLoaded.lock;
dreamLockInterface = dreamLockLoaded.interface;
@ -481,7 +481,7 @@ in let
project
// rec {
dreamLock =
(utils.dreamLock.readDreamLock {
(utils.dream-lock.readDreamLock {
dreamLock = "${toString config.projectRoot}/${project.dreamLockPath}";
})
.lock;

View File

@ -17,6 +17,7 @@
listDirs
listFiles
mergeFlakes
mkFunction
nameVersionPair
prepareSourceTree
readTextFile
@ -335,5 +336,13 @@
licenses = l.filter (license: license != null) _licenses;
in
licenses;
mkFunction = {type, ...} @ attrs:
l.mkOption (
attrs
// {
type = l.types.uniq (l.types.functionTo attrs.type);
}
);
in
dlib

View File

@ -52,7 +52,7 @@
# simpleTranslate2 puts dream-lock in result
dreamLock = dreamLock'.result or dreamLock';
in
dream2nix.framework.utils.dreamLock.toJSON
dream2nix.framework.utils.dream-lock.toJSON
# don't use nix to detect cycles, this will be more efficient in python
(dreamLock // {
_generic = builtins.removeAttrs dreamLock._generic [ \"cyclicDependencies\" ];

View File

@ -25,6 +25,11 @@ in {
./translators
./indexers
./utils
./utils.translator
./utils.index
./utils.override
./utils.toTOML
./utils.dream-lock
];
options = {
lib = lib.mkOption {

View File

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

View File

@ -6,7 +6,7 @@
dreamLock,
newSourceRoot,
} @ args: let
dreamLockLoaded = config.utils.dreamLock.readDreamLock {dreamLock = args.dreamLock;};
dreamLockLoaded = config.utils.dream-lock.readDreamLock {dreamLock = args.dreamLock;};
iface = dreamLockLoaded.interface;
patchVersion = version: source:
if
@ -320,7 +320,7 @@
in
json;
in {
config.utils.dreamLock = {
config.utils.dream-lock = {
inherit
compressDreamLock
decompressDreamLock

View File

@ -0,0 +1,35 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
in {
options.utils.dream-lock = {
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;
};
};
}

View File

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

View File

@ -0,0 +1,14 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
generatePackagesFromLocksTree = mkFunction {
type = t.attrsOf t.package;
};
makeOutputsForIndexes = mkFunction {
type = t.attrs;
};
};
}

View File

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

View File

@ -0,0 +1,14 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
applyOverridesToPackage = mkFunction {
type = t.attrs;
};
loadOverridesDirs = mkFunction {
type = t.attrs;
};
};
}

View File

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

View File

@ -0,0 +1,10 @@
{config, ...}: let
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
toTOML = config.dlib.mkFunction {
type = t.attrs;
};
};
}

View File

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

View File

@ -0,0 +1,10 @@
{config, ...}: let
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
simpleTranslate = config.dlib.mkFunction {
type = t.functionTo t.attrs;
};
};
}

View File

@ -216,13 +216,6 @@
script // {passthru = {inherit project;};};
};
in {
imports = [
./dream-lock.nix
./override.nix
./translator.nix
./toTOML.nix
./index
];
config = {
utils = impl;
};

View File

@ -1,14 +1,7 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
mkFunction = {type, ...} @ attrs:
l.mkOption (
attrs
// {
type = t.uniq (t.functionTo attrs.type);
}
);
in {
options.utils = {
scripts = {
@ -22,41 +15,9 @@ in {
type = t.path;
};
};
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;
};
@ -78,20 +39,5 @@ in {
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

@ -68,4 +68,4 @@
};
});
in
dream2nix.framework.utils.dreamLock.toJSON translated
dream2nix.framework.utils.dream-lock.toJSON translated

View File

@ -12,12 +12,12 @@
}: let
inherit (framework) utils fetchers;
lockUtils = utils.dreamLock;
lockUtils = utils.dream-lock;
updaters = callPackageDream ./updaters.nix {};
getUpdaterName = {dreamLock}: let
lock = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock;
lock = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
source = lockUtils.getMainPackageSource lock;
in
lock.updater
@ -28,7 +28,7 @@
dreamLock,
updater ? getUpdaterName {inherit dreamLock;},
}: let
lock = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock;
lock = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
source = lockUtils.getMainPackageSource lock;
updater' = updaters."${updater}";
in

View File

@ -26,7 +26,7 @@ exampleDreamLock = dict(
def test_dream_lock_inject():
result = nix_ffi.callNixFunction(
'framework.utils.dreamLock.injectDependencies',
'framework.utils.dream-lock.injectDependencies',
dreamLock=exampleDreamLock,
inject=dict(
example={
@ -43,7 +43,7 @@ def test_dream_lock_inject():
def test_dream_lock_replace_root_sources():
result = nix_ffi.callNixFunction(
'framework.utils.dreamLock.replaceRootSources',
'framework.utils.dream-lock.replaceRootSources',
dreamLock=exampleDreamLock,
newSourceRoot=dict(
type = "http",