Skip to content

Commit

Permalink
allow overriding nixpkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
figsoda committed Feb 3, 2023
1 parent 2f64d18 commit 0ff4f8c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::utils::{CommandExt, ResultExt};
#[serde(default, rename_all = "kebab-case")]
pub struct Config {
pub maintainers: Vec<String>,
pub nixpkgs: Option<String>,
pub access_tokens: AccessTokens,
}

Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub struct Opts {
#[arg(short, long)]
pub url: Option<String>,

/// Path to nixpkgs (in nix)
#[arg(short, long)]
pub nixpkgs: Option<String>,

/// Specify the config file
#[arg(short, long)]
pub config: Option<PathBuf>,
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,14 @@ async fn main() -> Result<()> {
editor.readline(&prompt("Enter pname"))?
};

let nixpkgs = opts
.nixpkgs
.or(cfg.nixpkgs)
.unwrap_or_else(|| "<nixpkgs>".into());
let mut cmd = Command::new("nurl");
cmd.arg(&url).arg(&rev);
// TODO: change to this once https://github.com/NixOS/nixpkgs/pull/214422 is in nixos-unstable
// cmd.arg(&url).arg(&rev).arg("-n").arg(&nixpkgs);

let src_expr = {
if let MaybeFetcher::Known(
Expand Down Expand Up @@ -279,7 +285,7 @@ async fn main() -> Result<()> {
.arg("--json")
.arg("--expr")
.arg(format!(
"let pname={pname:?};version={version:?};in(import<nixpkgs>{{}}).{}{src_expr}",
"let pname={pname:?};version={version:?};in(import({nixpkgs}){{}}).{}{src_expr}",
if matches!(fetcher, MaybeFetcher::Known(Fetcher::FetchPypi { .. })) {
"python3.pkgs."
} else {
Expand Down Expand Up @@ -525,7 +531,7 @@ async fn main() -> Result<()> {
let hash = if src_dir.join("vendor").is_dir() {
"null".into()
} else if let Some(hash) = fod_hash(format!(
r#"(import<nixpkgs>{{}}).buildGoModule{{pname={pname:?};version={version:?};src={src};vendorHash="{FAKE_HASH}";}}"#,
r#"(import({nixpkgs}){{}}).buildGoModule{{pname={pname:?};version={version:?};src={src};vendorHash="{FAKE_HASH}";}}"#,
)).await {
if hash == "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=" {
"null".into()
Expand Down Expand Up @@ -561,7 +567,7 @@ async fn main() -> Result<()> {
cargo,
} => {
let hash = if *cargo {
Some(cargo_deps_hash(&mut inputs, &pname, &version, &src, &src_dir).await)
Some(cargo_deps_hash(&mut inputs, &pname, &version, &src, &src_dir, &nixpkgs).await)
} else {
None
};
Expand Down Expand Up @@ -611,7 +617,8 @@ async fn main() -> Result<()> {
}

BuildType::BuildRustPackage => {
let hash = cargo_deps_hash(&mut inputs, &pname, &version, &src, &src_dir).await;
let hash =
cargo_deps_hash(&mut inputs, &pname, &version, &src, &src_dir, &nixpkgs).await;
let res = write_all_lambda_inputs(&mut out, &inputs, ["rustPlatform"])?;
writedoc!(
out,
Expand Down Expand Up @@ -650,7 +657,8 @@ async fn main() -> Result<()> {
}

BuildType::MkDerivationCargo => {
let hash = cargo_deps_hash(&mut inputs, &pname, &version, &src, &src_dir).await;
let hash =
cargo_deps_hash(&mut inputs, &pname, &version, &src, &src_dir, &nixpkgs).await;
let res = write_all_lambda_inputs(&mut out, &inputs, ["stdenv"])?;
writedoc!(
out,
Expand Down
3 changes: 2 additions & 1 deletion src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ pub async fn cargo_deps_hash(
version: impl Display,
src: impl Display,
src_dir: &Path,
nixpkgs: &str,
) -> String {
if let Ok(lock) = File::open(src_dir.join("Cargo.lock")) {
let (hash, ()) = tokio::join!(
fod_hash(format!(
r#"(import<nixpkgs>{{}}).rustPlatform.fetchCargoTarball{{name="{pname}-{version}";src={src};hash="{FAKE_HASH}";}}"#,
r#"(import({nixpkgs}){{}}).rustPlatform.fetchCargoTarball{{name="{pname}-{version}";src={src};hash="{FAKE_HASH}";}}"#,
)),
load_riff_dependencies(inputs, lock),
);
Expand Down

0 comments on commit 0ff4f8c

Please sign in to comment.