Skip to content

Commit

Permalink
Merge pull request #128 from DeterminateSystems/colemickens/uds
Browse files Browse the repository at this point in the history
login: support login via determinate-nix-ee via UDS socket
  • Loading branch information
colemickens authored Jul 30, 2024
2 parents c7efb00 + ddd19ca commit ec8adab
Show file tree
Hide file tree
Showing 12 changed files with 1,126 additions and 730 deletions.
1,151 changes: 695 additions & 456 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/DeterminateSystems/fh"

[dependencies]
async-trait = "0.1.73"
axum = { version = "0.7.5", features = ["macros"] }
chrono = "0.4.31"
clap = { version = "4.3.2", default-features = false, features = [
"color",
Expand All @@ -24,6 +25,10 @@ color-eyre = { version = "0.6.2", default-features = false, features = [
csv = "1.3.0"
gethostname = { version = "0.4.3", default-features = false }
handlebars = "4.4.0"
http = "1.0"
http-body-util = "0.1" # TODO(colemickens): revisit/remove
hyper = { version = "1.0.0", features = ["full"] }
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
indicatif = { version = "0.17.6", default-features = false }
inquire = "0.6.2"
nix = { version = "0.29.0", default-features = false, features = ["user"] }
Expand All @@ -42,7 +47,7 @@ serde_json = "1.0.105"
tabled = { version = "0.14.0", features = ["color"] }
tempfile = "3.10.1"
thiserror = { version = "1.0.44", default-features = false }
tokio = { version = "1.30.0", default-features = false, features = ["full"] }
tokio = { version = "1.39.1", default-features = false, features = ["full"] }
tracing = "0.1.37"
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.17", default-features = false, features = [
Expand All @@ -56,5 +61,5 @@ whoami = { version = "1.5.1", default-features = false }
xdg = "2.5.2"

[dev-dependencies]
axum = { version = "0.6.20", features = ["macros"] }
axum-test = "12.5.0"
axum = { version = "0.7.5", features = ["macros"] }
axum-test = "15.3.0"
40 changes: 21 additions & 19 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
description = "The official CLI for FlakeHub: search for flakes, and add new inputs to your Nix flake.";

inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.514192.tar.gz";
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/=0.1.650378.tar.gz";

fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1.1565.tar.gz";
url = "https://flakehub.com/f/nix-community/fenix/0.1.1584.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
};

naersk = {
url = "https://flakehub.com/f/nix-community/naersk/0.1.335.tar.gz";
url = "https://flakehub.com/f/nix-community/naersk/0.1.345.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand Down
10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix
214 changes: 109 additions & 105 deletions src/cli/cmd/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,97 +690,105 @@ mod test {
.route("/f/:org/:project", axum::routing::get(no_version))
}

fn test_server() -> axum_test::TestServer {
let test_server_config = axum_test::TestServerConfig::builder()
.http_transport()
.build();
axum_test::TestServer::new_with_config(
test_router().into_make_service(),
test_server_config,
)
.unwrap()
}

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

let input_url = url::Url::parse("github:someorg/somerepo").unwrap();
let tarball_url = super::convert_input_to_flakehub(&server_url, input_url)
.await
.ok()
.flatten()
.unwrap();
assert_eq!(tarball_url.path(), "/f/someorg/somerepo/*.tar.gz");
}
let test_server = test_server();
let server_addr = test_server.server_address();
let server_url = server_addr.unwrap();

let input_url = url::Url::parse("github:someorg/somerepo").unwrap();
let tarball_url = super::convert_input_to_flakehub(&server_url, input_url)
.await
.ok()
.flatten()
.unwrap();
assert_eq!(tarball_url.path(), "/f/someorg/somerepo/*.tar.gz");
}

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

let input_url = url::Url::parse("github:nixos/nixpkgs/nixos-23.05").unwrap();
let tarball_url = super::convert_input_to_flakehub(&server_url, input_url)
.await
.ok()
.flatten()
.unwrap();
assert_eq!(tarball_url.path(), "/f/nixos/nixpkgs/0.2305.0.tar.gz");
}
let test_server = test_server();
let server_addr = test_server.server_address();
let server_url = server_addr.unwrap();

let input_url = url::Url::parse("github:nixos/nixpkgs/nixos-23.05").unwrap();
let tarball_url = super::convert_input_to_flakehub(&server_url, input_url)
.await
.ok()
.flatten()
.unwrap();
assert_eq!(tarball_url.path(), "/f/nixos/nixpkgs/0.2305.0.tar.gz");
}

#[tokio::test]
async fn test_flake1_convert() {
if let Ok(test_server) = axum_test::TestServer::new(test_router().into_make_service()) {
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 = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/samples/flake1.test.nix"
));
let flake_contents = flake_contents.to_string();
let parsed = nixel::parse(flake_contents.clone());

let (new_flake_contents, flake_compat_input_name) = convert
.convert_inputs_to_flakehub(&parsed.expression, &flake_contents)
.await
.unwrap();
let new_flake_contents = convert
.make_implicit_nixpkgs_explicit(&parsed.expression, &new_flake_contents)
.await
.unwrap();
let new_flake_contents = convert
.fixup_flake_compat_input(&new_flake_contents, flake_compat_input_name.unwrap())
.await
.unwrap();
let test_server = test_server();
let server_addr = test_server.server_address();
let server_url = server_addr.unwrap();

let convert = super::ConvertSubcommand {
flake_path: "".into(),
dry_run: true,
api_addr: server_url,
};
let flake_contents = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/samples/flake1.test.nix"
));
let flake_contents = flake_contents.to_string();
let parsed = nixel::parse(flake_contents.clone());

assert!(new_flake_contents.contains(
let (new_flake_contents, flake_compat_input_name) = convert
.convert_inputs_to_flakehub(&parsed.expression, &flake_contents)
.await
.unwrap();
let new_flake_contents = convert
.make_implicit_nixpkgs_explicit(&parsed.expression, &new_flake_contents)
.await
.unwrap();
let new_flake_contents = convert
.fixup_flake_compat_input(&new_flake_contents, flake_compat_input_name.unwrap())
.await
.unwrap();

assert!(new_flake_contents.contains(
r#"flake-compat.url = "http://flakehub-localhost/f/edolstra/flake-compat/*.tar.gz";"#
));
assert!(new_flake_contents.contains("f/nixos/nixpkgs/0.2305.0.tar.gz"));

let nixpkgs_url_lines: Vec<_> = new_flake_contents
.lines()
.filter(|line| {
line.contains("nixpkgs.url") && line.contains("f/nixos/nixpkgs/0.2305.0.tar.gz")
})
.collect();
let num_nixpkgs_url_lines = nixpkgs_url_lines.len();
assert_eq!(num_nixpkgs_url_lines, 1);
}
assert!(new_flake_contents.contains("f/nixos/nixpkgs/0.2305.0.tar.gz"));

let nixpkgs_url_lines: Vec<_> = new_flake_contents
.lines()
.filter(|line| {
line.contains("nixpkgs.url") && line.contains("f/nixos/nixpkgs/0.2305.0.tar.gz")
})
.collect();
let num_nixpkgs_url_lines = nixpkgs_url_lines.len();
assert_eq!(num_nixpkgs_url_lines, 1);
}

#[tokio::test]
async fn test_nixpkgs_from_registry() {
if let Ok(test_server) = axum_test::TestServer::new(test_router().into_make_service()) {
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#"
let test_server = test_server();
let server_addr = test_server.server_address();
let server_url = server_addr.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";
Expand All @@ -791,42 +799,38 @@ mod test {
outputs = { self, ... } @ tes: { };
}
"#;
let flake_contents = flake_contents.to_string();
let parsed = nixel::parse(flake_contents.clone());
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();
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";"#
));
}
assert!(new_flake_contents
.contains(r#"nixpkgs.url = "http://flakehub-localhost/f/NixOS/nixpkgs/*.tar.gz";"#));
}

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

let input_url =
url::Url::parse("https://api.flakehub.com/f/NixOS/nixpkgs/0.1.514192.tar.gz")
.unwrap();
let tarball_url = super::convert_input_to_flakehub(&server_url, input_url)
.await
.ok()
.flatten()
.unwrap();
assert_eq!(
tarball_url.host().unwrap(),
url::Host::Domain("flakehub.com")
);
assert_ne!(
tarball_url.host().unwrap(),
url::Host::Domain("api.flakehub.com")
);
}
let test_server = test_server();
let server_addr = test_server.server_address();
let server_url = server_addr.unwrap();

let input_url =
url::Url::parse("https://api.flakehub.com/f/NixOS/nixpkgs/0.1.514192.tar.gz").unwrap();
let tarball_url = super::convert_input_to_flakehub(&server_url, input_url)
.await
.ok()
.flatten()
.unwrap();
assert_eq!(
tarball_url.host().unwrap(),
url::Host::Domain("flakehub.com")
);
assert_ne!(
tarball_url.host().unwrap(),
url::Host::Domain("api.flakehub.com")
);
}
}
Loading

0 comments on commit ec8adab

Please sign in to comment.