-
Notifications
You must be signed in to change notification settings - Fork 66
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
Support remote-building to macOS hosts #714
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c97ddd3
Support remote-building to macOS hosts
grahamc 951842c
Update the ticket number
grahamc 821db68
fixup
grahamc de176f8
Remove the whole section about nix not being in the path
grahamc 00c5d57
Add a couple perks
grahamc 618fefa
A million :)
grahamc 5cd0cef
quote the zshenv path in the plan
grahamc ae21843
Zshenv comment nit
grahamc 389f502
one action is a lot less work lol
grahamc da33c23
Update README.md
Hoverbear 42c5127
Update src/cli/subcommand/repair.rs
grahamc e6f9956
Update src/cli/subcommand/repair.rs
grahamc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
use crate::action::base::{create_or_insert_into_file, CreateOrInsertIntoFile}; | ||
use crate::action::{ | ||
Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction, | ||
}; | ||
|
||
use std::path::Path; | ||
use tokio::task::JoinSet; | ||
use tracing::{span, Instrument, Span}; | ||
|
||
const PROFILE_NIX_FILE_SHELL: &str = "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"; | ||
|
||
/** | ||
Configure macOS's zshenv to load the Nix environment when ForceCommand is used. | ||
This enables remote building, which requires `ssh host nix` to work. | ||
*/ | ||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] | ||
pub struct ConfigureRemoteBuilding { | ||
create_or_insert_into_files: Vec<StatefulAction<CreateOrInsertIntoFile>>, | ||
grahamc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
impl ConfigureRemoteBuilding { | ||
#[tracing::instrument(level = "debug", skip_all)] | ||
pub async fn plan() -> Result<StatefulAction<Self>, ActionError> { | ||
let mut create_or_insert_into_files = Vec::default(); | ||
|
||
let shell_buf = format!( | ||
r#" | ||
# Nix, only on remote SSH connections -- for remote building. | ||
grahamc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# See: <TICKET NUMBER> | ||
grahamc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if [ -e '{PROFILE_NIX_FILE_SHELL}' ] && [ -n "${{SSH_CONNECTION}}" ] && [ "${{SHLVL}}" -eq 1 ]; then | ||
. '{PROFILE_NIX_FILE_SHELL}' | ||
fi | ||
# End Nix | ||
"# | ||
); | ||
|
||
let profile_target_path = Path::new("/etc/zshenv"); | ||
create_or_insert_into_files.push( | ||
CreateOrInsertIntoFile::plan( | ||
profile_target_path, | ||
None, | ||
None, | ||
0o644, | ||
shell_buf.to_string(), | ||
create_or_insert_into_file::Position::Beginning, | ||
) | ||
.await | ||
.map_err(Self::error)?, | ||
); | ||
|
||
Ok(Self { | ||
create_or_insert_into_files, | ||
} | ||
.into()) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
#[typetag::serde(name = "configure_remote_building")] | ||
impl Action for ConfigureRemoteBuilding { | ||
fn action_tag() -> ActionTag { | ||
ActionTag("configure_remote_building") | ||
} | ||
fn tracing_synopsis(&self) -> String { | ||
"Configuring zsh to support using Nix in non-interactive shells".to_string() | ||
} | ||
|
||
fn tracing_span(&self) -> Span { | ||
span!(tracing::Level::DEBUG, "configure_remote_building",) | ||
} | ||
|
||
fn execute_description(&self) -> Vec<ActionDescription> { | ||
vec![ActionDescription::new( | ||
self.tracing_synopsis(), | ||
vec!["Update zshenv to import Nix".to_string()], | ||
grahamc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)] | ||
} | ||
|
||
#[tracing::instrument(level = "debug", skip_all)] | ||
async fn execute(&mut self) -> Result<(), ActionError> { | ||
let mut set = JoinSet::new(); | ||
let mut errors = vec![]; | ||
|
||
for (idx, create_or_insert_into_file) in | ||
self.create_or_insert_into_files.iter_mut().enumerate() | ||
{ | ||
let span = tracing::Span::current().clone(); | ||
let mut create_or_insert_into_file_clone = create_or_insert_into_file.clone(); | ||
let _abort_handle = set.spawn(async move { | ||
create_or_insert_into_file_clone | ||
.try_execute() | ||
.instrument(span) | ||
.await | ||
.map_err(Self::error)?; | ||
Result::<_, ActionError>::Ok((idx, create_or_insert_into_file_clone)) | ||
}); | ||
} | ||
|
||
while let Some(result) = set.join_next().await { | ||
match result { | ||
Ok(Ok((idx, create_or_insert_into_file))) => { | ||
self.create_or_insert_into_files[idx] = create_or_insert_into_file | ||
}, | ||
Ok(Err(e)) => errors.push(e), | ||
Err(e) => return Err(Self::error(e))?, | ||
}; | ||
} | ||
|
||
if !errors.is_empty() { | ||
if errors.len() == 1 { | ||
return Err(Self::error(errors.into_iter().next().unwrap()))?; | ||
} else { | ||
return Err(Self::error(ActionErrorKind::MultipleChildren( | ||
errors.into_iter().collect(), | ||
))); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn revert_description(&self) -> Vec<ActionDescription> { | ||
vec![ActionDescription::new( | ||
"Remove the Nix configuration from zsh's non-login shells".to_string(), | ||
vec!["Update zshenv to no longer import Nix".to_string()], | ||
grahamc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)] | ||
} | ||
|
||
#[tracing::instrument(level = "debug", skip_all)] | ||
async fn revert(&mut self) -> Result<(), ActionError> { | ||
let mut set = JoinSet::new(); | ||
let mut errors = vec![]; | ||
|
||
for (idx, create_or_insert_into_file) in | ||
self.create_or_insert_into_files.iter_mut().enumerate() | ||
{ | ||
let mut create_or_insert_file_clone = create_or_insert_into_file.clone(); | ||
let _abort_handle = set.spawn(async move { | ||
create_or_insert_file_clone.try_revert().await?; | ||
Result::<_, _>::Ok((idx, create_or_insert_file_clone)) | ||
}); | ||
} | ||
|
||
while let Some(result) = set.join_next().await { | ||
match result { | ||
Ok(Ok((idx, create_or_insert_into_file))) => { | ||
self.create_or_insert_into_files[idx] = create_or_insert_into_file | ||
}, | ||
Ok(Err(e)) => errors.push(e), | ||
// This is quite rare and generally a very bad sign. | ||
Err(e) => return Err(e).map_err(|e| Self::error(ActionErrorKind::from(e)))?, | ||
}; | ||
} | ||
|
||
if errors.is_empty() { | ||
Ok(()) | ||
} else if errors.len() == 1 { | ||
Err(errors | ||
.into_iter() | ||
.next() | ||
.expect("Expected 1 len Vec to have at least 1 item")) | ||
} else { | ||
Err(Self::error(ActionErrorKind::MultipleChildren(errors))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 part can be removed, we do not need to document old niche problems in the READMEs of new ones. I suspect we could look into cutting a new release quite soon, even.
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.
We might should keep a list of problems and quirks of old releases. Like the below note about nix-darwin should be solved now, 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.
The old releases have their own READMEs with quirk lists! :)
In the
nix-darwin
case, users may still try to uninstall Nix on their own before trying to use this tool, and we might get it wrong. We should be able to remove it if we implement a correct fix though.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.
Cool!