Merge pull request 'fix: respect directory parameter in machines_dir' (#5677) from fix-custom-directory into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5677 Reviewed-by: hsjobeki <hsjobeki@gmail.com>
This commit is contained in:
@@ -222,6 +222,18 @@ in
|
||||
inventoryClass =
|
||||
let
|
||||
flakeInputs = config.self.inputs;
|
||||
# Compute the relative directory path
|
||||
selfStr = toString config.self;
|
||||
dirStr = toString directory;
|
||||
relativeDirectory =
|
||||
if selfStr == dirStr then
|
||||
""
|
||||
else if lib.hasPrefix selfStr dirStr then
|
||||
lib.removePrefix (selfStr + "/") dirStr
|
||||
else
|
||||
# This shouldn't happen in normal usage, but can occur when
|
||||
# the flake is copied (e.g., in tests). Fall back to empty string.
|
||||
"";
|
||||
in
|
||||
{
|
||||
_module.args = {
|
||||
@@ -230,7 +242,12 @@ in
|
||||
imports = [
|
||||
../inventoryClass/default.nix
|
||||
{
|
||||
inherit inventory directory flakeInputs;
|
||||
inherit
|
||||
inventory
|
||||
directory
|
||||
flakeInputs
|
||||
relativeDirectory
|
||||
;
|
||||
exportsModule = config.exportsModule;
|
||||
}
|
||||
(
|
||||
|
||||
@@ -81,6 +81,14 @@ in
|
||||
directory = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
relativeDirectory = mkOption {
|
||||
type = types.str;
|
||||
internal = true;
|
||||
description = ''
|
||||
The relative directory path from the flake root to the clan directory.
|
||||
Empty string if directory equals the flake root.
|
||||
'';
|
||||
};
|
||||
machines = mkOption {
|
||||
type = types.attrsOf (submodule ({
|
||||
options = {
|
||||
|
||||
@@ -156,14 +156,28 @@ def vm_state_dir(flake_url: str, vm_name: str) -> Path:
|
||||
|
||||
|
||||
def machines_dir(flake: "Flake") -> Path:
|
||||
# Determine the base path
|
||||
if flake.is_local:
|
||||
return flake.path / "machines"
|
||||
base_path = flake.path
|
||||
else:
|
||||
store_path = flake.store_path
|
||||
if store_path is None:
|
||||
msg = "Invalid flake object. Doesn't have a store path"
|
||||
raise ClanError(msg)
|
||||
base_path = Path(store_path)
|
||||
|
||||
store_path = flake.store_path
|
||||
if store_path is None:
|
||||
msg = "Invalid flake object. Doesn't have a store path"
|
||||
raise ClanError(msg)
|
||||
return Path(store_path) / "machines"
|
||||
# Get the clan directory configuration from Nix
|
||||
# This is computed in Nix where store paths are consistent
|
||||
# Returns "" if no custom directory is set
|
||||
# Fall back to "" if the option doesn't exist (backwards compatibility)
|
||||
try:
|
||||
clan_dir = flake.select("clanInternals.inventoryClass.relativeDirectory")
|
||||
except ClanError:
|
||||
# Option doesn't exist in older clan-core versions
|
||||
# Assume no custom directory
|
||||
clan_dir = ""
|
||||
|
||||
return base_path / clan_dir / "machines"
|
||||
|
||||
|
||||
def specific_machine_dir(machine: "MachineSpecProtocol") -> Path:
|
||||
|
||||
Reference in New Issue
Block a user