Skip to content

Commit 7c5b1d6

Browse files
committed
Add docker image builder in nix
1 parent 8aa3ed1 commit 7c5b1d6

File tree

5 files changed

+60
-39
lines changed

5 files changed

+60
-39
lines changed

.github/workflows/docker-image.yml

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,16 @@ jobs:
1414
runs-on: ubuntu-latest
1515
permissions:
1616
contents: read
17-
packages: write
18-
outputs:
19-
linux-image: ${{ steps.meta.outputs.tags }}
2017
steps:
21-
- name: Set up Docker Buildx
22-
uses: docker/setup-buildx-action@v3
23-
24-
- name: Login to GitHub Container Registry
25-
uses: docker/login-action@v3
18+
- uses: actions/checkout@v4
19+
- uses: nixbuild/nix-quick-install-action@v30
20+
- name: Restore and save Nix store
21+
uses: nix-community/cache-nix-action@v6
2622
with:
27-
registry: ${{ env.REGISTRY }}
28-
username: ${{ github.actor }}
29-
password: ${{ secrets.GITHUB_TOKEN }}
30-
31-
- name: Docker meta
32-
id: meta
33-
uses: docker/metadata-action@v5
34-
with:
35-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-linux
36-
37-
- name: Build
38-
uses: docker/build-push-action@v5
39-
with:
40-
push: ${{ github.event_name != 'pull_request' }}
41-
tags: ${{ steps.meta.outputs.tags }}
42-
target: linux-build
43-
cache-from: type=gha
44-
cache-to: type=gha,mode=max
23+
primary-key: nix-${{ runner.os }}
24+
gc-max-store-size: 1G
25+
- name: Nix Build
26+
run: nix build '.#kernel'
4527

4628
build:
4729
runs-on: ubuntu-latest
@@ -53,19 +35,36 @@ jobs:
5335
matrix:
5436
os:
5537
- version: '2.15.1.1189'
56-
target: qemu-toltec
57-
- version: '3.3.2.1666'
58-
target: qemu-toltec
59-
- version: '3.5.2.1807'
60-
target: qemu-toltec
61-
- version: '3.8.2.1965'
62-
target: qemu-toltec
63-
- version: '3.20.0.92'
64-
target: qemu-toltec
38+
target: nix-toltec
39+
# - version: '3.3.2.1666'
40+
# target: qemu-toltec
41+
# - version: '3.5.2.1807'
42+
# target: qemu-toltec
43+
# - version: '3.8.2.1965'
44+
# target: qemu-toltec
45+
# - version: '3.20.0.92'
46+
# target: qemu-toltec
6547

6648
steps:
6749
- name: Set up Docker Buildx
6850
uses: docker/setup-buildx-action@v3
51+
with:
52+
# Have to use docker as we load an external image.
53+
# Prevents using cache
54+
driver: docker
55+
56+
- uses: actions/checkout@v4
57+
- uses: nixbuild/nix-quick-install-action@v30
58+
- name: Restore and save Nix store
59+
uses: nix-community/cache-nix-action@v6
60+
with:
61+
primary-key: nix-${{ runner.os }}
62+
gc-max-store-size: 3G
63+
64+
- name: Nix Build
65+
run: |
66+
nix build '.#"docker-${{ matrix.os.version }}"'
67+
./result | docker image load
6968
7069
- name: Login to GitHub Container Registry
7170
uses: docker/login-action@v3
@@ -89,10 +88,10 @@ jobs:
8988
push: ${{ github.event_name != 'pull_request' && github.ref_name == 'main' }}
9089
tags: ${{ steps.meta.outputs.tags }}
9190
target: ${{ matrix.os.target }}
92-
cache-from: type=gha
93-
cache-to: type=gha,mode=max
91+
# cache-from: type=gha
92+
# cache-to: type=gha,mode=max
93+
# linux_image=${{ needs.build-linux.outputs.linux-image }}
9494
build-args: |
9595
fw_version=${{ matrix.os.version }}
96-
linux_image=${{ needs.build-linux.outputs.linux-image }}
9796
9897

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ RUN nix build "/src#\"rm-emu-$fw_version\"" -o /result && \
182182

183183
CMD run_vm
184184

185-
FROM nix-emu AS nix-start
185+
FROM rm-emu:$fw_version AS nix-start
186186

187187
# First boot, disable xochitl and reboot service, and save state
188188
RUN run_vm -serial null -daemonize && \

bin/run_vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ssh_port=${SSH_PORT:-22}
1010

1111
if ! [ -f "$root_path" ] && [ -f "$backing_path" ]; then
1212
echo "No image found, creating new one"
13+
mkdir -p $(dirname $root_path)
1314
qemu-img create -b "$backing_path" -F qcow2 -f qcow2 "$root_path"
1415
fi
1516

flake.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,33 @@
4141
inherit kernel rootfs;
4242
})
4343
) allRootFs;
44+
45+
dockerImages = nixpkgs.lib.mapAttrs' (
46+
_: pkg:
47+
nixpkgs.lib.nameValuePair "docker-${pkg.version}" (
48+
pkgs.dockerTools.streamLayeredImage {
49+
name = "rm-emu";
50+
tag = "${pkg.version}";
51+
contents = [
52+
pkg
53+
pkgs.dockerTools.binSh
54+
pkgs.dockerTools.fakeNss
55+
];
56+
57+
config = {
58+
Cmd = [ "${pkg}/bin/run_vm" ];
59+
};
60+
}
61+
)
62+
) allEmus;
4463
in
4564
{
4665
inherit kernel extractor;
4766
default = allEmus."rm-emu-3.20.0.92";
4867
}
4968
// allEmus
5069
// allRootFs'
70+
// dockerImages
5171
);
5272
};
5373
}

nix/rm-emu.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ stdenvNoCC.mkDerivation {
8383
lib.makeBinPath [
8484
qemu
8585
gnugrep
86+
coreutils
8687
]
8788
}
8889

0 commit comments

Comments
 (0)