Open aMOPel opened 1 month ago
Do you know if the relatively new fileset lib could work? https://www.tweag.io/blog/2023-11-28-file-sets/
I fixed it now with
{
# ...
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
(pkgs.lib.fileset.fromSource (gitignore.gitignoreSource ./src))
./poetry.lock
./pyproject.toml
./README.md
];
};
}
with gitignore
being https://github.com/hercules-ci/gitignore.nix
, not the nixpkgs gitignore.
I think part of the problem for me was that this repo uses nixpkgs gitignore which (probably) doesn't account for parent directory gitignore and global gitignore, leading to discrepancy of what you think is ignored and what poetry2nix thinks is ignored.
The other part was my ignorance to the fact that things have to be gitignored to not be part of the build.
So the example from above with touch test
would still fail with my solution if it were touch src/test
, if src/test
was not gitignored.
You have to make sure everything that is not supposed to be part of the build is gitignored by the local .gitignore
to get reproducible builds.
IMO this should be documented in the readme.
Could you add a PR to add this info to https://github.com/nix-community/poetry2nix?tab=readme-ov-file#faq?
minimal-setup.tar.gz
Describe the issue
When setting
projectDir
inmkPoetryApplication
, the derivation depends on every file inprojectDir
.It would be better if it just depended on
I believe that would be the intended behavior but it seems the
cleanPythonSources { src = projectDir; }
is not working correctly.Why does it matter?
Because there can be untracked files in the projectDir, like editor files, cache files, etc that cause rebuilds.
minimal example
code mostly copied from the blog post https://www.tweag.io/blog/2020-08-12-poetry2nix/
see attachment or:
minimal setup
`imgapp/__init__.py` ```python from flask import send_file from flask import Flask from io import BytesIO from PIL import Image import requests app = Flask(__name__) IMAGE_URL = "https://farm1.staticflickr.com/422/32287743652_9f69a6e9d9_b.jpg" IMAGE_SIZE = (300, 300) @app.route('/') def hello(): return "Hello World!" @app.route('/image') def image(): r = requests.get(IMAGE_URL) if not r.status_code == 200: raise ValueError(f"Response code was '{r.status_code}'") img_io = BytesIO() img = Image.open(BytesIO(r.content)) img.thumbnail(IMAGE_SIZE) img.save(img_io, 'JPEG', quality=70) img_io.seek(0) return send_file(img_io, mimetype='image/jpeg') def main(): app.run() if __name__ == '__main__': main() ``` `default.nix`: ```nix let sources = import ./nix/sources.nix; pkgs = import sources.nixpkgs { }; poetry2nix = import sources.poetry2nix { inherit pkgs; }; in poetry2nix.mkPoetryApplication { projectDir = ./.; } ``` `pyproject.toml`: ```toml [tool.poetry] name = "imgapp" version = "0.1.0" description = "" authors = ["Your Namenix-build
touch test
nix-build
-> builds again unnecessarily