Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions flake-info/src/bin/flake-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ enum Command {
Nixpkgs {
#[structopt(help = "Nixpkgs channel to import")]
channel: String,

#[structopt(
help = "Restrict to importing a single attribute",
)]
attribute: Option<String>,
},

#[structopt(about = "Import nixpkgs channel from archive or local git path")]
Expand All @@ -68,6 +73,11 @@ enum Command {
default_value = "unstable"
)]
channel: String,

#[structopt(
help = "Restrict to importing a single attribute",
)]
attribute: Option<String>,
},

#[structopt(about = "Load and import a group of flakes from a file")]
Expand Down Expand Up @@ -217,7 +227,7 @@ async fn run_command(

Ok((Box::new(|| Ok(exports)), ident))
}
Command::Nixpkgs { channel } => {
Command::Nixpkgs { channel, attribute } => {
let nixpkgs = Source::nixpkgs(channel)
.await
.map_err(FlakeInfoError::Nixpkgs)?;
Expand All @@ -229,13 +239,13 @@ async fn run_command(

Ok((
Box::new(move || {
flake_info::process_nixpkgs(&Source::Nixpkgs(nixpkgs), &kind)
flake_info::process_nixpkgs(&Source::Nixpkgs(nixpkgs), &kind, &attribute)
.map_err(FlakeInfoError::Nixpkgs)
}),
ident,
))
}
Command::NixpkgsArchive { source, channel } => {
Command::NixpkgsArchive { source, channel, attribute } => {
let ident = (
"nixos".to_string(),
channel.to_owned(),
Expand All @@ -244,7 +254,7 @@ async fn run_command(

Ok((
Box::new(move || {
flake_info::process_nixpkgs(&Source::Git { url: source }, &kind)
flake_info::process_nixpkgs(&Source::Git { url: source }, &kind, &attribute)
.map_err(FlakeInfoError::Nixpkgs)
}),
ident,
Expand All @@ -265,7 +275,7 @@ async fn run_command(
let (exports_and_hashes, errors) = sources
.iter()
.map(|source| match source {
Source::Nixpkgs(nixpkgs) => flake_info::process_nixpkgs(source, &kind)
Source::Nixpkgs(nixpkgs) => flake_info::process_nixpkgs(source, &kind, &None)
.with_context(|| {
format!("While processing nixpkgs archive {}", source.to_flake_ref())
})
Expand Down
8 changes: 6 additions & 2 deletions flake-info/src/commands/nixpkgs_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::data::import::{NixOption, NixpkgsEntry, Package};
use crate::data::Nixpkgs;
use crate::Source;

pub fn get_nixpkgs_info(nixpkgs: &Source) -> Result<Vec<NixpkgsEntry>> {
pub fn get_nixpkgs_info(nixpkgs: &Source, attribute: &Option<String>) -> Result<Vec<NixpkgsEntry>> {
let mut command = Command::new("nix-env");
command.add_args(&[
"--json",
Expand All @@ -20,8 +20,12 @@ pub fn get_nixpkgs_info(nixpkgs: &Source) -> Result<Vec<NixpkgsEntry>> {
"config",
"import <nixpkgs/pkgs/top-level/packages-config.nix>",
"-qa",
"--meta",
]);
match attribute {
Some(attr) => { command.add_arg(attr); },
None => {},
}
command.add_arg("--meta");

command.enable_capture();
command.log_to = LogTo::Log;
Expand Down
4 changes: 2 additions & 2 deletions flake-info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ pub fn process_flake(
Ok((info, exports))
}

pub fn process_nixpkgs(nixpkgs: &Source, kind: &Kind) -> Result<Vec<Export>, anyhow::Error> {
pub fn process_nixpkgs(nixpkgs: &Source, kind: &Kind, attribute: &Option<String>) -> Result<Vec<Export>, anyhow::Error> {
let drvs = if matches!(kind, Kind::All | Kind::Package) {
commands::get_nixpkgs_info(nixpkgs)?
commands::get_nixpkgs_info(nixpkgs, attribute)?
} else {
Vec::new()
};
Expand Down