[DetSys#1123] Synchronize macOS UIDs and GIDs with upstream scripts to prepare for Sequoia

This removes the conditionality of the higher UID range and instead
makes all future installs on macOS use 351+.

(cherry picked from commit d8f9ed9dd92b1cb3ed9a73b3461065834c40b170)
Upstream-PR: https://github.com/DeterminateSystems/nix-installer/pull/1123
Fixes: #18
Fixes: #24
Change-Id: Ieb988f81d0acfa00cbbfe40c4305e8e82387f116
This commit is contained in:
Cole Helbling 2024-08-30 09:48:23 -07:00 committed by Jade Lovelace
parent 962d7bf745
commit 7c00e44b14

View file

@ -92,12 +92,11 @@ pub struct CommonSettings {
/// The Nix build group GID
#[cfg_attr(
feature = "cli",
clap(
long,
default_value_t = 30_000,
env = "NIX_INSTALLER_NIX_BUILD_GROUP_ID",
global = true
)
clap(long, env = "NIX_INSTALLER_NIX_BUILD_GROUP_ID", global = true)
)]
#[cfg_attr(
feature = "cli",
clap(default_value_t = default_nix_build_group_id())
)]
pub nix_build_group_id: u32,
@ -137,13 +136,9 @@ pub struct CommonSettings {
)]
#[cfg_attr(
all(target_os = "macos", feature = "cli"),
doc = "Service users on Mac should be between 200-400"
)]
#[cfg_attr(all(target_os = "macos", feature = "cli"), clap(default_value_t = 300))]
#[cfg_attr(
all(target_os = "linux", feature = "cli"),
clap(default_value_t = 30_000)
doc = "Service users on Mac should be between 350-400"
)]
#[cfg_attr(feature = "cli", clap(default_value_t = default_nix_build_user_id_base()))]
pub nix_build_user_id_base: u32,
/// The Nix package URL
@ -225,13 +220,29 @@ pub struct CommonSettings {
pub enable_flakes: bool,
}
fn default_nix_build_user_id_base() -> u32 {
use target_lexicon::OperatingSystem;
match OperatingSystem::host() {
OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => 350,
_ => 30_000,
}
}
fn default_nix_build_group_id() -> u32 {
use target_lexicon::OperatingSystem;
match OperatingSystem::host() {
OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => 350,
_ => 30_000,
}
}
impl CommonSettings {
/// The default settings for the given Architecture & Operating System
pub async fn default() -> Result<Self, InstallSettingsError> {
let url;
let nix_build_user_prefix;
let nix_build_user_id_base;
let nix_build_user_count;
use target_lexicon::{Architecture, OperatingSystem};
match (Architecture::host(), OperatingSystem::host()) {
@ -239,8 +250,6 @@ impl CommonSettings {
(Architecture::X86_64, OperatingSystem::Linux) => {
url = LIX_X86_64_LINUX_URL;
nix_build_user_prefix = "nixbld";
nix_build_user_id_base = 30000;
nix_build_user_count = 32;
},
// FIXME(i686): support i686-linux again
/*
@ -248,32 +257,24 @@ impl CommonSettings {
(Architecture::X86_32(_), OperatingSystem::Linux) => {
url = LIX_I686_LINUX_URL;
nix_build_user_prefix = "nixbld";
nix_build_user_id_base = 30000;
nix_build_user_count = 32;
},
*/
#[cfg(target_os = "linux")]
(Architecture::Aarch64(_), OperatingSystem::Linux) => {
url = LIX_AARCH64_LINUX_URL;
nix_build_user_prefix = "nixbld";
nix_build_user_id_base = 30000;
nix_build_user_count = 32;
},
#[cfg(target_os = "macos")]
(Architecture::X86_64, OperatingSystem::MacOSX { .. })
| (Architecture::X86_64, OperatingSystem::Darwin) => {
url = LIX_X86_64_DARWIN_URL;
nix_build_user_prefix = "_nixbld";
nix_build_user_id_base = 300;
nix_build_user_count = 32;
},
#[cfg(target_os = "macos")]
(Architecture::Aarch64(_), OperatingSystem::MacOSX { .. })
| (Architecture::Aarch64(_), OperatingSystem::Darwin) => {
url = LIX_AARCH64_DARWIN_URL;
nix_build_user_prefix = "_nixbld";
nix_build_user_id_base = 300;
nix_build_user_count = 32;
},
_ => {
return Err(InstallSettingsError::UnsupportedArchitecture(
@ -285,9 +286,9 @@ impl CommonSettings {
Ok(Self {
modify_profile: true,
nix_build_group_name: String::from("nixbld"),
nix_build_group_id: 30_000,
nix_build_user_id_base,
nix_build_user_count,
nix_build_group_id: default_nix_build_group_id(),
nix_build_user_id_base: default_nix_build_user_id_base(),
nix_build_user_count: 32,
nix_build_user_prefix: nix_build_user_prefix.to_string(),
nix_package_url: url.parse()?,
proxy: Default::default(),
@ -677,4 +678,4 @@ mod tests {
);
Ok(())
}
}
}