Skip to content

Commit

Permalink
fix: write nix runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Jan 17, 2024
1 parent 3d71ffb commit e7c3576
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion controller/app/models/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def write_nix(
for attr, value in module_settings.settings.items():
my_attr = getattr(self, attr)
assert isinstance(my_attr, models.Setting)
my_attr.write_nix(f, value, i)
my_attr.write_nix(f, value, priority)

f.write("}\n")
11 changes: 2 additions & 9 deletions controller/app/models/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@

class Setting(BaseModel):
name: str
value: object = None
type: str | object
default: object
description: str
example: Optional[str] = None

def get_value(self):
if self.value is not None:
return self.value
else:
return self.default

def write_nix(self, f, priority):
def write_nix(self, f, value, priority):
f.write(
f" {self.name} = lib.mkOverride {priority} {convert_python_value_to_nix(self.get_value())};\n"
f" {self.name} = lib.mkOverride {priority} {convert_python_value_to_nix(value.value)};\n"
)


Expand Down
4 changes: 2 additions & 2 deletions controller/app/models/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def write_nix(self, path: os.PathLike):
for module_settings in device.modules:
# module holds settings right now.
module = next(m for m in self.modules if m.type == module_settings.type)
module.write_nix(device_path, env, module_settings, HOST_PRIORITY)
module.write_nix(device_path, module_settings, HOST_PRIORITY)
# for each tag create its own folder
for tag in self.tags:
tag_path = path / "tags" / tag.name
Expand All @@ -59,7 +59,7 @@ def write_nix(self, path: os.PathLike):
for module_settings in tag.modules:
# module holds settings right now.
module = next(m for m in self.modules if m.type == module_settings.type)
module.write_nix(tag_path, env, module_settings, tag.priority)
module.write_nix(tag_path, module_settings, tag.priority)

def available_modules(self):
# return all modules that are not already included in the state
Expand Down
4 changes: 3 additions & 1 deletion controller/app/models/thymis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from . import Module, Setting
import pathlib

from app import models


class Thymis(Module):
repo_dir: Setting = Setting(
Expand Down Expand Up @@ -35,7 +37,7 @@ class Thymis(Module):
example="",
)

def write_nix(self, path: os.PathLike, env: Environment):
def write_nix(self, path: os.PathLike, module_settings: models.ModuleSettings, priority: int):
# return super().write_nix(path, env)
path = pathlib.Path(path)
with open(path / ".." / "thymis-settings.json", "w+") as f:
Expand Down

0 comments on commit e7c3576

Please sign in to comment.