Skip to content

Commit

Permalink
Append default.nix if path was given
Browse files Browse the repository at this point in the history
closes #45
  • Loading branch information
jonringer committed Apr 19, 2022
1 parent 6e0ef6a commit 8b28755
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- Fixes:
- Fix unprefixed versions being generated as `version = "version";` @blaggacao
- Fixed directories being passed as `[PATH]` not becoming `dir/default.nix`

## v0.2.0

Expand Down
26 changes: 24 additions & 2 deletions src/file_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ pub fn nix_file_paths(
return (file_path, module);
}

// assume that they want a directory for the individual package
if !radix.ends_with(&pname) && radix.extension() != Some(std::ffi::OsStr::new("nix")) {
radix.push(&pname);
}

// nix_path is the path used in pkgs/top-level/*.nix or nixos/tests/all-tests.nix
let mut nix_path = PathBuf::from("..");
nix_path.push(&radix);
Expand All @@ -80,7 +81,16 @@ pub fn nix_file_paths(
return (file_path, nix_path);
}

(path.to_path_buf(), PathBuf::from(""))
let mut path_buf = path.to_path_buf();

// if it's a directory, we need to default to using the default.nix which `import` expects
// Path.is_dir() appears to return false if the directory doesn't exist, so stringify and assert if path ends in '/'
if path.to_str().unwrap().ends_with("/") {
path_buf.push("default.nix");
eprintln!("Directory was passed as [PATH], defaulting to {:?}", path_buf.display());
}

(path_buf, PathBuf::from(""))
}

#[cfg(test)]
Expand Down Expand Up @@ -145,6 +155,18 @@ mod tests {
assert_paths(m, expected);
}

#[test]
#[serial]
fn test_dir_to_default_nix() {
let m =
build_cli().get_matches_from(vec!["nix-template", "python", "-p", "requests", "local/"]);
let expected = (
PathBuf::from("local/default.nix"),
PathBuf::from(""),
);
assert_paths(m, expected);
}

#[test]
#[serial]
fn test_python() {
Expand Down

0 comments on commit 8b28755

Please sign in to comment.