{ description = "Relay webhooks to ntfy.sh"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; flake-utils.url = "git+https://code.252.no/tommy/flake-utils"; }; 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 flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; # Generate cross-compiled packages for each target system crossPackages = builtins.listToAttrs (map (targetSystem: let crossPkgs = import nixpkgs { inherit system; crossSystem = targetSystem; }; architecture = archMap.${targetSystem}; # Build the Go application for the target system alertmanager-ntfy = crossPkgs.callPackage ./default.nix {}; # Build the Docker image for the target system container = crossPkgs.dockerTools.buildImage { inherit name; tag = version; created = "now"; # Set the architecture for the Docker image architecture = [ architecture ]; copyToRoot = crossPkgs.buildEnv { name = "root-env"; paths = [ alertmanager-ntfy crossPkgs.cacert ]; }; config.Cmd = [ "${alertmanager-ntfy}/bin/alertmanager-ntfy" ]; }; # Script to push the Docker image push-container = crossPkgs.writeShellScriptBin "push-container" '' #!/usr/bin/env bash set -e # Load the Docker image echo "Loading Docker image..." docker load < ${container} # 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; } ); }