2022-11-28 22:57:35 +00:00
|
|
|
/*! Configurable knobs and their related errors
|
|
|
|
*/
|
2022-10-28 19:44:07 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg(feature = "cli")]
|
2022-10-25 18:57:09 +00:00
|
|
|
use clap::ArgAction;
|
2022-09-14 22:18:13 +00:00
|
|
|
use url::Url;
|
|
|
|
|
2022-10-28 21:15:33 +00:00
|
|
|
use crate::channel_value::ChannelValue;
|
2022-10-28 19:44:07 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Linux x86_64
|
2022-10-25 18:57:09 +00:00
|
|
|
pub const NIX_X64_64_LINUX_URL: &str =
|
2023-02-08 19:41:36 +00:00
|
|
|
"https://releases.nixos.org/nix/nix-2.13.2/nix-2.13.2-x86_64-linux.tar.xz";
|
2023-02-06 15:50:23 +00:00
|
|
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Linux x86 (32 bit)
|
|
|
|
pub const NIX_I686_LINUX_URL: &str =
|
2023-02-08 19:41:36 +00:00
|
|
|
"https://releases.nixos.org/nix/nix-2.13.2/nix-2.13.2-i686-linux.tar.xz";
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Linux aarch64
|
2022-10-25 18:57:09 +00:00
|
|
|
pub const NIX_AARCH64_LINUX_URL: &str =
|
2023-02-08 19:41:36 +00:00
|
|
|
"https://releases.nixos.org/nix/nix-2.13.2/nix-2.13.2-aarch64-linux.tar.xz";
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Darwin x86_64
|
2022-10-25 18:57:09 +00:00
|
|
|
pub const NIX_X64_64_DARWIN_URL: &str =
|
2023-02-08 19:41:36 +00:00
|
|
|
"https://releases.nixos.org/nix/nix-2.13.2/nix-2.13.2-x86_64-darwin.tar.xz";
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for Darwin aarch64
|
2022-10-25 18:57:09 +00:00
|
|
|
pub const NIX_AARCH64_DARWIN_URL: &str =
|
2023-02-08 19:41:36 +00:00
|
|
|
"https://releases.nixos.org/nix/nix-2.13.2/nix-2.13.2-aarch64-darwin.tar.xz";
|
2022-10-25 18:57:09 +00:00
|
|
|
|
2023-02-01 20:35:52 +00:00
|
|
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, Copy)]
|
|
|
|
#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
|
|
|
|
pub enum InitSystem {
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
None,
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
Systemd,
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
Launchd,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for InitSystem {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
InitSystem::None => write!(f, "none"),
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
InitSystem::Systemd => write!(f, "systemd"),
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
InitSystem::Launchd => write!(f, "launchd"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/** Common settings used by all [`BuiltinPlanner`](crate::planner::BuiltinPlanner)s
|
|
|
|
|
|
|
|
Settings which only apply to certain [`Planner`](crate::planner::Planner)s should be located in the planner.
|
|
|
|
|
|
|
|
*/
|
2022-10-13 19:03:42 +00:00
|
|
|
#[serde_with::serde_as]
|
2022-11-28 22:57:35 +00:00
|
|
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
|
|
|
#[cfg_attr(feature = "cli", derive(clap::Parser))]
|
2022-10-26 16:27:50 +00:00
|
|
|
pub struct CommonSettings {
|
2022-12-23 19:07:14 +00:00
|
|
|
/// Channel(s) to add, for no default channel, pass `--channel`
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg_attr(
|
2022-12-16 18:55:28 +00:00
|
|
|
feature = "cli",
|
|
|
|
clap(
|
|
|
|
value_parser,
|
2022-12-23 19:07:14 +00:00
|
|
|
long = "channel",
|
|
|
|
num_args = 0..,
|
2022-12-16 18:55:28 +00:00
|
|
|
action = clap::ArgAction::Append,
|
2022-12-19 18:26:58 +00:00
|
|
|
env = "NIX_INSTALLER_CHANNELS",
|
2022-12-16 18:55:28 +00:00
|
|
|
default_value = "nixpkgs=https://nixos.org/channels/nixpkgs-unstable",
|
|
|
|
)
|
|
|
|
)]
|
2022-11-28 22:57:35 +00:00
|
|
|
pub(crate) channels: Vec<ChannelValue>,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-10-25 18:57:09 +00:00
|
|
|
/// Modify the user profile to automatically load nix
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
|
|
|
clap(
|
|
|
|
action(ArgAction::SetFalse),
|
|
|
|
default_value = "true",
|
|
|
|
global = true,
|
2023-01-20 20:08:34 +00:00
|
|
|
env = "NIX_INSTALLER_MODIFY_PROFILE",
|
|
|
|
long = "no-modify-profile"
|
2022-11-28 22:57:35 +00:00
|
|
|
)
|
2022-10-25 18:57:09 +00:00
|
|
|
)]
|
2022-11-28 22:57:35 +00:00
|
|
|
pub(crate) modify_profile: bool,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-10-25 18:57:09 +00:00
|
|
|
/// Number of build users to create
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
2022-12-16 18:55:28 +00:00
|
|
|
clap(
|
|
|
|
long,
|
|
|
|
default_value = "32",
|
2023-01-09 18:31:37 +00:00
|
|
|
alias = "daemon-user-count",
|
|
|
|
env = "NIX_INSTALLER_NIX_BUILD_USER_COUNT",
|
2022-12-16 18:55:28 +00:00
|
|
|
global = true
|
|
|
|
)
|
2022-11-28 22:57:35 +00:00
|
|
|
)]
|
2023-02-09 18:34:34 +00:00
|
|
|
pub(crate) nix_build_user_count: u32,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build group name
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
2022-12-16 18:55:28 +00:00
|
|
|
clap(
|
|
|
|
long,
|
|
|
|
default_value = "nixbld",
|
2022-12-19 18:26:58 +00:00
|
|
|
env = "NIX_INSTALLER_NIX_BUILD_GROUP_NAME",
|
2022-12-16 18:55:28 +00:00
|
|
|
global = true
|
|
|
|
)
|
2022-11-28 22:57:35 +00:00
|
|
|
)]
|
|
|
|
pub(crate) nix_build_group_name: String,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build group GID
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
2022-12-16 18:55:28 +00:00
|
|
|
clap(
|
|
|
|
long,
|
2023-02-01 18:41:10 +00:00
|
|
|
default_value_t = 30_000,
|
2022-12-19 18:26:58 +00:00
|
|
|
env = "NIX_INSTALLER_NIX_BUILD_GROUP_ID",
|
2022-12-16 18:55:28 +00:00
|
|
|
global = true
|
|
|
|
)
|
2022-11-28 22:57:35 +00:00
|
|
|
)]
|
2023-02-09 18:34:34 +00:00
|
|
|
pub(crate) nix_build_group_id: u32,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build user prefix (user numbers will be postfixed)
|
2022-12-16 18:55:28 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
2022-12-19 18:26:58 +00:00
|
|
|
clap(long, env = "NIX_INSTALLER_NIX_BUILD_USER_PREFIX", global = true)
|
2022-12-16 18:55:28 +00:00
|
|
|
)]
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
all(target_os = "macos", feature = "cli"),
|
|
|
|
clap(default_value = "_nixbld")
|
|
|
|
)]
|
|
|
|
#[cfg_attr(
|
|
|
|
all(target_os = "linux", feature = "cli"),
|
|
|
|
clap(default_value = "nixbld")
|
|
|
|
)]
|
|
|
|
pub(crate) nix_build_user_prefix: String,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build user base UID (ascending)
|
2022-12-16 18:55:28 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
2022-12-19 18:26:58 +00:00
|
|
|
clap(long, env = "NIX_INSTALLER_NIX_BUILD_USER_ID_BASE", global = true)
|
2022-12-16 18:55:28 +00:00
|
|
|
)]
|
2023-02-01 18:40:42 +00:00
|
|
|
// Service users on Mac should be between 200-400
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg_attr(all(target_os = "macos", feature = "cli"), clap(default_value_t = 300))]
|
|
|
|
#[cfg_attr(
|
|
|
|
all(target_os = "linux", feature = "cli"),
|
2023-02-01 18:41:10 +00:00
|
|
|
clap(default_value_t = 30_000)
|
2022-11-28 22:57:35 +00:00
|
|
|
)]
|
2023-02-09 18:34:34 +00:00
|
|
|
pub(crate) nix_build_user_id_base: u32,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix package URL
|
2022-12-16 18:55:28 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
2022-12-19 18:26:58 +00:00
|
|
|
clap(long, env = "NIX_INSTALLER_NIX_PACKAGE_URL", global = true)
|
2022-12-16 18:55:28 +00:00
|
|
|
)]
|
2022-10-25 18:57:09 +00:00
|
|
|
#[cfg_attr(
|
2022-11-28 22:57:35 +00:00
|
|
|
all(target_os = "macos", target_arch = "x86_64", feature = "cli"),
|
2022-10-25 18:57:09 +00:00
|
|
|
clap(
|
|
|
|
default_value = NIX_X64_64_DARWIN_URL,
|
|
|
|
)
|
|
|
|
)]
|
|
|
|
#[cfg_attr(
|
2022-11-28 22:57:35 +00:00
|
|
|
all(target_os = "macos", target_arch = "aarch64", feature = "cli"),
|
2022-10-25 18:57:09 +00:00
|
|
|
clap(
|
|
|
|
default_value = NIX_AARCH64_DARWIN_URL,
|
|
|
|
)
|
|
|
|
)]
|
|
|
|
#[cfg_attr(
|
2022-11-28 22:57:35 +00:00
|
|
|
all(target_os = "linux", target_arch = "x86_64", feature = "cli"),
|
2022-10-25 18:57:09 +00:00
|
|
|
clap(
|
|
|
|
default_value = NIX_X64_64_LINUX_URL,
|
|
|
|
)
|
|
|
|
)]
|
2023-02-06 15:50:23 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
all(target_os = "linux", target_arch = "x86", feature = "cli"),
|
|
|
|
clap(
|
|
|
|
default_value = NIX_I686_LINUX_URL,
|
|
|
|
)
|
|
|
|
)]
|
2022-10-25 18:57:09 +00:00
|
|
|
#[cfg_attr(
|
2022-11-28 22:57:35 +00:00
|
|
|
all(target_os = "linux", target_arch = "aarch64", feature = "cli"),
|
2022-10-25 18:57:09 +00:00
|
|
|
clap(
|
|
|
|
default_value = NIX_AARCH64_LINUX_URL,
|
|
|
|
)
|
|
|
|
)]
|
2022-11-28 22:57:35 +00:00
|
|
|
pub(crate) nix_package_url: Url,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Extra configuration lines for `/etc/nix.conf`
|
2022-12-19 18:26:58 +00:00
|
|
|
#[cfg_attr(feature = "cli", clap(long, action = ArgAction::Set, num_args = 0.., value_delimiter = ',', env = "NIX_INSTALLER_EXTRA_CONF", global = true))]
|
2022-12-02 15:31:15 +00:00
|
|
|
pub extra_conf: Vec<String>,
|
2022-10-26 16:27:50 +00:00
|
|
|
|
2022-12-19 18:26:58 +00:00
|
|
|
/// If `nix-installer` should forcibly recreate files it finds existing
|
2022-11-28 22:57:35 +00:00
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
|
|
|
clap(
|
|
|
|
long,
|
|
|
|
action(ArgAction::SetTrue),
|
|
|
|
default_value = "false",
|
|
|
|
global = true,
|
2022-12-19 18:26:58 +00:00
|
|
|
env = "NIX_INSTALLER_FORCE"
|
2022-11-28 22:57:35 +00:00
|
|
|
)
|
2022-10-25 18:57:09 +00:00
|
|
|
)]
|
2022-11-28 22:57:35 +00:00
|
|
|
pub(crate) force: bool,
|
2023-02-24 18:11:12 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
|
/// The URL or file path for an installation diagnostic to be sent
|
|
|
|
///
|
|
|
|
/// Sample of the data sent:
|
|
|
|
///
|
|
|
|
/// {
|
|
|
|
/// "version": "0.3.0",
|
|
|
|
/// "planner": "linux",
|
|
|
|
/// "configured-settings": [ "modify_profile" ],
|
|
|
|
/// "os-name": "Ubuntu",
|
|
|
|
/// "os-version": "22.04.1 LTS (Jammy Jellyfish)",
|
|
|
|
/// "triple": "x86_64-unknown-linux-gnu",
|
|
|
|
/// "action": "Install",
|
|
|
|
/// "status": "Success"
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// To disable diagnostic reporting, unset the default with `--diagnostic-endpoint=`
|
|
|
|
#[clap(
|
|
|
|
long,
|
|
|
|
env = "NIX_INSTALLER_DIAGNOSTIC_ENDPOINT",
|
|
|
|
global = true,
|
|
|
|
default_value = "https://install.determinate.systems/nix/diagnostic"
|
|
|
|
)]
|
|
|
|
pub diagnostic_endpoint: Option<Url>,
|
2022-09-14 22:18:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 16:27:50 +00:00
|
|
|
impl CommonSettings {
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The default settings for the given Architecture & Operating System
|
2023-02-01 20:35:52 +00:00
|
|
|
pub async fn default() -> Result<Self, InstallSettingsError> {
|
2022-10-13 18:26:43 +00:00
|
|
|
let url;
|
2022-10-24 23:16:18 +00:00
|
|
|
let nix_build_user_prefix;
|
|
|
|
let nix_build_user_id_base;
|
2022-10-13 18:26:43 +00:00
|
|
|
|
|
|
|
use target_lexicon::{Architecture, OperatingSystem};
|
|
|
|
match (Architecture::host(), OperatingSystem::host()) {
|
2023-02-01 20:35:52 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2022-10-13 18:26:43 +00:00
|
|
|
(Architecture::X86_64, OperatingSystem::Linux) => {
|
2022-10-25 18:57:09 +00:00
|
|
|
url = NIX_X64_64_LINUX_URL;
|
2022-10-24 23:16:18 +00:00
|
|
|
nix_build_user_prefix = "nixbld";
|
2023-02-24 18:11:12 +00:00
|
|
|
nix_build_user_id_base = 30000;
|
2022-10-13 18:26:43 +00:00
|
|
|
},
|
2023-02-01 20:35:52 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2023-02-06 15:50:23 +00:00
|
|
|
(Architecture::X86_32(_), OperatingSystem::Linux) => {
|
|
|
|
url = NIX_I686_LINUX_URL;
|
|
|
|
nix_build_user_prefix = "nixbld";
|
2023-02-24 18:11:12 +00:00
|
|
|
nix_build_user_id_base = 30000;
|
2023-02-06 15:50:23 +00:00
|
|
|
},
|
|
|
|
#[cfg(target_os = "linux")]
|
2022-10-13 18:26:43 +00:00
|
|
|
(Architecture::Aarch64(_), OperatingSystem::Linux) => {
|
2022-10-25 18:57:09 +00:00
|
|
|
url = NIX_AARCH64_LINUX_URL;
|
2022-10-24 23:16:18 +00:00
|
|
|
nix_build_user_prefix = "nixbld";
|
2023-02-24 18:11:12 +00:00
|
|
|
nix_build_user_id_base = 30000;
|
2022-10-13 18:26:43 +00:00
|
|
|
},
|
2023-02-01 20:35:52 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2022-10-19 22:12:50 +00:00
|
|
|
(Architecture::X86_64, OperatingSystem::MacOSX { .. })
|
|
|
|
| (Architecture::X86_64, OperatingSystem::Darwin) => {
|
2022-10-25 18:57:09 +00:00
|
|
|
url = NIX_X64_64_DARWIN_URL;
|
2022-10-24 23:16:18 +00:00
|
|
|
nix_build_user_prefix = "_nixbld";
|
|
|
|
nix_build_user_id_base = 300;
|
2022-10-13 18:26:43 +00:00
|
|
|
},
|
2023-02-01 20:35:52 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2022-10-19 22:12:50 +00:00
|
|
|
(Architecture::Aarch64(_), OperatingSystem::MacOSX { .. })
|
|
|
|
| (Architecture::Aarch64(_), OperatingSystem::Darwin) => {
|
2022-10-25 18:57:09 +00:00
|
|
|
url = NIX_AARCH64_DARWIN_URL;
|
2022-10-24 23:16:18 +00:00
|
|
|
nix_build_user_prefix = "_nixbld";
|
|
|
|
nix_build_user_id_base = 300;
|
2022-10-13 18:26:43 +00:00
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
return Err(InstallSettingsError::UnsupportedArchitecture(
|
|
|
|
target_lexicon::HOST,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Self {
|
2023-01-09 18:31:37 +00:00
|
|
|
nix_build_user_count: 32,
|
2022-11-21 18:50:12 +00:00
|
|
|
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"),
|
|
|
|
)],
|
2022-10-25 18:57:09 +00:00
|
|
|
modify_profile: true,
|
2022-09-15 19:11:46 +00:00
|
|
|
nix_build_group_name: String::from("nixbld"),
|
2023-02-24 21:07:11 +00:00
|
|
|
nix_build_group_id: 30_000,
|
2022-10-24 23:16:18 +00:00
|
|
|
nix_build_user_prefix: nix_build_user_prefix.to_string(),
|
|
|
|
nix_build_user_id_base,
|
2022-10-25 18:57:09 +00:00
|
|
|
nix_package_url: url.parse()?,
|
2022-09-21 20:26:45 +00:00
|
|
|
extra_conf: Default::default(),
|
|
|
|
force: false,
|
2023-02-24 18:11:12 +00:00
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
|
diagnostic_endpoint: Some(
|
2023-02-24 21:07:11 +00:00
|
|
|
"https://install.determinate.systems/nix/diagnostic".try_into()?,
|
2023-02-24 18:11:12 +00:00
|
|
|
),
|
2022-10-13 18:26:43 +00:00
|
|
|
})
|
2022-09-15 19:11:46 +00:00
|
|
|
}
|
2022-10-28 19:44:07 +00:00
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// A listing of the settings, suitable for [`Planner::settings`](crate::planner::Planner::settings)
|
|
|
|
pub fn settings(&self) -> Result<HashMap<String, serde_json::Value>, InstallSettingsError> {
|
2022-10-28 19:44:07 +00:00
|
|
|
let Self {
|
|
|
|
channels,
|
|
|
|
modify_profile,
|
2023-01-09 18:31:37 +00:00
|
|
|
nix_build_user_count,
|
2022-10-28 19:44:07 +00:00
|
|
|
nix_build_group_name,
|
|
|
|
nix_build_group_id,
|
|
|
|
nix_build_user_prefix,
|
|
|
|
nix_build_user_id_base,
|
|
|
|
nix_package_url,
|
|
|
|
extra_conf,
|
|
|
|
force,
|
2023-02-24 18:11:12 +00:00
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
|
diagnostic_endpoint,
|
2022-10-28 19:44:07 +00:00
|
|
|
} = self;
|
|
|
|
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(
|
|
|
|
"modify_profile".into(),
|
|
|
|
serde_json::to_value(modify_profile)?,
|
|
|
|
);
|
|
|
|
map.insert(
|
2023-01-09 18:31:37 +00:00
|
|
|
"nix_build_user_count".into(),
|
|
|
|
serde_json::to_value(nix_build_user_count)?,
|
2022-10-28 19:44:07 +00:00
|
|
|
);
|
|
|
|
map.insert(
|
|
|
|
"nix_build_group_name".into(),
|
|
|
|
serde_json::to_value(nix_build_group_name)?,
|
|
|
|
);
|
|
|
|
map.insert(
|
|
|
|
"nix_build_group_id".into(),
|
|
|
|
serde_json::to_value(nix_build_group_id)?,
|
|
|
|
);
|
|
|
|
map.insert(
|
|
|
|
"nix_build_user_prefix".into(),
|
|
|
|
serde_json::to_value(nix_build_user_prefix)?,
|
|
|
|
);
|
|
|
|
map.insert(
|
|
|
|
"nix_build_user_id_base".into(),
|
|
|
|
serde_json::to_value(nix_build_user_id_base)?,
|
|
|
|
);
|
|
|
|
map.insert(
|
|
|
|
"nix_package_url".into(),
|
|
|
|
serde_json::to_value(nix_package_url)?,
|
|
|
|
);
|
|
|
|
map.insert("extra_conf".into(), serde_json::to_value(extra_conf)?);
|
|
|
|
map.insert("force".into(), serde_json::to_value(force)?);
|
|
|
|
|
2023-02-24 18:11:12 +00:00
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
|
map.insert(
|
|
|
|
"diagnostic_endpoint".into(),
|
|
|
|
serde_json::to_value(diagnostic_endpoint)?,
|
|
|
|
);
|
|
|
|
|
2022-10-28 19:44:07 +00:00
|
|
|
Ok(map)
|
|
|
|
}
|
2022-09-15 19:11:46 +00:00
|
|
|
}
|
2023-02-01 20:35:52 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
async fn linux_detect_init() -> (InitSystem, bool) {
|
|
|
|
use std::process::Stdio;
|
|
|
|
|
|
|
|
let mut detected = InitSystem::None;
|
|
|
|
let mut started = false;
|
|
|
|
if std::path::Path::new("/run/systemd/system").exists() {
|
|
|
|
detected = InitSystem::Systemd;
|
|
|
|
started = if tokio::process::Command::new("systemctl")
|
|
|
|
.arg("status")
|
|
|
|
.stdin(Stdio::null())
|
|
|
|
.stdout(Stdio::null())
|
|
|
|
.stderr(Stdio::null())
|
|
|
|
.status()
|
|
|
|
.await
|
|
|
|
.ok()
|
|
|
|
.map(|exit| exit.success())
|
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Other inits
|
|
|
|
(detected, started)
|
|
|
|
}
|
2022-09-15 19:11:46 +00:00
|
|
|
|
2022-09-14 22:18:13 +00:00
|
|
|
// Builder Pattern
|
2022-10-26 16:27:50 +00:00
|
|
|
impl CommonSettings {
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Number of build users to create
|
2023-02-09 18:34:34 +00:00
|
|
|
pub fn nix_build_user_count(&mut self, count: u32) -> &mut Self {
|
2023-01-09 18:31:37 +00:00
|
|
|
self.nix_build_user_count = count;
|
2022-09-14 22:18:13 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Channel(s) to add
|
2022-09-14 22:18:13 +00:00
|
|
|
pub fn channels(&mut self, channels: impl IntoIterator<Item = (String, Url)>) -> &mut Self {
|
2022-10-25 18:57:09 +00:00
|
|
|
self.channels = channels.into_iter().map(Into::into).collect();
|
2022-09-14 22:18:13 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Modify the user profile to automatically load nix
|
2022-09-14 22:18:13 +00:00
|
|
|
pub fn modify_profile(&mut self, toggle: bool) -> &mut Self {
|
|
|
|
self.modify_profile = toggle;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build group name
|
2022-09-14 22:18:13 +00:00
|
|
|
pub fn nix_build_group_name(&mut self, val: String) -> &mut Self {
|
|
|
|
self.nix_build_group_name = val;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build group GID
|
2023-02-09 18:34:34 +00:00
|
|
|
pub fn nix_build_group_id(&mut self, count: u32) -> &mut Self {
|
2022-09-14 22:18:13 +00:00
|
|
|
self.nix_build_group_id = count;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build user prefix (user numbers will be postfixed)
|
2022-09-14 22:18:13 +00:00
|
|
|
pub fn nix_build_user_prefix(&mut self, val: String) -> &mut Self {
|
|
|
|
self.nix_build_user_prefix = val;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// The Nix build user base UID (ascending)
|
2023-02-09 18:34:34 +00:00
|
|
|
pub fn nix_build_user_id_base(&mut self, count: u32) -> &mut Self {
|
2022-09-14 22:18:13 +00:00
|
|
|
self.nix_build_user_id_base = count;
|
|
|
|
self
|
|
|
|
}
|
2022-11-28 22:57:35 +00:00
|
|
|
|
|
|
|
/// The Nix package URL
|
2022-09-20 18:42:20 +00:00
|
|
|
pub fn nix_package_url(&mut self, url: Url) -> &mut Self {
|
|
|
|
self.nix_package_url = url;
|
|
|
|
self
|
|
|
|
}
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Extra configuration lines for `/etc/nix.conf`
|
2022-12-02 15:31:15 +00:00
|
|
|
pub fn extra_conf(&mut self, extra_conf: Vec<String>) -> &mut Self {
|
2022-09-21 20:26:45 +00:00
|
|
|
self.extra_conf = extra_conf;
|
|
|
|
self
|
|
|
|
}
|
2022-11-28 22:57:35 +00:00
|
|
|
|
2022-12-19 18:26:58 +00:00
|
|
|
/// If `nix-installer` should forcibly recreate files it finds existing
|
2022-09-21 20:26:45 +00:00
|
|
|
pub fn force(&mut self, force: bool) -> &mut Self {
|
|
|
|
self.force = force;
|
|
|
|
self
|
|
|
|
}
|
2023-02-24 18:11:12 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
|
/// The URL or file path for an [`DiagnosticReport`][crate::diagnostics::DiagnosticReport] to be sent
|
|
|
|
pub fn diagnostic_endpoint(&mut self, diagnostic_endpoint: Option<Url>) -> &mut Self {
|
|
|
|
self.diagnostic_endpoint = diagnostic_endpoint;
|
|
|
|
self
|
|
|
|
}
|
2022-09-15 19:11:46 +00:00
|
|
|
}
|
2022-10-13 18:26:43 +00:00
|
|
|
|
2023-02-01 20:35:52 +00:00
|
|
|
#[serde_with::serde_as]
|
|
|
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
|
|
|
#[cfg_attr(feature = "cli", derive(clap::Parser))]
|
|
|
|
pub struct InitSettings {
|
|
|
|
/// Which init system to configure (if `--init none` Nix will be root-only)
|
|
|
|
#[cfg_attr(feature = "cli", clap(value_parser, long, env = "NIX_INSTALLER_INIT",))]
|
|
|
|
#[cfg_attr(
|
|
|
|
all(target_os = "macos", feature = "cli"),
|
|
|
|
clap(default_value_t = InitSystem::Launchd)
|
|
|
|
)]
|
|
|
|
#[cfg_attr(
|
|
|
|
all(target_os = "linux", feature = "cli"),
|
|
|
|
clap(default_value_t = InitSystem::Systemd)
|
|
|
|
)]
|
|
|
|
pub(crate) init: InitSystem,
|
|
|
|
|
|
|
|
/// Start the daemon (if not `--init none`)
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "cli",
|
|
|
|
clap(
|
|
|
|
value_parser,
|
|
|
|
long,
|
|
|
|
action(ArgAction::SetFalse),
|
|
|
|
env = "NIX_INSTALLER_START_DAEMON",
|
|
|
|
default_value_t = true,
|
|
|
|
long = "no-start-daemon"
|
|
|
|
)
|
|
|
|
)]
|
|
|
|
pub(crate) start_daemon: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl InitSettings {
|
|
|
|
/// The default settings for the given Architecture & Operating System
|
|
|
|
pub async fn default() -> Result<Self, InstallSettingsError> {
|
|
|
|
let init;
|
|
|
|
let start_daemon;
|
|
|
|
|
|
|
|
use target_lexicon::{Architecture, OperatingSystem};
|
|
|
|
match (Architecture::host(), OperatingSystem::host()) {
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
(Architecture::X86_64, OperatingSystem::Linux) => {
|
|
|
|
(init, start_daemon) = linux_detect_init().await;
|
|
|
|
},
|
|
|
|
#[cfg(target_os = "linux")]
|
2023-02-06 15:50:23 +00:00
|
|
|
(Architecture::X86_32(_), OperatingSystem::Linux) => {
|
|
|
|
(init, start_daemon) = linux_detect_init().await;
|
|
|
|
},
|
|
|
|
#[cfg(target_os = "linux")]
|
2023-02-01 20:35:52 +00:00
|
|
|
(Architecture::Aarch64(_), OperatingSystem::Linux) => {
|
|
|
|
(init, start_daemon) = linux_detect_init().await;
|
|
|
|
},
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
(Architecture::X86_64, OperatingSystem::MacOSX { .. })
|
|
|
|
| (Architecture::X86_64, OperatingSystem::Darwin) => {
|
|
|
|
(init, start_daemon) = (InitSystem::Launchd, true);
|
|
|
|
},
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
(Architecture::Aarch64(_), OperatingSystem::MacOSX { .. })
|
|
|
|
| (Architecture::Aarch64(_), OperatingSystem::Darwin) => {
|
|
|
|
(init, start_daemon) = (InitSystem::Launchd, true);
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
return Err(InstallSettingsError::UnsupportedArchitecture(
|
|
|
|
target_lexicon::HOST,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Self { init, start_daemon })
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A listing of the settings, suitable for [`Planner::settings`](crate::planner::Planner::settings)
|
|
|
|
pub fn settings(&self) -> Result<HashMap<String, serde_json::Value>, InstallSettingsError> {
|
|
|
|
let Self { init, start_daemon } = self;
|
|
|
|
let mut map = HashMap::default();
|
|
|
|
|
|
|
|
map.insert("init".into(), serde_json::to_value(init)?);
|
|
|
|
map.insert("start_daemon".into(), serde_json::to_value(start_daemon)?);
|
|
|
|
Ok(map)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Which init system to configure
|
|
|
|
pub fn init(&mut self, init: InitSystem) -> &mut Self {
|
|
|
|
self.init = init;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Start the daemon (if one is configured)
|
|
|
|
pub fn start_daemon(&mut self, toggle: bool) -> &mut Self {
|
|
|
|
self.start_daemon = toggle;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:57:35 +00:00
|
|
|
/// An error originating from a [`Planner::settings`](crate::planner::Planner::settings)
|
2022-10-13 18:26:43 +00:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
pub enum InstallSettingsError {
|
2022-12-19 18:26:58 +00:00
|
|
|
/// `nix-installer` does not support the architecture right now
|
|
|
|
#[error("`nix-installer` does not support the `{0}` architecture right now")]
|
2022-10-13 18:26:43 +00:00
|
|
|
UnsupportedArchitecture(target_lexicon::Triple),
|
2022-11-28 22:57:35 +00:00
|
|
|
/// Parsing URL
|
2022-10-25 18:57:09 +00:00
|
|
|
#[error("Parsing URL")]
|
|
|
|
Parse(
|
2022-10-14 22:14:03 +00:00
|
|
|
#[source]
|
|
|
|
#[from]
|
2022-10-25 18:57:09 +00:00
|
|
|
url::ParseError,
|
2022-10-14 22:14:03 +00:00
|
|
|
),
|
2022-11-28 22:57:35 +00:00
|
|
|
/// JSON serialization or deserialization error
|
|
|
|
#[error("JSON serialization or deserialization error")]
|
|
|
|
SerdeJson(
|
|
|
|
#[source]
|
|
|
|
#[from]
|
|
|
|
serde_json::Error,
|
|
|
|
),
|
2023-02-01 20:35:52 +00:00
|
|
|
#[error("No supported init system found")]
|
|
|
|
InitNotSupported,
|
2022-10-13 18:26:43 +00:00
|
|
|
}
|