Conversation
|
Closes #412559 |
pluiedev
left a comment
There was a problem hiding this comment.
Welcome to Nixpkgs 💜 Here are some suggestions for your addition:
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
buildRustPackage now supports the finalAttrs pattern too, so using a let-in here shouldn't be necessary
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
Place environment variables inside env
| RUSTC_BOOTSTRAP = 1; | |
| env.RUSTC_BOOTSTRAP = 1; |
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
Should not be necessary for buildRustPackage
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
The mainProgram is not guaranteed to always be the same as the package name, and it's better to spell it out explicitly
| mainProgram = pname; | |
| mainProgram = "pyrefly"; |
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
New uses of with lib; are discouraged as they introduce unclear variable references and scoping rules. Prefix each item under lib explicitly instead
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
Descriptions shouldn't start with an article (see pkgs/README.md)
| description = "A fast type checker and IDE for Python"; | |
| description = "Fast type checker and IDE for Python"; |
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
I think the recommended practice nowadays is to use fetchCargoVendor, and specify patches that add the required lockfile. This has the advantage of not requiring explicit Git hashes in the Nix source file, and would also eliminate the postPatch phase here
There was a problem hiding this comment.
I'm having some trouble with this. Since there's no Nvm, I just read your reply properly...Cargo.lock present in the pyrefly repo (removed in facebook/pyrefly@dfe73ff), I get a FileNotFound error for it. Do I add the Cargo.lock file via a patch?
specify patches that add the required lockfile
my bad. I'll do that
(sorry, I have never touched or even been near Rust, let alone in combination with Nix 😓 so a bit unfamiliar)
There was a problem hiding this comment.
Hmm... I tried this to generate a .patch file (not sure how else to do it if there's an easier way):
- fork
facebook/pyrefly - create new branch in fork
- generate
Cargo.lockand add it where needed - make PR
- add
.patchto end of URL: https://github.com/cybardev/pyrefly/pull/1.patch - download the
.patchfile generated by GitHub
But it still shows Cargo.lock is missing (I did stage my .patch file in the local repo):
error.txt
Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/hdwyx26pi61g77cg9r60gznc39gyrbz0-source
source root is source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
Traceback (most recent call last):
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 349, in <module>
main()
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 345, in main
subcommand_func()
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 336, in <lambda>
"create-vendor-staging": lambda: create_vendor_staging(lockfile_path=Path(sys.argv[2]), out_dir=Path(sys.argv[3])),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 127, in create_vendor_staging
cargo_lock_toml = load_toml(lockfile_path)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 23, in load_toml
with open(path, "rb") as f:
^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'Cargo.lock'
There was a problem hiding this comment.
For context, here's my current code:
- working: https://github.com/cybardev/nix-channel/blob/691d808e/pkgs/pyrefly/package.nix
- failing: https://github.com/cybardev/nix-channel/blob/697b0bd6/pkgs/pyrefly/package.nix
Failing is not because of empty hash. It fails with the previously posted error (not finding Cargo.lock) and does not get to the stage of failing while outputting the correct hash.
It also seems way more convenient to just generate and add the lock file instead of a patch. Not sure how much of a "bad practice" that is considered... Just thinking about having to update the patch every new update. 😓
There was a problem hiding this comment.
Well that's how it is unfortunately until upstream decides to commit lockfiles again 🤷♀️
There was a problem hiding this comment.
There was a problem hiding this comment.
Well that's how it is unfortunately until upstream decides to commit lockfiles again
Submitted an issue. What are they doing?? Why? They had to go out of their way to not commit the Cargo.lock...
There was a problem hiding this comment.
They fixed it. Apparently they are using their own in-house build system to do this, which does not generate the lockfile. I find this very strange as usually any cargo command that fetches the dependencies creates the lockfile, but ok. But now at least cargoHash should just work...
There was a problem hiding this comment.
Buck does generate a lockfile but they chose not to commit it before. But yeah, next update will be much better without all the Python/Maturin bloat.
There was a problem hiding this comment.
@dtomvan Actually there's still issues... See facebook/pyrefly#432 (comment)
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
Use tag for tagged releases and rev only for commit hashes
| rev = version; | |
| tag = version; |
|
@QuiNzX shared this code that uses
|
|
Interesting. I didn't know that the PyPI version has the lockfile - that is a very peculiar choice IMO. (We normally prefer packaging software directly from source, but I guess we can make an exception for this one.) I think the Python stuff is mainly for using Pyrefly as a wheel (Python library)? I'm not sure how, but it does appear to be something upstream supports. In that case, then I think it's fair to build this as a Python + Maturin package instead. |
|
Ok, sorry, I saw your message after the rebase push... I will do the Python version then. |
|
Also if we were to support the case of using Pyrefly as a library, then we should move the main derivation to {
python3Packages
}:
python3Packages.toPythonApplication python3Packages.pyreflySee the Nixpkgs manual for more detailed reasoning as to why we want to do this |
|
I can check with upstream but from what I understand it cannot be used like a Python library. That is, it is |
|
Oh yeah, then leave it in |
7edb455 to
2ce7b8a
Compare
|
I think I've ironed out the issues. Let me know if there's anything to change. Thanks for the review and help. 🙂 |
pluiedev
left a comment
There was a problem hiding this comment.
This is looking very, very good. Just one last stretch!
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
format is deprecated, actually 😅
| format = "pyproject"; | |
| pyproject = true; |
There was a problem hiding this comment.
I think pyproject = true; an indirect default nowadays. You can safely remove it. It causes a rebuild, and it has a different output. But with --check I found out that the build isn't reproducible anyways:
error: derivation '/nix/store/pcinwg72q15sykpq7jc6pi8psh3sck2a-pyrefly-0.17.1.drv' may not be deterministic: output '/nix/store/a8w3n650dwvv0qiwly397wf7fq9m49dd-pyrefly-0.17.1-dist' differs
But diffoscope with-pyproject-true without-pyproject-true only reports differences in the python bytecode, the pyrefly binary, and lib/python3.12/site-packages/pyrefly-0.17.1.dist-info/RECORD, where the latter contains a sha256sum of the pyrefly binary so that doesn't really count. The new output still works though.
Diffoscope (pyproject set/unset): diff.html.gz
Diffoscope (pyproject unset, two builds): diff.html.gz
5cd9812 to
37d02cd
Compare
|
Add another commit adding them as a maintainer, and then rebase the main commit on top of that I think |
|
I think I got it right? Let me know if this is ok or changes are needed. Thanks. (apologies, I have not used Git to this extent before 😓) |
pluiedev
left a comment
There was a problem hiding this comment.
Excellent. Thank you so much!
|
Thanks for the reviews, help, and guidance. 😊 |
pkgs/by-name/py/pyrefly/package.nix
Outdated
There was a problem hiding this comment.
I think it's normally nativeCheckInputs for Python packages
Co-authored-by: QuiNzX <[email protected]>
|
I am so sorry. I must've been mistaken. I was wrong about
It will definitely work when unset, so it doesn't entirely matter. But apparently the best practice isn't to only set it when needed, it should almost always be set, but it just isn't a default yet. They did set a Sorry for the confusion and the extra work, was just trying to do a thorough review, but I kinda achieved the opposite of what I wanted. I am new here, so I still make a bunch of mistakes. That being said, I see no reason why this could not get merged in its current state. The behaviour is the same whether it's set or not, because it's using maturin anyways, so it doesn't reach the setuptools fallback codepath. |
|
|
After locally verifying it works, I added |
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.