Enable the unix:// store on Windows#10556
Conversation
I don't think fewer bits matters for this, and `rand` but not `random` is available on Windows.
Windows now has some basic Unix Domain Socket support, see https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ Building `nix daemon` on Windows I've left for later, because the daemon currently forks per connection but this is not an option on Windows. But we can get the client part working right away.
unix:// store on Windows
puffnfresh
left a comment
There was a problem hiding this comment.
Looks good. Code has mostly just been moved around. I don't know whether srandom and srand have any internal relationship but seems fine to me.
|
I wonder if we can expose a socket from WSL. With this PR we'd then have |
|
Great point! If not, we can always use TCP #5265 |
|
I decided |
| /** | ||
| * Bind a Unix domain socket to a path. | ||
| */ | ||
| void bind(Socket fd, const std::string & path); |
There was a problem hiding this comment.
Won't "public" use of types like Socket and Descriptor cause type errors that are basically only caught in CI? (When forgetting to call toSocket, for example.)
I'd prefer a distinct type so that the compiler helps us get it right.
struct Socket {
#ifdef _WIN32
SOCKET socket;
#else
int socket;
#endif
};There was a problem hiding this comment.
How would you feel about this (for both types) being a follow up PR? I agree it is better, but I was wary of the "but now Unix needs to jump through more hoops" counter argument.
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2024-04-22-nix-team-meeting-minutes-141/44083/1 |
roberth
left a comment
There was a problem hiding this comment.
LGTM, modulo types for followup. 👍
| #include <cstring> | ||
|
|
||
| #ifdef _WIN32 | ||
| # include <winsock2.h> |
There was a problem hiding this comment.
# include vs. #include, i like it to be consistent, this happens multiple times in multiple documents. i wonder is this a _WIN32 thing we want to have?
There was a problem hiding this comment.
I liked the indentation to make nested if..endif easier to follow
There was a problem hiding this comment.
modern IDEs detect the _WIN32 switch an grey out others but so far didn't manage this in my visual studio code ssh IDE to pick up the compiler settings. for clion this required cmake to work properly and for other build systems at least one complete compile run and then IDEs sometimes pick up these settings.
this level of support would be nice for nix hacking!
There was a problem hiding this comment.
@qknight We have instructions for the clangd LSP if that's of use to you.
In support of this, we have make compile_commands.json. Maybe CLion supports that format too?
bear or similar isn't needed anymore since recently.
There was a problem hiding this comment.
Also note that clang-format is configured to do this sort of indentation now.
There was a problem hiding this comment.
@Ericson2314 @roberth interesting! So i would have to use the stdenv.cc.isClang for formatting? Or would I install nix-env -i clang-format into my shell before nix develop .#devShells.x86_64-linux.x86_64-w64-mingw32?
nativeBuildInputs = attrs.nativeBuildInputs or []
# TODO: Remove the darwin check once
# https://github.com/NixOS/nixpkgs/pull/291814 is available
++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear
++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) pkgs.buildPackages.clang-tools;
Tried to get my visual studio code setup to work with make compile_commands.json but the problem is that I would need to make the login shell (it uses ssh to attach to the machine) have what the nix develop ... brings in and I couldn't make this happen. There is no field in the configuration, https://code.visualstudio.com/docs/remote/ssh, where one could set env vars or commands to run prior.
There was a problem hiding this comment.
Just run make format, it is in all of Nix's dev shells.
| #ifndef _WIN32 | ||
| srandom(tv.tv_usec); | ||
| #endif | ||
| srand(tv.tv_usec); |
There was a problem hiding this comment.
Should it not be:
#ifndef _WIN32
srandom(tv.tv_usec);
#else
srand(tv.tv_usec);
#endif
There was a problem hiding this comment.
I made it use rand on all platforms in the one spot above, so srand is likewise needed: on Unix we now use all 4 functions, on Windows we use two.
Fix formatting violations, update blacklist to reflect moved files. PR NixOS#10556 passed CI before the new formating rules were added, and our CI has the race condition of allowing old results, resulting in master getting broken.
Motivation
Building
nix daemonon Windows I've left for later, because the daemon currently forks per connection but this is not an option on Windows. But we can get the client part working right away.Context
Reviewers: do double check the
random->randswitch. The long term solution is still #10541 since that library is supposed to be better for many reasons.Windows now has some basic Unix Domain Socket support, see https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.