1
0
Fork 0
alertmanager-ntfy/flake.nix

88 lines
2.7 KiB
Nix
Raw Normal View History

2022-11-02 13:16:19 +00:00
{
description = "Relay webhooks to ntfy.sh";
2022-11-02 13:16:19 +00:00
inputs = {
2024-08-11 19:02:39 +00:00
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
flake-utils.url = "git+https://code.252.no/tommy/flake-utils";
2022-11-02 13:16:19 +00:00
};
2024-08-11 19:02:39 +00:00
outputs = { self, nixpkgs, flake-utils, ... }:
let
# Define target systems for cross-compilation
targetSystems = [ "x86_64-linux" "aarch64-darwin" ];
name = "alertmanager-ntfy";
registry = "code.252.no/tommy/alertmanager-ntfy";
version = "1.1.0";
# Map target systems to Docker architectures
archMap = {
"x86_64-linux" = "amd64";
"aarch64-darwin" = "arm64";
};
in
2024-08-11 19:02:39 +00:00
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
2024-08-11 19:02:39 +00:00
# Generate cross-compiled packages for each target system
crossPackages = builtins.listToAttrs (map (targetSystem:
let
crossPkgs = import nixpkgs {
inherit system;
crossSystem = targetSystem;
2024-08-11 19:02:39 +00:00
};
architecture = archMap.${targetSystem};
2022-11-02 13:16:19 +00:00
# Build the Go application for the target system
alertmanager-ntfy = crossPkgs.callPackage ./default.nix {};
2024-09-09 19:16:27 +00:00
# Build the Docker image for the target system
container = crossPkgs.dockerTools.buildImage {
inherit name;
tag = version;
created = "now";
2024-09-09 19:16:27 +00:00
# Set the architecture for the Docker image
architecture = [ architecture ];
2024-09-09 19:16:27 +00:00
copyToRoot = crossPkgs.buildEnv {
name = "root-env";
paths = [ alertmanager-ntfy crossPkgs.cacert ];
};
config.Cmd = [ "${alertmanager-ntfy}/bin/alertmanager-ntfy" ];
};
2024-09-09 19:16:27 +00:00
# Script to push the Docker image
push-container = crossPkgs.writeShellScriptBin "push-container" ''
#!/usr/bin/env bash
set -e
2022-11-02 15:50:31 +00:00
# Load the Docker image
echo "Loading Docker image..."
docker load < ${container}
2022-11-02 13:16:19 +00:00
# Tag the image
echo "Tagging Docker image..."
docker tag ${name}:${version} ${registry}:${version}
# Push the image to the Docker registry
echo "Pushing Docker image to ${registry}:${version}..."
docker push ${registry}:${version}
'';
in {
name = targetSystem;
value = {
alertmanager-ntfy = alertmanager-ntfy;
container = container;
push-container = push-container;
};
}
) targetSystems);
in
{
packages = crossPackages;
2024-08-11 19:02:39 +00:00
}
);
2022-11-02 13:16:19 +00:00
}