-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
165 lines (144 loc) · 4.56 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
# 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.";
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 ];
};
# Initialize development nixpkgs for the specified `system`
devPkgsFor =
system:
import nixpkgs {
inherit system;
overlays = with self.overlays; [
default
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;
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "villas-node";
tag = "latest-nix";
contents = [ villas-node ];
config.ENTRYPOINT = "/bin/villas";
};
};
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;
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;
hardeningDisable = [ "all" ];
packages = with pkgs; [
bashInteractive
bc
boxfort
clang-tools
criterion
jq
libffi
libgit2
pcre
reuse
cppcheck
];
in
rec {
default = full;
full = pkgs.mkShell {
inherit hardeningDisable packages;
name = "full";
inputsFrom = with pkgs; [ villas-node ];
};
python = pkgs.mkShell {
inherit hardeningDisable;
name = "python";
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 ];
};
};
};
}