Closed lheckemann closed 10 months ago
@lheckemann You did it correctly. The flushing nuscience is indeed a symptom of this code being spaghetti-ish, making conceptual operations with low-level serialization details too much
https://github.com/NixOS/hydra/pull/1180 and then eventually https://github.com/NixOS/nix/pull/6134/files would solve this problem, separating concerns so the "serialization on the inside, misc IO like flushing on the outside" structure was more clear.
Successfully deployed my Hydra with Nix 2.17 and this change and so far, everything works fine.
One problem though: in my deployment I'm not using nix
from Hydra's flake input, but nixVersions.nix_2_17
from nixpkgs
. Turns out that Hydra fails to link against this if --enable-lto
is specified for nixVersions.nix_2_17
:
hydra-0.1.20230804.DIRTY> /nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/bash ../../libtool --tag=CXX --mode=link g++ -std=c++2a -I/nix/store/2wc8v442wwy4zqcnwr1l62v1vp9da2sq-nix-2.17.0-dev/include/nix -I/nix/store/ksqbb3np13si616y71y1bbxyyhqcm0pr-boehm-gc-8.2.2-dev/include -Wall -I ../libhydra -Wno-deprecated-declarations -g -O2 -include nix/config.h -o hydra-queue-runner hydra_queue_runner-hydra-queue-runner.o hydra_queue_runner-queue-monitor.o hydra_queue_runner-dispatcher.o hydra_queue_runner-builder.o hydra_queue_runner-build-result.o hydra_queue_runner-build-remote.o hydra_queue_runner-nar-extractor.o -L/nix/store/11vbrp5bsvh31ddb8vxl82ryyb1rqq2z-nix-2.17.0/lib -L/nix/store/3a9r1dwgnszi7x9vybsx8y8mhhl8s0n0-boehm-gc-8.2.2/lib -lnixmain -lnixexpr -lgc -lpthread -ldl -lnixstore -lnixutil -lpqxx -lprometheus-cpp-pull -lprometheus-cpp-core
hydra-0.1.20230804.DIRTY> libtool: link: g++ -std=c++2a -I/nix/store/2wc8v442wwy4zqcnwr1l62v1vp9da2sq-nix-2.17.0-dev/include/nix -I/nix/store/ksqbb3np13si616y71y1bbxyyhqcm0pr-boehm-gc-8.2.2-dev/include -Wall -I ../libhydra -Wno-deprecated-declarations -g -O2 -include nix/config.h -o hydra-queue-runner hydra_queue_runner-hydra-queue-runner.o hydra_queue_runner-queue-monitor.o hydra_queue_runner-dispatcher.o hydra_queue_runner-builder.o hydra_queue_runner-build-result.o hydra_queue_runner-build-remote.o hydra_queue_runner-nar-extractor.o -L/nix/store/11vbrp5bsvh31ddb8vxl82ryyb1rqq2z-nix-2.17.0/lib -L/nix/store/3a9r1dwgnszi7x9vybsx8y8mhhl8s0n0-boehm-gc-8.2.2/lib -lnixmain -lnixexpr /nix/store/3a9r1dwgnszi7x9vybsx8y8mhhl8s0n0-boehm-gc-8.2.2/lib/libgc.so -lpthread -ldl -lnixstore -lnixutil /nix/store/cwjk8rvgpvi8dd3ga76a4z0wca2s5vlg-libpqxx-7.7.0/lib/libpqxx.so -lprometheus-cpp-pull -lprometheus-cpp-core -Wl,-rpath -Wl,/nix/store/3a9r1dwgnszi7x9vybsx8y8mhhl8s0n0-boehm-gc-8.2.2/lib -Wl,-rpath -Wl,/nix/store/cwjk8rvgpvi8dd3ga76a4z0wca2s5vlg-libpqxx-7.7.0/lib -Wl,-rpath -Wl,/nix/store/3a9r1dwgnszi7x9vybsx8y8mhhl8s0n0-boehm-gc-8.2.2/lib -Wl,-rpath -Wl,/nix/store/cwjk8rvgpvi8dd3ga76a4z0wca2s5vlg-libpqxx-7.7.0/lib
hydra-0.1.20230804.DIRTY> /nix/store/dx8hynidprz3kf4ngcjipnwaxp6h229f-binutils-2.40/bin/ld: hydra_queue_runner-build-remote.o: in function `void nix::WorkerProto::write<std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > >(nix::Store const&, nix::WorkerProto::WriteConn, std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > const&)':
hydra-0.1.20230804.DIRTY> /nix/store/2wc8v442wwy4zqcnwr1l62v1vp9da2sq-nix-2.17.0-dev/include/nix/worker-protocol.hh:112: undefined reference to `nix::WorkerProto::Serialise<std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > >::write(nix::Store const&, nix::WorkerProto::WriteConn, std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > const&)'
hydra-0.1.20230804.DIRTY> /nix/store/dx8hynidprz3kf4ngcjipnwaxp6h229f-binutils-2.40/bin/ld: hydra_queue_runner-build-remote.o: in function `State::buildRemote(nix::ref<nix::Store>, std::shared_ptr<Machine>, std::shared_ptr<Step>, unsigned int, unsigned int, unsigned int, RemoteResult&, std::shared_ptr<State::ActiveStep>, std::function<void (StepState)>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, NarMemberData, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, NarMemberData> > >&)':
hydra-0.1.20230804.DIRTY> /build/source/src/hydra-queue-runner/build-remote.cc:127: undefined reference to `nix::WorkerProto::Serialise<std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > >::read(nix::Store const&, nix::WorkerProto::ReadConn)'
hydra-0.1.20230804.DIRTY> /nix/store/dx8hynidprz3kf4ngcjipnwaxp6h229f-binutils-2.40/bin/ld: /build/source/src/hydra-queue-runner/build-remote.cc:375: undefined reference to `nix::WorkerProto::Serialise<std::map<nix::DrvOutput, nix::Realisation, std::less<nix::DrvOutput>, std::allocator<std::pair<nix::DrvOutput const, nix::Realisation> > > >::read(nix::Store const&, nix::WorkerProto::ReadConn)'
hydra-0.1.20230804.DIRTY> /nix/store/dx8hynidprz3kf4ngcjipnwaxp6h229f-binutils-2.40/bin/ld: hydra_queue_runner-build-remote.o: in function `void nix::WorkerProto::write<std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > >(nix::Store const&, nix::WorkerProto::WriteConn, std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > const&)':
hydra-0.1.20230804.DIRTY> /nix/store/2wc8v442wwy4zqcnwr1l62v1vp9da2sq-nix-2.17.0-dev/include/nix/worker-protocol.hh:112: undefined reference to `nix::WorkerProto::Serialise<std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > >::write(nix::Store const&, nix::WorkerProto::WriteConn, std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > const&)'
hydra-0.1.20230804.DIRTY> /nix/store/dx8hynidprz3kf4ngcjipnwaxp6h229f-binutils-2.40/bin/ld: hydra_queue_runner-build-remote.o: in function `State::buildRemote(nix::ref<nix::Store>, std::shared_ptr<Machine>, std::shared_ptr<Step>, unsigned int, unsigned int, unsigned int, RemoteResult&, std::shared_ptr<State::ActiveStep>, std::function<void (StepState)>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, NarMemberData, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, NarMemberData> > >&)':
hydra-0.1.20230804.DIRTY> /build/source/src/hydra-queue-runner/build-remote.cc:458: undefined reference to `nix::WorkerProto::Serialise<std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > >::read(nix::Store const&, nix::WorkerProto::ReadConn)'
hydra-0.1.20230804.DIRTY> collect2: error: ld returned 1 exit status
hydra-0.1.20230804.DIRTY> make[3]: *** [Makefile:435: hydra-queue-runner] Error 1
hydra-0.1.20230804.DIRTY> make[3]: Leaving directory '/build/source/src/hydra-queue-runner'
hydra-0.1.20230804.DIRTY> make[2]: *** [Makefile:363: all-recursive] Error 1
hydra-0.1.20230804.DIRTY> make[2]: Leaving directory '/build/source/src'
hydra-0.1.20230804.DIRTY> make[1]: *** [Makefile:422: all-recursive] Error 1
hydra-0.1.20230804.DIRTY> make[1]: Leaving directory '/build/source'
hydra-0.1.20230804.DIRTY> make: *** [Makefile:350: all] Error 2
This can also be reproduced with the nixos/nix
flake when on the PR's (at rev b23431a657d8a9b2f478c95dd81034780751a262) branch with the following diff:
diff --git a/flake.nix b/flake.nix
index 7e7d50e2..d83a18e0 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,7 +14,7 @@
pkgsBySystem = forEachSystem (system: import nixpkgs {
inherit system;
- overlays = [ self.overlays.default nix.overlays.default ];
+ overlays = [ nix.overlays.default self.overlays.default ];
});
# NixOS configuration used for VM tests.
@@ -40,6 +40,9 @@
# A Nixpkgs overlay that provides a 'hydra' package.
overlays.default = final: prev: {
+ nix = prev.nix.overrideAttrs ({ configureFlags ? [], ... }: {
+ configureFlags = configureFlags ++ [ "--enable-lto" ];
+ });
# Add LDAP dependencies that aren't currently found within nixpkgs.
perlPackages = prev.perlPackages // {
Will also file a bug against Nix @Ericson2314 .
cc @Ericson2314 who authored the API changes, to make sure I'm not doing something really silly here.
I don't think it's nice to use the
WriteConn
/ReadConn
and theFdSink
s wrapped by them simultaneously, but I'm guessing the flushes are important -- and they can't be performed through theWriteConn
because not allSink
s are flushable.