SeedSigner / seedsigner

Use an air-gapped Raspberry Pi Zero to sign for Bitcoin transactions! (and do other cool stuff)
MIT License
699 stars 161 forks source link

[DRAFT] Nix flake with ss emulator (to get `nix develop` to work) #556

Open VzxPLnHqr opened 4 months ago

VzxPLnHqr commented 4 months ago

Description

This is an attempt to get a Nix flake working with the seedsigner repository and upstreaming the seedsigner-emulator.

The Goal

# clone seedsigner repo
$ cd seedsigner
$ nix develop
# now you are in a bash shell with all the dependencies you need to make changes to seedsigner
# and you can run the emulator to test those changes by simply:
$ python3 src/main.py

Strategy

This pull request is categorized as a:

Checklist

If you modified or added functionality/workflow, did you add new unit tests?

I have tested this PR on the following platforms/os:

Note: Keep your changes limited in scope; if you uncover other issues or improvements along the way, ideally submit those as a separate PR. The more complicated the PR the harder to review, test, and merge.

VzxPLnHqr commented 4 months ago

Unfortunately I currently do not know enough python nor the specifics of the seedsigner (and emulator) project code to figure out how to diagnose the following.

$ nix develop
$ python3 --version
Python 3.11.9
$ python3 src/main.py
Traceback (most recent call last):
  File "seedsigner/src/main.py", line 1, in <module>
    from seedsigner.controller import Controller
  File "seedsigner/src/seedsigner/controller.py", line 16, in <module>
    from seedsigner.views.screensaver import ScreensaverScreen
  File "seedsigner/src/seedsigner/views/__init__.py", line 1, in <module>
    from .view import *  # base class has to be first
    ^^^^^^^^^^^^^^^^^^^
  File "seedsigner/src/seedsigner/views/view.py", line 309, in <module>
    @dataclass
     ^^^^^^^^^
  File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/dataclasses.py", line 1232, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/dataclasses.py", line 1222, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'seedsigner.views.view.Destination'> for field next_destination is not allowed: use default_factory
VzxPLnHqr commented 4 months ago

with latest commit (ad55919) , emulator now loads up when running $ python3 main.py. Need to fix the camera though:

barcodes = pyzbar.decode(image, symbols=[ZBarSymbol.QRCODE], binary=is_binary)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: decode() got an unexpected keyword argument 'binary'
Appending next destination: UnhandledExceptionView({'error': ['TypeError', 'decode_qr.py, 316, in extract_qr_data', " decode() got an unexpected keyword argument 'binary'"]}) | clear_history: True
------------------------------
back_stack: [
     0: UnhandledExceptionView({'error': ['TypeError', 'decode_qr.py, 316, in extract_qr_data', " decode() got an unexpected keyword argument 'binary'"]}) | clear_history: True
]
Executing UnhandledExceptionView({'error': ['TypeError', 'decode_qr.py, 316, in extract_qr_data', " decode() got an unexpected keyword argument 'binary'"]}) | clear_history: True
VzxPLnHqr commented 4 months ago

Ok, with (675bd9b), the camera now works! This needs a bunch of refactoring, but we are getting closer to having a nice nix develop workflow for simple PRs or for custom code people may want to run on SS.

kdmukai commented 1 month ago

@VzxPLnHqr can you change this PR to "DRAFT" until it's finished?

VzxPLnHqr commented 1 month ago

@VzxPLnHqr can you change this PR to "DRAFT" until it's finished?

Yes, I changed it to DRAFT now. I am not sure when I will be able to finish it. Any idea if the emulator will be upstreamed? If so and SS can independently determine whether it is running inside the emulator or whether it is running on bare metal and behave accordingly, then it feels like this feature (making nix develop work) would be nice to have and lower the barrier to entry for future contributors.