clan_lib flake: get store path from NIX_STORE_DIR

This commit is contained in:
lassulus
2025-05-19 15:28:05 +02:00
parent 76e4ecb6d5
commit fb5839f929

View File

@@ -1,5 +1,6 @@
import json import json
import logging import logging
import os
from dataclasses import asdict, dataclass, field from dataclasses import asdict, dataclass, field
from enum import Enum from enum import Enum
from hashlib import sha1 from hashlib import sha1
@@ -318,9 +319,10 @@ class FlakeCacheEntry:
# strings need to be checked if they are store paths # strings need to be checked if they are store paths
# if they are, we store them as a dict with the outPath key # if they are, we store them as a dict with the outPath key
# this is to mirror nix behavior, where the outPath of an attrset is used if no further key is specified # this is to mirror nix behavior, where the outPath of an attrset is used if no further key is specified
elif isinstance(value, str) and value.startswith("/nix/store/"): elif isinstance(value, str) and value.startswith(
os.environ.get("NIX_STORE_DIR", "/nix/store")
):
assert selectors == [] assert selectors == []
if value.startswith("/nix/store/"):
self.value = {"outPath": FlakeCacheEntry(value)} self.value = {"outPath": FlakeCacheEntry(value)}
# if we have a normal scalar, we check if it conflicts with a maybe already store value # if we have a normal scalar, we check if it conflicts with a maybe already store value
@@ -337,7 +339,9 @@ class FlakeCacheEntry:
selector: Selector selector: Selector
# for store paths we have to check if they still exist, otherwise they have to be rebuild and are thus not cached # for store paths we have to check if they still exist, otherwise they have to be rebuild and are thus not cached
if isinstance(self.value, str) and self.value.startswith("/nix/store/"): if isinstance(self.value, str) and self.value.startswith(
os.environ.get("NIX_STORE_DIR", "/nix/store")
):
return Path(self.value).exists() return Path(self.value).exists()
# if self.value is not dict but we request more selectors, we assume we are cached and an error will be thrown in the select function # if self.value is not dict but we request more selectors, we assume we are cached and an error will be thrown in the select function