-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
57 lines (52 loc) · 1.57 KB
/
flake.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
{
description = "nix bundle proot";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
inputs.proot-static = {
url = "https://proot.gitlab.io/proot/bin/proot";
flake = false;
};
outputs = { self, nixpkgs, proot-static, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
rootfsName = drv: ((drv.name or drv.pname or "image") + ".rootfs");
prootName = drv: ((drv.name or drv.pname or "image") + ".proot");
toDockerImage = drv: (
pkgs.dockerTools.buildImage {
name = rootfsName drv;
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "image-root";
pathsToLink = ["/"];
paths = [
pkgs.coreutils
(if drv?outPath then drv else throw "provided installable is not a derivation and not coercible to an outPath")
];
};
}
);
toProot = drv: pkgs.runCommand (prootName drv) {
nativeBuildInputs = [ pkgs.go_1_21 ];
rootfs = toDockerImage drv;
proot = proot-static;
src = self;
} ''
export HOME=$(mktemp -d)
mkdir build
cd build
cp $rootfs rootfs.tar.gz
cp $src/main.go .
cp $proot proot-static
cp $src/go.mod .
cp $src/go.sum .
cp -rf $src/vendor .
CGO_ENABLE=0 GOOS=linux go build -o $out ./main.go
'';
in
{
bundlers.${system} = {
toProot = toProot;
};
};
}