-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
darwin.builder: init #206951
darwin.builder: init #206951
Conversation
Note that this is still missing documentation, which I will complete before merging this |
Fixes NixOS#108984 This originates from: https://github.com/Gabriella439/macos-builder … which in turn originates from: https://github.com/YorikSar/nixos-vm-on-macos
0ff9555
to
44c6fda
Compare
Thanks a lot for getting this in a frinedly state ❤️ |
… as suggested by @domenkozar Co-authored-by: Domen Kožar <[email protected]>
This also requires that port 22 on your machine is free (since Nix does not | ||
permit specifying a non-default SSH port for builders). |
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.
You should be able to change this via the root's ssh_config
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACCQVnMW/wZWqrdWrjrRPhfEFFq1KLYguagSflLhFnVQmwAAAJASuMMnErjD | ||
JwAAAAtzc2gtZWQyNTUxOQAAACCQVnMW/wZWqrdWrjrRPhfEFFq1KLYguagSflLhFnVQmw | ||
AAAEDIN2VWFyggtoSPXcAFy8dtG1uAig8sCuyE21eMDt2GgJBWcxb/Blaqt1auOtE+F8QU | ||
WrUotiC5qBJ+UuEWdVCbAAAACnJvb3RAbml4b3MBAgM= | ||
-----END OPENSSH PRIVATE KEY----- |
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 am not in favor of hardcoding a private key. What alternatives do we 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'm not aware of a good alternative here. However, in this case I think it's not an issue because this is only use as the SSH host key and not the client's key (which is still handled securely)
networking.nameservers = [ "8.8.8.8" ]; | ||
|
||
nix.settings = { | ||
auto-optimise-store = true; |
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 have turned this off since a while to reduce io load but didn't do benchmarking. Is the difference noticeable? Not sure if we should turn it on by default or not.
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 actually am not too attached to this setting. I don't remember why I added it
installCredentials = pkgs.writeShellScript "install-credentials" '' | ||
KEYS="''${1}" | ||
INSTALL=${hostPkgs.coreutils}/bin/install | ||
"''${INSTALL}" -g nixbld -m 600 "''${KEYS}/${user}_${keyType}" ${privateKey} | ||
"''${INSTALL}" -g nixbld -m 644 "''${KEYS}/${user}_${keyType}.pub" ${publicKey} |
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.
installCredentials = pkgs.writeShellScript "install-credentials" '' | |
KEYS="''${1}" | |
INSTALL=${hostPkgs.coreutils}/bin/install | |
"''${INSTALL}" -g nixbld -m 600 "''${KEYS}/${user}_${keyType}" ${privateKey} | |
"''${INSTALL}" -g nixbld -m 644 "''${KEYS}/${user}_${keyType}.pub" ${publicKey} | |
installCredentials = let | |
install = ${hostPkgs.coreutils}/bin/install; | |
in pkgs.writeShellScript "install-credentials" '' | |
"${install}" -g nixbld -m 600 "''${1}/${user}_${keyType}" ${privateKey} | |
"${install}" -g nixbld -m 644 "''${1}/${user}_${keyType}.pub" ${publicKey} |
If the goal is to make the script as easy as possible then this is in the end as easy as it gets.
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.
Yeah, I deliberately did not do it that way because I wanted the script to be easier to read. In particular, I wanted the script to fit within 80 columns
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.
Something does not get easier to read if it fits within 80 columns but has two extra lines.
KEYS="$(nix-store --add "$KEYS")" ${config.system.build.vm}/bin/run-nixos-vm | ||
''; | ||
|
||
system.stateVersion = "22.05"; |
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.
This should be taken from nixpkgs instead of being hardcoded here or set once on initialization.
I'm going to merge this because it improves the current state a lot and further improvements can be done once people start to use it. |
Successfully created backport PR #207097 for |
@domenkozar there is no time pressure here at all and new features should not be merged with barely any review just because people desperately want it. Doing major redesigns of new features straight after they where rushed to be merged is suboptimal for anyone that started to use the feature already. |
Did the review comments myself in #207486 |
It's not about time pressure, it's about getting this work to the devs to test and moving the bikeshedding into a step that can happen in parallel. |
crucially, getting hydra to put it in cache.nixos.org |
… until we can figure out why it's being rebuilt for seemingly unrelated changes. See: NixOS#206951 (comment)
Here's the PR to disable the build for now if people need this to be reverted: #207776 |
not sure if disabling the build is needed since Mic92/nixpkgs-review#291 is merged and nixpkgs-review users will not have to rebuild darwin.builder anymore, the only downside after nixpkgs-review is updated afaik would be the github labels which imo is not a big deal |
ofborg telling contributors that a zero rebuild PR causes one rebuild on each darwin platforms is rather confusing. |
Just to clarify: is |
I can reproduce this locally:
If it's git commits that's causing this, then I assume the darwin.builder needs to hard code a git revision, like in release.nix. |
@raphaelr: Thank you! I can reproduce now, too. I think the reason I could not originally reproduce was that I was using |
See the discussion starting here: NixOS#206951 (comment) The `darwin.builder` derivation had a gratuitous dependency on the current Nixpkgs revision due to `config.system.nixos.revision`. Setting the revision explicitly to null fixes this problem and prevents the derivation from being rebuilt on every change to Nixpkgs.
This should fix the gratuitous rebuilds: #207902 |
See the discussion starting here: #206951 (comment) The `darwin.builder` derivation had a gratuitous dependency on the current Nixpkgs revision due to `config.system.nixos.revision`. Setting the revision explicitly to null fixes this problem and prevents the derivation from being rebuilt on every change to Nixpkgs. (cherry picked from commit 474198f)
Just a few thoughts when I read the new manual entry:
|
@NiklasGollenstede: The only reason it says port 22 is required is because I thought it was a limitation of Nix's remote builder functionality (rather than a limitation of the VM). Are you saying that there's a way for Nix to specify a non-default port for a remote builder in the builder spec? I like the |
That would be nice, but no. I am pretty sure that such an option would be defined in either of these two files: What I was saying is that currently (I assume this is the default when not supplying |
@NiklasGollenstede: It turns out that an unprivileged https://developer.apple.com/forums/thread/674179 The good news is that you don't actually need to open up the firewall, so I put up a PR to document that: #208792 |
There may be an implementation reason, but looking from the outside, that's incredibly weird behavior. If macOS has some mechanism to prompt for firewall exceptions, (and it is now documented to deny that), then at least the security aspect of not binding all addresses is largely a mute point (assuming that on macOS users don't usually (or can't) disable the firewall). |
I've configured |
Right. That should work. (When I was researching this previously, modifying config files was not an option (and it is quite contrary to Nix's philosophy that it is required).) To do this without also modifying |
… as suggested by @NiklasGollenstede in: NixOS#206951 (comment) This simplifies the user experience for logging into and debugging the machine and also simplifies the instructions for shutting down the machine gracefully.
… as suggested by @NiklasGollenstede in: #206951 (comment) This simplifies the user experience for logging into and debugging the machine and also simplifies the instructions for shutting down the machine gracefully.
… as suggested by @NiklasGollenstede in: NixOS#206951 (comment) This simplifies the user experience for logging into and debugging the machine and also simplifies the instructions for shutting down the machine gracefully.
Fixes #108984
This originates from:
https://github.com/Gabriella439/macos-builder
… which in turn originates from:
https://github.com/YorikSar/nixos-vm-on-macos
Once this change is built and cached, the end user only needs to run:
$ nix run nixpkgs#darwin.builder
… to create a Linux builder on macOS
Description of changes
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes