forked from surrealdb/surrealdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.nix
96 lines (78 loc) · 2.76 KB
/
util.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{ lib, flake, systems, system }:
rec {
inherit systems system;
config = import ./config.nix;
supportedPlatforms = let
specDir = builtins.readDir ./spec;
nixExt = ".nix";
nixFilesFun = key: val:
val == "regular" && lib.strings.hasSuffix nixExt key;
trimNixExtFun = key: val: lib.strings.removeSuffix nixExt key;
nixFiles = lib.attrsets.filterAttrs nixFilesFun specDir;
in lib.attrsets.mapAttrsToList trimNixExtFun nixFiles;
systemPlatforms = let
matchingPlatforms = target:
let targetSystem = targetToSystem target;
in targetSystem == system;
in builtins.filter matchingPlatforms supportedPlatforms;
platforms = let
kvFun = platform: {
name = platform;
value = platform;
};
in builtins.listToAttrs (map kvFun supportedPlatforms);
targetToEnv = target:
let withoutDashes = builtins.replaceStrings [ "-" ] [ "_" ] target;
in lib.strings.toUpper withoutDashes;
targetToUpperEnv = target: lib.strings.toUpper (targetToEnv target);
targetToSystem = with builtins;
target:
let
parts = split "-" target;
arch = elemAt parts 0;
prefix = lib.strings.optionalString (arch == "armv7") "l";
os = elemAt parts 4;
in "${arch}${prefix}-${os}";
isNative = target:
let targetSystem = targetToSystem target;
in targetSystem == system;
cpu = with builtins;
target:
let
parts = split "-" target;
arch = elemAt parts 0;
in if arch == "armv7" then replaceStrings [ "v7" ] [ "" ] arch else arch;
cargoToml = with builtins;
let toml = readFile ../../Cargo.toml;
in fromTOML toml;
packageName = cargoToml.package.name;
fdbPackage = fdbPackages:
let
fdbPkgVersion = builtins.replaceStrings [ "." ] [ "" ] config.fdbVersion;
in fdbPackages."foundationdb${fdbPkgVersion}";
fdbSupported = fdbPackages:
let
package = fdbPackage fdbPackages;
fdbSystems = package.meta.platforms or [ ];
in builtins.elem system fdbSystems;
features = cargoToml.features // {
storage-fdb = let
fdbFeatureVersion =
builtins.replaceStrings [ "." ] [ "_" ] config.fdbVersion;
in [ "surrealdb/kv-fdb-${fdbFeatureVersion}" ];
};
buildMetadata = with lib.strings;
let
lastModifiedDate = flake.lastModifiedDate or flake.lastModified or "";
date = builtins.substring 0 8 lastModifiedDate;
shortRev = flake.shortRev or "dirty";
hasDateRev = lastModifiedDate != "" && shortRev != "";
dot = optionalString hasDateRev ".";
in "${date}${dot}${shortRev}";
version = with lib.strings;
let
hasBuildMetadata = buildMetadata != "";
plus = optionalString hasBuildMetadata "+";
in "${cargoToml.package.version}${plus}${buildMetadata}";
SURREAL_BUILD_METADATA = buildMetadata;
}