summaryrefslogtreecommitdiff
path: root/nix/docker.nix
blob: 79f49cccdd2e332f3ca2c0d48992c14b0c00037e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
  pkgs,
  arch,
  inputs,
}: let
  inherit (pkgs) lib;
  inputs' = lib.mapAttrs (_: lib.mapAttrs (_: v: v.${pkgs.system} or v)) inputs;

  crossTargets = with pkgs.pkgsCross; {
    x86_64 = musl64.pkgsStatic;
    aarch64 = aarch64-multiplatform.pkgsStatic;
  };

  rustStdFor = pkgs: inputs'.fenix.packages.targets.${pkgs.stdenv.hostPlatform.rust.rustcTarget}.stable.rust-std;
  toolchain = with inputs'.fenix.packages;
    combine (lib.flatten [
      stable.cargo
      stable.rustc
      (map rustStdFor (lib.attrValues crossTargets))
    ]);

  rustPlatformFor = pkgs:
    pkgs.makeRustPlatform (
      lib.genAttrs ["cargo" "rustc"] (lib.const toolchain)
    );
  crossPlatforms = lib.mapAttrs (lib.const rustPlatformFor) crossTargets;
in {
  "teawiebot-static-${arch}" = inputs'.self.packages.teawiebot.override {
    rustPlatform = crossPlatforms.${arch};
    optimizeSize = true;
  };

  "container-${arch}" = pkgs.dockerTools.buildLayeredImage {
    name = "teawiebot";
    tag = "latest-${arch}";
    contents = [pkgs.dockerTools.caCertificates];
    config.Cmd = [
      (lib.getExe inputs'.self.packages."teawiebot-static-${arch}")
    ];

    architecture = inputs.nixpkgs.legacyPackages."${arch}-linux".pkgsStatic.go.GOARCH;
  };
}