nix-config/flake.nix

396 lines
11 KiB
Nix
Raw Permalink Normal View History

2022-04-23 03:01:58 +02:00
{
2022-04-23 13:41:36 +02:00
inputs = {
2023-03-04 23:59:22 +01:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
# naersk and flake utils are not used by this flake directly, but needed
# for the follows in all the other ones.
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-03-17 19:51:49 +01:00
# DO NOT remame this to utils
flake-utils.url = github:numtide/flake-utils;
2023-03-16 22:55:12 +01:00
2022-05-14 22:47:54 +02:00
microvm = {
2023-02-19 22:28:44 +01:00
url = "github:astro/microvm.nix";
2022-06-06 22:41:04 +02:00
inputs.nixpkgs.follows = "nixpkgs";
2023-03-17 19:51:49 +01:00
inputs.flake-utils.follows = "flake-utils";
2022-05-14 22:47:54 +02:00
};
sops-nix = {
2023-02-19 22:28:44 +01:00
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-03-05 14:07:31 +01:00
## TLMS stuff below
documentation-src = {
2023-02-19 22:28:44 +01:00
url = "github:tlm-solutions/documentation";
flake = false;
};
2023-02-15 11:17:36 +01:00
trekkie = {
url = "github:tlm-solutions/trekkie";
2023-03-04 23:59:22 +01:00
inputs = {
nixpkgs.follows = "nixpkgs";
naersk.follows = "naersk";
2023-03-05 14:07:31 +01:00
tlms-rs.follows = "tlms-rs";
2023-03-17 19:51:49 +01:00
utils.follows = "flake-utils";
2023-03-04 23:59:22 +01:00
};
2023-02-15 11:17:36 +01:00
};
2023-02-19 22:28:44 +01:00
datacare = {
url = "github:tlm-solutions/datacare";
};
2023-02-24 14:25:30 +01:00
kindergarten = {
url = "github:tlm-solutions/kindergarten";
inputs.nixpkgs.follows = "nixpkgs";
2023-03-17 19:51:49 +01:00
inputs.utils.follows = "flake-utils";
2023-02-24 14:25:30 +01:00
};
2023-03-05 00:00:05 +01:00
telegram-decoder = {
url = "github:tlm-solutions/telegram-decoder";
inputs = {
nixpkgs.follows = "nixpkgs";
naersk.follows = "naersk";
2023-03-17 19:51:49 +01:00
utils.follows = "flake-utils";
2023-03-05 00:00:05 +01:00
};
};
2023-03-05 14:07:31 +01:00
gnuradio-decoder = {
url = "github:tlm-solutions/gnuradio-decoder";
inputs.nixpkgs.follows = "nixpkgs";
2023-03-17 19:51:49 +01:00
inputs.utils.follows = "flake-utils";
2023-03-05 14:07:31 +01:00
};
data-accumulator = {
url = "github:tlm-solutions/data-accumulator";
inputs.nixpkgs.follows = "nixpkgs";
inputs.naersk.follows = "naersk";
2023-03-17 19:51:49 +01:00
inputs.utils.follows = "flake-utils";
2023-03-05 14:07:31 +01:00
};
2023-04-12 17:20:07 +02:00
lizard = {
url = "github:tlm-solutions/lizard";
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
bureaucrat = {
url = "github:tlm-solutions/bureaucrat";
2023-03-05 14:07:31 +01:00
inputs.nixpkgs.follows = "nixpkgs";
2023-03-17 19:51:49 +01:00
inputs.utils.follows = "flake-utils";
2023-03-05 14:07:31 +01:00
};
funnel = {
url = "github:tlm-solutions/funnel";
inputs.nixpkgs.follows = "nixpkgs";
2023-03-17 19:51:49 +01:00
inputs.utils.follows = "flake-utils";
2023-03-05 14:07:31 +01:00
};
windshield = {
2023-04-09 20:03:52 +02:00
url = "github:tlm-solutions/windshield/hotfix";
2023-03-05 14:07:31 +01:00
inputs.nixpkgs.follows = "nixpkgs";
2023-03-17 19:51:49 +01:00
inputs.utils.follows = "flake-utils";
2023-03-05 14:07:31 +01:00
};
tlms-rs = {
url = "github:tlm-solutions/tlms.rs";
inputs.nixpkgs.follows = "nixpkgs";
};
chemo = {
url = "github:tlm-solutions/chemo";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-05-19 19:08:52 +02:00
borzoi = {
url = "github:tlm-solutions/borzoi";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-04-28 14:43:40 +02:00
};
2022-04-23 13:41:36 +02:00
2022-07-06 20:58:15 +02:00
outputs =
inputs@{ self
2023-05-19 19:08:52 +02:00
, borzoi
2023-03-05 14:07:31 +01:00
, data-accumulator
2023-02-19 22:28:44 +01:00
, datacare
2023-03-05 14:07:31 +01:00
, documentation-src
, funnel
, gnuradio-decoder
, kindergarten
2022-07-06 20:58:15 +02:00
, microvm
, nixpkgs
2022-07-06 20:58:15 +02:00
, sops-nix
2023-04-12 17:20:07 +02:00
, lizard
, bureaucrat
2023-03-05 14:07:31 +01:00
, telegram-decoder
2023-02-15 11:17:36 +01:00
, trekkie
2023-03-05 14:07:31 +01:00
, windshield
, chemo
2022-07-06 20:58:15 +02:00
, ...
}:
2022-04-30 23:41:24 +02:00
let
pkgs = nixpkgs.legacyPackages."x86_64-linux";
lib = pkgs.lib;
2022-05-28 06:12:39 +02:00
2022-05-28 21:24:15 +02:00
data-hoarder-modules = [
./modules/data-hoarder
2022-12-30 18:29:13 +01:00
./modules/TLMS
2023-03-05 14:07:31 +01:00
data-accumulator.nixosModules.default
2023-02-19 22:28:44 +01:00
datacare.nixosModules.default
2023-03-05 14:07:31 +01:00
funnel.nixosModules.default
sops-nix.nixosModules.sops
2023-04-12 17:20:07 +02:00
lizard.nixosModules.default
bureaucrat.nixosModules.default
2023-02-15 11:17:36 +01:00
trekkie.nixosModules.default
chemo.nixosModules.default
2022-05-28 21:24:15 +02:00
{
nixpkgs.overlays = [
2023-02-19 22:28:44 +01:00
datacare.overlays.default
2023-02-24 14:25:30 +01:00
kindergarten.overlays.default
2023-02-15 11:17:36 +01:00
trekkie.overlays.default
2023-04-12 17:20:07 +02:00
lizard.overlays.default
bureaucrat.overlays.default
2023-03-05 14:07:31 +01:00
funnel.overlays.default
data-accumulator.overlays.default
windshield.overlays.default
chemo.overlays.default
2022-10-02 22:14:34 +02:00
(final: prev: {
inherit documentation-src;
2022-09-03 22:14:43 +02:00
options-docs = (pkgs.nixosOptionsDoc {
2022-12-30 18:29:13 +01:00
options = self.nixosConfigurations.data-hoarder.options.TLMS;
2022-09-03 22:14:43 +02:00
}).optionsCommonMark;
})
2022-05-28 21:24:15 +02:00
];
}
];
2022-05-28 06:12:39 +02:00
stop-box-modules = [
2023-03-05 14:07:31 +01:00
./modules/TLMS
telegram-decoder.nixosModules.default
gnuradio-decoder.nixosModules.default
2022-09-27 01:01:20 +02:00
{
nixpkgs.overlays = [
2023-03-05 14:07:31 +01:00
telegram-decoder.overlays.default
gnuradio-decoder.overlays.default
2022-09-27 01:01:20 +02:00
];
}
];
# function that generates a system with the given number
generate_system = (id: arch: monitoring:
{
"traffic-stop-box-${toString id}" = nixpkgs.lib.nixosSystem
{
system = arch;
specialArgs = inputs;
modules =
let
monitoring-mod =
if monitoring
then { deployment-TLMS.monitoring.enable = true; }
else { deployment-TLMS.monitoring.enable = false; };
in
[
# box-specific config
./hosts/traffic-stop-box/${toString id}
# default modules
sops-nix.nixosModules.sops
./modules/traffic-stop-box
./modules/TLMS
{
deployment-TLMS.systemNumber = id;
}
monitoring-mod
] ++ stop-box-modules;
};
2022-04-30 23:41:24 +02:00
}
2022-04-28 14:43:40 +02:00
);
id_list = [
2022-08-24 18:48:33 +02:00
{
# Barkhausen Bau
id = 0;
arch = "x86_64-linux";
monitoring = true;
}
2022-08-24 18:48:33 +02:00
{
# Zentralwerk
id = 1;
arch = "x86_64-linux";
monitoring = true;
}
2022-08-24 18:48:33 +02:00
{
# Chemnitz
id = 2;
arch = "x86_64-linux";
monitoring = false;
}
{
# unused
id = 3;
arch = "aarch64-linux";
monitoring = false;
}
2022-08-30 16:55:40 +02:00
{
# Wundstr. 9
id = 4;
arch = "x86_64-linux";
monitoring = true;
2022-08-30 16:55:40 +02:00
}
2022-09-22 17:12:56 +02:00
{
2022-11-22 09:37:15 +01:00
# Warpzone
2022-09-22 17:12:56 +02:00
id = 6;
arch = "x86_64-linux";
monitoring = true;
2022-09-26 00:55:23 +02:00
}
2022-09-26 21:21:44 +02:00
{
id = 7;
arch = "x86_64-linux";
monitoring = false;
2022-09-26 21:21:44 +02:00
}
2022-11-28 19:24:54 +01:00
{
id = 8;
arch = "aarch64-linux";
monitoring = false;
2022-11-28 19:24:54 +01:00
}
2022-11-28 21:59:29 +01:00
{
id = 9;
arch = "aarch64-linux";
monitoring = false;
2022-11-28 21:59:29 +01:00
}
2023-03-11 11:46:18 +01:00
{
id = 10;
arch = "x86_64-linux";
monitoring = false;
2023-03-11 11:46:18 +01:00
}
];
2022-04-30 23:41:24 +02:00
# attribute set of all traffic stop boxes
stop_boxes = nixpkgs.lib.foldl (x: y: nixpkgs.lib.mergeAttrs x (generate_system y.id y.arch y.monitoring)) { } id_list;
2022-05-14 20:47:17 +02:00
2022-05-29 01:57:24 +02:00
packages = {
2022-05-28 21:24:15 +02:00
staging-microvm = self.nixosConfigurations.staging-data-hoarder.config.microvm.declaredRunner;
2023-05-01 05:51:43 +02:00
borken-microvm = self.nixosConfigurations.borken-data-hoarder.config.microvm.declaredRunner;
data-hoarder-microvm = self.nixosConfigurations.data-hoarder.config.microvm.declaredRunner;
2023-04-18 19:17:19 +02:00
fuck-microvm = self.nixosConfigurations.fuck.config.system.build.vm;
2022-09-04 15:06:02 +02:00
docs = pkgs.callPackage ./pkgs/documentation.nix {
inherit documentation-src;
2022-09-04 15:06:02 +02:00
options-docs = (pkgs.nixosOptionsDoc {
2022-12-30 18:29:13 +01:00
options = self.nixosConfigurations.data-hoarder.options.TLMS;
2022-09-04 15:06:02 +02:00
}).optionsCommonMark;
};
2023-04-18 21:48:32 +02:00
test-vm-wrapper =
let
cfg = self.nixosConfigurations.fuck.config;
in
(pkgs.writeScript "datacare-test-vm-wrapper"
2023-04-17 00:06:47 +02:00
''
set -e
echo Datacare-McTest: enterprise-grade, free-range, grass-fed testing vm
echo "ALL RELEVANT SERVICES WILL BE EXPOSED TO THE HOST:"
echo -e "Service\t\tPort"
echo -e "SSH:\t\t2223\troot:lol"
echo -e "trekkie:\t${toString cfg.TLMS.trekkie.port}"
echo -e "datacare:\t${toString cfg.TLMS.datacare.http.port}"
2023-04-17 00:06:47 +02:00
echo -e "data-accumulator:\t${toString cfg.TLMS.dataAccumulator.port}"
echo -e "funnel:\t${toString cfg.TLMS.funnel.defaultWebsocket.port}"
echo
set -x
export QEMU_NET_OPTS="hostfwd=tcp::2223-:22,hostfwd=tcp::80-:80,hostfwd=tcp::8050-:${toString cfg.TLMS.trekkie.port},hostfwd=tcp::8060-:${toString cfg.TLMS.datacare.http.port},hostfwd=tcp::8070-:${toString cfg.TLMS.dataAccumulator.port},hostfwd=tcp::8080-:${toString cfg.TLMS.funnel.defaultWebsocket.port}"
2023-04-17 00:06:47 +02:00
echo "running the vm now..."
2023-04-18 19:17:19 +02:00
${self.packages."x86_64-linux".fuck-microvm}/bin/run-staging-data-hoarder-vm
2023-04-17 00:06:47 +02:00
'');
}
// (import ./pkgs/deployment.nix { inherit self pkgs; systems = stop_boxes; })
// (lib.foldl (x: y: lib.mergeAttrs x { "${y.config.system.name}-vm" = y.config.system.build.vm; }) { } (lib.attrValues self.nixosConfigurations));
2022-09-25 21:36:26 +02:00
2022-04-30 23:41:24 +02:00
in
{
2022-05-14 20:47:17 +02:00
packages."x86_64-linux" = packages;
2022-04-28 14:43:40 +02:00
2022-05-28 06:12:39 +02:00
nixosConfigurations = stop_boxes // {
2022-09-25 21:36:26 +02:00
2022-05-28 21:24:15 +02:00
data-hoarder = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
2023-03-05 14:07:31 +01:00
specialArgs = { inherit inputs self; };
2022-05-29 01:57:24 +02:00
modules = [
microvm.nixosModules.microvm
2022-10-02 21:39:37 +02:00
./hosts/data-hoarder
2022-05-29 01:57:24 +02:00
] ++ data-hoarder-modules;
2022-05-28 06:12:39 +02:00
};
2022-05-28 21:24:15 +02:00
staging-data-hoarder = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
2023-03-05 14:07:31 +01:00
specialArgs = { inherit inputs self; };
2022-05-29 01:57:24 +02:00
modules = [
2022-10-02 21:39:37 +02:00
./hosts/staging-data-hoarder
2022-05-28 21:24:15 +02:00
microvm.nixosModules.microvm
2022-05-29 01:57:24 +02:00
] ++ data-hoarder-modules;
2022-05-28 21:24:15 +02:00
};
2023-04-17 00:06:47 +02:00
2023-05-01 05:51:43 +02:00
borken-data-hoarder = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs self; };
modules = [
./hosts/borken-data-hoarder
microvm.nixosModules.microvm
] ++ data-hoarder-modules;
};
2023-04-17 00:06:47 +02:00
fuck = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs self; };
modules = [
microvm.nixosModules.microvm
2023-04-17 00:06:47 +02:00
./hosts/staging-data-hoarder
./hosts/fuck
{
deployment-TLMS.monitoring.enable = false;
}
2023-04-17 00:06:47 +02:00
] ++ data-hoarder-modules;
};
2023-04-23 21:19:45 +02:00
notice-me-senpai = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs self; };
modules = [
sops-nix.nixosModules.sops
./modules/TLMS
./hosts/notice-me-senpai
];
};
2023-05-19 19:08:52 +02:00
tram-borzoi = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs self; };
modules = [
sops-nix.nixosModules.sops
microvm.nixosModules.microvm
borzoi.nixosModules.default
{ nixpkgs.overlays = [ borzoi.overlays.default ]; }
./modules/TLMS
./hosts/tram-borzoi
];
};
2023-04-17 00:06:47 +02:00
};
apps."x86_64-linux".mctest = {
type = "app";
program = "${self.packages."x86_64-linux".test-vm-wrapper}";
2022-12-07 20:06:46 +01:00
};
2022-04-29 11:52:57 +02:00
2022-12-21 02:47:45 +01:00
nixosModules."x86_64-linux".watch-me-senpai = import ./modules/watch-me-senpai;
2022-12-20 14:56:16 +01:00
2022-10-02 22:14:34 +02:00
hydraJobs = (lib.mapAttrs (_name: value: { ${value.config.system.build.toplevel.system} = value.config.system.build.toplevel; }) self.nixosConfigurations) // {
sops-binaries."x86_64-linux" = sops-nix.packages."x86_64-linux".sops-install-secrets;
2022-04-29 11:52:57 +02:00
};
2022-08-24 18:48:33 +02:00
};
2022-12-07 23:30:37 +01:00
}