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

--max-jobs 0 is ignored for preferLocalBuild derivations #1798

Closed
catern opened this issue Jan 13, 2018 · 10 comments
Closed

--max-jobs 0 is ignored for preferLocalBuild derivations #1798

catern opened this issue Jan 13, 2018 · 10 comments
Assignees
Labels
bug cli The old and/or new command line interface stale UX The way in which users interact with Nix. Higher level than UI.

Comments

@catern
Copy link
Contributor

catern commented Jan 13, 2018

The following command:

nix-build -j0 --expr 'derivation { system = builtins.currentSystem; name = "bad"; builder = "false"; preferLocalBuild = true; }'

should not build; rather it should fail with: "error: unable to start any build; either increase ‘--max-jobs’ or enable distributed builds".

Yet it does (try to) build:

catern@sandbox ~ $ nix-build -j0 --expr 'derivation { system = builtins.currentSystem; name = "bad"; builder = "false"; preferLocalBuild = true; }'
these derivations will be built:
  /nix/store/w4smiql512izr7859w62r8dbkp1hvhi1-bad.drv
building path(s) ‘/nix/store/jskp2i1jvnhhgq1ky5vc889ksgai69kk-bad’
while setting up the build environment: executing ‘false’: No such file or directory
builder for ‘/nix/store/w4smiql512izr7859w62r8dbkp1hvhi1-bad.drv’ failed with exit code 1
error: build of ‘/nix/store/w4smiql512izr7859w62r8dbkp1hvhi1-bad.drv’ failed

Among other things, this makes it harder to work around the lack of #1734 because builds will still be carried out when -j0 is passed, rather than forcing either substitution or immediate failure.

@catern
Copy link
Contributor Author

catern commented Jan 13, 2018

I believe this is the culprit:

https://github.com/NixOS/nix/blob/master/src/libstore/build.cc#L1440

    /* Make sure that we are allowed to start a build.  If this
       derivation prefers to be done locally, do it even if
       maxBuildJobs is 0. */
    unsigned int curBuilds = worker.getNrLocalBuilds();
    if (curBuilds >= settings.maxBuildJobs && !(buildLocally && curBuilds == 0)) {

buildLocally is set for preferLocalBuild derivations (as well as when --check or some other args are passed, which also causes the build to happen regardless of -j0).

Is there a reason that local builds should happen even if maxBuildJobs is 0? Can we just remove this escape hatch? I think if the user sets maxBuildJobs to 0, we really should not start any jobs.

@catern
Copy link
Contributor Author

catern commented Jan 14, 2018

I'm using the following workaround:

nix-instantiate --read-write-mode --eval --expr '__storePath [insert_store_path_here]'

This is essentially a hacky way to call ensurePath for that path. ensurePath fails immediately if the path is not valid and cannot be substituted, without trying to build. That's exactly what I want, so this workaround is perfectly functional for me. You can see how I use it in: https://github.com/catern/nix-utils/blob/master/fixedout.py#L53

Nevertheless, I think the original bug here should be fixed. Also, maybe a direct interface should be provided to use ensurePath?

@shlevy shlevy added the backlog label Apr 1, 2018
@shlevy shlevy self-assigned this Apr 1, 2018
@offlinehacker
Copy link
Contributor

This bug pretty annoying especially if you have slow upload, as it first downloads source files locally, and then uploads them to target machine, kinda does not make sense.

@stale
Copy link

stale bot commented Feb 15, 2021

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

@stale stale bot added the stale label Feb 15, 2021
@catern
Copy link
Contributor Author

catern commented Mar 9, 2021

I still care about this.

@stale stale bot removed the stale label Mar 9, 2021
@stale
Copy link

stale bot commented Sep 10, 2021

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

@stale stale bot added the stale label Sep 10, 2021
@catern
Copy link
Contributor Author

catern commented Sep 11, 2021

I still care about this.

@stale stale bot removed the stale label Sep 11, 2021
@maralorn
Copy link
Member

maralorn commented Nov 24, 2021

Good news, @catern: --max-jobs 0 is respected for preferLocalBuild in nix 2.4.

@catern
Copy link
Contributor Author

catern commented Nov 24, 2021

Nice! For me, anyway. I see in #5646 that you don't like this change. My ultimate desire is a way to do #1734 so if we have to give up on a fix for #1798, that would be fine if we can make some progress on #1734.

@stale stale bot added the stale label Aug 12, 2022
@fricklerhandwerk fricklerhandwerk added UX The way in which users interact with Nix. Higher level than UI. cli The old and/or new command line interface bug labels Sep 13, 2022
@tomberek
Copy link
Contributor

This looks resolved in post 2.4, though there is an ongoing discussion if this should be the behavior or not. (see linked issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cli The old and/or new command line interface stale UX The way in which users interact with Nix. Higher level than UI.
Projects
None yet
Development

No branches or pull requests

7 participants