From 5fe7dd982803c5d303d591b5a2660097bf8f4f96 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Wed, 8 Mar 2023 09:24:41 -0800 Subject: [PATCH] Remove nix channel placement (#304) * Remove place_channel_configuration.rs * Remove channels option * Add fixture updates --- src/action/base/setup_default_profile.rs | 41 +------ src/action/common/configure_nix.rs | 61 +--------- src/action/common/mod.rs | 2 - .../common/place_channel_configuration.rs | 115 ------------------ src/channel_value.rs | 50 -------- src/lib.rs | 2 - src/settings.rs | 37 ------ tests/fixtures/linux/linux.json | 24 +--- tests/fixtures/linux/steam-deck.json | 24 +--- tests/fixtures/macos/macos.json | 24 +--- 10 files changed, 14 insertions(+), 366 deletions(-) delete mode 100644 src/action/common/place_channel_configuration.rs delete mode 100644 src/channel_value.rs diff --git a/src/action/base/setup_default_profile.rs b/src/action/base/setup_default_profile.rs index 8ab21fb..cc10053 100644 --- a/src/action/base/setup_default_profile.rs +++ b/src/action/base/setup_default_profile.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use crate::{ action::{ActionError, ActionTag, StatefulAction}, - execute_command, set_env, ChannelValue, + execute_command, set_env, }; use glob::glob; @@ -16,14 +16,12 @@ use crate::action::{Action, ActionDescription}; Setup the default Nix profile with `nss-cacert` and `nix` itself. */ #[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] -pub struct SetupDefaultProfile { - channels: Vec, -} +pub struct SetupDefaultProfile {} impl SetupDefaultProfile { #[tracing::instrument(level = "debug", skip_all)] - pub async fn plan(channels: Vec) -> Result, ActionError> { - Ok(Self { channels }.into()) + pub async fn plan() -> Result, ActionError> { + Ok(Self {}.into()) } } @@ -38,16 +36,7 @@ impl Action for SetupDefaultProfile { } fn tracing_span(&self) -> Span { - span!( - tracing::Level::DEBUG, - "setup_default_profile", - channels = self - .channels - .iter() - .map(|ChannelValue(channel, url)| format!("{channel}={url}")) - .collect::>() - .join(","), - ) + span!(tracing::Level::DEBUG, "setup_default_profile",) } fn execute_description(&self) -> Vec { @@ -56,8 +45,6 @@ impl Action for SetupDefaultProfile { #[tracing::instrument(level = "debug", skip_all)] async fn execute(&mut self) -> Result<(), ActionError> { - let Self { channels } = self; - // Find an `nix` package let nix_pkg_glob = "/nix/store/*-nix-*"; 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", ); - 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(()) } fn revert_description(&self) -> Vec { vec![ActionDescription::new( "Unset the default Nix profile".to_string(), - vec!["TODO".to_string()], + vec![], )] } diff --git a/src/action/common/configure_nix.rs b/src/action/common/configure_nix.rs index 9099744..64b3b4a 100644 --- a/src/action/common/configure_nix.rs +++ b/src/action/common/configure_nix.rs @@ -1,7 +1,7 @@ use crate::{ action::{ base::SetupDefaultProfile, - common::{ConfigureShellProfile, PlaceChannelConfiguration, PlaceNixConfiguration}, + common::{ConfigureShellProfile, PlaceNixConfiguration}, Action, ActionDescription, ActionError, ActionTag, StatefulAction, }, settings::CommonSettings, @@ -16,14 +16,13 @@ Configure Nix and start it pub struct ConfigureNix { setup_default_profile: StatefulAction, configure_shell_profile: Option>, - place_channel_configuration: StatefulAction, place_nix_configuration: StatefulAction, } impl ConfigureNix { #[tracing::instrument(level = "debug", skip_all)] pub async fn plan(settings: &CommonSettings) -> Result, ActionError> { - let setup_default_profile = SetupDefaultProfile::plan(settings.channels.clone()) + let setup_default_profile = SetupDefaultProfile::plan() .await .map_err(|e| ActionError::Child(SetupDefaultProfile::action_tag(), Box::new(e)))?; @@ -34,12 +33,6 @@ impl ConfigureNix { } else { 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( settings.nix_build_group_name.clone(), settings.extra_conf.clone(), @@ -49,7 +42,6 @@ impl ConfigureNix { .map_err(|e| ActionError::Child(PlaceNixConfiguration::action_tag(), Box::new(e)))?; Ok(Self { - place_channel_configuration, place_nix_configuration, setup_default_profile, configure_shell_profile, @@ -76,13 +68,11 @@ impl Action for ConfigureNix { let Self { setup_default_profile, place_nix_configuration, - place_channel_configuration, configure_shell_profile, } = &self; let mut buf = setup_default_profile.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 { buf.append(&mut configure_shell_profile.describe_execute()); } @@ -94,18 +84,12 @@ impl Action for ConfigureNix { let Self { setup_default_profile, place_nix_configuration, - place_channel_configuration, configure_shell_profile, } = self; if let Some(configure_shell_profile) = configure_shell_profile { let setup_default_profile_span = tracing::Span::current().clone(); - let ( - place_nix_configuration_span, - place_channel_configuration_span, - configure_shell_profile_span, - ) = ( - setup_default_profile_span.clone(), + let (place_nix_configuration_span, configure_shell_profile_span) = ( 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)) }) }, - 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 { configure_shell_profile .try_execute() @@ -151,11 +123,8 @@ impl Action for ConfigureNix { }, )?; } else { - let place_channel_configuration_span = tracing::Span::current().clone(); - let (setup_default_profile_span, place_nix_configuration_span) = ( - place_channel_configuration_span.clone(), - place_channel_configuration_span.clone(), - ); + let setup_default_profile_span = tracing::Span::current().clone(); + let place_nix_configuration_span = setup_default_profile_span.clone(); tokio::try_join!( async move { setup_default_profile @@ -175,18 +144,6 @@ impl Action for ConfigureNix { 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 { setup_default_profile, place_nix_configuration, - place_channel_configuration, configure_shell_profile, } = &self; @@ -205,7 +161,6 @@ impl Action for ConfigureNix { if let Some(configure_shell_profile) = configure_shell_profile { 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 setup_default_profile.describe_revert()); @@ -219,12 +174,6 @@ impl Action for ConfigureNix { 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 .try_revert() .await diff --git a/src/action/common/mod.rs b/src/action/common/mod.rs index ae7c566..21de280 100644 --- a/src/action/common/mod.rs +++ b/src/action/common/mod.rs @@ -5,7 +5,6 @@ pub(crate) mod configure_nix; pub(crate) mod configure_shell_profile; pub(crate) mod create_nix_tree; pub(crate) mod create_users_and_groups; -pub(crate) mod place_channel_configuration; pub(crate) mod place_nix_configuration; pub(crate) mod provision_nix; @@ -14,6 +13,5 @@ pub use configure_nix::ConfigureNix; pub use configure_shell_profile::ConfigureShellProfile; pub use create_nix_tree::CreateNixTree; pub use create_users_and_groups::CreateUsersAndGroups; -pub use place_channel_configuration::{PlaceChannelConfiguration, PlaceChannelConfigurationError}; pub use place_nix_configuration::PlaceNixConfiguration; pub use provision_nix::ProvisionNix; diff --git a/src/action/common/place_channel_configuration.rs b/src/action/common/place_channel_configuration.rs deleted file mode 100644 index 78c5501..0000000 --- a/src/action/common/place_channel_configuration.rs +++ /dev/null @@ -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, - create_file: StatefulAction, -} - -impl PlaceChannelConfiguration { - #[tracing::instrument(level = "debug", skip_all)] - pub async fn plan( - channels: Vec, - force: bool, - ) -> Result, ActionError> { - let buf = channels - .iter() - .map(|ChannelValue(name, url)| format!("{} {}", url, name)) - .collect::>() - .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::>() - .join(", "), - ) - } - - fn execute_description(&self) -> Vec { - 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 { - 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, -} diff --git a/src/channel_value.rs b/src/channel_value.rs deleted file mode 100644 index 29080a2..0000000 --- a/src/channel_value.rs +++ /dev/null @@ -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 { - 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)) - } -} diff --git a/src/lib.rs b/src/lib.rs index 7ca6b97..b33e079 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,6 @@ match plan.install(None).await { */ pub mod action; -mod channel_value; #[cfg(feature = "cli")] pub mod cli; #[cfg(feature = "diagnostics")] @@ -85,7 +84,6 @@ use std::{ffi::OsStr, process::Output}; use action::{Action, ActionError}; -pub use channel_value::ChannelValue; pub use error::NixInstallerError; pub use plan::InstallPlan; use planner::BuiltinPlanner; diff --git a/src/settings.rs b/src/settings.rs index 1b05c77..5d9263e 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -6,8 +6,6 @@ use std::collections::HashMap; use clap::ArgAction; use url::Url; -use crate::channel_value::ChannelValue; - /// Default [`nix_package_url`](CommonSettings::nix_package_url) for Linux x86_64 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"; @@ -57,20 +55,6 @@ Settings which only apply to certain [`Planner`](crate::planner::Planner)s shoul #[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] #[cfg_attr(feature = "cli", derive(clap::Parser))] 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, - /// Modify the user profile to automatically load nix #[cfg_attr( feature = "cli", @@ -281,11 +265,6 @@ impl CommonSettings { Ok(Self { 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, nix_build_group_name: String::from("nixbld"), 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) pub fn settings(&self) -> Result, InstallSettingsError> { let Self { - channels, modify_profile, nix_build_user_count, nix_build_group_name, @@ -319,15 +297,6 @@ impl CommonSettings { } = self; let mut map = HashMap::default(); - map.insert( - "channels".into(), - serde_json::to_value( - channels - .iter() - .map(|ChannelValue(k, v)| format!("{k}={v}")) - .collect::>(), - )?, - ); map.insert( "modify_profile".into(), serde_json::to_value(modify_profile)?, @@ -405,12 +374,6 @@ impl CommonSettings { self } - /// Channel(s) to add - pub fn channels(&mut self, channels: impl IntoIterator) -> &mut Self { - self.channels = channels.into_iter().map(Into::into).collect(); - self - } - /// Modify the user profile to automatically load nix pub fn modify_profile(&mut self, toggle: bool) -> &mut Self { self.modify_profile = toggle; diff --git a/tests/fixtures/linux/linux.json b/tests/fixtures/linux/linux.json index 354c638..9b4c708 100644 --- a/tests/fixtures/linux/linux.json +++ b/tests/fixtures/linux/linux.json @@ -831,28 +831,6 @@ }, "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": { "action": { "create_directory": { @@ -918,4 +896,4 @@ "start_daemon": true } } -} +} \ No newline at end of file diff --git a/tests/fixtures/linux/steam-deck.json b/tests/fixtures/linux/steam-deck.json index 08e1fa3..50bfb4a 100644 --- a/tests/fixtures/linux/steam-deck.json +++ b/tests/fixtures/linux/steam-deck.json @@ -875,28 +875,6 @@ }, "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": { "action": { "create_directory": { @@ -967,4 +945,4 @@ "force": false } } -} +} \ No newline at end of file diff --git a/tests/fixtures/macos/macos.json b/tests/fixtures/macos/macos.json index 89ca8b1..a6595c1 100644 --- a/tests/fixtures/macos/macos.json +++ b/tests/fixtures/macos/macos.json @@ -885,28 +885,6 @@ }, "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": { "action": { "create_directory": { @@ -972,4 +950,4 @@ "volume_label": "Nix Store", "root_disk": "disk1" } -} +} \ No newline at end of file