-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Enable the unix://
store on Windows
#10556
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "indirect-root-store.hh" | ||
|
||
namespace nix { | ||
|
||
void IndirectRootStore::makeSymlink(const Path & link, const Path & target) | ||
{ | ||
/* Create directories up to `gcRoot'. */ | ||
createDirs(dirOf(link)); | ||
|
||
/* Create the new symlink. */ | ||
Path tempLink = fmt("%1%.tmp-%2%-%3%", link, getpid(), rand()); | ||
createSymlink(target, tempLink); | ||
|
||
/* Atomically replace the old one. */ | ||
renameFile(tempLink, link); | ||
} | ||
|
||
|
||
Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot) | ||
{ | ||
Path gcRoot(canonPath(_gcRoot)); | ||
|
||
if (isInStore(gcRoot)) | ||
throw Error( | ||
"creating a garbage collector root (%1%) in the Nix store is forbidden " | ||
"(are you running nix-build inside the store?)", gcRoot); | ||
|
||
/* Register this root with the garbage collector, if it's | ||
running. This should be superfluous since the caller should | ||
have registered this root yet, but let's be on the safe | ||
side. */ | ||
addTempRoot(storePath); | ||
|
||
/* Don't clobber the link if it already exists and doesn't | ||
point to the Nix store. */ | ||
if (pathExists(gcRoot) && (!isLink(gcRoot) || !isInStore(readLink(gcRoot)))) | ||
throw Error("cannot create symlink '%1%'; already exists", gcRoot); | ||
makeSymlink(gcRoot, printStorePath(storePath)); | ||
addIndirectRoot(gcRoot); | ||
|
||
return gcRoot; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
///@file | ||
|
||
#include "types.hh" | ||
#include "file-descriptor.hh" | ||
|
||
#ifdef _WIN32 | ||
# include <winsock2.h> | ||
#endif | ||
#include <unistd.h> | ||
|
||
namespace nix { | ||
|
||
/** | ||
* Create a Unix domain socket. | ||
*/ | ||
AutoCloseFD createUnixDomainSocket(); | ||
|
||
/** | ||
* Create a Unix domain socket in listen mode. | ||
*/ | ||
AutoCloseFD createUnixDomainSocket(const Path & path, mode_t mode); | ||
|
||
|
||
/** | ||
* Often we want to use `Descriptor`, but Windows makes a slightly | ||
* stronger file descriptor vs socket distinction, at least at the level | ||
* of C types. | ||
*/ | ||
using Socket = | ||
#ifdef _WIN32 | ||
SOCKET | ||
#else | ||
int | ||
#endif | ||
; | ||
|
||
#ifdef _WIN32 | ||
/** | ||
* Windows gives this a different name | ||
*/ | ||
# define SHUT_WR SD_SEND | ||
#endif | ||
|
||
/** | ||
* Convert a `Socket` to a `Descriptor` | ||
* | ||
* This is a no-op except on Windows. | ||
*/ | ||
static inline Socket toSocket(Descriptor fd) | ||
{ | ||
#ifdef _WIN32 | ||
return reinterpret_cast<Socket>(fd); | ||
#else | ||
return fd; | ||
#endif | ||
} | ||
|
||
/** | ||
* Convert a `Socket` to a `Descriptor` | ||
* | ||
* This is a no-op except on Windows. | ||
*/ | ||
static inline Descriptor fromSocket(Socket fd) | ||
{ | ||
#ifdef _WIN32 | ||
return reinterpret_cast<Descriptor>(fd); | ||
#else | ||
return fd; | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Bind a Unix domain socket to a path. | ||
*/ | ||
void bind(Socket fd, const std::string & path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't "public" use of types like 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
|
||
/** | ||
* Connect to a Unix domain socket. | ||
*/ | ||
void connect(Socket fd, const std::string & path); | ||
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked the indentation to make nested
if..endif
easier to followThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that
clang-format
is configured to do this sort of indentation now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 beforenix develop .#devShells.x86_64-linux.x86_64-w64-mingw32
?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 usesssh
to attach to the machine) have what thenix 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just run
make format
, it is in all of Nix's dev shells.