Skip to content

feat: Add attic support in om develop#475

Draft
niksingh710 wants to merge 2 commits intomainfrom
attic
Draft

feat: Add attic support in om develop#475
niksingh710 wants to merge 2 commits intomainfrom
attic

Conversation

@niksingh710
Copy link
Member

@niksingh710 niksingh710 commented Aug 13, 2025

Resolves: #474

srid

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

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

This deteriorates type safety.

relevant_checks.push(&health.caches);
};
// TODO: Re-calculate NixInfo since our nix.conf has changed (due to `cachix use`)
// TODO: Re-calculate NixInfo since our nix.conf has changed (due to `cachix use`, `attic login` and `attic use`)
Copy link
Member

Choose a reason for hiding this comment

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

attic login doesn’t change nix.conf

Comment on lines 65 to +104
let missing = health.caches.get_missing_caches(nix_info);
let (missing_cachix, missing_other) = parse_many(&missing, CachixCache::from_url);
let (missing_cachix, remaining_after_cachix) =
parse_many(&missing, |cache_spec| match cache_spec {
omnix_health::check::caches::CacheSpec::Cachix(name) => {
Some(CachixCache(name.clone()))
}
_ => None,
});
let (missing_attic, missing_other) = parse_many(&remaining_after_cachix, |cache_spec| {
match cache_spec {
omnix_health::check::caches::CacheSpec::Attic { .. } => {
// Convert back to URL string and use existing parsing logic
let url_string = cache_spec.to_url_string();
AtticCache::from_url_string(&url_string)
}
_ => None,
}
});

for cachix_cache in &missing_cachix {
tracing::info!("🐦 Running `cachix use` for {}", cachix_cache.0);
cachix_cache.cachix_use().await?;
}

for attic_cache in &missing_attic {
tracing::info!(
"🏺 Running `attic login {}` for server {}",
attic_cache.server_name,
attic_cache.cache_url
);
attic_cache.attic_login().await?;

tracing::info!(
"🏺 Running `attic use {}:{}`",
attic_cache.server_name,
attic_cache.cache_name
);
attic_cache.attic_use().await?;
}

Copy link
Member

Choose a reason for hiding this comment

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

You can instead:

let missing. = health.caches.get_missing_caches(nix_info);
for cache in &missing {
  match cache {
    Cachix(url_string) => { … }
    Attic {server_name, cache_url } => { … }
    _ => { //Do nothing }
  }
}

/// Use `om develop` for automatic installation of Cachix and Attic caches.
#[derive(Debug, Serialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "kebab-case")]
pub enum CacheSpec {
Copy link
Member

Choose a reason for hiding this comment

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

You could call it CacheType? I would’ve gone with Caches but that name is already taken

#[serde(rename_all = "kebab-case")]
pub enum CacheSpec {
/// Regular HTTP/HTTPS cache URL (must be added manually to Nix config)
Regular(String),
Copy link
Member

Choose a reason for hiding this comment

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

Other(String)

Comment on lines +17 to +22
Cachix(String),
/// Attic cache (automatically installed by `om develop` via `attic login` + `attic use`)
Attic {
server_name: String,
cache_url: String,
},
Copy link
Member

Choose a reason for hiding this comment

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

why not Cachix(CachixCache) and Attic(AtticCache) respectively?

This would also avoid having to convert to the respective cache type after parsing missing caches during om develop above.

Comment on lines +56 to +65
### Cache Types

omnix supports checking different types of binary caches:

- **Cachix caches**: Use standard HTTPS URLs like `https://yourproject.cachix.org`
- **Attic caches**: Use the format `attic+servername+https://cache.example.com/cachename`
- **Other caches**: Standard HTTPS URLs that must be manually configured in your Nix configuration

**Note**: `om health` only checks if these caches are configured. For automatic cache setup, use [`om develop`](develop.md#caches) with direnv.

Copy link
Member

Choose a reason for hiding this comment

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

om health doesn’t care about the cache type, it just validates if the url string is configured in nix.conf. Remove the section and just add a note callout.

/// Run `cachix use` for this cache
/// Run `cachix use` for this cache.
///
/// **Called by:** `om develop` only (not `om health`)
Copy link
Member

Choose a reason for hiding this comment

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

Caller info is unnecessary here


/// Run `attic use` for this cache (assumes login has already been done).
///
/// **Called by:** `om develop` only (not `om health`)
Copy link
Member

Choose a reason for hiding this comment

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

Caller info is unnecessary here


/// Run `attic login` for this cache server.
///
/// **Called by:** `om develop` only (not `om health`)
Copy link
Member

Choose a reason for hiding this comment

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

Caller info is unnecessary here

///
/// **Called by:** `om develop` only (not `om health`)
/// **Requires:** ATTIC_LOGIN_TOKEN environment variable
pub async fn attic_login(&self) -> anyhow::Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

Add a TODO in the doc to remove this function after zhaofengli/attic#243 is resolved

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 develop: Support attic

3 participants

Comments