Add flake.nix for Nix builds and dev shell

- Package builds with buildGoModule and CGO_ENABLED=0
- Dev shell provides go_latest, gopls, gotools

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Davíð Steinn Geirsson 2026-03-20 12:44:50 +00:00
parent 2bdb508672
commit 07a03c0578
3 changed files with 87 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/.apikey /.apikey
/pve-exporter /pve-exporter
/result

43
flake.lock generated Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1773628058,
"narHash": "sha256-hpXH0z3K9xv0fHaje136KY872VT2T5uwxtezlAskQgY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f8573b9c935cfaa162dd62cc9e75ae2db86f85df",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

43
flake.nix Normal file
View file

@ -0,0 +1,43 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs = {
self,
nixpkgs,
systems,
}: let
eachSystem = f:
nixpkgs.lib.genAttrs (import systems) (system:
f (import nixpkgs {inherit system;}));
in {
packages = eachSystem (pkgs: rec {
default = pve-exporter;
pve-exporter = pkgs.buildGoModule {
pname = "pve-exporter";
version = self.shortRev or self.dirtyShortRev or "dev";
src = ./.;
vendorHash = "sha256-VC80sdNcahVbxUffNNntlXWOg+ZDalck61d6tL9aWsM=";
env.CGO_ENABLED = 0;
ldflags = ["-s" "-w"];
doCheck = true;
meta = {
description = "Prometheus exporter for Proxmox VE";
mainProgram = "pve-exporter";
};
};
});
devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
go_latest
gopls
gotools
];
};
});
};
}