hive.rs: Canonicalize flake path

Relative paths are no longer allowed in newer Nix versions.
This commit is contained in:
Zhaofeng Li 2021-10-25 21:48:00 -07:00
parent f8feb40cbd
commit b48753239a
2 changed files with 8 additions and 2 deletions

View file

@ -39,7 +39,8 @@ impl HivePath {
if let Some(osstr) = path.file_name() { if let Some(osstr) = path.file_name() {
if osstr == "flake.nix" { if osstr == "flake.nix" {
let parent = path.parent().unwrap().to_str().unwrap(); let parent = path.parent().unwrap().canonicalize().unwrap();
let parent = parent.to_str().unwrap();
let uri = format!("path:{}", parent); let uri = format!("path:{}", parent);
return Self::Flake(uri); return Self::Flake(uri);

View file

@ -8,6 +8,7 @@ use std::hash::Hash;
use std::io::Write; use std::io::Write;
use std::iter::{FromIterator, Iterator}; use std::iter::{FromIterator, Iterator};
use std::ops::Deref; use std::ops::Deref;
use std::path::PathBuf;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use tokio_test::block_on; use tokio_test::block_on;
@ -148,7 +149,11 @@ fn test_parse_simple() {
#[test] #[test]
fn test_parse_flake() { fn test_parse_flake() {
let hive_path = HivePath::Flake("path:./src/nix/tests/simple-flake".to_string()); let flake_path = {
let p = PathBuf::from("./src/nix/tests/simple-flake");
p.canonicalize().unwrap()
};
let hive_path = HivePath::Flake(format!("path:{}", flake_path.to_str().unwrap()));
let mut hive = Hive::new(hive_path).unwrap(); let mut hive = Hive::new(hive_path).unwrap();
hive.set_show_trace(true); hive.set_show_trace(true);