Skip to content

Commit

Permalink
feat: Avoid fetching for known --system combinations
Browse files Browse the repository at this point in the history
This avoids having to `builtins.getFlake` on known nix-systems flakes.
  • Loading branch information
srid committed Jun 14, 2024
1 parent 6a672e2 commit 6164d6c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/nix/system_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,44 @@ pub struct SystemsList(pub Vec<System>);
impl SystemsList {
pub async fn from_flake(cmd: &NixCmd, url: &SystemsListFlakeRef) -> Result<Self> {
// Nix eval, and then return the systems
match SystemsList::from_known_flake(url) {
Some(systems) => Ok(systems),
None => SystemsList::from_remote_flake(cmd, url).await,
}
}

async fn from_remote_flake(cmd: &NixCmd, url: &SystemsListFlakeRef) -> Result<Self> {
let systems = nix_import_flake::<Vec<System>>(cmd, &url.0).await?;
Ok(SystemsList(systems))
}

fn from_known_flake(url: &SystemsListFlakeRef) -> Option<Self> {
match url.0 .0.as_str() {
"github:nix-systems/empty" => Some(SystemsList(vec![])),
"github:nix-systems/default-darwin" => Some(SystemsList(vec![
System::Darwin(nix_rs::flake::system::Arch::Aarch64),
System::Darwin(nix_rs::flake::system::Arch::X86_64),
])),
"github:nix-systems/default-linux" => Some(SystemsList(vec![
System::Linux(nix_rs::flake::system::Arch::Aarch64),
System::Linux(nix_rs::flake::system::Arch::X86_64),
])),
"github:nix-systems/aarch64-darwin" => Some(SystemsList(vec![System::Darwin(
nix_rs::flake::system::Arch::Aarch64,
)])),
"github:nix-systems/aarch64-linux" => Some(SystemsList(vec![System::Linux(
nix_rs::flake::system::Arch::Aarch64,
)])),
"github:nix-systems/x86_64-darwin" => Some(SystemsList(vec![System::Darwin(
nix_rs::flake::system::Arch::X86_64,
)])),
"github:nix-systems/x86_64-linux" => Some(SystemsList(vec![System::Linux(
nix_rs::flake::system::Arch::X86_64,
)])),

_ => None,
}
}
}

pub async fn nix_import_flake<T>(cmd: &NixCmd, url: &FlakeUrl) -> Result<T, NixCmdError>
Expand Down

0 comments on commit 6164d6c

Please sign in to comment.