2023-06-08 17:14:31 +02:00
|
|
|
# SPDX-FileCopyrightText: 2023 OPAL-RT Germany GmbH
|
2023-08-23 09:01:02 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2023-02-20 13:18:31 +01:00
|
|
|
{
|
2024-02-27 22:37:55 +01:00
|
|
|
description = "VILLASnode is a client/server application to connect simulation equipment and software.";
|
2023-02-20 13:18:31 +01:00
|
|
|
|
|
|
|
inputs = {
|
2024-03-26 09:41:30 +01:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
2023-02-20 13:18:31 +01:00
|
|
|
|
2023-08-17 09:39:35 +02:00
|
|
|
ethercat = {
|
|
|
|
url = "gitlab:etherlab.org/ethercat/stable-1.5";
|
|
|
|
flake = false;
|
|
|
|
};
|
2023-02-20 13:18:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
...
|
|
|
|
} @ inputs: let
|
|
|
|
inherit (nixpkgs) lib;
|
2023-06-08 17:14:31 +02:00
|
|
|
|
2024-02-27 22:34:57 +01:00
|
|
|
nixDir = ./packaging/nix;
|
|
|
|
|
2023-08-23 09:01:02 +02:00
|
|
|
# Add separateDebugInfo to a derivation
|
2023-08-22 16:13:12 +02:00
|
|
|
addSeparateDebugInfo = d:
|
|
|
|
d.overrideAttrs {
|
|
|
|
separateDebugInfo = true;
|
|
|
|
};
|
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Supported systems for native compilation
|
2023-02-20 13:18:31 +01:00
|
|
|
supportedSystems = ["x86_64-linux" "aarch64-linux"];
|
2023-06-08 17:14:31 +02:00
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Supported systems to cross compile to
|
2023-06-08 17:14:31 +02:00
|
|
|
supportedCrossSystems = ["aarch64-multiplatform"];
|
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Generate attributes corresponding to all the supported systems
|
2023-02-20 13:18:31 +01:00
|
|
|
forSupportedSystems = lib.genAttrs supportedSystems;
|
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Generate attributes corresponding to all supported combinations of system and crossSystem
|
2023-06-08 17:14:31 +02:00
|
|
|
forSupportedCrossSystems = f: forSupportedSystems (system: lib.genAttrs supportedCrossSystems (f system));
|
2023-02-20 13:18:31 +01:00
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Initialize nixpkgs for the specified `system`
|
2023-06-08 17:14:31 +02:00
|
|
|
pkgsFor = system:
|
|
|
|
import nixpkgs {
|
|
|
|
inherit system;
|
2023-08-22 16:13:12 +02:00
|
|
|
overlays = with self.overlays; [default];
|
2023-06-08 17:14:31 +02:00
|
|
|
};
|
2023-02-20 13:18:31 +01:00
|
|
|
|
2023-08-23 09:01:02 +02:00
|
|
|
# Initialize nixpkgs for cross-compiling from `system` to `crossSystem`
|
2023-06-23 11:50:07 +02:00
|
|
|
crossPkgsFor = system: crossSystem:
|
|
|
|
(import nixpkgs {
|
|
|
|
inherit system;
|
2023-08-22 16:13:12 +02:00
|
|
|
overlays = with self.overlays; [
|
|
|
|
default
|
|
|
|
minimal
|
2023-06-23 11:50:07 +02:00
|
|
|
];
|
|
|
|
})
|
2023-08-17 09:39:35 +02:00
|
|
|
.pkgsCross
|
|
|
|
.${crossSystem};
|
2023-06-08 17:14:31 +02:00
|
|
|
|
2023-08-23 09:01:02 +02:00
|
|
|
# Initialize development nixpkgs for the specified `system`
|
2023-08-22 16:13:12 +02:00
|
|
|
devPkgsFor = system:
|
|
|
|
import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = with self.overlays; [default debug];
|
|
|
|
};
|
|
|
|
|
2023-08-23 09:01:02 +02:00
|
|
|
# Build villas and its dependencies for the specified `pkgs`
|
2023-06-08 17:14:31 +02:00
|
|
|
packagesWith = pkgs: rec {
|
|
|
|
default = villas;
|
|
|
|
|
2024-02-27 22:34:57 +01:00
|
|
|
villas-python = pkgs.callPackage (nixDir + "/python.nix") {
|
|
|
|
src = ./python;
|
2023-09-19 11:54:37 +02:00
|
|
|
};
|
|
|
|
|
2024-02-27 22:34:57 +01:00
|
|
|
villas-minimal = pkgs.callPackage (nixDir + "/villas.nix") {
|
|
|
|
src = ./.;
|
2023-06-08 17:14:31 +02:00
|
|
|
version = "minimal";
|
|
|
|
};
|
|
|
|
|
|
|
|
villas = villas-minimal.override {
|
|
|
|
version = "full";
|
|
|
|
withAllExtras = true;
|
|
|
|
withAllFormats = true;
|
|
|
|
withAllHooks = true;
|
|
|
|
withAllNodes = true;
|
|
|
|
};
|
|
|
|
|
2024-02-27 22:34:57 +01:00
|
|
|
ethercat = pkgs.callPackage (nixDir + "/ethercat.nix") {
|
2023-08-17 09:39:35 +02:00
|
|
|
src = inputs.ethercat;
|
|
|
|
};
|
2023-06-08 17:14:31 +02:00
|
|
|
};
|
|
|
|
in {
|
2024-02-27 22:37:55 +01:00
|
|
|
# Standard flake attribute for normal packages (not cross-compiled)
|
2023-06-08 17:14:31 +02:00
|
|
|
packages = forSupportedSystems (
|
|
|
|
system:
|
|
|
|
packagesWith (pkgsFor system)
|
|
|
|
);
|
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Non-standard attribute for cross-compilated packages
|
2023-06-08 17:14:31 +02:00
|
|
|
crossPackages = forSupportedCrossSystems (
|
|
|
|
system: crossSystem:
|
|
|
|
packagesWith (crossPkgsFor system crossSystem)
|
2023-02-20 13:18:31 +01:00
|
|
|
);
|
2023-06-08 17:14:31 +02:00
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Standard flake attribute allowing you to add the villas packages to your nixpkgs
|
2023-06-08 17:14:31 +02:00
|
|
|
overlays = {
|
2023-06-23 11:50:07 +02:00
|
|
|
default = final: prev: packagesWith final;
|
2023-08-22 16:13:12 +02:00
|
|
|
debug = final: prev: {
|
|
|
|
jansson = addSeparateDebugInfo prev.jansson;
|
|
|
|
libmodbus = addSeparateDebugInfo prev.libmodbus;
|
|
|
|
};
|
2023-06-23 11:50:07 +02:00
|
|
|
minimal = final: prev: {
|
|
|
|
mosquitto = prev.mosquitto.override {systemd = final.systemdMinimal;};
|
|
|
|
rdma-core = prev.rdma-core.override {udev = final.systemdMinimal;};
|
|
|
|
};
|
2023-06-08 17:14:31 +02:00
|
|
|
};
|
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Standard flake attribute for defining developer environments
|
2023-05-26 03:16:58 +02:00
|
|
|
devShells = forSupportedSystems (
|
|
|
|
system: let
|
2023-08-22 16:13:12 +02:00
|
|
|
pkgs = devPkgsFor system;
|
2023-06-13 10:47:51 +02:00
|
|
|
shellHook = ''[ -z "$PS1" ] || exec "$SHELL"'';
|
|
|
|
hardeningDisable = ["all"];
|
2023-09-11 12:14:03 +02:00
|
|
|
packages = with pkgs; [
|
|
|
|
bashInteractive
|
|
|
|
bc
|
|
|
|
boxfort
|
|
|
|
clang-tools
|
|
|
|
criterion
|
|
|
|
jq
|
|
|
|
libffi
|
|
|
|
libgit2
|
|
|
|
pcre
|
|
|
|
reuse
|
2024-02-29 20:04:53 +01:00
|
|
|
cppcheck
|
2023-09-11 12:14:03 +02:00
|
|
|
];
|
2023-02-20 13:18:31 +01:00
|
|
|
in rec {
|
|
|
|
default = full;
|
|
|
|
|
|
|
|
minimal = pkgs.mkShell {
|
2023-06-23 11:34:21 +02:00
|
|
|
inherit shellHook hardeningDisable packages;
|
2023-02-20 13:18:31 +01:00
|
|
|
name = "minimal";
|
2023-06-23 11:34:21 +02:00
|
|
|
inputsFrom = with pkgs; [villas-minimal];
|
2023-02-20 13:18:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
full = pkgs.mkShell {
|
2023-06-23 11:34:21 +02:00
|
|
|
inherit shellHook hardeningDisable packages;
|
2023-02-20 13:18:31 +01:00
|
|
|
name = "full";
|
2023-06-23 11:34:21 +02:00
|
|
|
inputsFrom = with pkgs; [villas];
|
2023-02-20 13:18:31 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2023-06-08 17:14:31 +02:00
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Standard flake attribute to add additional checks to `nix flake check`
|
2023-05-26 03:16:58 +02:00
|
|
|
checks = forSupportedSystems (
|
|
|
|
system: let
|
2023-06-08 17:14:31 +02:00
|
|
|
pkgs = pkgsFor system;
|
2023-05-26 03:16:58 +02:00
|
|
|
in {
|
|
|
|
fmt = pkgs.runCommand "check-fmt" {} ''
|
|
|
|
cd ${self}
|
2023-09-08 13:52:26 +02:00
|
|
|
"${pkgs.alejandra}/bin/alejandra" --check . 2>> $out
|
2023-05-26 03:16:58 +02:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
);
|
2023-06-08 17:14:31 +02:00
|
|
|
|
2024-02-27 22:37:55 +01:00
|
|
|
# Standard flake attribute specifying the formatter invoked on `nix fmt`
|
2023-06-08 17:14:31 +02:00
|
|
|
formatter = forSupportedSystems (system: (pkgsFor system).alejandra);
|
2024-02-28 00:13:53 +01:00
|
|
|
|
|
|
|
# Standard flake attribute for NixOS modules
|
|
|
|
nixosModules = rec {
|
|
|
|
default = villas;
|
|
|
|
|
|
|
|
villas = {
|
|
|
|
imports = [(nixDir + "/module.nix")];
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
self.overlays.default
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2023-02-20 13:18:31 +01:00
|
|
|
};
|
|
|
|
}
|