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

types: Fix path.check for cleanSourceWith output #64691

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hamishmack
Copy link
Contributor

Advantage of cleanSourceWith is that it composes without copying intermediate output to the store. Currently using path.check breaks this. Consider:

let cleanedSource1 = cleanSourceWith { src = ./.; filter = filter1; };
in
  assert (path.check cleanedSource1);
  cleanSourceWith { src = cleanedSource1; filter = filter2; }

Currently this will copy all the files that pass filter1 to the store in order to check that the resulting path starts with "/".

Luckily cleanSourceWith exposes a origSrc property that we can check.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Advantage of `cleanSourceWith` is that it composes without copying intermediate output to the store.  Currently using `path.check` breaks this.  Consider:

```nix
let cleanedSource1 = cleanSourceWith { src = ./.; filter = filter1; };
in
  assert (path.check cleanedSource1);
  cleanSourceWith { src = cleanedSource1; filter = filter2; }
```

Currently this will copy all the files that pass filter1 to the store in order to check that the resulting path starts with "/".

Luckily `cleanSourceWith` exposes a `origSrc` property that we can check.
@roberth
Copy link
Member

roberth commented Sep 2, 2019

Alternatively one may call toString x or check x.outPath.
Multiple definitions are possible. Seems like we need to survey its usage in Nixpkgs before we can decide what's best.

@hamishmack
Copy link
Contributor Author

toString x is what path.check does now. The problem with toString x and x.outPath is that they force everything that is not yet filtered to be copied to the store. The second call to cleanSourceWith still works correctly, but it is too late to prevent the files we are filtering from being copied to the store by path.check.

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 3, 2020
@stale
Copy link

stale bot commented Jun 5, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 5, 2021
@L-as
Copy link
Member

L-as commented Sep 22, 2022

Is this still needed?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 22, 2022
@@ -243,7 +243,7 @@ rec {
path = mkOptionType {
name = "path";
# Hacky: there is no ‘isPath’ primop.
check = x: builtins.substring 0 1 (toString x) == "/";
check = x: builtins.substring 0 1 (toString (x.origSrc or x)) == "/";
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps something like this, for a more general and decoupled solution. Needs a new attr in cleanSource and friends.

Suggested change
check = x: builtins.substring 0 1 (toString (x.origSrc or x)) == "/";
check = x: x._isPath or builtins.substring 0 1 (toString x) == "/";

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@wegank wegank marked this pull request as draft March 20, 2024 15:13
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 0 10.rebuild-linux: 0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants