-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from nix-community/v1-compat
feat(v1): init compat module for pure legacy translators
- Loading branch information
Showing
11 changed files
with
2,212 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ lib, ireplace }: | ||
let | ||
inherit (builtins) elemAt match; | ||
operators = | ||
let | ||
matchWildCard = s: match "([^*])(\\.[*])" s; | ||
mkComparison = ret: version: v: builtins.compareVersions version v == ret; | ||
mkIdxComparison = idx: version: v: | ||
let | ||
ver = builtins.splitVersion v; | ||
minor = builtins.toString (lib.toInt (elemAt ver idx) + 1); | ||
upper = builtins.concatStringsSep "." (ireplace idx minor ver); | ||
in | ||
operators.">=" version v && operators."<" version upper; | ||
dropWildcardPrecision = f: version: constraint: | ||
let | ||
m = matchWildCard constraint; | ||
hasWildcard = m != null; | ||
c = if hasWildcard then (elemAt m 0) else constraint; | ||
v = | ||
if hasWildcard then (builtins.substring 0 (builtins.stringLength c) version) | ||
else version; | ||
in | ||
f v c; | ||
in | ||
{ | ||
# Prefix operators | ||
"==" = dropWildcardPrecision (mkComparison 0); | ||
">" = dropWildcardPrecision (mkComparison 1); | ||
"<" = dropWildcardPrecision (mkComparison (-1)); | ||
"!=" = v: c: ! operators."==" v c; | ||
">=" = v: c: operators."==" v c || operators.">" v c; | ||
"<=" = v: c: operators."==" v c || operators."<" v c; | ||
# Semver specific operators | ||
"~" = mkIdxComparison 1; | ||
"^" = mkIdxComparison 0; | ||
"~=" = v: c: | ||
let | ||
# Prune constraint | ||
parts = builtins.splitVersion c; | ||
pruned = lib.take ((builtins.length parts) - 1) parts; | ||
upper = builtins.toString ( | ||
(lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1 | ||
); | ||
upperConstraint = builtins.concatStringsSep "." (ireplace (builtins.length pruned - 1) upper pruned); | ||
in | ||
operators.">=" v c && operators."<" v upperConstraint; | ||
# Infix operators | ||
"-" = version: v: operators.">=" version v.vl && operators."<=" version v.vu; | ||
# Arbitrary equality clause, just run simple comparison | ||
"===" = v: c: v == c; | ||
# | ||
}; | ||
re = { | ||
operators = "([=><!~^]+)"; | ||
version = "([0-9.*x]+)"; | ||
}; | ||
parseConstraint = constraint: | ||
let | ||
constraintStr = builtins.replaceStrings [ " " ] [ "" ] constraint; | ||
# The common prefix operators | ||
mPre = match "${re.operators} *${re.version}" constraintStr; | ||
# There is also an infix operator to match ranges | ||
mIn = match "${re.version} *(-) *${re.version}" constraintStr; | ||
in | ||
( | ||
if mPre != null then { | ||
op = elemAt mPre 0; | ||
v = elemAt mPre 1; | ||
} | ||
# Infix operators are range matches | ||
else if mIn != null then { | ||
op = elemAt mIn 1; | ||
v = { | ||
vl = (elemAt mIn 0); | ||
vu = (elemAt mIn 2); | ||
}; | ||
} | ||
else throw "Constraint \"${constraintStr}\" could not be parsed" | ||
); | ||
satisfiesSemver = version: constraint: | ||
let | ||
inherit (parseConstraint constraint) op v; | ||
in | ||
if constraint == "*" then true else operators."${op}" version v; | ||
in | ||
{ inherit satisfiesSemver; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
{ | ||
config, | ||
options, | ||
extendModules, | ||
lib, | ||
drv-parts, | ||
... | ||
}: let | ||
l = lib // builtins; | ||
|
||
cfg = config.dream2nix-legacy; | ||
|
||
pkgs = drv-parts.inputs.nixpkgs.legacyPackages.x86_64-linux; | ||
|
||
dlib = | ||
(l.evalModules { | ||
modules = [ | ||
../../../../../src/modules/dlib | ||
../../../../../src/modules/dlib.construct | ||
../../../../../src/modules/dlib.parsing | ||
../../../../../src/modules/dlib.simpleTranslate2 | ||
libModule | ||
]; | ||
}) | ||
.config | ||
.dlib; | ||
|
||
utils = | ||
(l.evalModules { | ||
modules = [ | ||
../../../../../src/modules/utils | ||
../../../../../src/modules/utils.override | ||
../../../../../src/modules/utils.toTOML | ||
../../../../../src/modules/utils.translator | ||
../../../../../src/modules/dlib | ||
libModule | ||
]; | ||
}) | ||
.config | ||
.utils; | ||
|
||
legacy-interface = | ||
(l.evalModules { | ||
modules = [ | ||
../../../../../src/modules/dream2nix-interface | ||
../../../../../src/modules/dlib | ||
../../../../../src/modules/fetchers | ||
../../../../../src/modules/functions.default-fetcher | ||
../../../../../src/modules/functions.fetchers | ||
../../../../../src/modules/utils | ||
../../../../../src/modules/utils.dream-lock | ||
../../../../../src/modules/utils.override | ||
buildersModule | ||
configModule | ||
libModule | ||
pkgsModule | ||
]; | ||
}) | ||
.config | ||
.dream2nix-interface; | ||
|
||
buildersModule = { | ||
options.buildersBySubsystem = l.mkOption {type = l.types.raw;}; | ||
config.buildersBySubsystem = buildersBySubsystem; | ||
}; | ||
|
||
configModule = { | ||
options.dream2nixConfig = l.mkOption {type = l.types.raw;}; | ||
config.dream2nixConfig = { | ||
overridesDirs = [../../../../../overrides]; | ||
}; | ||
}; | ||
|
||
libModule = { | ||
options.lib = l.mkOption {type = l.types.raw;}; | ||
config.lib = lib // builtins; | ||
}; | ||
|
||
pkgsModule = { | ||
options.pkgs = l.mkOption {type = l.types.raw;}; | ||
config.pkgs = pkgs; | ||
}; | ||
|
||
buildersBySubsystem.${cfg.subsystem}.default = import (../../../../.. + "/src/subsystems/${cfg.subsystem}/builders/${cfg.builder}/default.nix") { | ||
inherit lib pkgs utils; | ||
dlib = {}; | ||
}; | ||
|
||
translator = | ||
(l.evalModules { | ||
modules = [ | ||
../../../../../src/modules/interfaces.translator/interface.nix | ||
(../../../../.. + "/src/subsystems/${cfg.subsystem}/translators/${cfg.translator}") | ||
libModule | ||
]; | ||
specialArgs = { | ||
inherit dlib utils; | ||
}; | ||
}) | ||
.config; | ||
|
||
tree = dlib.prepareSourceTree {inherit (cfg) source;}; | ||
|
||
project = { | ||
inherit (config) name; | ||
relPath = cfg.relPath; | ||
subsystemInfo = cfg.subsystemInfo; | ||
}; | ||
|
||
result = | ||
translator.translate | ||
(cfg.subsystemInfo | ||
// { | ||
inherit project tree; | ||
inherit (cfg) source; | ||
}); | ||
|
||
dreamLock = result.result or result; | ||
|
||
defaultSourceOverride = dreamLock: let | ||
defaultPackage = dreamLock._generic.defaultPackage; | ||
defaultPackageVersion = | ||
dreamLock._generic.packages."${defaultPackage}"; | ||
in { | ||
"${defaultPackage}"."${defaultPackageVersion}" = "${cfg.source}/${dreamLock._generic.location}"; | ||
}; | ||
|
||
dreamOverrides = let | ||
overridesDirs = [../../../../../overrides]; | ||
in | ||
utils.loadOverridesDirs overridesDirs pkgs; | ||
|
||
outputs = legacy-interface.makeOutputsForDreamLock { | ||
inherit dreamLock; | ||
sourceRoot = cfg.source; | ||
sourceOverrides = oldSources: | ||
dlib.recursiveUpdateUntilDepth | ||
1 | ||
(defaultSourceOverride dreamLock) | ||
(cfg.sourceOverrides oldSources); | ||
packageOverrides = | ||
l.recursiveUpdate | ||
(dreamOverrides."${dreamLock._generic.subsystem}" or {}) | ||
(cfg.packageOverrides or {}); | ||
}; | ||
|
||
drvModule = drv-parts.lib.makeModule { | ||
packageFunc = outputs.packages.default; | ||
}; | ||
|
||
# hacky call drvModule manually to prevent infinite recursions | ||
eval = drvModule { | ||
inherit config options extendModules; | ||
}; | ||
in { | ||
imports = [ | ||
./interface.nix | ||
]; | ||
|
||
public = l.mkForce eval.config.public; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
l = lib // builtins; | ||
t = l.types; | ||
in { | ||
options.dream2nix-legacy = { | ||
builder = l.mkOption { | ||
description = "Builder to use"; | ||
example = ["build-rust-package"]; | ||
type = t.str; | ||
}; | ||
relPath = l.mkOption { | ||
default = ""; | ||
description = "Relative path to project tree from source"; | ||
type = t.str; | ||
}; | ||
source = l.mkOption { | ||
type = t.either t.path t.package; | ||
description = "Source of the package to build with dream2nix"; | ||
}; | ||
subsystem = l.mkOption { | ||
description = ''Name of subsystem to use. Examples: rust, python, nodejs''; | ||
example = "nodejs"; | ||
type = t.str; | ||
}; | ||
subsystemInfo = l.mkOption { | ||
default = {}; | ||
description = "Translator specific arguments"; | ||
type = t.lazyAttrsOf (t.anything); | ||
}; | ||
translator = l.mkOption { | ||
description = "Translator to use"; | ||
example = ["yarn-lock" "package-json"]; | ||
type = t.str; | ||
}; | ||
|
||
# overrides | ||
packageOverrides = l.mkOption { | ||
default = {}; | ||
type = t.lazyAttrsOf t.attrs; | ||
description = "Overrides to customize build logic for dependencies or top-level packages"; | ||
}; | ||
sourceOverrides = l.mkOption { | ||
default = old: {}; | ||
type = t.functionTo (t.lazyAttrsOf (t.listOf t.package)); | ||
description = '' | ||
Override the sources of dependencies or top-level packages. | ||
For more details, refer to | ||
https://nix-community.github.io/dream2nix/intro/override-system.html | ||
''; | ||
example = l.literalExpression '' | ||
oldSources: { | ||
bar."13.2.0" = builtins.fetchTarball { | ||
url = "https://example.com/example.tar.gz"; | ||
sha256 = "sha256-0000000000000000000000000000000000000000000="; | ||
}; | ||
baz."1.0.0" = builtins.fetchTarball { | ||
url = "https://example2.com/example2.tar.gz"; | ||
sha256 = "sha256-0000000000000000000000000000000000000000000="; | ||
}; | ||
''; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.