Remove nix channel placement (#304)
* Remove place_channel_configuration.rs * Remove channels option * Add fixture updates
This commit is contained in:
parent
6219b2c48d
commit
5fe7dd9828
|
@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
action::{ActionError, ActionTag, StatefulAction},
|
action::{ActionError, ActionTag, StatefulAction},
|
||||||
execute_command, set_env, ChannelValue,
|
execute_command, set_env,
|
||||||
};
|
};
|
||||||
|
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
|
@ -16,14 +16,12 @@ use crate::action::{Action, ActionDescription};
|
||||||
Setup the default Nix profile with `nss-cacert` and `nix` itself.
|
Setup the default Nix profile with `nss-cacert` and `nix` itself.
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||||
pub struct SetupDefaultProfile {
|
pub struct SetupDefaultProfile {}
|
||||||
channels: Vec<ChannelValue>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SetupDefaultProfile {
|
impl SetupDefaultProfile {
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
#[tracing::instrument(level = "debug", skip_all)]
|
||||||
pub async fn plan(channels: Vec<ChannelValue>) -> Result<StatefulAction<Self>, ActionError> {
|
pub async fn plan() -> Result<StatefulAction<Self>, ActionError> {
|
||||||
Ok(Self { channels }.into())
|
Ok(Self {}.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,16 +36,7 @@ impl Action for SetupDefaultProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tracing_span(&self) -> Span {
|
fn tracing_span(&self) -> Span {
|
||||||
span!(
|
span!(tracing::Level::DEBUG, "setup_default_profile",)
|
||||||
tracing::Level::DEBUG,
|
|
||||||
"setup_default_profile",
|
|
||||||
channels = self
|
|
||||||
.channels
|
|
||||||
.iter()
|
|
||||||
.map(|ChannelValue(channel, url)| format!("{channel}={url}"))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(","),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_description(&self) -> Vec<ActionDescription> {
|
fn execute_description(&self) -> Vec<ActionDescription> {
|
||||||
|
@ -56,8 +45,6 @@ impl Action for SetupDefaultProfile {
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
#[tracing::instrument(level = "debug", skip_all)]
|
||||||
async fn execute(&mut self) -> Result<(), ActionError> {
|
async fn execute(&mut self) -> Result<(), ActionError> {
|
||||||
let Self { channels } = self;
|
|
||||||
|
|
||||||
// Find an `nix` package
|
// Find an `nix` package
|
||||||
let nix_pkg_glob = "/nix/store/*-nix-*";
|
let nix_pkg_glob = "/nix/store/*-nix-*";
|
||||||
let mut found_nix_pkg = None;
|
let mut found_nix_pkg = None;
|
||||||
|
@ -200,29 +187,13 @@ impl Action for SetupDefaultProfile {
|
||||||
"/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt",
|
"/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt",
|
||||||
);
|
);
|
||||||
|
|
||||||
if !channels.is_empty() {
|
|
||||||
let mut command = Command::new(nix_pkg.join("bin/nix-channel"));
|
|
||||||
command.process_group(0);
|
|
||||||
command.arg("--update");
|
|
||||||
for channel in channels {
|
|
||||||
command.arg(channel.0.clone());
|
|
||||||
}
|
|
||||||
command.env(
|
|
||||||
"NIX_SSL_CERT_FILE",
|
|
||||||
"/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt",
|
|
||||||
);
|
|
||||||
command.stdin(std::process::Stdio::null());
|
|
||||||
|
|
||||||
execute_command(&mut command).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn revert_description(&self) -> Vec<ActionDescription> {
|
fn revert_description(&self) -> Vec<ActionDescription> {
|
||||||
vec![ActionDescription::new(
|
vec![ActionDescription::new(
|
||||||
"Unset the default Nix profile".to_string(),
|
"Unset the default Nix profile".to_string(),
|
||||||
vec!["TODO".to_string()],
|
vec![],
|
||||||
)]
|
)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
action::{
|
action::{
|
||||||
base::SetupDefaultProfile,
|
base::SetupDefaultProfile,
|
||||||
common::{ConfigureShellProfile, PlaceChannelConfiguration, PlaceNixConfiguration},
|
common::{ConfigureShellProfile, PlaceNixConfiguration},
|
||||||
Action, ActionDescription, ActionError, ActionTag, StatefulAction,
|
Action, ActionDescription, ActionError, ActionTag, StatefulAction,
|
||||||
},
|
},
|
||||||
settings::CommonSettings,
|
settings::CommonSettings,
|
||||||
|
@ -16,14 +16,13 @@ Configure Nix and start it
|
||||||
pub struct ConfigureNix {
|
pub struct ConfigureNix {
|
||||||
setup_default_profile: StatefulAction<SetupDefaultProfile>,
|
setup_default_profile: StatefulAction<SetupDefaultProfile>,
|
||||||
configure_shell_profile: Option<StatefulAction<ConfigureShellProfile>>,
|
configure_shell_profile: Option<StatefulAction<ConfigureShellProfile>>,
|
||||||
place_channel_configuration: StatefulAction<PlaceChannelConfiguration>,
|
|
||||||
place_nix_configuration: StatefulAction<PlaceNixConfiguration>,
|
place_nix_configuration: StatefulAction<PlaceNixConfiguration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigureNix {
|
impl ConfigureNix {
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
#[tracing::instrument(level = "debug", skip_all)]
|
||||||
pub async fn plan(settings: &CommonSettings) -> Result<StatefulAction<Self>, ActionError> {
|
pub async fn plan(settings: &CommonSettings) -> Result<StatefulAction<Self>, ActionError> {
|
||||||
let setup_default_profile = SetupDefaultProfile::plan(settings.channels.clone())
|
let setup_default_profile = SetupDefaultProfile::plan()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ActionError::Child(SetupDefaultProfile::action_tag(), Box::new(e)))?;
|
.map_err(|e| ActionError::Child(SetupDefaultProfile::action_tag(), Box::new(e)))?;
|
||||||
|
|
||||||
|
@ -34,12 +33,6 @@ impl ConfigureNix {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let place_channel_configuration =
|
|
||||||
PlaceChannelConfiguration::plan(settings.channels.clone(), settings.force)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
ActionError::Child(PlaceChannelConfiguration::action_tag(), Box::new(e))
|
|
||||||
})?;
|
|
||||||
let place_nix_configuration = PlaceNixConfiguration::plan(
|
let place_nix_configuration = PlaceNixConfiguration::plan(
|
||||||
settings.nix_build_group_name.clone(),
|
settings.nix_build_group_name.clone(),
|
||||||
settings.extra_conf.clone(),
|
settings.extra_conf.clone(),
|
||||||
|
@ -49,7 +42,6 @@ impl ConfigureNix {
|
||||||
.map_err(|e| ActionError::Child(PlaceNixConfiguration::action_tag(), Box::new(e)))?;
|
.map_err(|e| ActionError::Child(PlaceNixConfiguration::action_tag(), Box::new(e)))?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
place_channel_configuration,
|
|
||||||
place_nix_configuration,
|
place_nix_configuration,
|
||||||
setup_default_profile,
|
setup_default_profile,
|
||||||
configure_shell_profile,
|
configure_shell_profile,
|
||||||
|
@ -76,13 +68,11 @@ impl Action for ConfigureNix {
|
||||||
let Self {
|
let Self {
|
||||||
setup_default_profile,
|
setup_default_profile,
|
||||||
place_nix_configuration,
|
place_nix_configuration,
|
||||||
place_channel_configuration,
|
|
||||||
configure_shell_profile,
|
configure_shell_profile,
|
||||||
} = &self;
|
} = &self;
|
||||||
|
|
||||||
let mut buf = setup_default_profile.describe_execute();
|
let mut buf = setup_default_profile.describe_execute();
|
||||||
buf.append(&mut place_nix_configuration.describe_execute());
|
buf.append(&mut place_nix_configuration.describe_execute());
|
||||||
buf.append(&mut place_channel_configuration.describe_execute());
|
|
||||||
if let Some(configure_shell_profile) = configure_shell_profile {
|
if let Some(configure_shell_profile) = configure_shell_profile {
|
||||||
buf.append(&mut configure_shell_profile.describe_execute());
|
buf.append(&mut configure_shell_profile.describe_execute());
|
||||||
}
|
}
|
||||||
|
@ -94,18 +84,12 @@ impl Action for ConfigureNix {
|
||||||
let Self {
|
let Self {
|
||||||
setup_default_profile,
|
setup_default_profile,
|
||||||
place_nix_configuration,
|
place_nix_configuration,
|
||||||
place_channel_configuration,
|
|
||||||
configure_shell_profile,
|
configure_shell_profile,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
if let Some(configure_shell_profile) = configure_shell_profile {
|
if let Some(configure_shell_profile) = configure_shell_profile {
|
||||||
let setup_default_profile_span = tracing::Span::current().clone();
|
let setup_default_profile_span = tracing::Span::current().clone();
|
||||||
let (
|
let (place_nix_configuration_span, configure_shell_profile_span) = (
|
||||||
place_nix_configuration_span,
|
|
||||||
place_channel_configuration_span,
|
|
||||||
configure_shell_profile_span,
|
|
||||||
) = (
|
|
||||||
setup_default_profile_span.clone(),
|
|
||||||
setup_default_profile_span.clone(),
|
setup_default_profile_span.clone(),
|
||||||
setup_default_profile_span.clone(),
|
setup_default_profile_span.clone(),
|
||||||
);
|
);
|
||||||
|
@ -128,18 +112,6 @@ impl Action for ConfigureNix {
|
||||||
ActionError::Child(place_nix_configuration.action_tag(), Box::new(e))
|
ActionError::Child(place_nix_configuration.action_tag(), Box::new(e))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async move {
|
|
||||||
place_channel_configuration
|
|
||||||
.try_execute()
|
|
||||||
.instrument(place_channel_configuration_span)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
ActionError::Child(
|
|
||||||
place_channel_configuration.action_tag(),
|
|
||||||
Box::new(e),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
async move {
|
async move {
|
||||||
configure_shell_profile
|
configure_shell_profile
|
||||||
.try_execute()
|
.try_execute()
|
||||||
|
@ -151,11 +123,8 @@ impl Action for ConfigureNix {
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
let place_channel_configuration_span = tracing::Span::current().clone();
|
let setup_default_profile_span = tracing::Span::current().clone();
|
||||||
let (setup_default_profile_span, place_nix_configuration_span) = (
|
let place_nix_configuration_span = setup_default_profile_span.clone();
|
||||||
place_channel_configuration_span.clone(),
|
|
||||||
place_channel_configuration_span.clone(),
|
|
||||||
);
|
|
||||||
tokio::try_join!(
|
tokio::try_join!(
|
||||||
async move {
|
async move {
|
||||||
setup_default_profile
|
setup_default_profile
|
||||||
|
@ -175,18 +144,6 @@ impl Action for ConfigureNix {
|
||||||
ActionError::Child(place_nix_configuration.action_tag(), Box::new(e))
|
ActionError::Child(place_nix_configuration.action_tag(), Box::new(e))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async move {
|
|
||||||
place_channel_configuration
|
|
||||||
.try_execute()
|
|
||||||
.instrument(place_channel_configuration_span)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
ActionError::Child(
|
|
||||||
place_channel_configuration.action_tag(),
|
|
||||||
Box::new(e),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
)?;
|
)?;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -197,7 +154,6 @@ impl Action for ConfigureNix {
|
||||||
let Self {
|
let Self {
|
||||||
setup_default_profile,
|
setup_default_profile,
|
||||||
place_nix_configuration,
|
place_nix_configuration,
|
||||||
place_channel_configuration,
|
|
||||||
configure_shell_profile,
|
configure_shell_profile,
|
||||||
} = &self;
|
} = &self;
|
||||||
|
|
||||||
|
@ -205,7 +161,6 @@ impl Action for ConfigureNix {
|
||||||
if let Some(configure_shell_profile) = configure_shell_profile {
|
if let Some(configure_shell_profile) = configure_shell_profile {
|
||||||
buf.append(&mut configure_shell_profile.describe_revert());
|
buf.append(&mut configure_shell_profile.describe_revert());
|
||||||
}
|
}
|
||||||
buf.append(&mut place_channel_configuration.describe_revert());
|
|
||||||
buf.append(&mut place_nix_configuration.describe_revert());
|
buf.append(&mut place_nix_configuration.describe_revert());
|
||||||
buf.append(&mut setup_default_profile.describe_revert());
|
buf.append(&mut setup_default_profile.describe_revert());
|
||||||
|
|
||||||
|
@ -219,12 +174,6 @@ impl Action for ConfigureNix {
|
||||||
ActionError::Child(configure_shell_profile.action_tag(), Box::new(e))
|
ActionError::Child(configure_shell_profile.action_tag(), Box::new(e))
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
self.place_channel_configuration
|
|
||||||
.try_revert()
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
ActionError::Child(self.place_channel_configuration.action_tag(), Box::new(e))
|
|
||||||
})?;
|
|
||||||
self.place_nix_configuration
|
self.place_nix_configuration
|
||||||
.try_revert()
|
.try_revert()
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -5,7 +5,6 @@ pub(crate) mod configure_nix;
|
||||||
pub(crate) mod configure_shell_profile;
|
pub(crate) mod configure_shell_profile;
|
||||||
pub(crate) mod create_nix_tree;
|
pub(crate) mod create_nix_tree;
|
||||||
pub(crate) mod create_users_and_groups;
|
pub(crate) mod create_users_and_groups;
|
||||||
pub(crate) mod place_channel_configuration;
|
|
||||||
pub(crate) mod place_nix_configuration;
|
pub(crate) mod place_nix_configuration;
|
||||||
pub(crate) mod provision_nix;
|
pub(crate) mod provision_nix;
|
||||||
|
|
||||||
|
@ -14,6 +13,5 @@ pub use configure_nix::ConfigureNix;
|
||||||
pub use configure_shell_profile::ConfigureShellProfile;
|
pub use configure_shell_profile::ConfigureShellProfile;
|
||||||
pub use create_nix_tree::CreateNixTree;
|
pub use create_nix_tree::CreateNixTree;
|
||||||
pub use create_users_and_groups::CreateUsersAndGroups;
|
pub use create_users_and_groups::CreateUsersAndGroups;
|
||||||
pub use place_channel_configuration::{PlaceChannelConfiguration, PlaceChannelConfigurationError};
|
|
||||||
pub use place_nix_configuration::PlaceNixConfiguration;
|
pub use place_nix_configuration::PlaceNixConfiguration;
|
||||||
pub use provision_nix::ProvisionNix;
|
pub use provision_nix::ProvisionNix;
|
||||||
|
|
|
@ -1,115 +0,0 @@
|
||||||
use crate::action::base::CreateFile;
|
|
||||||
use crate::action::{Action, ActionDescription, StatefulAction};
|
|
||||||
use crate::action::{ActionError, ActionTag};
|
|
||||||
use crate::ChannelValue;
|
|
||||||
use tracing::{span, Span};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Place a channel configuration containing `channels` to the `$ROOT_HOME/.nix-channels` file
|
|
||||||
*/
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
|
||||||
pub struct PlaceChannelConfiguration {
|
|
||||||
channels: Vec<ChannelValue>,
|
|
||||||
create_file: StatefulAction<CreateFile>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PlaceChannelConfiguration {
|
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
|
||||||
pub async fn plan(
|
|
||||||
channels: Vec<ChannelValue>,
|
|
||||||
force: bool,
|
|
||||||
) -> Result<StatefulAction<Self>, ActionError> {
|
|
||||||
let buf = channels
|
|
||||||
.iter()
|
|
||||||
.map(|ChannelValue(name, url)| format!("{} {}", url, name))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join("\n");
|
|
||||||
let create_file = CreateFile::plan(
|
|
||||||
dirs::home_dir()
|
|
||||||
.ok_or_else(|| {
|
|
||||||
ActionError::Custom(Box::new(PlaceChannelConfigurationError::NoRootHome))
|
|
||||||
})?
|
|
||||||
.join(".nix-channels"),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
0o0644,
|
|
||||||
buf,
|
|
||||||
force,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(|e| ActionError::Child(CreateFile::action_tag(), Box::new(e)))?;
|
|
||||||
Ok(Self {
|
|
||||||
create_file,
|
|
||||||
channels,
|
|
||||||
}
|
|
||||||
.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
#[typetag::serde(name = "place_channel_configuration")]
|
|
||||||
impl Action for PlaceChannelConfiguration {
|
|
||||||
fn action_tag() -> ActionTag {
|
|
||||||
ActionTag("place_channel_configuration")
|
|
||||||
}
|
|
||||||
fn tracing_synopsis(&self) -> String {
|
|
||||||
format!(
|
|
||||||
"Place channel configuration at `{}`",
|
|
||||||
self.create_file.inner().path.display()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tracing_span(&self) -> Span {
|
|
||||||
span!(
|
|
||||||
tracing::Level::DEBUG,
|
|
||||||
"place_channel_configuration",
|
|
||||||
channels = self
|
|
||||||
.channels
|
|
||||||
.iter()
|
|
||||||
.map(|ChannelValue(c, u)| format!("{c}={u}"))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", "),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn execute_description(&self) -> Vec<ActionDescription> {
|
|
||||||
vec![ActionDescription::new(self.tracing_synopsis(), vec![])]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
|
||||||
async fn execute(&mut self) -> Result<(), ActionError> {
|
|
||||||
self.create_file
|
|
||||||
.try_execute()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ActionError::Child(self.create_file.action_tag(), Box::new(e)))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn revert_description(&self) -> Vec<ActionDescription> {
|
|
||||||
vec![ActionDescription::new(
|
|
||||||
format!(
|
|
||||||
"Remove channel configuration at `{}`",
|
|
||||||
self.create_file.inner().path.display()
|
|
||||||
),
|
|
||||||
vec![],
|
|
||||||
)]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
|
||||||
async fn revert(&mut self) -> Result<(), ActionError> {
|
|
||||||
self.create_file
|
|
||||||
.try_revert()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ActionError::Child(self.create_file.action_tag(), Box::new(e)))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[non_exhaustive]
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum PlaceChannelConfigurationError {
|
|
||||||
#[error("No root home found to place channel configuration in")]
|
|
||||||
NoRootHome,
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
use reqwest::Url;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
/**
|
|
||||||
A pair of [`String`] and [`Url`] destined for the list of subscribed channels for [`nix-channel`](https://nixos.org/manual/nix/stable/command-ref/nix-channel.html)
|
|
||||||
*/
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct ChannelValue(pub String, pub Url);
|
|
||||||
|
|
||||||
#[cfg(feature = "cli")]
|
|
||||||
impl clap::builder::ValueParserFactory for ChannelValue {
|
|
||||||
type Parser = ChannelValueParser;
|
|
||||||
fn value_parser() -> Self::Parser {
|
|
||||||
ChannelValueParser
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<(String, Url)> for ChannelValue {
|
|
||||||
fn from((string, url): (String, Url)) -> Self {
|
|
||||||
Self(string, url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct ChannelValueParser;
|
|
||||||
|
|
||||||
#[cfg(feature = "cli")]
|
|
||||||
impl clap::builder::TypedValueParser for ChannelValueParser {
|
|
||||||
type Value = ChannelValue;
|
|
||||||
|
|
||||||
fn parse_ref(
|
|
||||||
&self,
|
|
||||||
_cmd: &clap::Command,
|
|
||||||
_arg: Option<&clap::Arg>,
|
|
||||||
value: &std::ffi::OsStr,
|
|
||||||
) -> Result<Self::Value, clap::Error> {
|
|
||||||
let buf = value.to_str().ok_or_else(|| {
|
|
||||||
clap::Error::raw(clap::error::ErrorKind::InvalidValue, "Should be all UTF-8")
|
|
||||||
})?;
|
|
||||||
let (name, url) = buf.split_once('=').ok_or_else(|| {
|
|
||||||
clap::Error::raw(
|
|
||||||
clap::error::ErrorKind::InvalidValue,
|
|
||||||
"`--channel` should be formatted `name=url`, eg `--channel nixpkgs=https://nixos.org/channels/nixpkgs-unstable`. To not use a channel, pass `--channel`",
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
let name = name.to_owned();
|
|
||||||
let url = url.parse().unwrap();
|
|
||||||
Ok(ChannelValue(name, url))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -70,7 +70,6 @@ match plan.install(None).await {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub mod action;
|
pub mod action;
|
||||||
mod channel_value;
|
|
||||||
#[cfg(feature = "cli")]
|
#[cfg(feature = "cli")]
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
|
@ -85,7 +84,6 @@ use std::{ffi::OsStr, process::Output};
|
||||||
|
|
||||||
use action::{Action, ActionError};
|
use action::{Action, ActionError};
|
||||||
|
|
||||||
pub use channel_value::ChannelValue;
|
|
||||||
pub use error::NixInstallerError;
|
pub use error::NixInstallerError;
|
||||||
pub use plan::InstallPlan;
|
pub use plan::InstallPlan;
|
||||||
use planner::BuiltinPlanner;
|
use planner::BuiltinPlanner;
|
||||||
|
|
|
@ -6,8 +6,6 @@ use std::collections::HashMap;
|
||||||
use clap::ArgAction;
|
use clap::ArgAction;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::channel_value::ChannelValue;
|
|
||||||
|
|
||||||
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Linux x86_64
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Linux x86_64
|
||||||
pub const NIX_X64_64_LINUX_URL: &str =
|
pub const NIX_X64_64_LINUX_URL: &str =
|
||||||
"https://releases.nixos.org/nix/nix-2.13.3/nix-2.13.3-x86_64-linux.tar.xz";
|
"https://releases.nixos.org/nix/nix-2.13.3/nix-2.13.3-x86_64-linux.tar.xz";
|
||||||
|
@ -57,20 +55,6 @@ Settings which only apply to certain [`Planner`](crate::planner::Planner)s shoul
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||||
#[cfg_attr(feature = "cli", derive(clap::Parser))]
|
#[cfg_attr(feature = "cli", derive(clap::Parser))]
|
||||||
pub struct CommonSettings {
|
pub struct CommonSettings {
|
||||||
/// Channel(s) to add, for no default channel, pass `--channel`
|
|
||||||
#[cfg_attr(
|
|
||||||
feature = "cli",
|
|
||||||
clap(
|
|
||||||
value_parser,
|
|
||||||
long = "channel",
|
|
||||||
num_args = 0..,
|
|
||||||
action = clap::ArgAction::Append,
|
|
||||||
env = "NIX_INSTALLER_CHANNELS",
|
|
||||||
default_value = "nixpkgs=https://nixos.org/channels/nixpkgs-unstable",
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
pub(crate) channels: Vec<ChannelValue>,
|
|
||||||
|
|
||||||
/// Modify the user profile to automatically load nix
|
/// Modify the user profile to automatically load nix
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "cli",
|
feature = "cli",
|
||||||
|
@ -281,11 +265,6 @@ impl CommonSettings {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
nix_build_user_count: 32,
|
nix_build_user_count: 32,
|
||||||
channels: vec![ChannelValue(
|
|
||||||
"nixpkgs".into(),
|
|
||||||
reqwest::Url::parse("https://nixos.org/channels/nixpkgs-unstable")
|
|
||||||
.expect("Embedded default URL was not a URL, please report this"),
|
|
||||||
)],
|
|
||||||
modify_profile: true,
|
modify_profile: true,
|
||||||
nix_build_group_name: String::from("nixbld"),
|
nix_build_group_name: String::from("nixbld"),
|
||||||
nix_build_group_id: 30_000,
|
nix_build_group_id: 30_000,
|
||||||
|
@ -304,7 +283,6 @@ impl CommonSettings {
|
||||||
/// A listing of the settings, suitable for [`Planner::settings`](crate::planner::Planner::settings)
|
/// A listing of the settings, suitable for [`Planner::settings`](crate::planner::Planner::settings)
|
||||||
pub fn settings(&self) -> Result<HashMap<String, serde_json::Value>, InstallSettingsError> {
|
pub fn settings(&self) -> Result<HashMap<String, serde_json::Value>, InstallSettingsError> {
|
||||||
let Self {
|
let Self {
|
||||||
channels,
|
|
||||||
modify_profile,
|
modify_profile,
|
||||||
nix_build_user_count,
|
nix_build_user_count,
|
||||||
nix_build_group_name,
|
nix_build_group_name,
|
||||||
|
@ -319,15 +297,6 @@ impl CommonSettings {
|
||||||
} = self;
|
} = self;
|
||||||
let mut map = HashMap::default();
|
let mut map = HashMap::default();
|
||||||
|
|
||||||
map.insert(
|
|
||||||
"channels".into(),
|
|
||||||
serde_json::to_value(
|
|
||||||
channels
|
|
||||||
.iter()
|
|
||||||
.map(|ChannelValue(k, v)| format!("{k}={v}"))
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
)?,
|
|
||||||
);
|
|
||||||
map.insert(
|
map.insert(
|
||||||
"modify_profile".into(),
|
"modify_profile".into(),
|
||||||
serde_json::to_value(modify_profile)?,
|
serde_json::to_value(modify_profile)?,
|
||||||
|
@ -405,12 +374,6 @@ impl CommonSettings {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel(s) to add
|
|
||||||
pub fn channels(&mut self, channels: impl IntoIterator<Item = (String, Url)>) -> &mut Self {
|
|
||||||
self.channels = channels.into_iter().map(Into::into).collect();
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Modify the user profile to automatically load nix
|
/// Modify the user profile to automatically load nix
|
||||||
pub fn modify_profile(&mut self, toggle: bool) -> &mut Self {
|
pub fn modify_profile(&mut self, toggle: bool) -> &mut Self {
|
||||||
self.modify_profile = toggle;
|
self.modify_profile = toggle;
|
||||||
|
|
24
tests/fixtures/linux/linux.json
vendored
24
tests/fixtures/linux/linux.json
vendored
|
@ -831,28 +831,6 @@
|
||||||
},
|
},
|
||||||
"state": "Uncompleted"
|
"state": "Uncompleted"
|
||||||
},
|
},
|
||||||
"place_channel_configuration": {
|
|
||||||
"action": {
|
|
||||||
"channels": [
|
|
||||||
[
|
|
||||||
"nixpkgs",
|
|
||||||
"https://nixos.org/channels/nixpkgs-unstable"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"create_file": {
|
|
||||||
"action": {
|
|
||||||
"path": "/root/.nix-channels",
|
|
||||||
"user": null,
|
|
||||||
"group": null,
|
|
||||||
"mode": 436,
|
|
||||||
"buf": "https://nixos.org/channels/nixpkgs-unstable nixpkgs",
|
|
||||||
"force": false
|
|
||||||
},
|
|
||||||
"state": "Uncompleted"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"state": "Uncompleted"
|
|
||||||
},
|
|
||||||
"place_nix_configuration": {
|
"place_nix_configuration": {
|
||||||
"action": {
|
"action": {
|
||||||
"create_directory": {
|
"create_directory": {
|
||||||
|
@ -918,4 +896,4 @@
|
||||||
"start_daemon": true
|
"start_daemon": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
24
tests/fixtures/linux/steam-deck.json
vendored
24
tests/fixtures/linux/steam-deck.json
vendored
|
@ -875,28 +875,6 @@
|
||||||
},
|
},
|
||||||
"state": "Uncompleted"
|
"state": "Uncompleted"
|
||||||
},
|
},
|
||||||
"place_channel_configuration": {
|
|
||||||
"action": {
|
|
||||||
"channels": [
|
|
||||||
[
|
|
||||||
"nixpkgs",
|
|
||||||
"https://nixos.org/channels/nixpkgs-unstable"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"create_file": {
|
|
||||||
"action": {
|
|
||||||
"path": "/home/ubuntu/.nix-channels",
|
|
||||||
"user": null,
|
|
||||||
"group": null,
|
|
||||||
"mode": 436,
|
|
||||||
"buf": "https://nixos.org/channels/nixpkgs-unstable nixpkgs",
|
|
||||||
"force": false
|
|
||||||
},
|
|
||||||
"state": "Uncompleted"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"state": "Uncompleted"
|
|
||||||
},
|
|
||||||
"place_nix_configuration": {
|
"place_nix_configuration": {
|
||||||
"action": {
|
"action": {
|
||||||
"create_directory": {
|
"create_directory": {
|
||||||
|
@ -967,4 +945,4 @@
|
||||||
"force": false
|
"force": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
24
tests/fixtures/macos/macos.json
vendored
24
tests/fixtures/macos/macos.json
vendored
|
@ -885,28 +885,6 @@
|
||||||
},
|
},
|
||||||
"state": "Uncompleted"
|
"state": "Uncompleted"
|
||||||
},
|
},
|
||||||
"place_channel_configuration": {
|
|
||||||
"action": {
|
|
||||||
"channels": [
|
|
||||||
[
|
|
||||||
"nixpkgs",
|
|
||||||
"https://nixos.org/channels/nixpkgs-unstable"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"create_file": {
|
|
||||||
"action": {
|
|
||||||
"path": "/Users/ephemeraladmin/.nix-channels",
|
|
||||||
"user": null,
|
|
||||||
"group": null,
|
|
||||||
"mode": 436,
|
|
||||||
"buf": "https://nixos.org/channels/nixpkgs-unstable nixpkgs",
|
|
||||||
"force": false
|
|
||||||
},
|
|
||||||
"state": "Uncompleted"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"state": "Uncompleted"
|
|
||||||
},
|
|
||||||
"place_nix_configuration": {
|
"place_nix_configuration": {
|
||||||
"action": {
|
"action": {
|
||||||
"create_directory": {
|
"create_directory": {
|
||||||
|
@ -972,4 +950,4 @@
|
||||||
"volume_label": "Nix Store",
|
"volume_label": "Nix Store",
|
||||||
"root_disk": "disk1"
|
"root_disk": "disk1"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue