forked from helsinki-systems/harmonia
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented rewrite to real path in dump_path
This fixes #254 by adding a function, get_real_store_dir, to libnixstore to support non-root nix stores, where the physical and logical paths differ. prettier code Applied formatter and clippy recommendation Fixed string comparison Added test cases, fixed web serve paths
- Loading branch information
Showing
10 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::path::PathBuf; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct Store { | ||
virtual_store: String, | ||
real_store: Option<String>, | ||
} | ||
|
||
impl Store { | ||
pub fn new() -> Self { | ||
let real_store = libnixstore::get_real_store_dir(); | ||
let virtual_store = libnixstore::get_store_dir(); | ||
|
||
if virtual_store == real_store { | ||
return Self { | ||
virtual_store, | ||
real_store: None, | ||
}; | ||
} | ||
Self { | ||
virtual_store, | ||
real_store: Some(real_store), | ||
} | ||
} | ||
pub fn get_real_path(&self, virtual_path: &str) -> PathBuf { | ||
if let Some(real_store) = &self.real_store { | ||
if virtual_path.starts_with(&self.virtual_store) { | ||
return PathBuf::from(format!( | ||
"{}{}", | ||
real_store, | ||
&virtual_path[self.virtual_store.len()..] | ||
)); | ||
} | ||
} | ||
PathBuf::from(virtual_path) | ||
} | ||
pub fn real_store(&self) -> &str { | ||
self.real_store | ||
.as_ref() | ||
.map_or(&self.virtual_store, |s| s.as_str()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(import ./lib.nix) | ||
({ ... }: | ||
{ | ||
name = "t03-chroot"; | ||
|
||
nodes = { | ||
harmonia = { pkgs, ... }: | ||
{ | ||
imports = [ ../module.nix ]; | ||
|
||
services.harmonia-dev.enable = true; | ||
# We need to manipulate the target store first | ||
systemd.services."harmonia-dev".wantedBy = pkgs.lib.mkForce [ ]; | ||
|
||
networking.firewall.allowedTCPPorts = [ 5000 ]; | ||
nix.settings.store = "/guest?read-only=1"; | ||
nix.extraOptions = '' | ||
experimental-features = nix-command read-only-local-store | ||
''; | ||
}; | ||
|
||
client01 = { lib, ... }: | ||
{ | ||
nix.settings.require-sigs = false; | ||
nix.settings.substituters = lib.mkForce [ "http://harmonia:5000" ]; | ||
nix.extraOptions = '' | ||
experimental-features = nix-command | ||
''; | ||
}; | ||
}; | ||
|
||
testScript = | ||
'' | ||
import json | ||
start_all() | ||
harmonia.wait_until_succeeds("echo 'test contents' > /my-file") | ||
harmonia.wait_until_succeeds("mkdir /my-dir && cp /my-file /my-dir/") | ||
f = harmonia.wait_until_succeeds("nix store --store /guest add-file /my-file") | ||
d = harmonia.wait_until_succeeds("nix store --store /guest add-path /my-dir") | ||
harmonia.systemctl("start harmonia-dev.service") | ||
harmonia.wait_for_unit("harmonia-dev.service") | ||
client01.wait_until_succeeds("curl -f http://harmonia:5000/version") | ||
client01.succeed("curl -f http://harmonia:5000/nix-cache-info") | ||
client01.wait_until_succeeds(f"nix copy --from http://harmonia:5000/ {f}") | ||
client01.succeed(f"grep 'test contents' {f}") | ||
dhash = d.removeprefix("/nix/store/") | ||
dhash = dhash[:dhash.find('-')] | ||
out = client01.wait_until_succeeds(f"curl -v http://harmonia:5000/{dhash}.ls") | ||
data = json.loads(out) | ||
print(out) | ||
assert data["version"] == 1, "version is not correct" | ||
assert data["root"]["entries"]["my-file"]["type"] == "regular", "expect my-file file in listing" | ||
out = client01.wait_until_succeeds(f"curl -v http://harmonia:5000/serve/{dhash}/") | ||
print(out) | ||
assert "my-file" in out, "my-file not in listing" | ||
out = client01.wait_until_succeeds(f"curl -v http://harmonia:5000/serve/{dhash}/my-file").strip() | ||
print(out) | ||
assert "test contents" == out, f"expected 'test contents', got '{out}'" | ||
''; | ||
}) |