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
|
|
|
{
|
|
|
|
description = "a tool for connecting real-time power grid simulation equipment";
|
|
|
|
|
|
|
|
inputs = {
|
2023-06-23 11:50:07 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
|
2023-02-20 13:18:31 +01:00
|
|
|
|
2023-05-25 18:47:27 +02:00
|
|
|
common = {
|
2023-06-08 17:14:31 +02:00
|
|
|
url = "github:VILLASframework/common";
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
fpga = {
|
2023-06-19 20:18:27 +02:00
|
|
|
type = "git";
|
|
|
|
url = "https://github.com/VILLASframework/fpga.git";
|
|
|
|
submodules = true;
|
2023-02-20 13:18:31 +01:00
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
lib60870 = {
|
|
|
|
url = "github:mz-automation/lib60870/v2.3.2";
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
2023-06-12 17:57:04 +02:00
|
|
|
libdatachannel = {
|
|
|
|
type = "git";
|
|
|
|
url = "https://github.com/paullouisageneau/libdatachannel.git";
|
|
|
|
ref = "refs/tags/v0.18.4";
|
|
|
|
submodules = true;
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
2023-02-20 13:18:31 +01:00
|
|
|
libiec61850 = {
|
|
|
|
url = "github:mz-automation/libiec61850/v1.5.1";
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
...
|
|
|
|
} @ inputs: let
|
|
|
|
inherit (nixpkgs) lib;
|
2023-06-08 17:14:31 +02:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-06-08 17:14:31 +02: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
|
|
|
|
|
|
|
# supported systems to cross compile to
|
|
|
|
supportedCrossSystems = ["aarch64-multiplatform"];
|
|
|
|
|
|
|
|
# generate attributes corresponding to all the supported systems
|
2023-02-20 13:18:31 +01:00
|
|
|
forSupportedSystems = lib.genAttrs supportedSystems;
|
|
|
|
|
2023-06-08 17:14:31 +02:00
|
|
|
# generate attributes corresponding to all supported combinations of system and crossSystem
|
|
|
|
forSupportedCrossSystems = f: forSupportedSystems (system: lib.genAttrs supportedCrossSystems (f system));
|
2023-02-20 13:18:31 +01:00
|
|
|
|
2023-06-08 17:14:31 +02:00
|
|
|
# initialize nixpkgs for the specified `system`
|
|
|
|
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;
|
|
|
|
|
2023-09-19 11:54:37 +02:00
|
|
|
villas-python = pkgs.callPackage ./python.nix {
|
|
|
|
src = ../../python;
|
|
|
|
};
|
|
|
|
|
2023-06-08 17:14:31 +02:00
|
|
|
villas-minimal = pkgs.callPackage ./villas.nix {
|
|
|
|
src = ../..;
|
|
|
|
version = "minimal";
|
|
|
|
inherit (inputs) fpga common;
|
|
|
|
};
|
|
|
|
|
|
|
|
villas = villas-minimal.override {
|
|
|
|
version = "full";
|
|
|
|
withAllExtras = true;
|
|
|
|
withAllFormats = true;
|
|
|
|
withAllHooks = true;
|
|
|
|
withAllNodes = true;
|
|
|
|
};
|
|
|
|
|
2023-08-17 09:39:35 +02:00
|
|
|
ethercat = pkgs.callPackage ./ethercat.nix {
|
|
|
|
src = inputs.ethercat;
|
|
|
|
};
|
|
|
|
|
2023-06-08 17:14:31 +02:00
|
|
|
lib60870 = pkgs.callPackage ./lib60870.nix {
|
|
|
|
src = inputs.lib60870;
|
|
|
|
};
|
|
|
|
|
2023-06-12 17:57:04 +02:00
|
|
|
libdatachannel = pkgs.callPackage ./libdatachannel.nix {
|
|
|
|
src = inputs.libdatachannel;
|
|
|
|
};
|
|
|
|
|
2023-06-08 17:14:31 +02:00
|
|
|
libiec61850 = pkgs.callPackage ./libiec61850.nix {
|
|
|
|
src = inputs.libiec61850;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
# standard flake attribute for normal packages (not cross-compiled)
|
|
|
|
packages = forSupportedSystems (
|
|
|
|
system:
|
|
|
|
packagesWith (pkgsFor system)
|
|
|
|
);
|
|
|
|
|
|
|
|
# non-standard attribute for cross-compilated packages
|
|
|
|
crossPackages = forSupportedCrossSystems (
|
|
|
|
system: crossSystem:
|
|
|
|
packagesWith (crossPkgsFor system crossSystem)
|
2023-02-20 13:18:31 +01:00
|
|
|
);
|
2023-06-08 17:14:31 +02:00
|
|
|
|
|
|
|
# standard flake attribute allowing you to add the villas packages to your nixpkgs
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
# 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
|
|
|
|
];
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# standard flake attribute specifying the formatter invoked on `nix fmt`
|
|
|
|
formatter = forSupportedSystems (system: (pkgsFor system).alejandra);
|
2023-02-20 13:18:31 +01:00
|
|
|
};
|
|
|
|
}
|