From d2ca8bb5c97a0a7c0ecdb5849a48c12e88ec19ac Mon Sep 17 00:00:00 2001 From: Yannik Sander Date: Thu, 17 Mar 2022 08:14:36 +0100 Subject: [PATCH] Import Nixpkgs from path (#445) --- flake-info/src/bin/flake-info.rs | 31 +++++++++++++++++++++++++++++-- flake-info/src/data/source.rs | 16 ++++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/flake-info/src/bin/flake-info.rs b/flake-info/src/bin/flake-info.rs index f1ba9e4..a3573c9 100644 --- a/flake-info/src/bin/flake-info.rs +++ b/flake-info/src/bin/flake-info.rs @@ -43,6 +43,7 @@ struct Args { #[derive(StructOpt, Debug)] enum Command { + #[structopt(about = "Import a flake")] Flake { #[structopt(help = "Flake identifier passed to nix to gather information about")] flake: String, @@ -56,10 +57,25 @@ enum Command { #[structopt(long, help = "Whether to gc the store after info or not")] gc: bool, }, + #[structopt(about = "Import official nixpkgs channel")] Nixpkgs { #[structopt(help = "Nixpkgs channel to import")] channel: String, }, + + #[structopt(about = "Import nixpkgs channel from archive or local git path")] + NixpkgsArchive { + #[structopt(help = "Nixpkgs archive to import")] + source: String, + + #[structopt( + help = "Which channel to assign nixpkgs to", + default_value = "unstable" + )] + channel: String, + }, + + #[structopt(about = "Load and import a group of flakes from a file")] Group { #[structopt( help = "Points to a TOML or JSON file containing info targets. If file does not end in 'toml' json is assumed" @@ -219,14 +235,25 @@ async fn run_command( .map_err(FlakeInfoError::Nixpkgs)?; let ident = ( "nixos".to_owned(), - nixpkgs.channel.clone(), - nixpkgs.git_ref.clone(), + nixpkgs.channel.to_owned(), + nixpkgs.git_ref.to_owned(), ); let exports = flake_info::process_nixpkgs(&Source::Nixpkgs(nixpkgs), &kind) .map_err(FlakeInfoError::Nixpkgs)?; Ok((exports, ident)) } + Command::NixpkgsArchive { source, channel } => { + let ident = ( + "nixos".to_string(), + channel.to_owned(), + "latest".to_string(), + ); + let exports = flake_info::process_nixpkgs(&Source::Git { url: source }, &kind) + .map_err(FlakeInfoError::Nixpkgs)?; + + Ok((exports, ident)) + } Command::Group { targets, temp_store, diff --git a/flake-info/src/data/source.rs b/flake-info/src/data/source.rs index 2267bed..3159c99 100644 --- a/flake-info/src/data/source.rs +++ b/flake-info/src/data/source.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use std::{ ffi::OsStr, fs::{self, File}, - io::{Read, self}, + io::{self, Read}, path::Path, }; @@ -115,15 +115,14 @@ impl Source { let response = request.send().await?; if !response.status().is_success() { - Err(anyhow::anyhow!("GitHub returned {:?} {}", response.status(), response.text().await?)) + Err(anyhow::anyhow!( + "GitHub returned {:?} {}", + response.status(), + response.text().await? + )) } else { - let git_ref = response.json::() - .await? - .commit - .sha; - + let git_ref = response.json::().await?.commit.sha; let nixpkgs = Nixpkgs { channel, git_ref }; - Ok(nixpkgs) } } @@ -132,5 +131,6 @@ impl Source { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Nixpkgs { pub channel: String, + pub git_ref: String, }