apiary/flake.nix

102 lines
2.7 KiB
Nix

{
description = "SSH honeypot with frontend";
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: {
apiary = self.packages.${prev.system}.default;
};
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 ./version.go)
)
)) 2
);
geoDb = pkgs.fetchFromGitHub {
owner = "geoacumen";
repo = "geoacumen-country";
rev = "5f770af620465f40427c3f421446a7b7845e2699";
sha256 = "sha256-t3ELkhAbJC40z6r6wJeQI4Kutfw26fRg6n7a6FmhvkA=";
};
frontend = pkgs.buildNpmPackage {
inherit version;
name = "apiary-frontend";
src = ./frontend;
npmDepsHash = "sha256-hFoGepzNZjDFaHhb6tO3FUmW6AdEyOTXIQ6rDcUokLo=";
installPhase = ''
mkdir -p $out
cp -r dist/* $out
'';
};
in
pkgs.buildGoModule {
inherit version;
pname = "apiary";
src = src;
prePatch = ''
cp ${geoDb}/Geoacumen-Country.mmdb honeypot/ssh
mkdir -p web/frontend/dist
cp -r ${frontend}/* web/frontend/dist
'';
vendorHash = "sha256-griWN9fQ0X2ClPDOzVXV80MpdcEFZfe/WaYm7L7fAc8=";
tags = [
"embed"
];
};
}
);
devShells = forAllSystems (
{ pkgs }:
{
default = pkgs.mkShell {
packages = with pkgs; [
go
golangci-lint
];
};
frontend = pkgs.mkShell {
packages = with pkgs; [
nodejs
yarn
];
};
}
);
};
}