forked from oxalica/nocargo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
140 lines (123 loc) · 4.68 KB
/
flake.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
registry-crates-io = {
url = "github:rust-lang/crates.io-index";
flake = false;
};
};
outputs = { self, flake-utils, nixpkgs, registry-crates-io }@inputs:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
inherit (builtins) toJSON typeOf;
inherit (nixpkgs.lib) isDerivation isFunction isAttrs mapAttrsToList listToAttrs flatten;
nocargo-lib = import ./lib { inherit (nixpkgs) lib; };
in flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
defaultRegistries = {
"https://github.com/rust-lang/crates.io-index" =
nocargo-lib.pkg-info.mkIndex pkgs.fetchurl registry-crates-io
(import ./crates-io-override {
inherit (nixpkgs) lib;
inherit pkgs;
});
};
in rec {
apps.default = {
type = "app";
program = "${packages.noc}/bin/noc";
};
# Is there a better place? `naersk` places builders under `lib.${system}`.
lib = rec {
mkIndex = nocargo-lib.pkg-info.mkIndex pkgs.fetchurl;
buildRustCrate = pkgs.callPackage ./build-rust-crate {
inherit (packages) toml2json;
inherit nocargo-lib;
};
mkRustPackageOrWorkspace = pkgs.callPackage nocargo-lib.support.mkRustPackageOrWorkspace {
inherit defaultRegistries buildRustCrate;
};
};
packages = rec {
default = noc;
toml2json = pkgs.callPackage ./toml2json { };
noc = (lib.mkRustPackageOrWorkspace {
src = ./noc;
}).release.nocargo.bin;
cache = pkgs.callPackage ./cache {
inherit (lib) mkRustPackageOrWorkspace;
};
};
checks = let
okDrv = derivation {
name = "success";
inherit system;
builder = "/bin/sh";
args = [ "-c" ": >$out" ];
};
checkArgs = {
inherit pkgs defaultRegistries;
assertEq = got: expect: {
__assertion = true;
fn = name:
if toJSON got == toJSON expect then
okDrv
else
pkgs.runCommand name {
nativeBuildInputs = [ pkgs.jq ];
got = toJSON got;
expect = toJSON expect;
} ''
if [[ ''${#got} < 32 && ''${#expect} < 32 ]]; then
echo "got: $got"
echo "expect: $expect"
else
echo "got:"
jq . <<<"$got"
echo
echo "expect:"
jq . <<<"$expect"
echo
echo "diff:"
diff -y <(jq . <<<"$got") <(jq . <<<"$expect")
exit 1
fi
'';
};
};
tests = with nocargo-lib; {
_0000-semver-compare = semver.semver-compare-tests;
_0001-semver-req = semver.semver-req-tests;
_0002-cfg-parser = target-cfg.cfg-parser-tests;
_0003-cfg-eval = target-cfg.cfg-eval-tests;
_0004-platform-cfg = target-cfg.platform-cfg-tests;
_0005-glob = glob.glob-tests;
_0006-sanitize-relative-path = support.sanitize-relative-path-tests;
_0100-pkg-info-from-toml = pkg-info.pkg-info-from-toml-tests;
_0101-preprocess-feature = resolve.preprocess-feature-tests;
_0102-update-feature = resolve.update-feature-tests;
_0103-resolve-feature = resolve.resolve-feature-tests;
_0200-resolve-deps = resolve.resolve-deps-tests;
_0201-build-from-src-dry = support.build-from-src-dry-tests;
} // import ./tests {
inherit pkgs self inputs defaultRegistries;
};
flattenTests = prefix: v:
if isDerivation v then {
name = prefix;
value = v;
} else if v ? __assertion then {
name = prefix;
value = v.fn prefix;
} else if isFunction v then
flattenTests prefix (v checkArgs)
else if isAttrs v then
mapAttrsToList (name: flattenTests "${prefix}-${name}") v
else
throw "Unexpect test type: ${typeOf v}";
tests' = listToAttrs (flatten (mapAttrsToList flattenTests tests));
in tests';
});
}