Skip to content

Instantly share code, notes, and snippets.

@ento
Last active April 30, 2023 04:19
Show Gist options
  • Select an option

  • Save ento/641ad9dd18db0fabd4fca1a3dfd78efb to your computer and use it in GitHub Desktop.

Select an option

Save ento/641ad9dd18db0fabd4fca1a3dfd78efb to your computer and use it in GitHub Desktop.

Revisions

  1. ento revised this gist Apr 30, 2023. No changes.
  2. ento created this gist Apr 30, 2023.
    26 changes: 26 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    FROM nixos/nix:latest AS builder

    RUN nix-env --install jq

    COPY . /tmp/build
    WORKDIR /tmp/build

    RUN drvpath=$(nix --extra-experimental-features "nix-command flakes" derivation show | jq -r 'to_entries[0] | .key') \
    && echo $drvpath is the path \
    && closure=$(nix-store --query --requisites $drvpath | grep -v -F $drvpath) \
    && nix-store -r $closure
    RUN nix \
    --extra-experimental-features "nix-command flakes" \
    --option filter-syscalls false \
    build

    RUN mkdir /tmp/nix-store-closure
    RUN cp -R $(nix-store -qR result/) /tmp/nix-store-closure

    FROM scratch

    WORKDIR /app

    COPY --from=builder /tmp/nix-store-closure /nix/store
    COPY --from=builder /tmp/build/result /app
    CMD ["/app/bin/app"]