-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
218 lines (217 loc) · 8.37 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
{
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.11;
nixpkgs-master.url = github:NixOS/nixpkgs/master;
home-manager = {
url = github:nix-community/home-manager/release-24.11;
inputs.nixpkgs.follows = "nixpkgs";
};
utils.url = github:numtide/flake-utils;
crane.url = github:ipetkov/crane;
rust-overlay = {
url = github:oxalica/rust-overlay;
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs = {
url = github:serokell/deploy-rs;
inputs = {
nixpkgs.follows = "nixpkgs";
utils.follows = "utils";
};
};
};
outputs = { self, nixpkgs, home-manager, utils, rust-overlay, crane, deploy-rs, nixpkgs-master }:
utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
pkgs-master = import nixpkgs-master {
inherit system;
};
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.nightly.latest.default);
onnxruntime = pkgs-master.onnxruntime.overrideAttrs (final: prev: {
src = pkgs-master.fetchFromGitHub {
owner = "microsoft";
repo = "onnxruntime";
rev = "b522df0ae477e59f60acbe6c92c8a64eda96cace";
hash = "sha256-ACAaMyOlhknFZ1NJex/VlPGqiDZv6LRgBvwq1DrDglg=";
fetchSubmodules = true;
};
patches = [ (builtins.elemAt prev.patches 0) ];
});
# Library dependencies
dependencies = [ onnxruntime pkgs.libffi ];
# Native build inputs
nativeBuildInputs = [ onnxruntime ];
# Common arguments to building censorlab and deps
onnx_vars = {
ORT_STRATEGY = "system";
ORT_LIB_LOCATION = "${onnxruntime}";
};
common_args = onnx_vars // {
strictDeps = true;
inherit nativeBuildInputs;
buildInputs = dependencies;
};
# Build just the dependencies, without any of the extra stuff
# Pulls from a clean cargo repo so it doesnt get updated when e.g. scripts or documentation get updated
cargoArtifacts = craneLib.buildDepsOnly (common_args // {
src = craneLib.cleanCargoSource ./.;
# Additional arguments specific to this derivation can be added here.
# Be warned that using `//` will not do a deep copy of nested
# structures
pname = "censorlab-deps";
});
in
{
# Shell used for developing censorlab
devShells.default = pkgs.mkShell ({
nativeBuildInputs = nativeBuildInputs ++ [
(pkgs.rust-bin.nightly.latest.default.override {
extensions = [ "rust-src" "rustfmt" "rust-analyzer" "clippy" ];
})
pkgs.zola
];
buildInputs = [ ] ++ dependencies;
} // onnx_vars);
devShells.website = pkgs.mkShell {
nativeBuildInputs =
let
zola-serve = pkgs.writeShellScriptBin "zola-serve" ''
#!/bin/sh
${pkgs.zola}/bin/zola --root $(${pkgs.git}/bin/git rev-parse --show-toplevel)/website serve
''
;
in
[
pkgs.zola
zola-serve
];
};
# Censorlab package
packages = rec {
default = censorlab;
# TODO: split scripts out into a second derivation
censorlab = craneLib.buildPackage (common_args // {
# Install from source (remove all the extra stuff)
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: _type: (craneLib.filterCargoSources path _type) ||
builtins.match ".*lalrpop" path != null ||
builtins.match ".*sh" path != null;
name = "source";
};
# Dependencies
inherit cargoArtifacts nativeBuildInputs;
});
censorlab-vm-docs = pkgs.callPackage
({ stdenv, pandoc, ... }: stdenv.mkDerivation {
pname = "censorlab-vm-docs";
version = "0.1";
src = ./vm/docs;
nativeBuildInputs = [ pandoc ];
installPhase = ''
mkdir -p $out/share/censorlab
pandoc -f gfm ./README.md > $out/share/censorlab/README.html
'';
})
{ };
censorlab-demos = pkgs.callPackage
({ stdenv, pandoc, ... }: stdenv.mkDerivation {
pname = "censorlab-demos";
version = "0.1";
src = ./demos;
nativeBuildInputs = [ ];
installPhase = ''
mkdir -p $out/share/censorlab-demos
cp -r ./* $out/share/censorlab-demos/
'';
})
{ };
censorlab-update = pkgs.writeShellScriptBin "censorlab-update" ''
nix-collect-garbage -d
nixos-rebuild switch --flake github:SPIN-UMass/censorlab#censorlab --use-remote-sudo
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch
'';
censorlab-update-arm = pkgs.writeShellScriptBin "censorlab-update" ''
nix-collect-garbage -d
nixos-rebuild switch --flake github:SPIN-UMass/censorlab#censorlab-arm --use-remote-sudo
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch
'';
};
}) // {
# Censorlab overlay
overlays = rec {
censorlab = final: prev: {
censorlab = self.packages.x86_64-linux.censorlab;
censorlab-vm-docs = self.packages.x86_64-linux.censorlab-vm-docs;
censorlab-demos = self.packages.x86_64-linux.censorlab-demos;
censorlab-update = self.packages.x86_64-linux.censorlab-update;
};
censorlab-arm = final: prev: {
censorlab = self.packages.aarch64-linux.censorlab;
censorlab-vm-docs = self.packages.aarch64-linux.censorlab-vm-docs;
censorlab-demos = self.packages.aarch64-linux.censorlab-demos;
censorlab-update = self.packages.aarch64-linux.censorlab-update-arm;
};
};
# System configuration for the VM
nixosConfigurations.censorlab = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
{
nixpkgs.overlays = [ self.overlays.censorlab ];
nixpkgs.config.allowUnfree = true;
}
(import ./vm/configuration.nix)
(import ./vm/hardware-x8664.nix)
home-manager.nixosModules.default
];
};
nixosConfigurations.censorlab-arm = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
{
nixpkgs.overlays = [ self.overlays.censorlab-arm ];
nixpkgs.config.allowUnfree = true;
}
(import ./vm/configuration.nix)
(import ./vm/hardware-aarch64.nix)
home-manager.nixosModules.default
];
};
# Deploy config
deploy.nodes.censorlab = {
# Deploy as root to localhost:2222 (set up as a port forward in the vm
sshUser = "root";
hostname = "localhost";
sshOpts = [ "-p" "2222" "-i" "./vm/id_ed25519" ];
# Build locally rather than on the slow vm
remoteBuild = false;
fastConnection = true;
# Deploy the censorlab system profile
profiles.system = {
user = "root";
path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.censorlab;
};
};
deploy.nodes.censorlab-arm = {
sshUser = "root";
hostname = "167.235.134.18";
sshOpts = [ "-i" "./vm/id_ed25519" ];
# build remotely because cross arch is weird
remoteBuild = true;
fastConnection = false;
# Deploy the censorlab system profile
profiles.system = {
user = "root";
path = deploy-rs.lib.aarch64-linux.activate.nixos self.nixosConfigurations.censorlab-arm;
};
};
# Perform checks
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
};
}