vrchat-prometheus-adapter/flake.nix

149 lines
4 KiB
Nix
Raw Normal View History

2023-10-20 22:08:51 +01:00
{
description = "VRChat Event Tracker";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
flake-utils.url = "github:numtide/flake-utils";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }: {
nixosModules.default = ({ pkgs, ... }: {
imports = [ ./module.nix ];
# defined overlays injected by the nixflake
nixpkgs.overlays = [
(_self: _super: {
vrchat-prometheus-adapter = self.packages.${pkgs.system}.vrchat-prometheus-adapter;
})
];
});
} //
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
inherit (pkgs) lib;
craneLib = crane.lib.${system};
src = lib.cleanSourceWith {
src = craneLib.path ./.; # The original, unfiltered source
filter = path: type:
let
protoFilter = path: _type: builtins.match ".*proto$" path != null;
protoOrCargo = path: type:
(protoFilter path type) || (craneLib.filterCargoSources path type);
in
protoOrCargo path type;
};
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
buildInputs = [
pkgs.sqlite
pkgs.pkg-config
pkgs.openssl
pkgs.protobuf
] ++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
craneLibLLvmTools = craneLib.overrideToolchain
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]);
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
my-crate = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
dockerImage = pkgs.dockerTools.buildImage {
name = "vrchat-prometheus-exporter";
config = {
Cmd = [ "${my-crate}/bin/vr-event-tracker" ];
2023-11-10 14:20:31 +00:00
contents = [ my-crate pkgs.cacert ];
ExposedPorts = {
"6534/tcp" = {};
};
2023-10-20 22:08:51 +01:00
};
};
in
{
checks = {
inherit my-crate;
my-crate-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
my-crate-doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts;
});
my-crate-fmt = craneLib.cargoFmt {
inherit src;
};
my-crate-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
my-crate-nextest = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
});
2023-10-20 22:08:51 +01:00
};
packages = {
default = my-crate;
docker = dockerImage;
my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
inherit cargoArtifacts;
});
2023-10-20 22:08:51 +01:00
};
apps.default = flake-utils.lib.mkApp {
drv = my-crate;
};
2023-10-20 22:08:51 +01:00
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks.${system};
nativeBuildInputs = with pkgs; [
cargo
rustc
rust-analyzer
cargo-flamegraph
cargo-bloat
];
};
});
2023-10-20 22:08:51 +01:00
}