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

Dummy source derivation relying on source when using flake's self argument as source #28

Closed
winterqt opened this issue May 14, 2022 · 3 comments · Fixed by #32
Closed
Labels
bug Something isn't working

Comments

@winterqt
Copy link

winterqt commented May 14, 2022

When using self over ./. for the source to buildPackage, the dummy source derivation relies on the source of the flake.

Good:

    "inputSrcs": [
      "/nix/store/xxx-default-builder.sh",
      "/nix/store/xxx-Cargo.lock"
    ],
    "inputDrvs": {
      "/nix/store/xxx-dummy.rs.drv": [
        "out"
      ],
      "/nix/store/xxx-Cargo.toml.drv": [
        "out"
      ],
      "/nix/store/xxx-stdenv-darwin.drv": [
        "out"
      ],
      "/nix/store/xxx-bash-5.1-p16.drv": [
        "out"
      ]
    },

Bad:

    "inputSrcs": [
      "/nix/store/xxx-default-builder.sh",
      "/nix/store/xxx-source"
    ],
    "inputDrvs": {
      "/nix/store/xxx-bash-5.1-p16.drv": [
        "out"
      ],
      "/nix/store/xxx-stdenv-linux.drv": [
        "out"
      ],
      "/nix/store/xxx-Cargo.toml.drv": [
        "out"
      ],
      "/nix/store/xxx-dummy.rs.drv": [
        "out"
      ]
    },

A reproduction is available at https://github.com/winterqt/crane-dummy-src-invalidation. This may be outside of Crane's control (as in, this may be an issue with how this attribute of flakes are implemented).

@winterqt winterqt changed the title Dummy source derivation relying on source Dummy source derivation relying on source when using flake's self argument as source May 14, 2022
@ipetkov
Copy link
Owner

ipetkov commented May 14, 2022

Hi @winterqt thanks for the reproduction flake! I was able to reproduce the issue and here are some of my observations:

Normally I stick my actual rust/cargo files in their own directory and then do craneLib.buildPackage { src = ./mycrate; } because I explicitly do not want changes to the flake (or other nix files) to needlessly invalidate any builds (namely the second build of the actual crate). Changing your flake to this pattern seems to resolve the issue (that is, changing the main.rs file only rebuilds the final derivation; without the change, changing the main.rs file leads to the dependencies being rebuilt as well).


The source dummification tries to only copy the exact files needed (example) in an attempt to make sure that the dummy-src derivation only depends on things like Cargo.{toml,lock} files and not the rest of the flake source.

I don't know if there is some different kinds of interactions (i.e. source cleaning) that Nix does under the hood when a derivation's input is a sub-directory of the flake vs taking the entire flake source itself. Either way, this is undesired behavior and it would be good to find a way to avoid it (maybe an explicit cleanSources call is needed? will need to investigate it further)

@ipetkov
Copy link
Owner

ipetkov commented May 15, 2022

Did a quick proof of concept of cleaning the source directory (to exclude anything we don't need for making the dummy source) and it appears to fix the cache invalidation bug. Will post a PR sometime later!

@ipetkov
Copy link
Owner

ipetkov commented May 29, 2022

@winterqt I believe this is fixed now, please feel free to open an issue if you run into anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants