-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
60 lines (52 loc) · 2.44 KB
/
Dockerfile
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
# The following information is from https://hub.docker.com/r/nixos/nix/tags
FROM nixos/nix:2.9.0@sha256:13b257cd42db29dc851f9818ea1bc2f9c7128c51fdf000971fa6058c66fbe4b6 as cross-rs_builder
############################################################
# Step 1: Prepare nixpkgs and cross for deterministic builds
############################################################
WORKDIR /build
# Custom project name
ENV RUST_PROJECT_NAME="rust-cross-build-nix"
# 22.05
#ENV NIXPKGS_COMMIT_SHA="ce6aa13369b667ac2542593170993504932eb836"
# This version has podman 4.2.0, which contains bugfix
# https://github.com/containers/podman/pull/14787
ENV NIXPKGS_COMMIT_SHA="692574660e1f1e397b6e48065c931e8758c5ad16"
# 0.2.4
ENV CROSS_COMMIT_SHA="4645d937bdae6952d9df38eff3ecb91fd719c3bd"
# Apple M1 workaround
COPY nix.conf /build/nix.conf
ENV NIX_USER_CONF_FILES=/build/nix.conf
RUN nix-env --option filter-syscalls false -i git gnused && \
mkdir -p /build/nixpkgs && \
cd nixpkgs && \
git init && \
git remote add origin https://github.com/NixOS/nixpkgs.git && \
git fetch --depth 1 origin ${NIXPKGS_COMMIT_SHA} && \
git checkout FETCH_HEAD && \
cd .. && \
mkdir -p /build/cross && \
git clone https://github.com/cross-rs/cross.git && \
cd cross && \
git checkout ${CROSS_COMMIT_SHA} && \
cd .. && \
mkdir -p /build/.cargo && \
mkdir -p /build/.rustup && \
mkdir -p /build/${RUST_PROJECT_NAME}
ENV NIX_PATH=nixpkgs=/build/nixpkgs
ENV RUSTC_VERSION=1.63.0
ENV CARGO_HOME="/build/.cargo"
ENV RUSTUP_HOME="/build/.rustup"
ENV PATH="${CARGO_HOME}/bin:${RUSTUP_HOME}/toolchains/${RUSTC_VERSION}-x86_64-unknown-linux-gnu/bin:${PATH}"
#########################################################
# Step 2: Prepare Rust project
#########################################################
COPY nix-cross-rs/src /build/${RUST_PROJECT_NAME}/src
COPY nix-cross-rs/Cargo.toml /build/${RUST_PROJECT_NAME}/Cargo.toml
COPY nix-cross-rs/Cross.toml /build/${RUST_PROJECT_NAME}/Cross.toml
COPY nix-cross-rs/Cargo.lock /build/${RUST_PROJECT_NAME}/Cargo.lock
COPY nix-cross-rs/rust-toolchain /build/${RUST_PROJECT_NAME}/rust-toolchain
COPY nix-cross-rs/nixbuild.sh /build/${RUST_PROJECT_NAME}/nixbuild.sh
COPY nix-cross-rs/shell.nix /build/${RUST_PROJECT_NAME}/shell.nix
# String substitution
RUN sed -i "s/RUST_PROJECT_NAME/${RUST_PROJECT_NAME}/g" /build/${RUST_PROJECT_NAME}/nixbuild.sh
ENTRYPOINT [ "/bin/sh", "-c", "exec /build/${RUST_PROJECT_NAME}/nixbuild.sh" ]