Skip to content

Commit

Permalink
Small bug fixes & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
htngr committed Nov 6, 2024
1 parent 8c2ba0f commit 04a183e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
11 changes: 6 additions & 5 deletions codchi/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn init(
platform_status: PlatformStatus::NotInstalled,
};
machine.write_flake()?;
machine.update_flake()?;
Ok(machine)
}

Expand Down Expand Up @@ -570,9 +571,10 @@ fn inquire_module_url(
}
}

#[allow(clippy::too_many_arguments)]
pub fn clone(
machine_name: &str,
url: GitUrl,
git_url: GitUrl,
input_options: &InputOptions,
module_paths: &Vec<ModuleAttrPath>,
dir: &Option<RelativePath>,
Expand All @@ -586,7 +588,6 @@ pub fn clone(
log::warn!("Ignoring option `--no-build`.");
input_options.no_build = true;
}
let git_url = GitUrl::from(url);
if git_url.scheme != Scheme::Http && git_url.scheme != Scheme::Https {
bail!("Only HTTP(S) is available at the moment.")
}
Expand Down Expand Up @@ -625,13 +626,13 @@ pub fn clone(
git_opts.push(format!("--depth {depth}"));
}
if *single_branch {
git_opts.push(format!("--single-branch"));
git_opts.push("--single-branch".to_string());
}
if *recurse_submodules {
git_opts.push(format!("--recurse-submodules"));
git_opts.push("--recurse-submodules".to_string());
}
if *shallow_submodules {
git_opts.push(format!("--shallow-submodules"));
git_opts.push("--shallow-submodules".to_string());
}
let git_opts = git_opts.join(" ");

Expand Down
2 changes: 2 additions & 0 deletions codchi/src/platform/cmd/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub trait NixDriver: LinuxCommandTarget {
let list_attr_names = |attr_path: &str| -> Result<Vec<String>> {
let args = [
"eval",
"--refresh",
"--no-write-lock-file",
"--json",
"--quiet",
Expand Down Expand Up @@ -101,6 +102,7 @@ pub trait NixDriver: LinuxCommandTarget {
let args = [
"flake",
"metadata",
"--refresh",
"--json",
"--no-write-lock-file",
&self.quote_shell_arg(url),
Expand Down
2 changes: 1 addition & 1 deletion codchi/src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ tail -f "{log_file}"
}

fn create_exec_cmd(&self, cmd: &[&str]) -> super::LinuxCommandBuilder {
let args = [&vec![consts::user::DEFAULT_NAME], cmd].concat();
let args = [&[consts::user::DEFAULT_NAME], cmd].concat();
let cmd = self.cmd().raw("su", &args);

cmd.with_cwd(consts::user::DEFAULT_HOME.clone())
Expand Down
24 changes: 15 additions & 9 deletions codchi/src/platform/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ fi
Ok(())
}

pub fn update_flake(&self) -> Result<()> {
Driver::store()
.cmd()
.script(r#"ndd $NIX_VERBOSITY flake update"#.to_string())
.with_cwd(consts::store::DIR_CONFIG.join_machine(&self.config.name))
.output_ok_streaming(channel().1, |line| {
log_progress("build", log::Level::Debug, &line)
})?;
Ok(())
}

pub fn build(&self, no_update: bool) -> Result<()> {
self.write_flake()?;

Expand Down Expand Up @@ -223,17 +234,11 @@ fi

set_progress_status(format!("Building {}...", self.config.name));
if !no_update {
Driver::store()
.cmd()
.script(format!(r#"ndd $NIX_VERBOSITY flake update"#))
.with_cwd(consts::store::DIR_CONFIG.join_machine(&self.config.name))
.output_ok_streaming(channel().1, |line| {
log_progress("build", log::Level::Debug, &line)
})?;
self.update_flake()?;
}
Driver::store()
.cmd()
.script(format!(
.script(
r#"
NIX_CFG_FILE="$(ndd build $NIX_VERBOSITY --no-link --print-out-paths \
'.#nixosConfigurations.default.config.environment.etc."nix/nix.conf".source')"
Expand All @@ -247,7 +252,8 @@ fi
pwd
git add flake.*
"#
))
.to_string(),
)
.with_cwd(consts::store::DIR_CONFIG.join_machine(&self.config.name))
.output_ok_streaming(channel().1, |line| {
log_progress("build", log::Level::Debug, &line)
Expand Down
10 changes: 5 additions & 5 deletions codchi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,21 @@ pub trait PathExt: AsRef<Path> + Sized + Debug {

/// Create the directory recursively if it doesn't exist and return its path
fn list_dir(&self) -> anyhow::Result<Vec<String>> {
if let Ok(meta) = fs::metadata(&self) {
if let Ok(meta) = fs::metadata(self) {
if meta.is_dir() {
let mut filenames = vec![];

for entry in fs::read_dir(&self)? {
for entry in fs::read_dir(self)? {
let entry =
entry.with_context(|| format!("Failed to read an entry in {:?}", self))?;
filenames.push(entry.file_name().to_string_lossy().to_string());
}
return Ok(filenames);
Ok(filenames)
} else {
bail!("Path '{self:?}' is not a directory");
bail!("Path '{self:?}' is not a directory")
}
} else {
bail!("Couldn't find path '{self:?}'");
bail!("Couldn't find path '{self:?}'")
}
}
}
Expand Down

0 comments on commit 04a183e

Please sign in to comment.