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

Fix Python tests #236

Merged
merged 6 commits into from
Jun 17, 2024
Merged

Fix Python tests #236

merged 6 commits into from
Jun 17, 2024

Conversation

jaen
Copy link
Contributor

@jaen jaen commented May 24, 2024

Makes pytest . ran from nix develop pass.

Fixing the formatter issue mentioned in #235 required updating the repo tool to the newest version. Since mk_repo_file uses a fork that adds additional commands to dump repo information, I have rebased it on top of the upstream v2.45 (see jaen/tools_repo#1 for diff). Not sure where do we want to put this, though.

Copy link
Contributor

@Atemu Atemu left a comment

Choose a reason for hiding this comment

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

The rest LGTM

flavors/lineageos/test_lineageos_updater.py Outdated Show resolved Hide resolved
Comment on lines 24 to 25
"--repo-url=https://github.com/danielfullmer/tools_repo",
"--repo-rev=9ecb9713ee5adba95120acbc0bfef1c77b02637f",
"--repo-url=https://github.com/jaen/tools_repo",
"--repo-rev=dca531f6d6e9fdcf00aa9d18f0153bd66a2e32ea",
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably just turn this into a plain old patch simply apply it to the regular gitRepo drv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds reasonable,I'll try implementing it like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out that doesn't help much, because the regular gitRepo derivation is basically just a launcher (c.f. https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/version-management/git-repo/default.nix#L32) that will then download the missing code from the interwebs (c.f. https://github.com/jaen/tools_repo/blob/main/repo#L669-L674). While it would be nice to make it reproducible, I'd say it's maybe out of scope for a simple test fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did overlay v2.45 in pkgs, though. Not sure if there's any downside to those versions not being the same, but might as well have them match.

freetype # Needed by jdk9 prebuilt
fontconfig

# Goldfish doesn't need py2 anymore in Android 12+!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay not 100% sure how to trace this commit to Android version, but I think that's right

@jaen
Copy link
Contributor Author

jaen commented May 25, 2024

FWIW I have successfully built the following ROM on this branch:

nix-build --arg configuration '{ device="lemonade"; flavor="lineageos"; androidVersion=13; apps.chromium.enable = false; webview.prebuilt.enable = false; webview.chromium.enable = false; webview.chromium.availableByDefault = false; }' -A factoryImg

Can't test it, because it's not my phone, but at least something builds.

@Atemu
Copy link
Contributor

Atemu commented May 25, 2024

Please note that the files you touched don't really influence build results very much but rather generating the sources.

@jaen
Copy link
Contributor Author

jaen commented May 25, 2024

@Atemu I would think envpackage.nix and release.nix would have some influence on the build (having it potentially fail due to wrong Python version)? Which is why I figured building a ROM might make sense? But I don't know a lot about AOSP builds, so might've misunderstood something.

I have also just now modified the repo tool derivation to provide local sources, patched for repo2nix, like you asked for — it's kind of ugly, but at least doesn't require referencing my GitHub repo.

I ran update scripts for GrapheneOS (used ./update.sh SP2A.220405.004.2022041600, files were identical) and for LineageOS (use ./update.sh lineage-20.0 files differed by timestamps and hashes, it also later failed because this repo does not exist: https://github.com/LineageOS/android_device_walmart_dopinder) and it seems to work.

@jaen
Copy link
Contributor Author

jaen commented May 26, 2024

Re: above — added flake-compat to the flake and added a common entry-point for it, as I noticed later there were to places that used it (and I updated only one). It should be a bit more maintainable that way, hope you don't mind.

@jaen jaen force-pushed the fix-python-tests branch 4 times, most recently from 5991c71 to c21880a Compare May 26, 2024 13:01
pkgs/gitRepo/default.nix Outdated Show resolved Hide resolved
pkgs/gitRepo/default.nix Outdated Show resolved Hide resolved
pkgs/gitRepo/00001-add-support-for-repo2nix.patch Outdated Show resolved Hide resolved
Comment on lines 34 to 37
prefix = os.getenv('NIX_REMOTE');
prefix = os.getenv('NIX_REMOTE')
if prefix and not prefix.startswith('/'):
raise Exception('Must be run on a local Nix store.')
return f"{prefix}/{path}"
return os.path.join(*filter(None, [prefix, path]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, can you explain why? I've done it like this, so this function doesn't inadvertently turn a relative path to an absolute one rooted at /. Is doing that a desired behaviour of this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

This function's purpose is to turn a nix store path to an absolute path that can be opened on the filesystem.

I've rewritten it, could you take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems reasonable; I'll re-test it locally just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, after testing I'm kind of confused on what exactly NIX_REMOTE is. Nix itself seems to have that parameter (https://nix.dev/manual/nix/2.22/command-ref/env-common#env-NIX_REMOTE) but it doesn't seem to be that (because it's supposed to be a daemon socket).

From the context it looks like a mountpoint for some alternate store — but also not quite. When I added some logging to the code I get paths like /nix/store/deadbeef-hudson, and if you relativise them to root, you'll end up with paths like /your/prefix/nix/store/deadbeef-hudson which makes it not a store path IMO, I'd rather expect /your/prefix/deadbeef-hudson in this case, as if you specified NIX_STORE_DIR (https://nix.dev/manual/nix/2.22/command-ref/env-common#env-NIX_STORE_DIR) with that value.

But this is a bit of a documentation issue, I guess. I proposed a bit improved implementation in a separate commit — it leaves the path untouched if NIX_REMOTE is not set, otherwise it does the same logic but with pathlib which makes it a bit cleaner, as you don't have to worry about . not being resolved or knowing what is the root path to relativise the store path against.

Copy link
Contributor

Choose a reason for hiding this comment

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

NIX_REMOTE specifies a "remote" nix store. It's the equivalent of the --store flag.

If you set it to a local path, nix would then use the nix store under that prefix but it does not change the NIX_STORE_DIR. Build sandboxes are mounted such that the paths are available under /nix/.
You can't directly run software off of such a store without a chroot but that's of little relevance for my robotnix builds.
The reason I use this is to store the 60GB+ build-time closure and hundreds of prefetched source dirs in a separate Nix store to my system's because I don't want to trash it. I explicitly do not want the NIX_STORE_DIR to change here.

(You can also point it at another machine via ssh in which case it builds on the remote machine but that doesn't work for the updater.)

In the updater, we need to be able to access the lineage.dependencies file in a fetched repo and to do that while NIX_REMOTE points at some other location on the filesystem, you need this function. The returned string is not a store path but an absolute path that you can simply open and read.

Thanks for the pathlib patch, that looks a lot more robust. I don't have any experience with python to speak of, so this is much appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I did roughly understand what this function is for and it's a reasonable thing to want — I just wasn't sure what exactly it represents in terms of nix config/options/envvars (since nothing seemed to naively match it) and as such what I should expect the correct behaviour to be when testing it.

But it makes a lot more sense now that you explained what it's supposed to represent in terms of nix options/behaviour and I guess it actually indeed is NIX_REMOTE as described here, it's just that the description in the manual doesn't really make it clear that all values from this list are valid and your explanation clarified that.

@Atemu
Copy link
Contributor

Atemu commented Jun 5, 2024

I'm currently cleaning this up a little and will force push your branch in a bit, just FYI.

@Atemu Atemu force-pushed the fix-python-tests branch 2 times, most recently from 0926f07 to adf0c0e Compare June 5, 2024 09:50
pkgs/default.nix Outdated Show resolved Hide resolved
jaen added 6 commits June 17, 2024 18:08
It wouldn't work without NIX_REMOTE set before. This is a lot more robust now.
Suggested-by: Atemu <atemu.main@gmail.com>
Reviewed-by: Atemu <atemu.main@gmail.com>
The `repo` tool derivation by default includes only the main wrapper script
which fetches the actual tool sources from the internet. We modify the
derivation to provide default local sources patched with support for repo2nix,
unless specified otherwise with CLI parameters.

Flake compat was updated and nixpkgs-unstable re-introduced to facilitate this
change.
@Atemu Atemu merged commit f079afb into nix-community:master Jun 17, 2024
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.

None yet

2 participants