summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseth <[email protected]>2024-03-17 03:06:14 -0400
committerseth <[email protected]>2024-03-17 03:06:14 -0400
commit362b80924010d0e425dc41885c8ee148f6d9ca36 (patch)
tree32f25de12b1967be94922cc68d29d7fdd1c3b3bb
parentd89807ba60b88ce7dad7a743db76bb8732c7a8b8 (diff)
nix: factor out functions for docker image
-rw-r--r--nix/deployment.nix70
1 files changed, 39 insertions, 31 deletions
diff --git a/nix/deployment.nix b/nix/deployment.nix
index 080cac9..88a9f51 100644
--- a/nix/deployment.nix
+++ b/nix/deployment.nix
@@ -16,26 +16,27 @@
inputs',
...
}: let
- containerFor = arch: let
- crossPkgs = {
- "x86_64-linux" = {
- "x86_64" = pkgs.pkgsStatic;
- "aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
- };
-
- "aarch64-linux" = {
- "x86_64" = pkgs.pkgsCross.musl64;
- "aarch64" = pkgs.pkgsStatic;
- };
+ crossPkgs = {
+ "x86_64-linux" = {
+ "x86_64" = pkgs.pkgsStatic;
+ "aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
+ };
- "x86_64-darwin" = {
- "x86_64" = pkgs.pkgsCross.musl64;
- "aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
- };
+ "aarch64-linux" = {
+ "x86_64" = pkgs.pkgsCross.musl64;
+ "aarch64" = pkgs.pkgsStatic;
+ };
- "aarch64-darwin" = crossPkgs."x86_64-darwin";
+ "x86_64-darwin" = {
+ "x86_64" = pkgs.pkgsCross.musl64;
+ "aarch64" = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic;
};
- inherit (crossPkgs.${system}.${arch}.stdenv) cc;
+
+ "aarch64-darwin" = crossPkgs."x86_64-darwin";
+ };
+
+ teawieFor = arch: let
+ inherit (crossPkgs.${system}.${arch}.llvmPackages.stdenv) cc;
target = "${arch}-unknown-linux-musl";
target' = builtins.replaceStrings ["-"] ["_"] target;
@@ -52,28 +53,35 @@
cargo = toolchain;
rustc = toolchain;
};
-
- teawiebot =
- (config.packages.teawiebot.override {
- inherit naersk;
- optimizeSize = true;
- })
- .overrideAttrs (new:
- lib.const {
- CARGO_BUILD_TARGET = target;
- "CC_${target'}" = "${cc}/bin/${cc.targetPrefix}cc";
- "CARGO_TARGET_${targetUpper}_RUSTFLAGS" = "-C target-feature=+crt-static";
- "CARGO_TARGET_${targetUpper}_LINKER" = new."CC_${target'}";
- });
in
+ (config.packages.teawiebot.override {
+ inherit naersk;
+ lto = true;
+ optimizeSize = true;
+ })
+ .overrideAttrs (new:
+ lib.const {
+ CARGO_BUILD_TARGET = target;
+ "CC_${target'}" = "${cc}/bin/${cc.targetPrefix}cc";
+ "CARGO_TARGET_${targetUpper}_RUSTFLAGS" = "-C target-feature=+crt-static";
+ "CARGO_TARGET_${targetUpper}_LINKER" = new."CC_${target'}";
+ });
+
+ containerFor = arch:
pkgs.dockerTools.buildLayeredImage {
name = "teawiebot";
tag = "latest-${arch}";
contents = [pkgs.dockerTools.caCertificates];
- config.Cmd = [(lib.getExe teawiebot)];
+ config.Cmd = [
+ (lib.getExe (teawieFor arch))
+ ];
+
+ architecture = crossPkgs.${system}.${arch}.go.GOARCH;
};
in {
packages = {
+ teawiebot-static-x86_64 = teawieFor "x86_64";
+ teawiebot-static-aarch64 = teawieFor "aarch64";
container-x86_64 = containerFor "x86_64";
container-aarch64 = containerFor "aarch64";
};