feat: shell for packages and custom flakes

This commit is contained in:
Callum Leslie 2024-09-10 19:59:23 +01:00
parent 89c01b9845
commit 0e3dc2cc29
Signed by: cleslie
GPG key ID: D382C4AFEECEAA90
4 changed files with 1101 additions and 1 deletions

1049
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,6 @@ version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.17", features = ["derive"] }
runix = "0.1.1"
tokio = { version = "1", features = ["full"] }

View file

@ -73,4 +73,9 @@
};
}
);
nixConfig = {
extra-substituters = ["callumio-public.cachix.org"];
extra-trusted-public-keys = ["callumio-public.cachix.org-1:VucOSl7vh44GdqcILwMIeHlI0ufuAnHAl8cO1U/7yhg="];
};
}

View file

@ -1 +1,44 @@
fn main() {}
use clap::Parser;
use runix::{
arguments::{
eval::EvaluationArgs, flake::FlakeArgs, source::SourceArgs, InstallablesArgs, NixArgs,
},
command::Shell,
default::NixCommandLine,
installable::Installable,
Run,
};
#[derive(Parser, Debug)]
#[command(version, about)]
struct Args {
/// List of packages to include in the shell.
///
/// <package> to implicitly use nixpkgs
///
/// <flake#package> to use a different flake
#[arg(value_parser = preprocess)]
pkgs: Vec<Installable>,
}
fn preprocess(s: &str) -> Result<Installable, String> {
Ok(Installable::from(if s.contains('#') {
s.to_owned()
} else {
format!("nixpkgs#{}", s)
}))
}
#[tokio::main]
async fn main() -> Result<(), runix::default::NixCommandLineRunError> {
let cli = Args::parse();
dbg!(&cli.pkgs);
Shell {
flake: FlakeArgs::default(),
eval: EvaluationArgs::default(),
source: SourceArgs::default(),
installables: InstallablesArgs::from(cli.pkgs),
}
.run(&NixCommandLine::default(), &NixArgs::default())
.await
}