-
Notifications
You must be signed in to change notification settings - Fork 11
/
flake.nix
166 lines (149 loc) · 4.72 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
inputs.pre-commit-hooks.inputs.flake-utils.follows = "flake-utils";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.rust-overlay.inputs.flake-utils.follows = "flake-utils";
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
inputs.naersk.url = "github:nix-community/naersk";
inputs.naersk.inputs.nixpkgs.follows = "nixpkgs";
nixConfig.extra-substituters = [
"https://iog.cachix.org"
"https://hydra.iohk.io"
];
nixConfig.extra-trusted-public-keys = [
"iog.cachix.org-1:nYO0M9xTk/s5t1Bs9asZ/Sww/1Kt/hRhkLP0Hhv/ctY="
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
outputs = {
self,
nixpkgs,
flake-compat,
flake-utils,
pre-commit-hooks,
rust-overlay,
naersk,
}:
flake-utils.lib.eachSystem
[
flake-utils.lib.system.x86_64-linux
flake-utils.lib.system.aarch64-linux
]
(
system: let
readTOML = file: builtins.fromTOML (builtins.readFile file);
workspaceCargo = readTOML ./Cargo.toml;
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rust = let
_rust = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analysis"
"rls-preview"
"rustfmt-preview"
"clippy-preview"
];
};
in
pkgs.buildEnv {
name = _rust.name;
inherit (_rust) meta;
buildInputs = [pkgs.makeWrapper];
paths = [_rust];
pathsToLink = ["/" "/bin"];
# XXX: This is needed because cargo and clippy commands need to
# also be aware of other binaries in order to work properly.
# https://github.com/cachix/pre-commit-hooks.nix/issues/126
postBuild = ''
for i in $out/bin/*; do
wrapProgram "$i" --prefix PATH : "$out/bin"
done
'';
};
naersk-lib = naersk.lib."${system}".override {
cargo = rust;
rustc = rust;
};
mkPackage = name: let
pkgCargo = readTOML ./${name}/Cargo.toml;
cargoOptions = [
"--package"
name
];
in
naersk-lib.buildPackage {
root = self;
cargoBuildOptions = x: x ++ cargoOptions;
cargoTestOptions = x: x ++ cargoOptions;
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
nativeBuildInputs = with pkgs; [
pkg-config
protobuf
rustfmt
];
buildInputs = with pkgs; [
openssl
];
};
workspace =
builtins.listToAttrs
(
builtins.map
(name: {
inherit name;
value = mkPackage name;
})
workspaceCargo.workspace.members
);
pre-commit = pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
alejandra = {
enable = true;
};
rustfmt = {
enable = true;
entry = pkgs.lib.mkForce "${rust}/bin/cargo-fmt fmt -- --check --color always";
};
};
};
warnToUpdateNix = pkgs.lib.warn "Consider updating to Nix > 2.7 to remove this warning!";
in rec {
packages =
workspace
// {
inherit pre-commit;
default = workspace.vit-servicing-station-server;
};
devShells.default = pkgs.mkShell {
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
buildInputs =
[rust]
++ (with pkgs; [
pkg-config
openssl
protobuf
]);
shellHook =
pre-commit.shellHook
+ ''
echo "=== vit-servicing-station development shell ==="
echo "Info: Git hooks can be installed using \`pre-commit install\`"
'';
};
checks.pre-commit = pre-commit;
hydraJobs = packages;
defaultPackage = warnToUpdateNix packages.default;
devShell = warnToUpdateNix devShells.default;
}
);
}