Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Build bunq2ynab image with nix and Bazel #544

Merged
merged 92 commits into from
Oct 30, 2023

Conversation

mvgijssel
Copy link
Member

@mvgijssel mvgijssel commented Sep 21, 2023

ref #451

History trying to get nix to work inside BuildBuddy

error: getting status of '/home/buildbuddy/workspace/output-base/external/raw_python38_base_image/bazel-support/nix-out-link': No such file or directory

TODO:

How the end result macro should look:

py_image(
  name = "bunq2ynab_image",
  binary = ":bunq2ynab",
  base = "@raw_python38_base_image//:image",
)

The py_image rule will wrap the binary with a task which sets the target_platforms flag to containerized to make sure we are not copying in the hermetic interpreter.

@mvgijssel
Copy link
Member Author

Steps to setup on macOS. Following the documentation from https://nixos.org/manual/nixpkgs/stable/#chap-special

  1. Run linux builder machine using nix run --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#darwin.linux-builder

  2. Setup /etc/nix/nix.conf with the following

build-users-group = nixbld
builders = ssh://builder@localhost aarch64-linux /etc/nix/builder_ed25519 4
  1. Update /var/root/.ssh/config with
Host localhost
  User builder
  HostName 127.0.0.1
  Port 31022
  IdentityFile /etc/nix/builder_ed25519
  1. Restart the nix-daemon
sudo launchctl kickstart -k system/org.nixos.nix-daemon

@mvgijssel
Copy link
Member Author

Copied an example from https://github.com/jvolkman/bazel-nix-example/tree/134e5c9d66b7e3baa0f29ce049bf27d9794f352b. It kinda works, if I modify the app.binary inside the docker image to point to the right python executable (instead of using the embedded one).

Let's try if we can make this work with rules_oci

@mvgijssel
Copy link
Member Author

@mvgijssel
Copy link
Member Author

Now running into an issue with wheels

bash-5.2# /opt/tools/bunq2ynab/bunq2ynab
/config.json
Traceback (most recent call last):
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/bunq2ynab/bunq2ynab.py", line 1, in <module>
    from lib.sync import Sync
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/bunq2ynab/lib/sync.py", line 5, in <module>
    from lib import bunq_api
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/bunq2ynab/lib/bunq_api.py", line 1, in <module>
    from lib import bunq
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/bunq2ynab/lib/bunq.py", line 2, in <module>
    from OpenSSL import crypto
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/rules_python~0.25.0~pip~pip-setup_310_pyopenssl/site-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import SSL, crypto
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/rules_python~0.25.0~pip~pip-setup_310_pyopenssl/site-packages/OpenSSL/SSL.py", line 9, in <module>
    from OpenSSL._util import (
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/rules_python~0.25.0~pip~pip-setup_310_pyopenssl/site-packages/OpenSSL/_util.py", line 6, in <module>
    from cryptography.hazmat.bindings.openssl.binding import Binding
  File "/opt/tools/bunq2ynab/bunq2ynab.runfiles/rules_python~0.25.0~pip~pip-setup_310_cryptography/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 15, in <module>
    from cryptography.hazmat.bindings._rust import _openssl, openssl
ImportError: /opt/tools/bunq2ynab/bunq2ynab.runfiles/rules_python~0.25.0~pip~pip-setup_310_cryptography/site-packages/cryptography/hazmat/bindings/_rust.abi3.so: invalid ELF header

As mentioned here pyca/cryptography#6378 (comment) this might be because the wrong wheel files are downloaded by Bazel or that the nix base image is missing necessary files. The latter would also explain why the hermetic interpreter wouldn't run in the first place 🤔

@mvgijssel mvgijssel mentioned this pull request Oct 30, 2023
17 tasks
@mvgijssel mvgijssel enabled auto-merge (squash) October 30, 2023 11:06
@mvgijssel mvgijssel merged commit 65fa40b into master Oct 30, 2023
3 checks passed
@mvgijssel mvgijssel deleted the mg/451/try-building-docker-with-nix branch October 30, 2023 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant