-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.nix
67 lines (63 loc) · 2.01 KB
/
default.nix
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ pkgs ? import <nixpkgs> {} }:
rec {
src = {
pname = "nix-sandwich";
version = "0.0.4";
vendorHash = "sha256-XSnuy6VkWh6ygxBXx8WPopaCyD1H3/cv7Fm7RMVmArA=";
src = pkgs.lib.sourceByRegex ./. [ ".*.go" "go.(mod|sum)" ];
};
nix-sandwich-local = pkgs.buildGoModule (src // {
buildInputs = with pkgs; [
brotli.dev
];
ldflags = with pkgs; [
"-X main.catBin=${coreutils}/bin/cat"
"-X main.gzipBin=${gzip}/bin/gzip"
"-X main.nixBin=${nix}/bin/nix"
"-X main.xzBin=${xz}/bin/xz"
"-X main.zstdBin=${zstd}/bin/zstd"
];
});
nix-sandwich-image = pkgs.buildGoModule (src // {
tags = [ "lambda.norpc" ];
# CGO is only needed for cbrotli, which is only used on the client side.
# Disabling CGO shrinks the binary a little more.
CGO_ENABLED = "0";
ldflags = [
# "-s" "-w" # only saves 3.6% of image size
"-X main.gzipBin=${gzStaticBin}/bin/gzip"
"-X main.xzBin=${xzStaticBin}/bin/xz"
"-X main.zstdBin=${zstdStaticBin}/bin/zstd"
];
});
# Use static binaries and take only the main binaries to make the image as
# small as possible:
zstdStaticBin = pkgs.stdenv.mkDerivation {
name = "zstd-binonly";
src = pkgs.pkgsStatic.zstd;
installPhase = "mkdir -p $out/bin && cp $src/bin/zstd $out/bin/";
};
xzStaticBin = pkgs.stdenv.mkDerivation {
name = "xz-binonly";
src = pkgs.pkgsStatic.xz;
installPhase = "mkdir -p $out/bin && cp $src/bin/xz $out/bin/";
};
gzStaticBin = pkgs.stdenv.mkDerivation {
name = "gzip-binonly";
src = pkgs.pkgsStatic.gzip;
installPhase = "mkdir -p $out/bin && cp $src/bin/.gzip-wrapped $out/bin/gzip";
};
image = pkgs.dockerTools.streamLayeredImage {
name = "lambda";
# TODO: can we make it run on arm?
# architecture = "arm64";
# Not needed for now. Maybe if we allow configurable upstreams.
#contents = [
# pkgs.cacert
#];
config = {
User = "1000:1000";
Cmd = [ "${nix-sandwich-image}/bin/nix-sandwich" ];
};
};
}