Skip to content

Commit ea3acfb

Browse files
authored
Add an option to prefer upstream Nix, implementing ItS#3 part one (#1664)
* Add an option to prefer upstream Nix, implementing ItS#3 part one Ref: https://determinate.systems/blog/installer-dropping-upstream/ * Make determinate-nixd non-optional to simplify the prefer-upstream flag * Clean up the messaging, notify users about upstream support going away * Fixup docs generation (thank you coderabbit.)
1 parent 2244bc0 commit ea3acfb

File tree

10 files changed

+112
-46
lines changed

10 files changed

+112
-46
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ repository = "https://github.com/DeterminateSystems/nix-installer"
99
documentation = "https://docs.rs/nix-installer/latest/nix_installer"
1010

1111
[features]
12-
default = ["cli", "diagnostics", "determinate-nix"]
13-
determinate-nix = []
12+
default = ["cli", "diagnostics"]
1413
cli = ["eyre", "color-eyre", "clap", "tracing-subscriber", "tracing-error"]
1514
diagnostics = ["detsys-ids-client", "is_ci"]
1615

@@ -73,6 +72,6 @@ lto = true
7372
# available in docs.rs's build. It doesn't influence docs, so it's fine to set it to a bogus (but
7473
# existing-file) value.
7574
cargo-args = [
76-
"--config", "env.NIX_INSTALLER_TARBALL_PATH=\"../Cargo.toml\"",
75+
"--config", "env.DETERMINATE_NIX_TARBALL_PATH=\"../Cargo.toml\"",
7776
"--config", "env.DETERMINATE_NIXD_BINARY_PATH=\"../Cargo.toml\""
7877
]

src/action/common/provision_determinate_nixd.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ pub struct ProvisionDeterminateNixd {
2323
impl ProvisionDeterminateNixd {
2424
#[tracing::instrument(level = "debug", skip_all)]
2525
pub async fn plan() -> Result<StatefulAction<Self>, ActionError> {
26-
crate::distribution::DETERMINATE_NIXD_BINARY
27-
.ok_or_else(|| Self::error(ActionErrorKind::DeterminateNixUnavailable))?;
28-
29-
let this = Self {
26+
Ok(StatefulAction::uncompleted(Self {
3027
binary_location: DETERMINATE_NIXD_BINARY_PATH.into(),
31-
};
32-
33-
Ok(StatefulAction::uncompleted(this))
28+
}))
3429
}
3530
}
3631

@@ -61,8 +56,7 @@ impl Action for ProvisionDeterminateNixd {
6156

6257
#[tracing::instrument(level = "debug", skip_all)]
6358
async fn execute(&mut self) -> Result<(), ActionError> {
64-
let bytes = crate::distribution::DETERMINATE_NIXD_BINARY
65-
.ok_or_else(|| Self::error(ActionErrorKind::DeterminateNixUnavailable))?;
59+
let bytes = crate::distribution::DETERMINATE_NIXD_BINARY;
6660

6761
crate::util::remove_file(&self.binary_location, OnMissing::Ignore)
6862
.await

src/cli/subcommand/install/determinate.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ const PRE_PKG_SUGGEST: &str = "For a more robust Nix installation, use the Deter
1111
const INSTALL_DETERMINATE_NIX_PROMPT: &str = "\
1212
Install Determinate Nix?
1313
14-
Selecting 'no' will install Nix from NixOS.org, without automated garbage collection and enterprise certificate support.\
14+
It has stable flakes, lazy trees, parallel evaluation, and more.
15+
16+
Selecting 'no' will install upstream Nix, which comes from NixOS.org.\
1517
";
1618

1719
const DETERMINATE_MSG_EXPLAINER: &str = "\
1820
Determinate Nix is Determinate Systems' validated and secure downstream Nix distribution for enterprises. \
21+
It is the direct result of our work to ship meaningful user experience and reliability improvements to Nix.
1922
It comes bundled with Determinate Nixd, a helpful daemon that automates some otherwise-unpleasant aspects of using Nix, such as garbage collection, and enables you to easily authenticate with FlakeHub.
2023
2124
For more details: https://dtr.mn/determinate-nix\
@@ -41,7 +44,51 @@ pub(crate) async fn prompt_for_determinate<T: Feedback>(
4144
) -> eyre::Result<Option<String>> {
4245
let planner_settings = planner.common_settings_mut();
4346

44-
if !planner_settings.determinate_nix && std::io::stdin().is_terminal() && !no_confirm {
47+
if !planner_settings.determinate_nix {
48+
// This is deliberately checking the determinate_nix option, and not `.distribution()`.
49+
// When we default to Determinate Nix on November 10, we'll change prefer_upstream's default to false.
50+
// Then, .distribution() will be Determinate Nix, but .determinate_nix will still be false.
51+
// That means we'll still show this warning.
52+
53+
eprintln!();
54+
eprintln!(
55+
"{} The Determinate Nix Installer will stop distributing upstream Nix no sooner than {}.",
56+
"Important:".bold().red().italic(),
57+
"January 1, 2026".italic()
58+
);
59+
60+
eprintln!("\n{}", "Timeline".bold().underline());
61+
62+
eprintln!(
63+
"* {}: we are changing the installer to default to Determinate Nix.",
64+
"November 10".bold()
65+
);
66+
eprintln!(
67+
" You can add the `{}` flag now to keep upstream Nix as the default.",
68+
"--prefer-upstream-nix".italic()
69+
);
70+
eprintln!(
71+
"* {}: we are removing support for installing upstream Nix.",
72+
"January 1".bold()
73+
);
74+
eprintln!(
75+
" The `{}` flag will not have an effect any longer.",
76+
"--prefer-upstream-nix".italic()
77+
);
78+
79+
eprintln!(
80+
"\nThe DeterminateSystems/nix-installer-action GitHub Action is also affected.\n"
81+
);
82+
eprintln!(
83+
"{} https://determinate.systems/blog/installer-dropping-upstream/",
84+
"Details:".bold().italic()
85+
);
86+
}
87+
88+
if planner_settings.distribution().is_upstream()
89+
&& std::io::stdin().is_terminal()
90+
&& !no_confirm
91+
{
4592
let base_prompt = feedback
4693
.get_feature_ptr_payload::<String>("dni-det-msg-interactive-prompt-ptr")
4794
.await
@@ -86,7 +133,7 @@ pub(crate) async fn prompt_for_determinate<T: Feedback>(
86133
}
87134

88135
let post_install_message_feature = match (
89-
planner_settings.determinate_nix,
136+
planner_settings.distribution().is_determinate(),
90137
std::io::stdin().is_terminal() && !no_confirm,
91138
) {
92139
(true, true) => Some("dni-post-det-int-ptr"),

src/diagnostics.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,24 @@ impl crate::feedback::Feedback for DiagnosticData {
219219
.set_fact("planner", planner.typetag_name().into())
220220
.await;
221221

222+
self.ids_client
223+
.set_fact(
224+
"install_determinate_nix",
225+
planner
226+
.common_settings()
227+
.distribution()
228+
.is_determinate()
229+
.into(),
230+
)
231+
.await;
232+
222233
if let Ok(ref settings) = planner.configured_settings().await {
223234
self.ids_client
224235
.set_fact(
225236
"configured_settings",
226237
settings.keys().cloned().collect::<Vec<_>>().into(),
227238
)
228239
.await;
229-
230-
self.ids_client
231-
.set_fact(
232-
"install_determinate_nix",
233-
settings
234-
.get("determinate_nix")
235-
.cloned()
236-
.unwrap_or(serde_json::Value::Bool(false)),
237-
)
238-
.await;
239240
}
240241

241242
Ok(())

src/distribution.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ pub enum Distribution {
99
}
1010

1111
impl Distribution {
12+
pub fn is_determinate(&self) -> bool {
13+
self == &Self::DeterminateNix
14+
}
15+
pub fn is_upstream(&self) -> bool {
16+
self == &Self::Nix
17+
}
18+
1219
pub fn tarball_location_or(&self, user_preference: &Option<UrlOrPath>) -> TarballLocation {
1320
if let Some(pref) = user_preference {
1421
return TarballLocation::UrlOrPath(pref.clone());
@@ -24,10 +31,7 @@ impl Distribution {
2431
.expect("Fault: the built-in Nix tarball URL does not parse."),
2532
),
2633
Distribution::DeterminateNix => {
27-
TarballLocation::InMemory(
28-
DETERMINATE_NIX_TARBALL_PATH.expect("Fault: this build of Determinate Nix Installer is not equipped to install Determinate Nix."),
29-
DETERMINATE_NIX_TARBALL.expect("Fault: this build of Determinate Nix Installer is not equipped to install Determinate Nix.")
30-
)
34+
TarballLocation::InMemory(DETERMINATE_NIX_TARBALL_PATH, DETERMINATE_NIX_TARBALL)
3135
},
3236
}
3337
}
@@ -40,25 +44,13 @@ pub enum TarballLocation {
4044

4145
pub const NIX_TARBALL_URL: &str = env!("NIX_TARBALL_URL");
4246

43-
#[cfg(feature = "determinate-nix")]
44-
pub const DETERMINATE_NIX_TARBALL_PATH: Option<&str> = Some(env!("DETERMINATE_NIX_TARBALL_PATH"));
45-
#[cfg(feature = "determinate-nix")]
47+
pub const DETERMINATE_NIX_TARBALL_PATH: &str = env!("DETERMINATE_NIX_TARBALL_PATH");
4648
/// The DETERMINATE_NIX_TARBALL environment variable should point to a target-appropriate
4749
/// Determinate Nix installation tarball, like determinate-nix-2.21.2-aarch64-darwin.tar.xz.
4850
/// The contents are embedded in the resulting binary.
49-
pub const DETERMINATE_NIX_TARBALL: Option<&[u8]> =
50-
Some(include_bytes!(env!("DETERMINATE_NIX_TARBALL_PATH")));
51+
pub const DETERMINATE_NIX_TARBALL: &[u8] = include_bytes!(env!("DETERMINATE_NIX_TARBALL_PATH"));
5152

52-
#[cfg(feature = "determinate-nix")]
5353
/// The DETERMINATE_NIXD_BINARY_PATH environment variable should point to a target-appropriate
5454
/// static build of the Determinate Nixd binary. The contents are embedded in the resulting
55-
/// binary if the determinate-nix feature is turned on.
56-
pub const DETERMINATE_NIXD_BINARY: Option<&[u8]> =
57-
Some(include_bytes!(env!("DETERMINATE_NIXD_BINARY_PATH")));
58-
59-
#[cfg(not(feature = "determinate-nix"))]
60-
pub const DETERMINATE_NIXD_BINARY: Option<&[u8]> = None;
61-
#[cfg(not(feature = "determinate-nix"))]
62-
pub const DETERMINATE_NIX_TARBALL: Option<&[u8]> = None;
63-
#[cfg(not(feature = "determinate-nix"))]
64-
pub const DETERMINATE_NIX_TARBALL_PATH: Option<&str> = None;
55+
/// binary.
56+
pub const DETERMINATE_NIXD_BINARY: &[u8] = include_bytes!(env!("DETERMINATE_NIXD_BINARY_PATH"));

src/planner/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ impl BuiltinPlanner {
226226
Ok(built)
227227
}
228228

229+
pub fn common_settings(&self) -> &CommonSettings {
230+
match self {
231+
BuiltinPlanner::Linux(inner) => &inner.settings,
232+
BuiltinPlanner::SteamDeck(inner) => &inner.settings,
233+
BuiltinPlanner::Ostree(inner) => &inner.settings,
234+
BuiltinPlanner::Macos(inner) => &inner.settings,
235+
}
236+
}
237+
229238
pub fn common_settings_mut(&mut self) -> &mut CommonSettings {
230239
match self {
231240
BuiltinPlanner::Linux(inner) => &mut inner.settings,

src/settings.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ pub struct CommonSettings {
5353
)]
5454
pub determinate_nix: bool,
5555

56+
/// Prefer installing upstream Nix if possible when run in an automated context.
57+
#[cfg_attr(
58+
feature = "cli",
59+
clap(
60+
long = "prefer-upstream-nix",
61+
env = "NIX_INSTALLER_PREFER_UPSTREAM_NIX",
62+
// Note this default is replicated in a default() implementation
63+
default_value = "true"
64+
)
65+
)]
66+
pub prefer_upstream: bool,
67+
5668
/// Modify the user profile to automatically load Nix
5769
#[cfg_attr(
5870
feature = "cli",
@@ -228,6 +240,7 @@ impl CommonSettings {
228240

229241
Ok(Self {
230242
determinate_nix: false,
243+
prefer_upstream: true,
231244
modify_profile: true,
232245
nix_build_group_name: String::from(crate::settings::DEFAULT_NIX_BUILD_USER_GROUP_NAME),
233246
nix_build_group_id: default_nix_build_group_id(),
@@ -247,6 +260,7 @@ impl CommonSettings {
247260
pub fn settings(&self) -> Result<HashMap<String, serde_json::Value>, InstallSettingsError> {
248261
let Self {
249262
determinate_nix,
263+
prefer_upstream,
250264
modify_profile,
251265
nix_build_group_name,
252266
nix_build_group_id,
@@ -266,6 +280,10 @@ impl CommonSettings {
266280
"determinate_nix".into(),
267281
serde_json::to_value(determinate_nix)?,
268282
);
283+
map.insert(
284+
"prefer_upstream".into(),
285+
serde_json::to_value(prefer_upstream)?,
286+
);
269287
map.insert(
270288
"modify_profile".into(),
271289
serde_json::to_value(modify_profile)?,
@@ -306,8 +324,11 @@ impl CommonSettings {
306324
pub fn distribution(&self) -> Distribution {
307325
if self.determinate_nix {
308326
Distribution::DeterminateNix
309-
} else {
327+
} else if self.prefer_upstream {
328+
// If the user passed --prefer-upstream (or it defaults to true), default back to Nix
310329
Distribution::Nix
330+
} else {
331+
Distribution::DeterminateNix
311332
}
312333
}
313334
}

tests/fixtures/linux/linux.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@
11451145
"planner": "linux",
11461146
"settings": {
11471147
"determinate_nix": false,
1148+
"prefer_upstream": true,
11481149
"modify_profile": true,
11491150
"nix_build_group_name": "nixbld",
11501151
"nix_build_group_id": 30000,

tests/fixtures/linux/steam-deck.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@
11731173
"persistence": "/home/nix",
11741174
"settings": {
11751175
"determinate_nix": false,
1176+
"prefer_upstream": true,
11761177
"modify_profile": true,
11771178
"nix_build_group_name": "nixbld",
11781179
"nix_build_group_id": 30000,

tests/fixtures/macos/macos.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@
12451245
"planner": "macos",
12461246
"settings": {
12471247
"determinate_nix": false,
1248+
"prefer_upstream": true,
12481249
"modify_profile": true,
12491250
"nix_build_group_name": "nixbld",
12501251
"nix_build_group_id": 350,

0 commit comments

Comments
 (0)