Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
378 changes: 362 additions & 16 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ documentation = "https://docs.rs/nix-installer/latest/nix_installer"
default = ["cli", "diagnostics", "determinate-nix"]
determinate-nix = []
cli = ["eyre", "color-eyre", "clap", "tracing-subscriber", "tracing-error"]
diagnostics = ["is_ci"]
diagnostics = ["detsys-ids-client", "is_ci"]

[[bin]]
name = "nix-installer"
Expand All @@ -23,6 +23,7 @@ async-trait = { version = "0.1.57", default-features = false }
bytes = { version = "1.2.1", default-features = false, features = ["std", "serde"] }
clap = { version = "4", features = ["std", "color", "usage", "help", "error-context", "suggestions", "derive", "env"], optional = true }
color-eyre = { version = "0.6.2", default-features = false, features = [ "track-caller", "issue-url", "tracing-error", "capture-spantrace", "color-spantrace" ], optional = true }
detsys-ids-client = { version = "0.1", optional = true }
eyre = { version = "0.6.8", default-features = false, features = [ "track-caller" ], optional = true }
glob = { version = "0.3.0", default-features = false }
nix = { version = "0.29.0", default-features = false, features = ["user", "fs", "process", "term"] }
Expand Down
70 changes: 32 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,26 +499,26 @@ These settings are available for all commands.

### Installation (`nix-installer install`)

| Flag(s) | Description | Default (if any) | Environment variable |
| -------------------------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | -------------------------------------- |
| `--determinate` | Installs [Determinate] | `NIX_INSTALLER_DETERMINATE` |
| `--diagnostic-attribution` | Relate the install diagnostic to a specific value | | `NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION` |
| `--diagnostic-endpoint` | The URL or file path for an installation diagnostic to be sent | `https://install.determinate.systems/nix/diagnostic` | `NIX_INSTALLER_DIAGNOSTIC_ENDPOINT` |
| `--explain` | Provide an explanation of the changes the installation process will make to your system | `false` | `NIX_INSTALLER_EXPLAIN` |
| `--extra-conf` | Extra configuration lines for `/etc/nix.conf` | | `NIX_INSTALLER_EXTRA_CONF` |
| `--force` | Whether the installer should forcibly recreate files it finds existing | `false` | `NIX_INSTALLER_FORCE` |
| `--init` | Which init system to configure (if `--init none` Nix will be root-only) | `launchd` (macOS), `systemd` (Linux) | `NIX_INSTALLER_INIT` |
| `--nix-build-group-id` | The Nix build group GID | `350` (macOS), `30000` (Linux) | `NIX_INSTALLER_NIX_BUILD_GROUP_ID` |
| `--nix-build-group-name` | The Nix build group name | `nixbld` | `NIX_INSTALLER_NIX_BUILD_GROUP_NAME` |
| `--nix-build-user-count` | The number of build users to create | `32` | `NIX_INSTALLER_NIX_BUILD_USER_COUNT` |
| `--nix-build-user-id-base` | The Nix build user base UID (ascending) (NOTE: the first UID will be this base + 1) | `350` (macOS), `30000` (Linux) | `NIX_INSTALLER_NIX_BUILD_USER_ID_BASE` |
| `--nix-build-user-prefix` | The Nix build user prefix (user numbers will be postfixed) | `_nixbld` (macOS), `nixbld` (Linux) | `NIX_INSTALLER_NIX_BUILD_USER_PREFIX` |
| `--nix-package-url` | The Nix package URL | | `NIX_INSTALLER_NIX_PACKAGE_URL` |
| `--no-confirm` | Run installation without requiring explicit user confirmation | `false` | `NIX_INSTALLER_NO_CONFIRM` |
| `--no-modify-profile` | Modify the user profile to automatically load Nix. | `true` | `NIX_INSTALLER_MODIFY_PROFILE` |
| `--proxy` | The proxy to use (if any); valid proxy bases are `https://$URL`, `http://$URL` and `socks5://$URL` | | `NIX_INSTALLER_PROXY` |
| `--ssl-cert-file` | An SSL cert to use (if any); used for fetching Nix and sets `ssl-cert-file` in `/etc/nix/nix.conf` | | `NIX_INSTALLER_SSL_CERT_FILE` |
| `--no-start-daemon` | Start the daemon (if not `--init none`) | `true` | `NIX_INSTALLER_START_DAEMON` |
| Flag(s) | Description | Default (if any) | Environment variable |
| -------------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------ | -------------------------------------- |
| `--determinate` | Installs [Determinate] | `NIX_INSTALLER_DETERMINATE` |
| `--diagnostic-attribution` | Relate the install diagnostic to a specific distinct user ID | | `NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION` |
| `--diagnostic-endpoint` | The URL or file path for an installation diagnostic to be sent | | `NIX_INSTALLER_DIAGNOSTIC_ENDPOINT` |
| `--explain` | Provide an explanation of the changes the installation process will make to your system | `false` | `NIX_INSTALLER_EXPLAIN` |
| `--extra-conf` | Extra configuration lines for `/etc/nix.conf` | | `NIX_INSTALLER_EXTRA_CONF` |
| `--force` | Whether the installer should forcibly recreate files it finds existing | `false` | `NIX_INSTALLER_FORCE` |
| `--init` | Which init system to configure (if `--init none` Nix will be root-only) | `launchd` (macOS), `systemd` (Linux) | `NIX_INSTALLER_INIT` |
| `--nix-build-group-id` | The Nix build group GID | `350` (macOS), `30000` (Linux) | `NIX_INSTALLER_NIX_BUILD_GROUP_ID` |
| `--nix-build-group-name` | The Nix build group name | `nixbld` | `NIX_INSTALLER_NIX_BUILD_GROUP_NAME` |
| `--nix-build-user-count` | The number of build users to create | `32` | `NIX_INSTALLER_NIX_BUILD_USER_COUNT` |
| `--nix-build-user-id-base` | The Nix build user base UID (ascending) (NOTE: the first UID will be this base + 1) | `350` (macOS), `30000` (Linux) | `NIX_INSTALLER_NIX_BUILD_USER_ID_BASE` |
| `--nix-build-user-prefix` | The Nix build user prefix (user numbers will be postfixed) | `_nixbld` (macOS), `nixbld` (Linux) | `NIX_INSTALLER_NIX_BUILD_USER_PREFIX` |
| `--nix-package-url` | The Nix package URL | | `NIX_INSTALLER_NIX_PACKAGE_URL` |
| `--no-confirm` | Run installation without requiring explicit user confirmation | `false` | `NIX_INSTALLER_NO_CONFIRM` |
| `--no-modify-profile` | Modify the user profile to automatically load Nix. | `true` | `NIX_INSTALLER_MODIFY_PROFILE` |
| `--proxy` | The proxy to use (if any); valid proxy bases are `https://$URL`, `http://$URL` and `socks5://$URL` | | `NIX_INSTALLER_PROXY` |
| `--ssl-cert-file` | An SSL cert to use (if any); used for fetching Nix and sets `ssl-cert-file` in `/etc/nix/nix.conf` | | `NIX_INSTALLER_SSL_CERT_FILE` |
| `--no-start-daemon` | Start the daemon (if not `--init none`) | `true` | `NIX_INSTALLER_START_DAEMON` |

You can also specify a planner with the first argument:

Expand Down Expand Up @@ -564,23 +564,18 @@ nix-installer uninstall /path/to/receipt.json
## Diagnostics

The goal of Determinate Nix Installer is to successfully and correctly install Nix.
The `curl | sh` pipeline and the installer collects a little bit of diagnostic information to help us make that true.

Here is a table of the [diagnostic data we collect][diagnosticdata]:

| Field | Use |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `version` | The version of Determinate Nix Installer. |
| `planner` | The method of installing Nix (`linux`, `macos`, `steam-deck`) |
| `configured_settings` | The names of planner settings which were changed from their default. Does _not_ include the values. |
| `os_name` | The running operating system. |
| `os_version` | The version of the operating system. |
| `triple` | The architecture/operating system/binary format of your system. |
| `is_ci` | Whether the installer is being used in CI (e.g. GitHub Actions). |
| `action` | Either `Install` or `Uninstall`. |
| `status` | One of `Success`, `Failure`, `Pending`, or `Cancelled`. |
| `attribution` | Optionally defined by the user, associate the diagnostics of this run to the provided value. |
| `failure_chain` | A high level description of what the failure was, if any. For example: `Command("diskutil")` if the command `diskutil list` failed. |
The `curl | sh` pipeline and the installer collects a little bit of anonymous diagnostic information to help us make that true.

The anonymous diagnostics we collect to help us improve the installer includes:

- The installer version
- Which planner is used (`linux`, `macos`, `steam-deck`)
- What action was taken (install, uninstall)
- The result (`Success`, `Failure`, `Pending`, or `Cancelled`)
- The customized planner setting names (_not_ the values)
- Information about your host, like the OS and version, architecture, binary format, etc.
- Whether you're in CI or not
- A high level description of what the failure was, like if a specific command failed.

To disable diagnostic reporting, set the diagnostics URL to an empty string by passing `--diagnostic-endpoint=""` or setting `NIX_INSTALLER_DIAGNOSTIC_ENDPOINT=""`.

Expand All @@ -595,7 +590,6 @@ You can read the full privacy policy for [Determinate Systems][detsys], the crea
[determinate-flake]: https://github.com/DeterminateSystems/determinate
[detsys]: https://determinate.systems
[docker]: https://docker.com
[diagnosticdata]: https://github.com/DeterminateSystems/nix-installer/blob/f9f927840d532b71f41670382a30cfcbea2d8a35/src/diagnostics.rs#L29-L43
[enabling-systemd]: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/#how-can-you-get-systemd-on-your-machine
[flakehub]: https://flakehub.com
[flakes]: https://zero-to-nix.com/concepts/flakes
Expand Down
19 changes: 3 additions & 16 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Note: if the struct has no fields, don't add the `serde` attribute to the struct
use std::{error::Error, collections::HashMap};
use tracing::{Span, span};
use nix_installer::{
feedback,
InstallPlan,
settings::{CommonSettings, InstallSettingsError},
planner::{Planner, PlannerError},
Expand Down Expand Up @@ -158,20 +159,6 @@ impl Planner for MyPlanner {
Ok(settings)
}

#[cfg(feature = "diagnostics")]
async fn diagnostic_data(&self) -> Result<nix_installer::diagnostics::DiagnosticData, PlannerError> {
Ok(nix_installer::diagnostics::DiagnosticData::new(
self.common.diagnostic_attribution.clone(),
self.common.diagnostic_endpoint.clone(),
self.typetag_name().into(),
self.configured_settings()
.await?
.into_keys()
.collect::<Vec<_>>(),
self.common.ssl_cert_file.clone(),
)?)
}

async fn platform_check(&self) -> Result<(), PlannerError> {
use target_lexicon::OperatingSystem;
match target_lexicon::OperatingSystem::host() {
Expand All @@ -187,14 +174,14 @@ impl Planner for MyPlanner {
# async fn custom_planner_install() -> color_eyre::Result<()> {
let planner = MyPlanner::default().await?;
let mut plan = InstallPlan::plan(planner).await?;
match plan.install(None).await {
match plan.install(feedback::devnull::DevNull{}, None).await {
Ok(()) => tracing::info!("Done"),
Err(e) => {
match e.source() {
Some(source) => tracing::error!("{e}: {}", source),
None => tracing::error!("{e}"),
};
plan.uninstall(None).await?;
plan.uninstall(feedback::devnull::DevNull{}, None).await?;
},
};

Expand Down
19 changes: 18 additions & 1 deletion src/bin/nix-installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{io::IsTerminal, process::ExitCode};

use clap::Parser;
use nix_installer::cli::CommandExecute;
use nix_installer::feedback::FeedbackWorker;

#[tokio::main]
async fn main() -> eyre::Result<ExitCode> {
Expand All @@ -23,5 +24,21 @@ async fn main() -> eyre::Result<ExitCode> {

tracing::info!("nix-installer v{}", env!("CARGO_PKG_VERSION"));

cli.execute().await
#[cfg(not(feature = "diagnostics"))]
let (feedback, feedback_worker) = nix_installer::feedback::devnull::dev_null();

#[cfg(feature = "diagnostics")]
let (feedback, feedback_worker) = nix_installer::diagnostics::diagnostics(
cli.diagnostic_attribution.clone(),
cli.diagnostic_endpoint.clone(),
cli.ssl_cert_file.clone(),
cli.proxy.clone(),
)
.await;

let err = cli.execute(feedback).await;

feedback_worker.submit().await;

err
}
Loading
Loading