warthunder-leak-counter/flake.nix

140 lines
3.5 KiB
Nix
Raw Permalink Normal View History

2024-06-22 02:54:58 -03:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
flake-utils.url = "github:numtide/flake-utils";
2024-06-22 13:42:24 -03:00
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-06-22 02:54:58 -03:00
};
outputs =
{
self,
nixpkgs,
flake-utils,
2024-06-22 13:42:24 -03:00
crane,
2024-06-22 02:54:58 -03:00
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
2024-06-22 13:42:24 -03:00
craneLib = crane.mkLib pkgs;
commonArgs = {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl ];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
my-crate = craneLib.buildPackage (
commonArgs
// {
src = ./.; # Allow access to assets, like ./templates
inherit cargoArtifacts;
meta.mainProgram = "warthunder-leak-counter";
}
);
2024-06-22 02:54:58 -03:00
in
{
2024-06-22 13:42:24 -03:00
checks = {
my-crate-fmt = craneLib.cargoFmt { inherit (commonArgs) src; };
};
packages.default = my-crate;
devShells.default = pkgs.mkShell {
inherit (commonArgs) buildInputs;
nativeBuildInputs =
with pkgs;
(
[
rustc
cargo
rustfmt
rust-analyzer
clippy
cargo-feature
cargo-watch
curl
]
++ commonArgs.nativeBuildInputs
);
};
2024-06-22 02:54:58 -03:00
}
2024-06-22 14:20:17 -03:00
)
// {
nixosModules.default =
{
pkgs,
lib,
config,
...
}:
let
cfg = config.services.warthunder-leak-counter;
in
{
options.services.warthunder-leak-counter = {
enable = lib.mkEnableOption "Enable Warthunder Leak Counter";
staticDir = lib.mkOption {
default = toString ./static;
type = lib.types.str;
};
port = lib.mkOption {
type = lib.types.port;
default = 6263;
};
};
config = lib.mkIf cfg.enable {
systemd.services.warthunder-leak-counter = {
script = lib.getExe self.packages.${pkgs.system}.default;
environment = {
WARTHUNDER_LEAK_SERVE_PORT = toString cfg.port;
WARTHUNDER_LEAK_STATIC_DIR = cfg.staticDir;
};
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
};
};
};
nixosConfigurations.test-server = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
self.nixosModules.default
(nixpkgs + "/nixos/modules/virtualisation/qemu-vm.nix")
(
{ config, ... }:
{
services.warthunder-leak-counter.enable = true;
users.users.root.password = "root";
networking.firewall.enable = false;
virtualisation.forwardPorts = [
{
from = "host";
host.port = 8888;
guest.port = config.services.warthunder-leak-counter.port;
}
];
system.stateVersion = "24.05";
}
)
];
};
};
2024-06-22 02:54:58 -03:00
}