-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoverlay.nix
More file actions
156 lines (151 loc) · 4.64 KB
/
Copy pathoverlay.nix
File metadata and controls
156 lines (151 loc) · 4.64 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
final: prev:
let
inherit (prev) lib rustPlatform;
manifest = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
src = lib.cleanSourceWith {
inherit (manifest) name;
src = lib.cleanSource ./.;
filter = path: type:
let
path' = (toString path);
base = baseNameOf path';
parentDir = baseNameOf (dirOf path');
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
".rs"
".toml"
];
isCargoFile = base == "Cargo.lock";
isCargoConfig = parentDir == ".cargo" && base == "config";
in
type == "directory" || matchesSuffix || isCargoFile || isCargoConfig;
};
commonArgs = {
inherit src;
inherit (manifest) version;
pname = manifest.name;
strictDeps = true;
cargoLock.lockFile = src + "/Cargo.lock";
nativeBuildInputs = with prev; [
installShellFiles
] ++ lib.optionals stdenv.isLinux [
autoPatchelfHook
];
buildInputs = with prev; [
libgcc
] ++ lib.optionals stdenv.isDarwin [
libiconv
];
};
in
{
cargo-reaper = rustPlatform.buildRustPackage (commonArgs // {
# NOTE: `installShellCompletion` only has support for Bash, Zsh and Fish
postInstall = ''
installShellCompletion --cmd cargo-reaper \
--bash <($out/bin/cargo-reaper completions bash) \
--fish <($out/bin/cargo-reaper completions fish) \
--zsh <($out/bin/cargo-reaper completions zsh)
'';
doCheck = false;
passthru.tests = {
cargo-clippy = rustPlatform.buildRustPackage (commonArgs // {
pname = "${manifest.name}-clippy";
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ prev.clippy ];
buildPhase = ''
runHook preBuild
cargo clippy --all-targets -- --deny warnings
runHook postBuild
'';
installPhase = ''
runHook preInstall
touch $out
runHook postInstall
'';
doCheck = false;
});
cargo-doc = rustPlatform.buildRustPackage (commonArgs // {
pname = "${manifest.name}-doc";
buildPhase = ''
runHook preBuild
cargo doc --no-deps
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r target/doc $out
runHook postInstall
'';
doCheck = false;
});
cargo-deny = rustPlatform.buildRustPackage (commonArgs // {
pname = "${manifest.name}-deny";
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ prev.cargo-deny ];
buildPhase = ''
runHook preBuild
cargo deny check --config .deny.toml bans licenses sources
runHook postBuild
'';
installPhase = ''
runHook preInstall
touch $out
runHook postInstall
'';
doCheck = false;
});
};
});
rustPlatform = prev.rustPlatform.overrideScope (rfinal: rprev: {
buildReaperExtension =
{ package
, plugin ? package
, target ? null
, profile ? "release"
, ...
}@crateArgs:
let
args = lib.escapeShellArgs (
[
"--no-symlink"
"--package"
"${package}"
"--lib"
]
++ lib.optionals (profile != "debug") (
if profile == "release" then
[ "--release" ]
else
[ "--profile" profile ]
)
++ lib.optionals (target != null) [ "--target" target ]
);
in
rfinal.buildRustPackage (crateArgs // {
pname = package;
version = crateArgs.version or "0.0.0";
cargoLock = crateArgs.cargoLock or {
lockFile = crateArgs.src + "/Cargo.lock";
allowBuiltinFetchGit = true;
};
doCheck = crateArgs.doCheck or false;
# Run `cargo-reaper`, passing trailing args to the cargo invocation.
# We do not symlink the plugin since the `UserPlugins` directory is in
# the `$HOME` directory which is inaccessible to the sandbox.
buildPhase = ''
runHook preBuild
cargo reaper build ${args}
runHook postBuild
'';
# Include extension plugin in the build result.
installPhase = ''
runHook preInstall
mkdir -p $out/lib
mv target${lib.optionalString (target != null) "/${target}"}/${profile}/${plugin}.* $out/lib
runHook postInstall
'';
nativeBuildInputs = (crateArgs.nativeBuildInputs or [ ]) ++ [
# Add `cargo-reaper` as a build time dependency of this derivation.
final.buildPackages.cargo-reaper
];
});
});
}