Skip to content

Commit

Permalink
Check if there's a nixpkgs input before adding another one
Browse files Browse the repository at this point in the history
We check if there's a `{ nixpkgs, ... }` as the outputs function,
and then check if there's an input named `nixpkgs` before we add
maybe-another one.
  • Loading branch information
cole-h committed Oct 6, 2023
1 parent cd38eed commit 21074e1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/cli/cmd/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const RELEASE_BRANCH_REGEX: Lazy<regex::Regex> = Lazy::new(|| {
regex::Regex::new(r"(nixos|nixpkgs)-(?<year>[[:digit:]]{2})\.(?<month>[[:digit:]]{2})").unwrap()
});

const NIXPKGS_IMPLICIT_INPUT_NAME: &str = "nixpkgs";
const SHELL_NIX: &str = "shell.nix";
const DEFAULT_NIX: &str = "default.nix";
const FLAKE_COMPAT_MARKER: &str = "https://github.com/edolstra/flake-compat/archive";
Expand Down Expand Up @@ -171,15 +172,26 @@ impl ConvertSubcommand {
flake_contents: &str,
) -> color_eyre::Result<String> {
let mut new_flake_contents = flake_contents.to_string();
let input_name = String::from(NIXPKGS_IMPLICIT_INPUT_NAME);
let outputs_attr = crate::cli::cmd::add::flake::find_first_attrset_by_path(
&expr,
Some(["outputs".into()].into()),
)?;

let nixpkgs_input_attr = crate::cli::cmd::add::flake::find_first_attrset_by_path(
&expr,
Some(["inputs".into(), input_name.clone()].into()),
)?;

// If there's already an input that matches the nixpkgs implicit input name, we don't need
// to insert another input for it.
if nixpkgs_input_attr.is_some() {
return Ok(new_flake_contents);
}

// - has no nixpkgs in inputs but does have it in flake.lock, add it to flakehub.com/f/nixos/nixpkgs/0.1.0.tar.gz
if let Some(outputs_attr) = outputs_attr {
if let nixel::Expression::Function(f) = &*outputs_attr.to {
let input_name = String::from("nixpkgs");
match &f.head {
// outputs = { nixpkgs, ... } @ inputs: { }
nixel::FunctionHead::Destructured(head)
Expand Down

0 comments on commit 21074e1

Please sign in to comment.