-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathflake.nix
More file actions
240 lines (204 loc) · 6.89 KB
/
flake.nix
File metadata and controls
240 lines (204 loc) · 6.89 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# SPDX-FileCopyrightText: 2023 OPAL-RT Germany GmbH
# SPDX-License-Identifier: Apache-2.0
{
description = "VILLASnode is a client/server application to connect simulation equipment and software.";
nixConfig = {
extra-substituters = [
"https://villas.cachix.org"
];
extra-trusted-public-keys = [
"villas.cachix.org-1:vCWp9IzwxFT6ovZivQAvn5ZuLST01bpAGXWwlGTZ9fA="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
{
self,
nixpkgs,
...
}:
let
inherit (nixpkgs) lib;
nixDir = ./packaging/nix;
# Add separateDebugInfo to a derivation
addSeparateDebugInfo = d: d.overrideAttrs { separateDebugInfo = true; };
# Supported systems for native compilation
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
];
# Generate attributes corresponding to all the supported systems
forSupportedSystems = lib.genAttrs supportedSystems;
# Initialize nixpkgs for the specified `system`
pkgsFor =
system:
import nixpkgs {
inherit system;
overlays = with self.overlays; [
default
patches
];
};
# Initialize development nixpkgs for the specified `system`
devPkgsFor =
system:
import nixpkgs {
inherit system;
overlays = with self.overlays; [
default
patches
debug
];
};
# Build villas and its dependencies for the specified `pkgs`
packagesWith = pkgs: rec {
default = villas-node;
villas-node-python = pkgs.callPackage (nixDir + "/python.nix") { src = ./.; };
villas-node-minimal = pkgs.callPackage (nixDir + "/villas.nix") {
src = ./.;
version = "minimal";
};
villas-node = villas-node-minimal.override {
version = "full";
withAllExtras = true;
withAllFormats = true;
withAllHooks = true;
withAllNodes = true;
};
villas-node-clang = pkgs.villas-node.override {
stdenv = pkgs.clangStdenv;
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "villas-node";
tag = "latest-nix";
contents = [ villas-node ];
config.ENTRYPOINT = "/bin/villas";
};
# Cross-compiled packages
villas-node-x86_64-linux =
if pkgs.system == "x86_64-linux" then pkgs.villas-node else pkgs.pkgsCross.x86_64-linux.villas-node;
villas-node-aarch64-linux =
if pkgs.system == "aarch64-linux" then
pkgs.villas-node
else
pkgs.pkgsCross.aarch64-multiplatform.villas-node;
dockerImage-x86_64-linux = pkgs.dockerTools.buildLayeredImage {
name = "villas-node";
tag = "latest-nix-x86_64-linux";
contents = [ villas-node-x86_64-linux ];
config.ENTRYPOINT = "/bin/villas";
};
dockerImage-aarch64-linux = pkgs.dockerTools.buildLayeredImage {
name = "villas-node";
tag = "latest-nix-aarch64-linux";
contents = [ villas-node-aarch64-linux ];
config.ENTRYPOINT = "/bin/villas";
};
# Third-party dependencies
opendssc = pkgs.callPackage (nixDir + "/opendssc.nix") { };
orchestra = pkgs.callPackage (nixDir + "/orchestra.nix") { };
};
in
{
# Standard flake attribute for normal packages (not cross-compiled)
packages = forSupportedSystems (system: packagesWith (pkgsFor system));
# Standard flake attribute allowing you to add the villas packages to your nixpkgs
overlays = {
default = final: prev: packagesWith final;
patches = import ./packaging/nix/patches.nix;
debug = final: prev: {
jansson = addSeparateDebugInfo prev.jansson;
libmodbus = addSeparateDebugInfo prev.libmodbus;
};
minimal = final: prev: {
mosquitto = prev.mosquitto.override { systemd = final.systemdMinimal; };
rdma-core = prev.rdma-core.override { udev = final.systemdMinimal; };
};
};
# Standard flake attribute for defining developer environments
devShells = forSupportedSystems (
system:
let
pkgs = devPkgsFor system;
packages = with pkgs; [
bashInteractive
bc
boxfort
clang-tools
criterion
gdb
jq
libffi
libgit2
pcre
reuse
cppcheck
pre-commit
ruby # for pre-commit markdownlint hook
];
mkShellFor = stdenv: pkg: stdenv.mkDerivation {
name = "${pkg.pname}-${stdenv.cc.cc.pname}-devShell";
# disable all hardening to suppress warnings in debug builds
hardeningDisable = [ "all" ];
# inherit inputs from pkg
buildInputs = pkg.buildInputs ++ packages;
nativeBuildInputs = pkg.nativeBuildInputs ++ packages;
propagatedBuildInputs = pkg.propagatedBuildInputs;
propagatedNativeBuildInputs = pkg.propagatedNativeBuildInputs;
# configure nix-ld for pre-commit
env = {
NIX_LD = lib.fileContents "${stdenv.cc}/nix-support/dynamic-linker";
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.gcc-unwrapped.lib ];
};
};
in
rec {
default = gcc;
gcc = mkShellFor pkgs.stdenv pkgs.villas-node;
clang = mkShellFor pkgs.clangStdenv pkgs.villas-node;
python = pkgs.mkShell {
name = "villas-python-devShell";
hardeningDisable = [ "all" ];
inputsFrom = with pkgs; [ villas-node-python ];
packages =
with pkgs;
packages
++ [
(python3.withPackages (python-pkgs: [
python-pkgs.build
python-pkgs.twine
]))
];
};
}
);
# Standard flake attribute to add additional checks to `nix flake check`
checks = forSupportedSystems (
system:
let
pkgs = pkgsFor system;
in
{
fmt = pkgs.runCommand "check-fmt" { } ''
cd ${self}
"${pkgs.nixfmt}/bin/nixfmt" --check . 2>> $out
'';
}
);
# Standard flake attribute specifying the formatter invoked on `nix fmt`
formatter = forSupportedSystems (system: (pkgsFor system).alejandra);
# Standard flake attribute for NixOS modules
nixosModules = rec {
default = villas;
villas = {
imports = [ (nixDir + "/module.nix") ];
nixpkgs.overlays = [
self.overlays.default
self.overlays.patches
];
};
};
};
}