Skip to content

Commit 7af459c

Browse files
committed
pynixd-nixkube: conform to pynixd stores dict API
1 parent 5a5211e commit 7af459c

5 files changed

Lines changed: 55 additions & 41 deletions

File tree

kubenix/pynixd.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@ let
3434
config file mounted in the pynixd pod. Corresponds to the PynixdSettings
3535
pydantic model (see pynixd.config).
3636
37-
Common keys include stores (list of StoreSpec), ranking weights,
38-
GC intervals, etc. When stores include SSH stores, their client
39-
keys are auto-discovered from HOME/.ssh/ if client_keys is omitted.
37+
Common keys include stores (dict of StoreSpec keyed by store ID),
38+
ranking weights, GC intervals, etc. When stores include SSH stores,
39+
their client keys are auto-discovered from HOME/.ssh/ if client_keys
40+
is omitted.
4041
'';
4142
type = jsonFormat.type;
4243
default = { };
4344
example = lib.literalExpression ''
4445
{
45-
stores = [
46-
{
46+
stores = {
47+
builder1 = {
4748
type = "ssh-subprocess";
4849
host = "builder.example.com";
4950
port = 22;
5051
username = "nix";
5152
systems = [ "x86_64-linux" ];
52-
}
53-
];
53+
};
54+
};
5455
}
5556
'';
5657
};

pkgs/pynixd-nixkube/pynixd_nixkube/__main__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from pathlib import Path
55

66
import structlog
7-
from pynixd.config import PynixdSettings
7+
from pynixd.config import LocalSocketStoreSpec, PynixdSettings
88
from pynixd.instance import Server
99
from pynixd.store import LocalSocketStore
10+
from pynixd.types.ids import StoreId
1011

1112
from .setup import configure_logging, install_nss
1213
from .ssh_keys import watch_authorized_keys
@@ -20,18 +21,19 @@ async def _main():
2021
install_nss()
2122

2223
local_store = LocalSocketStore(
23-
store_id="local",
24-
store_path=Path("/"),
25-
use_db=False,
26-
monitor=False,
24+
LocalSocketStoreSpec(
25+
store_id=StoreId("local"),
26+
store_path=Path("/"),
27+
use_db=False,
28+
monitor=False,
29+
)
2730
)
2831

2932
settings = PynixdSettings()
3033

31-
server = Server(local_store=local_store, settings=settings)
34+
server = Server(stores={StoreId("local"): local_store}, settings=settings)
3235

3336
async with server:
34-
await server.add_store(local_store)
3537
keys_watch = asyncio.create_task(watch_authorized_keys(server))
3638
server.background_tasks.append(keys_watch)
3739
log.info("pynixd_nixkube_running")

pkgs/pynixd-nixkube/pynixd_nixkube/builder_main.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from pathlib import Path
55

66
import structlog
7-
from pynixd.config import PynixdSettings
7+
from pynixd.config import LocalSocketStoreSpec, PynixdSettings
88
from pynixd.instance import Server
99
from pynixd.store import LocalSocketStore
10+
from pynixd.types.ids import StoreId
1011

1112
from .setup import configure_logging, install_nss
1213

@@ -19,15 +20,18 @@ async def _main() -> None:
1920
install_nss()
2021

2122
local_store = LocalSocketStore(
22-
store_id="local",
23-
store_path=Path("/"),
24-
use_db=False,
25-
monitor=False,
23+
LocalSocketStoreSpec(
24+
store_id=StoreId("local"),
25+
store_path=Path("/"),
26+
use_db=False,
27+
monitor=False,
28+
extra_args=["--option", "build-dir", "/nix/var/nix/builds"],
29+
)
2630
)
2731

2832
settings = PynixdSettings()
2933

30-
server = Server(local_store=local_store, settings=settings)
34+
server = Server(stores={StoreId("local"): local_store}, settings=settings)
3135

3236
async with server:
3337
log.info("pynixd_nixkube_builder_running")

pkgs/pynixd-nixkube/pynixd_nixkube/builder_manager.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import kr8s.asyncio as k8s
1010
import structlog
1111
from kr8s.asyncio.objects import Job, PodTemplate
12+
from pynixd.config import SSHSubprocessStoreSpec
1213
from pynixd.store import SSHSubprocessStore
14+
from pynixd.types.ids import StoreId
1315

1416
if TYPE_CHECKING:
1517
from pynixd.instance import Server
@@ -371,14 +373,16 @@ async def _register_builder(
371373
self, store_id: str, pod_ip: str, job_name: str = "", probe: bool = False
372374
) -> None:
373375
store = SSHSubprocessStore(
374-
host=pod_ip,
375-
store_id=store_id,
376-
port=22,
377-
username="nix",
378-
client_keys=["/etc/ssh-key/id_ed25519"],
379-
nix_bin="/nix/var/result/bin/nix",
380-
monitor=False,
381-
no_schedule=probe,
376+
SSHSubprocessStoreSpec(
377+
store_id=StoreId(store_id),
378+
host=pod_ip,
379+
port=22,
380+
username="nix",
381+
client_keys=["/etc/ssh-key/id_ed25519"],
382+
nix_bin="/nix/var/result/bin/nix",
383+
monitor=False,
384+
no_schedule=probe,
385+
)
382386
)
383387
try:
384388
await self.server.add_store(store, dynamic=True)

pkgs/pynixd-nixkube/pynixd_nixkube/central_main.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from pathlib import Path
55

66
import structlog
7-
from pynixd.config import PynixdSettings
7+
from pynixd.config import LocalSocketStoreSpec, PynixdSettings
88
from pynixd.instance import Server
9-
from pynixd.store import LocalSocketStore
9+
from pynixd.store import LocalSocketStore, Store
10+
from pynixd.types.ids import StoreId
1011

1112
from .builder_manager import BuilderManager
1213
from .config import NixkubeCentralSettings
@@ -22,30 +23,32 @@ async def _main() -> None:
2223
install_nss()
2324

2425
local_store = LocalSocketStore(
25-
store_id="local",
26-
store_path=Path("/"),
27-
use_db=False,
28-
monitor=False,
26+
LocalSocketStoreSpec(
27+
store_id=StoreId("local"),
28+
store_path=Path("/data"),
29+
use_db=False,
30+
monitor=False,
31+
)
2932
)
3033

3134
pynixd_settings = PynixdSettings()
3235
settings = NixkubeCentralSettings()
3336

34-
server = Server(local_store=local_store, settings=pynixd_settings)
35-
37+
stores: dict[StoreId, Store] = {StoreId("local"): local_store}
3638
if pynixd_settings.stores:
37-
_, remote_stores = pynixd_settings.to_stores()
38-
server.ctx._stores.update(remote_stores)
39+
config_stores = pynixd_settings.to_stores()
40+
for store_id, store in config_stores.items():
41+
if store_id != StoreId("local"):
42+
stores[store_id] = store
43+
44+
server = Server(stores=stores, settings=pynixd_settings)
3945

4046
builder_manager: BuilderManager | None = None
4147

4248
async with server:
4349
keys_watch = asyncio.create_task(watch_authorized_keys(server))
4450
server.background_tasks.append(keys_watch)
4551

46-
if pynixd_settings.schedule_mode != "scheduler":
47-
await server.add_store(local_store)
48-
4952
if settings.kube_namespace:
5053
builder_manager = BuilderManager(
5154
server=server,

0 commit comments

Comments
 (0)