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

Nix dev shell #2166

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

fidgetingbits
Copy link
Contributor

@fidgetingbits fidgetingbits commented May 13, 2024

NOTE: This is a stacked PR based on #2165

This adds a nix development shell, which can be entered using nix develop or direnv allow (via the added .envrc file).

It breaks out the poetry derivation into a new file so it can be re-used by the regular pwndbg build and the devshell. It also makes it so the development options can be used by the development environment, without any manual changes.

In order to build a version of gdbinit.py that works for testing so it automatically picks up the pi project dev dependencies, you have to nix build .#pwndbg-dev. The development shell itself will automatically get those so running certain python scripts manually will work already. If one of the nix people has a better idea how todo this I'm open to suggestions.

Finally it modifies the way the pwndbg command is invoked to use an auto-patched gdbinit.py, which also allows for gdbinit.py to be lazy loaded on nix and still have access to the correct python environment. This is useful both for when you need it, and also because there is at least one test script that explicitly loads gdbinit.py.

I have future modifications for making the tests work, which will come in a separate PR.

@fidgetingbits fidgetingbits force-pushed the nix-dev-shell branch 2 times, most recently from bea588f to d4e4246 Compare May 13, 2024 07:17
@disconnect3d
Copy link
Member

@patryk4815 @arcz can you folks review this PR?

nix/pwndbg.nix Outdated Show resolved Hide resolved
nix/pwndbg.nix Outdated Show resolved Hide resolved
nix/portable.nix Outdated Show resolved Hide resolved
# I purposely use insert() so I can re-import during development without having to restart gdb
sed "2 i import sys, os\n\
sys.path.insert(0, '${pyEnv}/${pyEnv.sitePackages}')\n\
sys.path.insert(0, '$out/share/pwndbg/')\n\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys.path.insert(0, '$out/share/pwndbg/')
🤔 why is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyEnv only provides the dependencies of pwndbg, whereas for gdbinit.py to import pwndbg, it needs to import from share/pwndbg/ as that is where the pwndbg python module is installed to.

This is without that line:

(gdb) source result/pwndbg/share/gdbinit.py
result/pwndbg/share/gdbinit.py: No such file or directory.
(gdb) source result/share/pwndbg/gdbinit.py
Traceback (most recent call last):
  File "result/share/pwndbg/gdbinit.py", line 65, in <module>
    import pwndbg  # noqa: F401
    ^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pwndbg'

If there's some better way, happy to change it.

Reminds me even though pwndbg.nix links the .venv/ folder, there is no activation script created by the poetry derivation in .venv/bin/. Is anyone actually using the venv on nix? Since it won't include pwndbg (as it only links the poetry sitePackages) I think it might not work? Maybe I'm missing something.

@fidgetingbits
Copy link
Contributor Author

#2120 broke this PR, because it added a new development dependency sortedcontainers-stubs. But I will update it shortly. Tested with

      sortedcontainers-stubs = super.sortedcontainers-stubs.overridePythonAttrs (old: {
        buildInputs = (old.buildInputs or [ ]) ++ [ super.poetry-core ];
      });

and seems to be working...

It might be worth eventually having a CI workflow for building the nix development environment that at least warns when it breaks (but may be not fail a merge, since it's not something most people will be using)

@fidgetingbits
Copy link
Contributor Author

happy to squash these commits before this goes in if needed, but keeping them for now because of the review discussion

@gsingh93
Copy link
Member

#2165 was merged, this needs a rebase now.

@fidgetingbits
Copy link
Contributor Author

should be rebased now

@disconnect3d
Copy link
Member

I think the failing qemu test is unrelated, isn't it?

@patryk4815 anything else to be done here or do u think we can merge it?

@fidgetingbits
Copy link
Contributor Author

I think the failing qemu test is unrelated, isn't it?

@patryk4815 anything else to be done here or do u think we can merge it?

Ya, I don't see how that qemu test would be related of hand...

@fidgetingbits
Copy link
Contributor Author

Noticed a bug where ZIGPATH was set to the wrong version, so just fixed that.

@disconnect3d
Copy link
Member

@fidgetingbits needs fixing a conflict in gitignore :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants