Skip to content

Commit

Permalink
feat: nixify
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmcgee committed Jun 20, 2024
1 parent d5f0a12 commit d1b1c2f
Show file tree
Hide file tree
Showing 8 changed files with 1,170 additions and 43 deletions.
9 changes: 9 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
fi

watch_file flake.nix
watch_file devshell.nix

use flake

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/telegraf.gz
/vendor
.DS_Store
result*
119 changes: 119 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
description = "The plugin-driven server agent for collecting & reporting metrics";

# Add all your dependencies here
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
blueprint = {
url = "github:numtide/blueprint";
inputs.nixpkgs.follows = "nixpkgs";
};
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
};

# Keep the magic invocations to minimum.
outputs =
inputs:
inputs.blueprint {
inherit inputs;
prefix = "nix/";
};
}
43 changes: 0 additions & 43 deletions go.sum

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
inputs,
pkgs,
system,
perSystem,
...
}:
let
inherit (pkgs) lib;
# we can't use perSystem.devshell.mkShell because it prefers ".packages" over ".legacyPackages" and the devshell
# flake doesn't expose these utils, only the legacy compat stuff does
inherit (inputs.devshell.legacyPackages.${system}) mkShell;
in
mkShell {

env = [
{
name = "DEVSHELL_NO_MOTD";
value = 1;
}
{
name = "GOROOT";
value = pkgs.go + "/share/go";
}
];

packages = lib.mkMerge [
(with pkgs; [
go
delve
pprof
graphviz
])
];
}
39 changes: 39 additions & 0 deletions nix/packages/telegraf/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
args@{
flake,
inputs,
system,
pkgs,
...
}:
let
inherit (pkgs) go lib;
in
pkgs.buildGoModule rec {
pname = "telegraf";
# there's no good way of tying in the version to a git tag or branch
# so for simplicity's sake we set the version as the commit revision hash
# we remove the `-dirty` suffix to avoid a lot of unnecessary rebuilds in local dev
version = lib.removeSuffix "-dirty" (flake.shortRev or flake.dirtyShortRev);

subPackages = [ "cmd/telegraf" ];

# ensure we are using the same version of go to build with
inherit go;

src = pkgs.lib.cleanSource ../../../.;
vendorHash = "sha256-rItG0x0FWc3CGzueEx2lIVcVYRD9SSsDLYJtaU9Aodk=";
proxyVendor = true;

ldflags = [
"-s"
"-w"
"-X github.com/omc/telegraf/internal.Commit=${flake.shortRev or flake.dirtyShortRev}"
"-X github.com/omc/telegraf/internal.Version=${version}"
];

meta = with lib; {
description = "The plugin-driven server agent for collecting & reporting metrics";
mainProgram = "telegraf";
license = licenses.mit;
};
}
Loading

0 comments on commit d1b1c2f

Please sign in to comment.