Skip to content

Commit 18a6949

Browse files
authored
Refactor diagnostics into Feedback, replace ours with detsys-ids-client (#1414)
* Refactor diagnostics into Feedback, replace ours with detsys-ids-client This replaces the Diagnosticdata and pervasive feature-checking with a trait with a null implementation by default. The null implementation is more ergonomic for a couple reasons 1. needing to feature-check everywhere made it harder to write correct code for both cases. 2. Option's can't be map()'d and other combinators with async closures. This also introduces the possibility of feature flagging behavior. The feature flags come from the `feedback` provider, and the null version has none. If you specify a `--diagnostic-endpoint` of `file://....` the diagnostics are sent to that path. The format of this output has changed. With a file endpoint, you can set the `DETSYS_IDS_CHECKIN_FILE` environment variable to a file to provide the feature flag data. If you specify a `--diagnostic-endpoint` of an HTTP(S) address, the specific path is truncated and replaced with `/check-in` and `/events/batch`. Note the default endpoint is now set to None, which means use the default backend. This is because the specific host used for diagnostics is identified using an SRV record for failover and traffic shaping purposes. Overall, this change replaces the initial and ad-hoc IDS client with a crate dedicated to the task.
1 parent 43b1eb8 commit 18a6949

File tree

27 files changed

+1021
-673
lines changed

27 files changed

+1021
-673
lines changed

Cargo.lock

Lines changed: 362 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ documentation = "https://docs.rs/nix-installer/latest/nix_installer"
1212
default = ["cli", "diagnostics", "determinate-nix"]
1313
determinate-nix = []
1414
cli = ["eyre", "color-eyre", "clap", "tracing-subscriber", "tracing-error"]
15-
diagnostics = ["is_ci"]
15+
diagnostics = ["detsys-ids-client", "is_ci"]
1616

1717
[[bin]]
1818
name = "nix-installer"
@@ -23,6 +23,7 @@ async-trait = { version = "0.1.57", default-features = false }
2323
bytes = { version = "1.2.1", default-features = false, features = ["std", "serde"] }
2424
clap = { version = "4", features = ["std", "color", "usage", "help", "error-context", "suggestions", "derive", "env"], optional = true }
2525
color-eyre = { version = "0.6.2", default-features = false, features = [ "track-caller", "issue-url", "tracing-error", "capture-spantrace", "color-spantrace" ], optional = true }
26+
detsys-ids-client = { version = "0.1", optional = true }
2627
eyre = { version = "0.6.8", default-features = false, features = [ "track-caller" ], optional = true }
2728
glob = { version = "0.3.0", default-features = false }
2829
nix = { version = "0.29.0", default-features = false, features = ["user", "fs", "process", "term"] }

README.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -499,26 +499,26 @@ These settings are available for all commands.
499499

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

502-
| Flag(s) | Description | Default (if any) | Environment variable |
503-
| -------------------------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | -------------------------------------- |
504-
| `--determinate` | Installs [Determinate] | `NIX_INSTALLER_DETERMINATE` |
505-
| `--diagnostic-attribution` | Relate the install diagnostic to a specific value | | `NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION` |
506-
| `--diagnostic-endpoint` | The URL or file path for an installation diagnostic to be sent | `https://install.determinate.systems/nix/diagnostic` | `NIX_INSTALLER_DIAGNOSTIC_ENDPOINT` |
507-
| `--explain` | Provide an explanation of the changes the installation process will make to your system | `false` | `NIX_INSTALLER_EXPLAIN` |
508-
| `--extra-conf` | Extra configuration lines for `/etc/nix.conf` | | `NIX_INSTALLER_EXTRA_CONF` |
509-
| `--force` | Whether the installer should forcibly recreate files it finds existing | `false` | `NIX_INSTALLER_FORCE` |
510-
| `--init` | Which init system to configure (if `--init none` Nix will be root-only) | `launchd` (macOS), `systemd` (Linux) | `NIX_INSTALLER_INIT` |
511-
| `--nix-build-group-id` | The Nix build group GID | `350` (macOS), `30000` (Linux) | `NIX_INSTALLER_NIX_BUILD_GROUP_ID` |
512-
| `--nix-build-group-name` | The Nix build group name | `nixbld` | `NIX_INSTALLER_NIX_BUILD_GROUP_NAME` |
513-
| `--nix-build-user-count` | The number of build users to create | `32` | `NIX_INSTALLER_NIX_BUILD_USER_COUNT` |
514-
| `--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` |
515-
| `--nix-build-user-prefix` | The Nix build user prefix (user numbers will be postfixed) | `_nixbld` (macOS), `nixbld` (Linux) | `NIX_INSTALLER_NIX_BUILD_USER_PREFIX` |
516-
| `--nix-package-url` | The Nix package URL | | `NIX_INSTALLER_NIX_PACKAGE_URL` |
517-
| `--no-confirm` | Run installation without requiring explicit user confirmation | `false` | `NIX_INSTALLER_NO_CONFIRM` |
518-
| `--no-modify-profile` | Modify the user profile to automatically load Nix. | `true` | `NIX_INSTALLER_MODIFY_PROFILE` |
519-
| `--proxy` | The proxy to use (if any); valid proxy bases are `https://$URL`, `http://$URL` and `socks5://$URL` | | `NIX_INSTALLER_PROXY` |
520-
| `--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` |
521-
| `--no-start-daemon` | Start the daemon (if not `--init none`) | `true` | `NIX_INSTALLER_START_DAEMON` |
502+
| Flag(s) | Description | Default (if any) | Environment variable |
503+
| -------------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------ | -------------------------------------- |
504+
| `--determinate` | Installs [Determinate] | `NIX_INSTALLER_DETERMINATE` |
505+
| `--diagnostic-attribution` | Relate the install diagnostic to a specific distinct user ID | | `NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION` |
506+
| `--diagnostic-endpoint` | The URL or file path for an installation diagnostic to be sent | | `NIX_INSTALLER_DIAGNOSTIC_ENDPOINT` |
507+
| `--explain` | Provide an explanation of the changes the installation process will make to your system | `false` | `NIX_INSTALLER_EXPLAIN` |
508+
| `--extra-conf` | Extra configuration lines for `/etc/nix.conf` | | `NIX_INSTALLER_EXTRA_CONF` |
509+
| `--force` | Whether the installer should forcibly recreate files it finds existing | `false` | `NIX_INSTALLER_FORCE` |
510+
| `--init` | Which init system to configure (if `--init none` Nix will be root-only) | `launchd` (macOS), `systemd` (Linux) | `NIX_INSTALLER_INIT` |
511+
| `--nix-build-group-id` | The Nix build group GID | `350` (macOS), `30000` (Linux) | `NIX_INSTALLER_NIX_BUILD_GROUP_ID` |
512+
| `--nix-build-group-name` | The Nix build group name | `nixbld` | `NIX_INSTALLER_NIX_BUILD_GROUP_NAME` |
513+
| `--nix-build-user-count` | The number of build users to create | `32` | `NIX_INSTALLER_NIX_BUILD_USER_COUNT` |
514+
| `--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` |
515+
| `--nix-build-user-prefix` | The Nix build user prefix (user numbers will be postfixed) | `_nixbld` (macOS), `nixbld` (Linux) | `NIX_INSTALLER_NIX_BUILD_USER_PREFIX` |
516+
| `--nix-package-url` | The Nix package URL | | `NIX_INSTALLER_NIX_PACKAGE_URL` |
517+
| `--no-confirm` | Run installation without requiring explicit user confirmation | `false` | `NIX_INSTALLER_NO_CONFIRM` |
518+
| `--no-modify-profile` | Modify the user profile to automatically load Nix. | `true` | `NIX_INSTALLER_MODIFY_PROFILE` |
519+
| `--proxy` | The proxy to use (if any); valid proxy bases are `https://$URL`, `http://$URL` and `socks5://$URL` | | `NIX_INSTALLER_PROXY` |
520+
| `--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` |
521+
| `--no-start-daemon` | Start the daemon (if not `--init none`) | `true` | `NIX_INSTALLER_START_DAEMON` |
522522

523523
You can also specify a planner with the first argument:
524524

@@ -564,23 +564,18 @@ nix-installer uninstall /path/to/receipt.json
564564
## Diagnostics
565565

566566
The goal of Determinate Nix Installer is to successfully and correctly install Nix.
567-
The `curl | sh` pipeline and the installer collects a little bit of diagnostic information to help us make that true.
568-
569-
Here is a table of the [diagnostic data we collect][diagnosticdata]:
570-
571-
| Field | Use |
572-
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
573-
| `version` | The version of Determinate Nix Installer. |
574-
| `planner` | The method of installing Nix (`linux`, `macos`, `steam-deck`) |
575-
| `configured_settings` | The names of planner settings which were changed from their default. Does _not_ include the values. |
576-
| `os_name` | The running operating system. |
577-
| `os_version` | The version of the operating system. |
578-
| `triple` | The architecture/operating system/binary format of your system. |
579-
| `is_ci` | Whether the installer is being used in CI (e.g. GitHub Actions). |
580-
| `action` | Either `Install` or `Uninstall`. |
581-
| `status` | One of `Success`, `Failure`, `Pending`, or `Cancelled`. |
582-
| `attribution` | Optionally defined by the user, associate the diagnostics of this run to the provided value. |
583-
| `failure_chain` | A high level description of what the failure was, if any. For example: `Command("diskutil")` if the command `diskutil list` failed. |
567+
The `curl | sh` pipeline and the installer collects a little bit of anonymous diagnostic information to help us make that true.
568+
569+
The anonymous diagnostics we collect to help us improve the installer includes:
570+
571+
- The installer version
572+
- Which planner is used (`linux`, `macos`, `steam-deck`)
573+
- What action was taken (install, uninstall)
574+
- The result (`Success`, `Failure`, `Pending`, or `Cancelled`)
575+
- The customized planner setting names (_not_ the values)
576+
- Information about your host, like the OS and version, architecture, binary format, etc.
577+
- Whether you're in CI or not
578+
- A high level description of what the failure was, like if a specific command failed.
584579

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

@@ -595,7 +590,6 @@ You can read the full privacy policy for [Determinate Systems][detsys], the crea
595590
[determinate-flake]: https://github.com/DeterminateSystems/determinate
596591
[detsys]: https://determinate.systems
597592
[docker]: https://docker.com
598-
[diagnosticdata]: https://github.com/DeterminateSystems/nix-installer/blob/f9f927840d532b71f41670382a30cfcbea2d8a35/src/diagnostics.rs#L29-L43
599593
[enabling-systemd]: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/#how-can-you-get-systemd-on-your-machine
600594
[flakehub]: https://flakehub.com
601595
[flakes]: https://zero-to-nix.com/concepts/flakes

src/action/mod.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Note: if the struct has no fields, don't add the `serde` attribute to the struct
4949
use std::{error::Error, collections::HashMap};
5050
use tracing::{Span, span};
5151
use nix_installer::{
52+
feedback,
5253
InstallPlan,
5354
settings::{CommonSettings, InstallSettingsError},
5455
planner::{Planner, PlannerError},
@@ -158,20 +159,6 @@ impl Planner for MyPlanner {
158159
Ok(settings)
159160
}
160161
161-
#[cfg(feature = "diagnostics")]
162-
async fn diagnostic_data(&self) -> Result<nix_installer::diagnostics::DiagnosticData, PlannerError> {
163-
Ok(nix_installer::diagnostics::DiagnosticData::new(
164-
self.common.diagnostic_attribution.clone(),
165-
self.common.diagnostic_endpoint.clone(),
166-
self.typetag_name().into(),
167-
self.configured_settings()
168-
.await?
169-
.into_keys()
170-
.collect::<Vec<_>>(),
171-
self.common.ssl_cert_file.clone(),
172-
)?)
173-
}
174-
175162
async fn platform_check(&self) -> Result<(), PlannerError> {
176163
use target_lexicon::OperatingSystem;
177164
match target_lexicon::OperatingSystem::host() {
@@ -187,14 +174,14 @@ impl Planner for MyPlanner {
187174
# async fn custom_planner_install() -> color_eyre::Result<()> {
188175
let planner = MyPlanner::default().await?;
189176
let mut plan = InstallPlan::plan(planner).await?;
190-
match plan.install(None).await {
177+
match plan.install(feedback::devnull::DevNull{}, None).await {
191178
Ok(()) => tracing::info!("Done"),
192179
Err(e) => {
193180
match e.source() {
194181
Some(source) => tracing::error!("{e}: {}", source),
195182
None => tracing::error!("{e}"),
196183
};
197-
plan.uninstall(None).await?;
184+
plan.uninstall(feedback::devnull::DevNull{}, None).await?;
198185
},
199186
};
200187

src/bin/nix-installer.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{io::IsTerminal, process::ExitCode};
22

33
use clap::Parser;
44
use nix_installer::cli::CommandExecute;
5+
use nix_installer::feedback::FeedbackWorker;
56

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

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

26-
cli.execute().await
27+
#[cfg(not(feature = "diagnostics"))]
28+
let (feedback, feedback_worker) = nix_installer::feedback::devnull::dev_null();
29+
30+
#[cfg(feature = "diagnostics")]
31+
let (feedback, feedback_worker) = nix_installer::diagnostics::diagnostics(
32+
cli.diagnostic_attribution.clone(),
33+
cli.diagnostic_endpoint.clone(),
34+
cli.ssl_cert_file.clone(),
35+
cli.proxy.clone(),
36+
)
37+
.await;
38+
39+
let err = cli.execute(feedback).await;
40+
41+
feedback_worker.submit().await;
42+
43+
err
2744
}

0 commit comments

Comments
 (0)