Skip to content

Commit

Permalink
Barely support (fix) inputs that get Nixpkgs from the flake registry
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h committed Oct 6, 2023
1 parent 951ec4b commit 0653634
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions src/cli/cmd/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,25 @@ impl ConvertSubcommand {

let url = find_input_value_by_path(&input.to, ["url".into()].into())?;

if let Some(ref url) = url {
if url == "github:edolstra/flake-compat" {
// Save the flake-compat input name for later (so we can find it again)
flake_compat_input_name = Some(input_name.clone());
continue;
let url = match url {
Some(url) => {
if url == "github:edolstra/flake-compat" {
// Save the flake-compat input name for later (so we can find it again)
flake_compat_input_name = Some(input_name.clone());
continue;
}

// Bare-minimum Nixpkgs-from-flake-registry handling
if url == "nixpkgs" || url.starts_with("nixpkgs/") {
let mut url = url;
url.insert_str(0, "github:NixOS/");
Some(url)
} else {
Some(url)
}
}
}
None => None,
};

let maybe_parsed_url = url.and_then(|u| u.parse::<url::Url>().ok());

Expand Down Expand Up @@ -724,4 +736,38 @@ mod test {
let num_nixpkgs_url_lines = nixpkgs_url_lines.len();
assert_eq!(num_nixpkgs_url_lines, 1);
}

#[tokio::test]
async fn test_nixpkgs_from_registry() {
let test_server = axum_test::TestServer::new(test_router().into_make_service()).unwrap();
let server_addr = test_server.server_address();
let server_url = server_addr.parse().unwrap();

let convert = super::ConvertSubcommand {
flake_path: "".into(),
dry_run: true,
api_addr: server_url,
};
let flake_contents = r#"
{
description = "cole-h's NixOS configuration";
inputs = {
nixpkgs.url = "nixpkgs";
};
outputs = { self, ... } @ tes: { };
}
"#;
let flake_contents = flake_contents.to_string();
let parsed = nixel::parse(flake_contents.clone());

let (new_flake_contents, _) = convert
.convert_inputs_to_flakehub(&parsed.expression, &flake_contents)
.await
.unwrap();

assert!(new_flake_contents
.contains(r#"nixpkgs.url = "http://flakehub-localhost/f/NixOS/nixpkgs/*.tar.gz";"#));
}
}

0 comments on commit 0653634

Please sign in to comment.