Skip to content

feature: Flake check for detSys installed nix#473

Closed
niksingh710 wants to merge 5 commits intomainfrom
fix#472
Closed

feature: Flake check for detSys installed nix#473
niksingh710 wants to merge 5 commits intomainfrom
fix#472

Conversation

@niksingh710
Copy link
Member

@niksingh710 niksingh710 commented Aug 12, 2025

Resolves: #472 (based on the approach 2 mentioned in #472)

On MacOs virtual Machine

image

On Ubuntu virtual Machine (Simple Nix installation)

image

Commands used to test the package for backward compatibility.

  • Run Version Parsing Tests: cargo test --package nix_rs test_parse_nix_version
  • Run Flake Detection Tests: cargo test --package omnix-health flake_enabled
  • Test Core Packages cargo test --package nix_rs --package omnix-health
  • Build and Test Health Command cargo build --bin om
  • Verify JSON Output ./target/debug/om health --json

Backward Compatibility

✅ No breaking changes - all existing functionality preserved
✅ Regular Nix installations continue to work as before
✅ Adds new capability without removing existing features

Expected Behavior

  • DetSys Nix users: Health check shows "✅ Flakes Enabled" with message "Flakes enabled via Determinate Systems Nix"
  • Regular Nix users: Existing behavior unchanged - checks experimental-features config

@niksingh710
Copy link
Member Author

niksingh710 commented Aug 12, 2025

For minimal changes diff, I guess we can drop the test cases that I got implemented by llm juspay/vertex in commit e6648a3
(the project juspay/vertex is impressive and makes writing test cases and stuff ease)

@niksingh710 niksingh710 requested a review from Copilot August 12, 2025 08:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for detecting Determinate Systems Nix installations in the flake enabled health check. It automatically considers flakes enabled for DetSys Nix installations without requiring explicit configuration.

  • Modified flake enabled check to detect DetSys installations and treat them as having flakes enabled by default
  • Updated NixVersion struct to include an is_detsys field and enhanced version parsing to detect DetSys installations
  • Added comprehensive tests covering both DetSys and regular Nix scenarios

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/omnix-health/src/check/flake_enabled.rs Enhanced flake enabled check logic to handle DetSys installations and added comprehensive test coverage
crates/nix_rs/src/version.rs Added is_detsys field to NixVersion struct and updated parsing logic to detect Determinate Systems installations
crates/nix_rs/src/version_spec.rs Updated NixVersionSpec tests to include the new is_detsys field
crates/nix_rs/src/config.rs Updated static NixVersion constant to include the new is_detsys field

@niksingh710 niksingh710 requested a review from srid August 12, 2025 08:29
pub patch: u32,
/// Nix installation type
pub installation_type: NixInstallationType,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What effect does this have on comparing two NixVersion with same version but different installation type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example:

- NixVersion { major: 2, minor: 13, patch: 0, installation_type: Official }
- NixVersion { major: 2, minor: 13, patch: 0, installation_type: DeterminateSystems }

The above two are no longer equal because their installation_type values differ.

For ordering (>, >=, <, <=):

  • Rust’s derived PartialOrd compares fields in declaration order.
  • It compares major, then minor, then patch, and finally installation_type.
  • Since Official is declared before DeterminateSystems in the enum, Official < DeterminateSystems.

I believe this behavior is fine, which is why I haven’t implemented custom PartialOrd or Eq for NixVersion comparisons. If you think it’s necessary, I can implement them as well.

Copy link
Member

@srid srid Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srid: What effect does this have [..]
...
@niksingh710 [..] The above two are no longer equal because their installation_type values differ.

Does it not have the effect of breaking the nix_version check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on both a virtual device and my personal system with different versions in the yaml file, and confirmed that the nix_version check works correctly, since Rust’s PartialOrd handles it well.

Copy link
Member

@srid srid Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How exhaustive was your test? Can you read the code around:

NixVersionSpec::Gt(v) => version > v,

And see how the > check can fail or pass depending on the installation_type field?

The presence of installation_type seems quite problematic to me in this regard. NixVersion means just that ... nix version (conceptually, it says nothing about the provider of that installation).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the installer info should go in NixInfo

pub struct NixInfo {
/// Nix version string
pub nix_version: NixVersion,
/// nix.conf configuration
pub nix_config: NixConfig,
/// Environment in which Nix was installed
pub nix_env: NixEnv,
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to disable flakes on DetSys installer? And if so, does the PR behave correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a bit of searching and will be doing a more thorough check on how to disable flakes in DetSys. So far, I haven’t seen any option in the installer to disable flakes. In the configuration, extra-experimental-features is being used to enable flakes.
However, removing flakes from there still kept flakes enabled.

does the PR behave correctly?

For now, if the installed nix is from Determinate Systems the health output is green for flakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having two similar matches in the same function here sounds like a code smell

Comment on lines 89 to 94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need all these irrelevant settings in the mock config? KISS and as small a code as possible.

@srid
Copy link
Member

srid commented Aug 18, 2025

@niksingh710 For future reference, please do not use non-standard characters in your branch name (i.e., # in your fix#472), as that makes it impossible (or so it seems) to nix run the branch:

image image

EDIT: nix run github:juspay/omnix/pull/473/head works

Comment on lines 26 to 44
let flakes_enabled =
val.contains(&"flakes".to_string()) && val.contains(&"nix-command".to_string());
if flakes_enabled {
(
flakes_enabled,
format!("experimental-features = {}", val.join(" ")),
CheckResult::Green,
)
} else {
(
flakes_enabled,
format!("experimental-features = {}", val.join(" ")),
CheckResult::Red {
msg: "Nix flakes are not enabled".into(),
suggestion: "See https://nixos.wiki/wiki/Flakes#Enable_flakes".into(),
},
)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should DRY this up.

Comment on lines 70 to 112
Copy link
Member

@srid srid Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too verbose for my taste. Just mock the nix.conf file itself (keep it 1 line; for experimental-features), and then parse it.

The more code you introduce, the more PITA it can be to maintain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test only what matters. Why do we care about title equality here, for instance? Tests should be minimal.

Comment on lines +64 to +74
let config_json = format!(
r#"{{
"experimental-features": {{ "value": [{}], "defaultValue": [], "description": "" }},
"cores": {{ "value": 1, "defaultValue": 1, "description": "" }},
"extra-platforms": {{ "value": [], "defaultValue": [], "description": "" }},
"flake-registry": {{ "value": "", "defaultValue": "", "description": "" }},
"max-jobs": {{ "value": 1, "defaultValue": 1, "description": "" }},
"substituters": {{ "value": [], "defaultValue": [], "description": "" }},
"system": {{ "value": "x86_64-linux", "defaultValue": "x86_64-linux", "description": "" }},
"trusted-users": {{ "value": [], "defaultValue": [], "description": "" }}
}}"#,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just mock the nix.conf file itself (keep it 1 line; for experimental-features), and then parse it.

nix.conf is in INI format, not JSON, as you are mocking here.

@niksingh710
Copy link
Member Author

niksingh710 commented Aug 21, 2025

Closing in favour of #478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

om health shows false negative against DetSys graphical installer

2 participants

Comments