❄️ Add nix flake

This commit is contained in:
Sam Willcocks 2021-11-17 14:38:24 +00:00
parent 037d384074
commit 68d6b98230
3 changed files with 65 additions and 0 deletions

41
flake.lock Normal file
View File

@ -0,0 +1,41 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1637156900,
"narHash": "sha256-nusyaSsL1RLyUEWufUUywDrGKMXw+4ugSSZ3ss8TSuw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "12fc0f19fefa9dff68bc3e0938b815ab8d89df90",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

21
flake.nix Normal file
View File

@ -0,0 +1,21 @@
{
description = "Samw's APC PDU MQTT bridge";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; }; in
rec {
packages.apc2mqtt = pkgs.buildGoModule {
name = "apc2mqtt";
src = self;
vendorSha256 = "sha256-GlRcuUNrsNnONigXut2xFx0kX+5k80Djn07c3UutCLU=";
ldflags = ''
-X main.version=${if self ? rev then self.rev else "dirty"}
'';
};
defaultPackage = packages.apc2mqtt;
}
);
}

View File

@ -14,6 +14,8 @@ import (
log "github.com/sirupsen/logrus"
)
var version = "unknown"
// OIDs of interest.
// snmptranslate -m PowerNet-MIB -Pu -Tso | less
const (
@ -200,6 +202,7 @@ func spawnTarget(target targetConfig, mqttClient mqtt.Client) {
func main() {
var configpath = flag.String("conf", "config.toml", "Path to toml config file")
flag.Parse()
log.Infof("Starting version %s", version)
conf, err := parseConfig(*configpath)
check(err)