natstonotify/flake.nix

95 lines
2.6 KiB
Nix

{
description = "NATS to notification service";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{ self, nixpkgs }:
let
allSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems =
f:
nixpkgs.lib.genAttrs allSystems (
system:
f {
pkgs = import nixpkgs { inherit system; };
}
);
in
{
overlays.default = final: prev: {
natstonotify = self.packages.${prev.system}.default;
};
checks = forAllSystems (
{ pkgs }:
{
lint = self.packages.${pkgs.system}.default.overrideAttrs (old: {
name = "golangci-lint";
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.golangci-lint ];
buildPhase = ''
HOME=$TMPDIR golangci-lint run --timeout 360s --out-format=junit-xml > lint.xml
'';
doCheck = false;
installPhase = ''
mkdir -p "$out"
install lint.xml "$out/lint.xml"
'';
fixupPhase = ":";
});
}
);
packages = forAllSystems (
{ pkgs }:
{
default =
let
src = pkgs.lib.sourceFilesBySuffices ./. [
"go.mod"
"go.sum"
".go"
];
version = pkgs.lib.strings.removePrefix "v" (
builtins.elemAt (pkgs.lib.strings.split "\"" (
pkgs.lib.lists.findFirst (x: pkgs.lib.strings.hasInfix "Version" x) null (
pkgs.lib.strings.splitString "\n" (builtins.readFile ./main.go)
)
)) 2
);
in
pkgs.buildGoModule {
version = version;
pname = "natstonotify";
src = src;
vendorHash = "sha256-xAFxgUH2QUkmdCXJB4NzURozedgMIyawdf/g3vxOyC0=";
nativeBuildInputs = [ pkgs.installShellFiles ];
postInstall = ''
installShellCompletion --cmd natstonotify \
--bash <($out/bin/natstonotify completion bash) \
--zsh <($out/bin/natstonotify completion zsh) \
--fish <($out/bin/natstonotify completion fish)
'';
};
}
);
devShells = forAllSystems (
{ pkgs }:
{
default = pkgs.mkShell {
packages = with pkgs; [
go
golangci-lint
(self.packages.${pkgs.system}.default)
];
};
}
);
};
}