Skip to content

treewide: Modular setup hooks - #40139

Merged
Ericson2314 merged 3 commits into
NixOS:stagingfrom
obsidiansystems:modular-setup-hooks
May 7, 2018
Merged

Ericson2314 merged 3 commits into
NixOS:stagingfrom
obsidiansystems:modular-setup-hooks

Conversation

@Ericson2314

@Ericson2314 Ericson2314 commented May 7, 2018 •

Copy link
Copy Markdown
Member
Motivation for this change

It's error prone to copy paste this "role" stuff everywhere. Also, the more similar the *-wrappers are, the easier it will be add a pkgconfig-wrapper as @bgamari once mentioned needing. Also some of the env hooks should just be setup hooks (setup hooks directly rather than setup hooks that define env hooks).

I don't really like this setupHooks bloat, but after #31414 we can just make these helper setup hooks dependencies, which will work fine. I'd have loved to land that PR first, but fixing it requires #26004 which would be easier (but still hard) with this, so I do this stop-gap first.

Fixes #40046

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So were addEnvHooks ever needed here? I was not really sure what they were doing but it was used in many places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope! and env hook does something per dependency. It's a way to accumulate a bunch of things which are for-eached at the end. Basically, If your hook doesn't use $1, it shouldn't be an env hook.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is making these bash scripts? I know we have in the past assumed bash - but it seemed nice to make these in theory work on non-Bash shells.

@Ericson2314 Ericson2314 May 7, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Virtually all our stuff is bash-only. Given we're not on MS-DOS with max-3 file extensions, I figure it's best to be honest on use .bash not .sh :D. More seriously, editors highlight better with .bash: emacs will at least check the shebang, but many of these hook files don't have one.

Also fix some setup hooks that unnecessarily used environment hooks,
which revolted in the same variable being modified too many times.
@Ericson2314
Ericson2314 force-pushed the modular-setup-hooks branch from ba95564 to 8b0fce8 Compare May 7, 2018 19:11
@matthewbauer

Copy link
Copy Markdown
Member

Fixes #40134

I think you have the wrong number there.

@Ericson2314

Copy link
Copy Markdown
Member Author

fixed: #40046

@GrahamcOfBorg GrahamcOfBorg added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels May 7, 2018

setupHooks = [
../setup-hooks/role.bash
./setup-hook.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we just source this in the setup-hook.sh? That would mean we shouldn't need to add the setupHooks logic (yet).

@Ericson2314 Ericson2314 May 7, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@matthewbauer well it still needs to be part of the derivation closure which means extra hoops anyways.

@Ericson2314
Ericson2314 merged commit 4f7cdd3 into NixOS:staging May 7, 2018
@Ericson2314
Ericson2314 deleted the modular-setup-hooks branch May 7, 2018 19:32
@matthewbauer

Copy link
Copy Markdown
Member

Awesome work!

@GrahamcOfBorg

Copy link
Copy Markdown

Success on x86_64-linux (full log)

Attempted: stdenv

Partial log (click to expand)

shrinking /nix/store/f07sgxxhq5ysc92gy0yd48ibv276fick-findutils-4.6.0/libexec/code
shrinking /nix/store/f07sgxxhq5ysc92gy0yd48ibv276fick-findutils-4.6.0/libexec/bigram
gzipping man pages under /nix/store/f07sgxxhq5ysc92gy0yd48ibv276fick-findutils-4.6.0/share/man/
strip is /nix/store/d1prcspbh2qsviipvnaxizcj8l3g7fpw-bootstrap-tools/bin/strip
stripping (with command strip and flags -S) in /nix/store/f07sgxxhq5ysc92gy0yd48ibv276fick-findutils-4.6.0/libexec  /nix/store/f07sgxxhq5ysc92gy0yd48ibv276fick-findutils-4.6.0/bin
checking for references to /build in /nix/store/f07sgxxhq5ysc92gy0yd48ibv276fick-findutils-4.6.0...
shrinking RPATHs of ELF executables and libraries in /nix/store/mmrpfl978dnl5msc5jrx25xp0yxs98n1-findutils-4.6.0-info
strip is /nix/store/d1prcspbh2qsviipvnaxizcj8l3g7fpw-bootstrap-tools/bin/strip
checking for references to /build in /nix/store/mmrpfl978dnl5msc5jrx25xp0yxs98n1-findutils-4.6.0-info...
building '/nix/store/sy38sm75r6zgai3lsmhsf355wzh52d9p-stdenv-linux.drv'...

@matthewbauer

Copy link
Copy Markdown
Member

Also might want to look to see if this fixes #40013. We also have a hack for inkscape having long args in a276d51...047c937 that may no longer be needed.

@GrahamcOfBorg

Copy link
Copy Markdown

Failure on x86_64-darwin (full log)

Attempted: stdenv

Partial log (click to expand)

cannot build derivation '/nix/store/190nn5mlssm8z0jvclig2a2621smbcw2-cctools-port-895.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/wnsn4fjdq23bymqxwrp9prkys51wfrm2-hook.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/48kf92ls06827dcmni2adsiy7bbmyid9-ICU-osx-10.10.5.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/zfkxsb39m9fcbqni4s6q3a6g6rms6dav-cctools-binutils-darwin.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/ag6s2phnm5j915fpb0nmllj6j1wg2bxb-gnutar-1.30.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/h78rrv2yn2f8b3956adg1bzspsa2ka1q-CF-osx-10.10.5.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/lz3bhkvdyjf35l798cdinnp9zl7dwmw9-cctools-binutils-darwin-wrapper.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/9bxrk07qamgjzzfql9zpkgvpfijza43f-clang-wrapper-5.0.2.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/vjlrnb63rmf4x97c90k79h43vj97cmfz-stdenv-darwin.drv': 35 dependencies couldn't be built
error: build of '/nix/store/vjlrnb63rmf4x97c90k79h43vj97cmfz-stdenv-darwin.drv' failed

@GrahamcOfBorg

Copy link
Copy Markdown

Success on aarch64-linux (full log)

Attempted: stdenv

Partial log (click to expand)

shrinking /nix/store/zic2s2k09xbp2vwc0z6xqh5gpsgqcsq2-findutils-4.6.0/bin/find
gzipping man pages under /nix/store/zic2s2k09xbp2vwc0z6xqh5gpsgqcsq2-findutils-4.6.0/share/man/
strip is /nix/store/gfgczbs0cy0blibb0acv39cayq7qbplg-bootstrap-tools/bin/strip
stripping (with command strip and flags -S) in /nix/store/zic2s2k09xbp2vwc0z6xqh5gpsgqcsq2-findutils-4.6.0/libexec  /nix/store/zic2s2k09xbp2vwc0z6xqh5gpsgqcsq2-findutils-4.6.0/bin
checking for references to /build in /nix/store/zic2s2k09xbp2vwc0z6xqh5gpsgqcsq2-findutils-4.6.0...
shrinking RPATHs of ELF executables and libraries in /nix/store/13xa2x7bsnbbh5fm29g596fl6ymqal0p-findutils-4.6.0-info
strip is /nix/store/gfgczbs0cy0blibb0acv39cayq7qbplg-bootstrap-tools/bin/strip
checking for references to /build in /nix/store/13xa2x7bsnbbh5fm29g596fl6ymqal0p-findutils-4.6.0-info...
building '/nix/store/cdv0qphnqinlmplf1p6hsg4rqlslximv-stdenv-linux.drv'...
/nix/store/wbkfacq1s26d6n7a9n0s073ifwbjd4i8-stdenv-linux

@matthewbauer

Copy link
Copy Markdown
Member

@Ericson2314
Just a heads up but this is giving an issue in staging:

https://hydra.nixos.org/build/74502711/nixlog/1

/nix/store/9i0zrfqzfcx639s20x95r10fv9j7v6id-libiconv-osx-10.11.6/nix-support/setup-hook: line 5: getHostRole: command not found
builder for '/nix/store/rcfli01dwjbzvbwhw5k1lpkwzh57rqky-cairo-1.15.10.drv' failed with exit code 127

Not sure if it's since been fixed or not.

matthewbauer added a commit that referenced this pull request May 23, 2018
Fixes issue from PR #40139.
@matthewbauer

Copy link
Copy Markdown
Member

Hopefully fixed in 89e196d.

esac

content="${content//"$pattern"/$replacement}"
eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What’s this commit do? Such major changes to the internals of stdenv should at least have an extensive commit message of all the implications. I’m told substituteInPlace is very slow (in the order of seconds), so on inquiring this is the last commit that popped up, with no commit description whatsoever. :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it was slow before, but evaling is a strong contender. This line should have a comment why it is necessary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this resolved? Does this still have a performance problem? (If so, is there a known way to reproduce it?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To reproduce it, try changing something in pkgs/development/tools/build-managers/bazel/default.nix and then run nix-build -A bazel /path/to/nixpkgs.

You should see that the substitution of every file takes like half a second, which is a lot for a simple text substitution.

See also #35304 (comment), cc @mboes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's always been O(size of file * number of @var@ definitions), which is quiet shitty.

Just as we did for "expand response params", we should probably rewrite this in C or something.

@dtzWill

dtzWill commented Jan 3, 2019 via email

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: stdenv Standard environment 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants