{ 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"; copyToRoot = [ my-crate pkgs.cacert ]; config = { Cmd = [ "${my-crate}/bin/vr-event-tracker" ]; ExposedPorts = { "6534/tcp" = {}; }; }; }; 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"; }); }; packages = { default = my-crate; docker = dockerImage; my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // { inherit cargoArtifacts; }); }; apps.default = flake-utils.lib.mkApp { drv = my-crate; }; devShells.default = pkgs.mkShell { inputsFrom = builtins.attrValues self.checks.${system}; nativeBuildInputs = with pkgs; [ cargo rustc rust-analyzer cargo-flamegraph cargo-bloat ]; }; }); }