-
-
Notifications
You must be signed in to change notification settings - Fork 93
nh: mock tests, VM tests and other testing infra #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7a81dec
nh: move checks to a dedicated module; validate nix setup
NotAShelf a5a0de7
check: set minimum Lix version to 2.91.1; add comment
NotAShelf 2b5a5ac
check: add tests
NotAShelf bd93a0c
check: ignore environment checks if `NH_NO_CHECKS` is set
NotAShelf 0bf7e92
nix: ignore environment checks during build
NotAShelf 2867847
check: only return missing required features
NotAShelf 27d1eca
check: better debug logging
NotAShelf abf1465
chore: make tooling configuration hidden files
NotAShelf 0239894
nix: initial testing framework
NotAShelf 6d2db08
testing: initialize complete unit testing interface
NotAShelf d5dc66a
testing: standardize environment management
NotAShelf 4be2b3a
treewide: format with new formatter rules
NotAShelf dccf1ed
ci: build flake checks via GH workflows
NotAShelf 7fc874a
treewide: format again
NotAShelf 3ab9c63
nix: move completions to `postInstall`
NotAShelf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| use std::cmp::Ordering; | ||
|
|
||
| use color_eyre::{eyre, Result}; | ||
| use semver::Version; | ||
|
|
||
| use crate::util; | ||
|
|
||
| /// Verifies if the installed Nix version meets requirements | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// * `Result<()>` - Ok if version requirements are met, error otherwise | ||
| pub fn check_nix_version() -> Result<()> { | ||
| let version = util::get_nix_version()?; | ||
| let is_lix_binary = util::is_lix()?; | ||
|
|
||
| let min_version = if is_lix_binary { "2.91.0" } else { "2.26.1" }; | ||
|
|
||
| let current = Version::parse(&version)?; | ||
| let required = Version::parse(min_version)?; | ||
|
|
||
| match current.cmp(&required) { | ||
| Ordering::Less => { | ||
| let binary_name = if is_lix_binary { "Lix" } else { "Nix" }; | ||
| Err(eyre::eyre!( | ||
| "{} version {} is too old. Minimum required version is {}", | ||
| binary_name, | ||
| version, | ||
| min_version | ||
| )) | ||
| } | ||
| _ => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Verifies if the required experimental features are enabled | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// * `Result<()>` - Ok if all required features are enabled, error otherwise | ||
| pub fn check_nix_features() -> Result<()> { | ||
| let mut required_features = vec!["nix-command", "flakes"]; | ||
|
|
||
| // Lix still uses repl-flake, which is removed in the latest version of Nix. | ||
| if util::is_lix()? { | ||
| required_features.push("repl-flake"); | ||
| } | ||
|
|
||
| if !util::has_all_experimental_features(&required_features)? { | ||
| return Err(eyre::eyre!( | ||
| "Missing required experimental features. Please enable: {}", | ||
| required_features.join(", ") | ||
| )); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Handles environment variable setup and returns if a warning should be shown | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// * `Result<bool>` - True if a warning should be shown about the FLAKE variable, false otherwise | ||
| pub fn setup_environment() -> Result<bool> { | ||
| let mut do_warn = false; | ||
|
|
||
| if let Ok(f) = std::env::var("FLAKE") { | ||
| // Set NH_FLAKE if it's not already set | ||
| if std::env::var("NH_FLAKE").is_err() { | ||
| std::env::set_var("NH_FLAKE", f); | ||
|
|
||
| // Only warn if FLAKE is set and we're using it to set NH_FLAKE | ||
| // AND none of the command-specific env vars are set | ||
| if std::env::var("NH_OS_FLAKE").is_err() | ||
| && std::env::var("NH_HOME_FLAKE").is_err() | ||
| && std::env::var("NH_DARWIN_FLAKE").is_err() | ||
| { | ||
| do_warn = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(do_warn) | ||
| } | ||
|
|
||
| /// Runs all necessary checks for Nix functionality | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// * `Result<()>` - Ok if all checks pass, error otherwise | ||
| pub fn verify_nix_environment() -> Result<()> { | ||
| check_nix_version()?; | ||
| check_nix_features()?; | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.