-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnpins.nix
71 lines (62 loc) · 1.35 KB
/
npins.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
{
lib,
pkgs,
rustPlatform,
nix-gitignore,
makeWrapper,
runCommand,
stdenv,
darwin,
# runtime dependencies
nix, # for nix-prefetch-url
nix-prefetch-git,
git, # for git ls-remote
}:
let
paths = [
"^/src$"
"^/src/.+$"
"^/Cargo.lock$"
"^/Cargo.toml$"
];
extractSource =
src:
let
baseDir = toString src;
in
expressions:
builtins.path {
path = src;
filter =
path:
let
suffix = lib.removePrefix baseDir path;
in
_: lib.any (r: builtins.match r suffix != null) expressions;
name = "source";
};
src = extractSource ./. paths;
cargoToml = builtins.fromTOML (builtins.readFile (src + "/Cargo.toml"));
runtimePath = lib.makeBinPath [
nix
nix-prefetch-git
git
];
self = rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
version = cargoToml.package.version;
cargoLock = {
lockFile = src + "/Cargo.lock";
};
inherit src;
buildInputs = lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security ]);
nativeBuildInputs = [ makeWrapper ];
# (Almost) all tests require internet
doCheck = false;
postFixup = ''
wrapProgram $out/bin/npins --prefix PATH : "${runtimePath}"
'';
meta.tests = pkgs.callPackage ./test.nix { npins = self; };
};
in
self