mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-21 06:39:09 -04:00
Compare commits
85 Commits
feature/ad
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 203bdfe89b | |||
| edcacfcecc | |||
| 156d624d81 | |||
| 9a7cf03a00 | |||
| 6299d42f75 | |||
| e6472b2cf5 | |||
| 41d3a8fe1a | |||
|
|
e6ac8f8021 | ||
| 0f8f6f96d6 | |||
| 4cb4bd6f3d | |||
| c046710258 | |||
| 7f9fbe3602 | |||
|
|
8ee3b4d6e5 | ||
| 18b7fb2d60 | |||
| 2f1fa5c750 | |||
| 164d0dd59e | |||
| d4459643ab | |||
| c09dba0c37 | |||
| 409f376166 | |||
| a9a6e1f932 | |||
| 6472f07a88 | |||
|
|
51c79f6b40 | ||
| b0d5147296 | |||
| c56082b516 | |||
| 34b728c88f | |||
| 5697458bad | |||
| 276c2ac74b | |||
| 69e5aa20d5 | |||
| 3d1f773fa5 | |||
| 14dd1fe52e | |||
| 30fe41ea1b | |||
| 3a17c5514d | |||
| c6586db91e | |||
| 81b199373e | |||
| a957e23041 | |||
| 52389f729d | |||
| cc2a609f52 | |||
| ca4693a1ba | |||
| 90e5e0855d | |||
| e339667c2b | |||
| 85540ee920 | |||
| 3be1b8aa8f | |||
| 7c56954cda | |||
| 290f972346 | |||
| 72c3ccfb6d | |||
| 9630633ff5 | |||
| 8c83f306b2 | |||
| 5b4609dc3b | |||
| d1be25c6e8 | |||
| 31910586d2 | |||
| b8dfd0852a | |||
| 6ce622e93e | |||
| 55e652a51d | |||
| b5455a5483 | |||
| 8baf388061 | |||
| 7ffb7b4a37 | |||
| eb04f4a56d | |||
| 5b8e543226 | |||
| da48f62195 | |||
| 60f2ab1039 | |||
| c1de454005 | |||
| 391e37b746 | |||
|
|
27565173d4 | ||
| 0c0ed92cb4 | |||
|
|
cc9996d6fa | ||
| 102f36eb1b | |||
| 9ec988729b | |||
| 4e3c25afb4 | |||
| 0d482aca4b | |||
|
|
c624781d84 | ||
| f4996b71e4 | |||
| 58a29214d3 | |||
| c4171b56b5 | |||
| d6d48516ea | |||
| ae882ba578 | |||
| 100b8145e8 | |||
| e99cd8e54a | |||
| de9348432c | |||
| b1fa596f37 | |||
| 908bccb8dc | |||
| b8cc9c5772 | |||
| d62076a900 | |||
| 0c9bd40659 | |||
| f713b8d4fa | |||
| ddba7d1068 |
2
.github/workflows/build_systems.yml
vendored
2
.github/workflows/build_systems.yml
vendored
@@ -25,4 +25,4 @@ jobs:
|
|||||||
- name: Build default package
|
- name: Build default package
|
||||||
run: "nixos-rebuild build --flake ./#${{ matrix.system }}"
|
run: "nixos-rebuild build --flake ./#${{ matrix.system }}"
|
||||||
- name: copy to nix-cache
|
- name: copy to nix-cache
|
||||||
run: nix copy --to ssh://jeeves .#nixosConfigurations.${{ matrix.system }}.config.system.build.toplevel
|
run: nix copy --accept-flake-config --to unix:///host-nix/var/nix/daemon-socket/socket .#nixosConfigurations.${{ matrix.system }}.config.system.build.toplevel
|
||||||
|
|||||||
2
.github/workflows/pytest.yml
vendored
2
.github/workflows/pytest.yml
vendored
@@ -16,4 +16,4 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: pytest tests
|
run: nix develop .#devShells.x86_64-linux.default -c pytest tests
|
||||||
|
|||||||
22
.vscode/settings.json
vendored
22
.vscode/settings.json
vendored
@@ -81,7 +81,6 @@
|
|||||||
"FASTFOX",
|
"FASTFOX",
|
||||||
"ffmpegthumbnailer",
|
"ffmpegthumbnailer",
|
||||||
"filebot",
|
"filebot",
|
||||||
"filebrowser",
|
|
||||||
"fileroller",
|
"fileroller",
|
||||||
"findbar",
|
"findbar",
|
||||||
"Fira",
|
"Fira",
|
||||||
@@ -98,6 +97,7 @@
|
|||||||
"getch",
|
"getch",
|
||||||
"getmaxyx",
|
"getmaxyx",
|
||||||
"ghdeploy",
|
"ghdeploy",
|
||||||
|
"gitea",
|
||||||
"globalprivacycontrol",
|
"globalprivacycontrol",
|
||||||
"gparted",
|
"gparted",
|
||||||
"gtts",
|
"gtts",
|
||||||
@@ -116,7 +116,9 @@
|
|||||||
"httpchk",
|
"httpchk",
|
||||||
"hurlenko",
|
"hurlenko",
|
||||||
"hwloc",
|
"hwloc",
|
||||||
|
"ical",
|
||||||
"ignorelist",
|
"ignorelist",
|
||||||
|
"improv",
|
||||||
"INITDB",
|
"INITDB",
|
||||||
"iocharset",
|
"iocharset",
|
||||||
"ioit",
|
"ioit",
|
||||||
@@ -126,6 +128,8 @@
|
|||||||
"jnoortheen",
|
"jnoortheen",
|
||||||
"jsbc",
|
"jsbc",
|
||||||
"kagi",
|
"kagi",
|
||||||
|
"keyformat",
|
||||||
|
"keylocation",
|
||||||
"kuma",
|
"kuma",
|
||||||
"lazer",
|
"lazer",
|
||||||
"levelname",
|
"levelname",
|
||||||
@@ -225,12 +229,9 @@
|
|||||||
"pylint",
|
"pylint",
|
||||||
"pymetno",
|
"pymetno",
|
||||||
"pymodbus",
|
"pymodbus",
|
||||||
|
"pyopenweathermap",
|
||||||
"pyownet",
|
"pyownet",
|
||||||
"pytest",
|
"pytest",
|
||||||
"qbit",
|
|
||||||
"qbittorrent",
|
|
||||||
"qbittorrentvpn",
|
|
||||||
"qbitvpn",
|
|
||||||
"quicksuggest",
|
"quicksuggest",
|
||||||
"radarr",
|
"radarr",
|
||||||
"readahead",
|
"readahead",
|
||||||
@@ -252,6 +253,7 @@
|
|||||||
"schemeless",
|
"schemeless",
|
||||||
"scrollback",
|
"scrollback",
|
||||||
"SECUREFOX",
|
"SECUREFOX",
|
||||||
|
"sessionmaker",
|
||||||
"sessionstore",
|
"sessionstore",
|
||||||
"shellcheck",
|
"shellcheck",
|
||||||
"signon",
|
"signon",
|
||||||
@@ -263,6 +265,7 @@
|
|||||||
"socialtracking",
|
"socialtracking",
|
||||||
"sonarr",
|
"sonarr",
|
||||||
"sponsorblock",
|
"sponsorblock",
|
||||||
|
"sqlalchemy",
|
||||||
"sqltools",
|
"sqltools",
|
||||||
"ssdp",
|
"ssdp",
|
||||||
"SSHOPTS",
|
"SSHOPTS",
|
||||||
@@ -286,9 +289,11 @@
|
|||||||
"twimg",
|
"twimg",
|
||||||
"typer",
|
"typer",
|
||||||
"uaccess",
|
"uaccess",
|
||||||
|
"ubiquiti",
|
||||||
"ublock",
|
"ublock",
|
||||||
"uiprotect",
|
"uiprotect",
|
||||||
"uitour",
|
"uitour",
|
||||||
|
"unifi",
|
||||||
"unrar",
|
"unrar",
|
||||||
"unsubmitted",
|
"unsubmitted",
|
||||||
"uptimekuma",
|
"uptimekuma",
|
||||||
@@ -325,5 +330,10 @@
|
|||||||
"zoxide",
|
"zoxide",
|
||||||
"zram",
|
"zram",
|
||||||
"zstd"
|
"zstd"
|
||||||
]
|
],
|
||||||
|
"python-envs.defaultEnvManager": "ms-python.python:system",
|
||||||
|
"python-envs.pythonProjects": [],
|
||||||
|
"python.testing.pytestArgs": ["tests"],
|
||||||
|
"python.testing.unittestEnabled": false,
|
||||||
|
"python.testing.pytestEnabled": true
|
||||||
}
|
}
|
||||||
|
|||||||
5
AGENTS.md
Normal file
5
AGENTS.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
## Dev environment tips
|
||||||
|
|
||||||
|
- use treefmt to format all files
|
||||||
|
- make python code ruff compliant
|
||||||
|
- use pytest to test python code
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
boot = {
|
boot = {
|
||||||
tmp.useTmpfs = true;
|
tmp.useTmpfs = true;
|
||||||
kernelPackages = lib.mkDefault pkgs.linuxPackages_6_12;
|
kernelPackages = lib.mkDefault pkgs.linuxPackages_6_12;
|
||||||
zfs.package = lib.mkDefault pkgs.zfs_2_3;
|
zfs.package = lib.mkDefault pkgs.zfs_2_4;
|
||||||
};
|
};
|
||||||
|
|
||||||
hardware.enableRedistributableFirmware = true;
|
hardware.enableRedistributableFirmware = true;
|
||||||
@@ -44,7 +44,10 @@
|
|||||||
# firmware update
|
# firmware update
|
||||||
fwupd.enable = true;
|
fwupd.enable = true;
|
||||||
|
|
||||||
snapshot_manager.enable = lib.mkDefault true;
|
snapshot_manager = {
|
||||||
|
enable = lib.mkDefault true;
|
||||||
|
PYTHONPATH = "${inputs.self}/";
|
||||||
|
};
|
||||||
|
|
||||||
zfs = {
|
zfs = {
|
||||||
trim.enable = lib.mkDefault true;
|
trim.enable = lib.mkDefault true;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
inputs,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
@@ -17,6 +16,12 @@ in
|
|||||||
default = ./snapshot_config.toml;
|
default = ./snapshot_config.toml;
|
||||||
description = "Path to the snapshot_manager TOML config.";
|
description = "Path to the snapshot_manager TOML config.";
|
||||||
};
|
};
|
||||||
|
PYTHONPATH = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = ''
|
||||||
|
the PYTHONPATH to use for the snapshot_manager service.
|
||||||
|
'';
|
||||||
|
};
|
||||||
EnvironmentFile = lib.mkOption {
|
EnvironmentFile = lib.mkOption {
|
||||||
type = lib.types.nullOr (lib.types.coercedTo lib.types.path toString lib.types.str);
|
type = lib.types.nullOr (lib.types.coercedTo lib.types.path toString lib.types.str);
|
||||||
default = null;
|
default = null;
|
||||||
@@ -35,11 +40,12 @@ in
|
|||||||
requires = [ "zfs-import.target" ];
|
requires = [ "zfs-import.target" ];
|
||||||
after = [ "zfs-import.target" ];
|
after = [ "zfs-import.target" ];
|
||||||
path = [ pkgs.zfs ];
|
path = [ pkgs.zfs ];
|
||||||
|
environment = {
|
||||||
|
PYTHONPATH = cfg.PYTHONPATH;
|
||||||
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "${
|
ExecStart = "${pkgs.my_python}/bin/python -m python.tools.snapshot_manager ${lib.escapeShellArg cfg.path}";
|
||||||
inputs.system_tools.packages.${pkgs.system}.default
|
|
||||||
}/bin/snapshot_manager ${lib.escapeShellArg cfg.path}";
|
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs (cfg.EnvironmentFile != null) {
|
// lib.optionalAttrs (cfg.EnvironmentFile != null) {
|
||||||
EnvironmentFile = cfg.EnvironmentFile;
|
EnvironmentFile = cfg.EnvironmentFile;
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
TcpKeepAlive = "no";
|
TcpKeepAlive = "no";
|
||||||
X11Forwarding = lib.mkDefault false;
|
X11Forwarding = lib.mkDefault false;
|
||||||
KexAlgorithms = [
|
KexAlgorithms = [
|
||||||
|
"sntrup761x25519-sha512@openssh.com"
|
||||||
|
"mlkem768x25519-sha256"
|
||||||
"curve25519-sha256@libssh.org"
|
"curve25519-sha256@libssh.org"
|
||||||
"diffie-hellman-group-exchange-sha256"
|
"diffie-hellman-group-exchange-sha256"
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
boot = {
|
boot = {
|
||||||
kernelPackages = pkgs.linuxPackages_6_16;
|
kernelPackages = pkgs.linuxPackages_6_18;
|
||||||
zfs.package = pkgs.zfs_2_3;
|
zfs.package = pkgs.zfs_2_4;
|
||||||
};
|
};
|
||||||
|
|
||||||
hardware.bluetooth = {
|
hardware.bluetooth = {
|
||||||
|
|||||||
@@ -1,129 +0,0 @@
|
|||||||
esphome:
|
|
||||||
name: batteries
|
|
||||||
friendly_name: batteries
|
|
||||||
|
|
||||||
esp32:
|
|
||||||
board: esp32dev
|
|
||||||
framework:
|
|
||||||
type: arduino
|
|
||||||
|
|
||||||
logger:
|
|
||||||
|
|
||||||
api:
|
|
||||||
encryption:
|
|
||||||
key: !secret api_key
|
|
||||||
|
|
||||||
external_components:
|
|
||||||
- source: github://syssi/esphome-jk-bms@main
|
|
||||||
|
|
||||||
ota:
|
|
||||||
- platform: esphome
|
|
||||||
password: !secret ota_password
|
|
||||||
|
|
||||||
wifi:
|
|
||||||
ssid: !secret wifi_ssid
|
|
||||||
password: !secret wifi_password
|
|
||||||
|
|
||||||
captive_portal:
|
|
||||||
|
|
||||||
esp32_ble_tracker:
|
|
||||||
scan_parameters:
|
|
||||||
interval: 1100ms
|
|
||||||
window: 1100ms
|
|
||||||
active: true
|
|
||||||
|
|
||||||
ble_client:
|
|
||||||
- mac_address: "C8:47:80:29:0F:DB"
|
|
||||||
id: jk_ble0
|
|
||||||
- mac_address: "C8:47:80:37:9D:DD"
|
|
||||||
id: jk_ble1
|
|
||||||
|
|
||||||
jk_bms_ble:
|
|
||||||
- ble_client_id: jk_ble0
|
|
||||||
protocol_version: JK02_32S
|
|
||||||
throttle: 1s
|
|
||||||
id: jk_bms0
|
|
||||||
|
|
||||||
- ble_client_id: jk_ble1
|
|
||||||
protocol_version: JK02_32S
|
|
||||||
throttle: 1s
|
|
||||||
id: jk_bms1
|
|
||||||
|
|
||||||
sensor:
|
|
||||||
# BMS1 sensors
|
|
||||||
- platform: jk_bms_ble
|
|
||||||
jk_bms_ble_id: jk_bms0
|
|
||||||
total_voltage:
|
|
||||||
name: "JK0 Total Voltage"
|
|
||||||
current:
|
|
||||||
name: "JK0 Current"
|
|
||||||
state_of_charge:
|
|
||||||
name: "JK0 SoC"
|
|
||||||
power:
|
|
||||||
name: "JK0 Power"
|
|
||||||
temperature_sensor_1:
|
|
||||||
name: "JK0 Temp 1"
|
|
||||||
temperature_sensor_2:
|
|
||||||
name: "JK0 Temp 2"
|
|
||||||
balancing:
|
|
||||||
name: "JK0 balancing"
|
|
||||||
charging_cycles:
|
|
||||||
name: "JK0 charging cycles"
|
|
||||||
total_runtime:
|
|
||||||
name: "JK0 total runtime"
|
|
||||||
balancing_current:
|
|
||||||
name: "JK0 balancing current"
|
|
||||||
|
|
||||||
# BMS2 sensors
|
|
||||||
- platform: jk_bms_ble
|
|
||||||
jk_bms_ble_id: jk_bms1
|
|
||||||
total_voltage:
|
|
||||||
name: "JK1 Total Voltage"
|
|
||||||
current:
|
|
||||||
name: "JK1 Current"
|
|
||||||
state_of_charge:
|
|
||||||
name: "JK1 SoC"
|
|
||||||
power:
|
|
||||||
name: "Jk1 Power"
|
|
||||||
temperature_sensor_1:
|
|
||||||
name: "JK1 Temp 1"
|
|
||||||
temperature_sensor_2:
|
|
||||||
name: "Jk1 Temp 2"
|
|
||||||
balancing:
|
|
||||||
name: "JK1 balancing"
|
|
||||||
charging_cycles:
|
|
||||||
name: "JK1 charging cycles"
|
|
||||||
total_runtime:
|
|
||||||
name: "JK1 total runtime"
|
|
||||||
balancing_current:
|
|
||||||
name: "JK1 balancing current"
|
|
||||||
|
|
||||||
text_sensor:
|
|
||||||
- platform: jk_bms_ble
|
|
||||||
jk_bms_ble_id: jk_bms0
|
|
||||||
errors:
|
|
||||||
name: "JK0 Errors"
|
|
||||||
|
|
||||||
- platform: jk_bms_ble
|
|
||||||
jk_bms_ble_id: jk_bms1
|
|
||||||
errors:
|
|
||||||
name: "JK1 Errors"
|
|
||||||
|
|
||||||
switch:
|
|
||||||
- platform: jk_bms_ble
|
|
||||||
jk_bms_ble_id: jk_bms0
|
|
||||||
charging:
|
|
||||||
name: "JK0 Charging"
|
|
||||||
discharging:
|
|
||||||
name: "JK0 Discharging"
|
|
||||||
balancer:
|
|
||||||
name: "JK0 Balancing"
|
|
||||||
|
|
||||||
- platform: jk_bms_ble
|
|
||||||
jk_bms_ble_id: jk_bms1
|
|
||||||
charging:
|
|
||||||
name: "JK1 Charging"
|
|
||||||
discharging:
|
|
||||||
name: "JK1 Discharging"
|
|
||||||
balancer:
|
|
||||||
name: "JK1 Balancing"
|
|
||||||
132
esphome/battery0.yml
Normal file
132
esphome/battery0.yml
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
esphome:
|
||||||
|
name: batteries
|
||||||
|
friendly_name: batteries
|
||||||
|
|
||||||
|
esp32:
|
||||||
|
board: esp32dev
|
||||||
|
framework:
|
||||||
|
type: arduino
|
||||||
|
|
||||||
|
logger:
|
||||||
|
|
||||||
|
api:
|
||||||
|
encryption:
|
||||||
|
key: !secret api_key
|
||||||
|
|
||||||
|
external_components:
|
||||||
|
- source: github://syssi/esphome-jk-bms@main
|
||||||
|
|
||||||
|
ota:
|
||||||
|
- platform: esphome
|
||||||
|
password: !secret ota_password
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: !secret wifi_ssid
|
||||||
|
password: !secret wifi_password
|
||||||
|
fast_connect: on
|
||||||
|
|
||||||
|
captive_portal:
|
||||||
|
|
||||||
|
esp32_ble_tracker:
|
||||||
|
scan_parameters:
|
||||||
|
interval: 1100ms
|
||||||
|
window: 1100ms
|
||||||
|
active: true
|
||||||
|
|
||||||
|
ble_client:
|
||||||
|
- mac_address: "C8:47:80:29:0F:DB"
|
||||||
|
id: jk_ble0
|
||||||
|
|
||||||
|
jk_bms_ble:
|
||||||
|
- ble_client_id: jk_ble0
|
||||||
|
protocol_version: JK02_32S
|
||||||
|
throttle: 1s
|
||||||
|
id: jk_bms0
|
||||||
|
|
||||||
|
button:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
retrieve_settings:
|
||||||
|
name: "JK0 retrieve settings"
|
||||||
|
retrieve_device_info:
|
||||||
|
name: "JK0 retrieve device info"
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
jk_bms_ble_id: jk_bms0
|
||||||
|
total_voltage:
|
||||||
|
name: "JK0 Total Voltage"
|
||||||
|
state_of_charge:
|
||||||
|
name: "JK0 SoC"
|
||||||
|
charging_power:
|
||||||
|
name: "JK0 charging power"
|
||||||
|
discharging_power:
|
||||||
|
name: "JK0 discharging power"
|
||||||
|
temperature_sensor_1:
|
||||||
|
name: "JK0 Temp 1"
|
||||||
|
temperature_sensor_2:
|
||||||
|
name: "JK0 Temp 2"
|
||||||
|
balancing:
|
||||||
|
name: "JK0 balancing"
|
||||||
|
total_runtime:
|
||||||
|
name: "JK0 total runtime"
|
||||||
|
balancing_current:
|
||||||
|
name: "JK0 balancing current"
|
||||||
|
delta_cell_voltage:
|
||||||
|
name: "JK0 cell delta voltage"
|
||||||
|
average_cell_voltage:
|
||||||
|
name: "JK0 cell average voltage"
|
||||||
|
cell_voltage_1:
|
||||||
|
name: "JK0 cell voltage 1"
|
||||||
|
cell_voltage_2:
|
||||||
|
name: "JK0 cell voltage 2"
|
||||||
|
cell_voltage_3:
|
||||||
|
name: "JK0 cell voltage 3"
|
||||||
|
cell_voltage_4:
|
||||||
|
name: "JK0 cell voltage 4"
|
||||||
|
cell_voltage_5:
|
||||||
|
name: "JK0 cell voltage 5"
|
||||||
|
cell_voltage_6:
|
||||||
|
name: "JK0 cell voltage 6"
|
||||||
|
cell_voltage_7:
|
||||||
|
name: "JK0 cell voltage 7"
|
||||||
|
cell_voltage_8:
|
||||||
|
name: "JK0 cell voltage 8"
|
||||||
|
cell_resistance_1:
|
||||||
|
name: "JK0 cell resistance 1"
|
||||||
|
cell_resistance_2:
|
||||||
|
name: "JK0 cell resistance 2"
|
||||||
|
cell_resistance_3:
|
||||||
|
name: "JK0 cell resistance 3"
|
||||||
|
cell_resistance_4:
|
||||||
|
name: "JK0 cell resistance 4"
|
||||||
|
cell_resistance_5:
|
||||||
|
name: "JK0 cell resistance 5"
|
||||||
|
cell_resistance_6:
|
||||||
|
name: "JK0 cell resistance 6"
|
||||||
|
cell_resistance_7:
|
||||||
|
name: "JK0 cell resistance 7"
|
||||||
|
cell_resistance_8:
|
||||||
|
name: "JK0 cell resistance 8"
|
||||||
|
total_charging_cycle_capacity:
|
||||||
|
name: "JK0 total charging cycle capacity"
|
||||||
|
|
||||||
|
text_sensor:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
jk_bms_ble_id: jk_bms0
|
||||||
|
errors:
|
||||||
|
name: "JK0 Errors"
|
||||||
|
|
||||||
|
switch:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
jk_bms_ble_id: jk_bms0
|
||||||
|
charging:
|
||||||
|
name: "JK0 Charging"
|
||||||
|
discharging:
|
||||||
|
name: "JK0 Discharging"
|
||||||
|
balancer:
|
||||||
|
name: "JK0 Balancing"
|
||||||
|
|
||||||
|
- platform: ble_client
|
||||||
|
ble_client_id: jk_ble0
|
||||||
|
name: "JK0 enable bluetooth connection"
|
||||||
|
id: ble_client_switch0
|
||||||
132
esphome/battery1.yml
Normal file
132
esphome/battery1.yml
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
esphome:
|
||||||
|
name: battery1
|
||||||
|
friendly_name: battery1
|
||||||
|
|
||||||
|
esp32:
|
||||||
|
board: esp32dev
|
||||||
|
framework:
|
||||||
|
type: arduino
|
||||||
|
|
||||||
|
logger:
|
||||||
|
|
||||||
|
api:
|
||||||
|
encryption:
|
||||||
|
key: !secret api_key
|
||||||
|
|
||||||
|
external_components:
|
||||||
|
- source: github://syssi/esphome-jk-bms@main
|
||||||
|
|
||||||
|
ota:
|
||||||
|
- platform: esphome
|
||||||
|
password: !secret ota_password
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: !secret wifi_ssid
|
||||||
|
password: !secret wifi_password
|
||||||
|
fast_connect: on
|
||||||
|
|
||||||
|
captive_portal:
|
||||||
|
|
||||||
|
esp32_ble_tracker:
|
||||||
|
scan_parameters:
|
||||||
|
interval: 1100ms
|
||||||
|
window: 1100ms
|
||||||
|
active: true
|
||||||
|
|
||||||
|
ble_client:
|
||||||
|
- mac_address: "C8:47:80:37:9D:DD"
|
||||||
|
id: jk_ble1
|
||||||
|
|
||||||
|
jk_bms_ble:
|
||||||
|
- ble_client_id: jk_ble1
|
||||||
|
protocol_version: JK02_32S
|
||||||
|
throttle: 1s
|
||||||
|
id: jk_bms1
|
||||||
|
|
||||||
|
button:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
retrieve_settings:
|
||||||
|
name: "JK1 retrieve settings"
|
||||||
|
retrieve_device_info:
|
||||||
|
name: "JK1 retrieve device info"
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
jk_bms_ble_id: jk_bms1
|
||||||
|
total_voltage:
|
||||||
|
name: "JK1 Total Voltage"
|
||||||
|
state_of_charge:
|
||||||
|
name: "JK1 SoC"
|
||||||
|
charging_power:
|
||||||
|
name: "JK1 charging power"
|
||||||
|
discharging_power:
|
||||||
|
name: "JK1 discharging power"
|
||||||
|
temperature_sensor_1:
|
||||||
|
name: "JK1 Temp 1"
|
||||||
|
temperature_sensor_2:
|
||||||
|
name: "JK1 Temp 2"
|
||||||
|
balancing:
|
||||||
|
name: "JK1 balancing"
|
||||||
|
total_runtime:
|
||||||
|
name: "JK1 total runtime"
|
||||||
|
balancing_current:
|
||||||
|
name: "JK1 balancing current"
|
||||||
|
delta_cell_voltage:
|
||||||
|
name: "JK1 cell delta voltage"
|
||||||
|
average_cell_voltage:
|
||||||
|
name: "JK1 cell average voltage"
|
||||||
|
cell_voltage_1:
|
||||||
|
name: "JK1 cell voltage 1"
|
||||||
|
cell_voltage_2:
|
||||||
|
name: "JK1 cell voltage 2"
|
||||||
|
cell_voltage_3:
|
||||||
|
name: "JK1 cell voltage 3"
|
||||||
|
cell_voltage_4:
|
||||||
|
name: "JK1 cell voltage 4"
|
||||||
|
cell_voltage_5:
|
||||||
|
name: "JK1 cell voltage 5"
|
||||||
|
cell_voltage_6:
|
||||||
|
name: "JK1 cell voltage 6"
|
||||||
|
cell_voltage_7:
|
||||||
|
name: "JK1 cell voltage 7"
|
||||||
|
cell_voltage_8:
|
||||||
|
name: "JK1 cell voltage 8"
|
||||||
|
cell_resistance_1:
|
||||||
|
name: "JK1 cell resistance 1"
|
||||||
|
cell_resistance_2:
|
||||||
|
name: "JK1 cell resistance 2"
|
||||||
|
cell_resistance_3:
|
||||||
|
name: "JK1 cell resistance 3"
|
||||||
|
cell_resistance_4:
|
||||||
|
name: "JK1 cell resistance 4"
|
||||||
|
cell_resistance_5:
|
||||||
|
name: "JK1 cell resistance 5"
|
||||||
|
cell_resistance_6:
|
||||||
|
name: "JK1 cell resistance 6"
|
||||||
|
cell_resistance_7:
|
||||||
|
name: "JK1 cell resistance 7"
|
||||||
|
cell_resistance_8:
|
||||||
|
name: "JK1 cell resistance 8"
|
||||||
|
total_charging_cycle_capacity:
|
||||||
|
name: "JK1 total charging cycle capacity"
|
||||||
|
|
||||||
|
text_sensor:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
jk_bms_ble_id: jk_bms1
|
||||||
|
errors:
|
||||||
|
name: "JK1 Errors"
|
||||||
|
|
||||||
|
switch:
|
||||||
|
- platform: jk_bms_ble
|
||||||
|
jk_bms_ble_id: jk_bms1
|
||||||
|
charging:
|
||||||
|
name: "JK1 Charging"
|
||||||
|
discharging:
|
||||||
|
name: "JK1 Discharging"
|
||||||
|
balancer:
|
||||||
|
name: "JK1 Balancing"
|
||||||
|
|
||||||
|
- platform: ble_client
|
||||||
|
ble_client_id: jk_ble1
|
||||||
|
name: "JK1 enable bluetooth connection"
|
||||||
|
id: ble_client_switch0
|
||||||
48
esphome/environment.yml
Normal file
48
esphome/environment.yml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
esphome:
|
||||||
|
name: "environment"
|
||||||
|
friendly_name: "environment"
|
||||||
|
|
||||||
|
esp32:
|
||||||
|
board: esp32dev
|
||||||
|
framework:
|
||||||
|
type: arduino
|
||||||
|
|
||||||
|
i2c:
|
||||||
|
sda: GPIO21
|
||||||
|
scl: GPIO22
|
||||||
|
scan: True
|
||||||
|
id: bus_a
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: aht10
|
||||||
|
i2c_id: bus_a
|
||||||
|
address: 0x38
|
||||||
|
variant: AHT20
|
||||||
|
temperature:
|
||||||
|
name: "environment Temperature"
|
||||||
|
id: aht10_temperature
|
||||||
|
humidity:
|
||||||
|
name: "environment Humidity"
|
||||||
|
id: aht10_humidity
|
||||||
|
update_interval: 5s
|
||||||
|
|
||||||
|
web_server:
|
||||||
|
port: 80
|
||||||
|
|
||||||
|
logger:
|
||||||
|
level: DEBUG
|
||||||
|
|
||||||
|
api:
|
||||||
|
encryption:
|
||||||
|
key: !secret api_key
|
||||||
|
|
||||||
|
ota:
|
||||||
|
- platform: esphome
|
||||||
|
password: !secret ota_password
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: !secret wifi_ssid
|
||||||
|
password: !secret wifi_password
|
||||||
|
fast_connect: on
|
||||||
|
|
||||||
|
captive_portal:
|
||||||
135
flake.lock
generated
135
flake.lock
generated
@@ -8,11 +8,11 @@
|
|||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "pkgs/firefox-addons",
|
"dir": "pkgs/firefox-addons",
|
||||||
"lastModified": 1760673822,
|
"lastModified": 1766762570,
|
||||||
"narHash": "sha256-h+liPhhMw1yYvkDGLHzQJQShQs+yLjNgjfAyZX+sRrM=",
|
"narHash": "sha256-Nevsj5NYurwp3I6nSMeh3uirwoinVSbCldqOXu4smms=",
|
||||||
"owner": "rycee",
|
"owner": "rycee",
|
||||||
"repo": "nur-expressions",
|
"repo": "nur-expressions",
|
||||||
"rev": "5cca27f1bb30a26140d0cf60ab34daa45b4fa11f",
|
"rev": "03d7d310ea91d6e4b47ed70aa86c781fcc5b38e1",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -29,11 +29,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760662441,
|
"lastModified": 1766682973,
|
||||||
"narHash": "sha256-mlDqR1Ntgs9uYYEAUR1IhamKBO0lxoNS4zGLzEZaY0A=",
|
"narHash": "sha256-GKO35onS711ThCxwWcfuvbIBKXwriahGqs+WZuJ3v9E=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "722792af097dff5790f1a66d271a47759f477755",
|
"rev": "91cdb0e2d574c64fae80d221f4bf09d5592e9ec2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -44,11 +44,11 @@
|
|||||||
},
|
},
|
||||||
"nixos-hardware": {
|
"nixos-hardware": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760106635,
|
"lastModified": 1766568855,
|
||||||
"narHash": "sha256-2GoxVaKWTHBxRoeUYSjv0AfSOx4qw5CWSFz2b+VolKU=",
|
"narHash": "sha256-UXVtN77D7pzKmzOotFTStgZBqpOcf8cO95FcupWp4Zo=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixos-hardware",
|
"repo": "nixos-hardware",
|
||||||
"rev": "9ed85f8afebf2b7478f25db0a98d0e782c0ed903",
|
"rev": "c5db9569ac9cc70929c268ac461f4003e3e5ca80",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -60,11 +60,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760524057,
|
"lastModified": 1766651565,
|
||||||
"narHash": "sha256-EVAqOteLBFmd7pKkb0+FIUyzTF61VKi7YmvP1tw4nEw=",
|
"narHash": "sha256-QEhk0eXgyIqTpJ/ehZKg9IKS7EtlWxF3N7DXy42zPfU=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "544961dfcce86422ba200ed9a0b00dd4b1486ec5",
|
"rev": "3e2499d5539c16d0d173ba53552a4ff8547f4539",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -76,11 +76,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-master": {
|
"nixpkgs-master": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760751316,
|
"lastModified": 1766794443,
|
||||||
"narHash": "sha256-1296zQfPiLZNrLKzX1t+kunadeI/mH82hKze3voduEI=",
|
"narHash": "sha256-Q8IyTQ3Lu8vX/iqO3U+E4pjLbP1NsqFih6uElf8OYrQ=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d85429339c0bcf0428084fe1306c970aed364417",
|
"rev": "088b069b8270ee36d83533c86b9f91d924d185d9",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -106,56 +106,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pyproject-build-systems": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"system_tools",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pyproject-nix": [
|
|
||||||
"system_tools",
|
|
||||||
"pyproject-nix"
|
|
||||||
],
|
|
||||||
"uv2nix": [
|
|
||||||
"system_tools",
|
|
||||||
"uv2nix"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1744599653,
|
|
||||||
"narHash": "sha256-nysSwVVjG4hKoOjhjvE6U5lIKA8sEr1d1QzEfZsannU=",
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "build-system-pkgs",
|
|
||||||
"rev": "7dba6dbc73120e15b558754c26024f6c93015dd7",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "build-system-pkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pyproject-nix": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"system_tools",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1746540146,
|
|
||||||
"narHash": "sha256-QxdHGNpbicIrw5t6U3x+ZxeY/7IEJ6lYbvsjXmcxFIM=",
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "pyproject.nix",
|
|
||||||
"rev": "e09c10c24ebb955125fda449939bfba664c467fd",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "pyproject.nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"firefox-addons": "firefox-addons",
|
"firefox-addons": "firefox-addons",
|
||||||
@@ -165,7 +115,6 @@
|
|||||||
"nixpkgs-master": "nixpkgs-master",
|
"nixpkgs-master": "nixpkgs-master",
|
||||||
"nixpkgs-stable": "nixpkgs-stable",
|
"nixpkgs-stable": "nixpkgs-stable",
|
||||||
"sops-nix": "sops-nix",
|
"sops-nix": "sops-nix",
|
||||||
"system_tools": "system_tools",
|
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -176,11 +125,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760393368,
|
"lastModified": 1766289575,
|
||||||
"narHash": "sha256-8mN3kqyqa2PKY0wwZ2UmMEYMcxvNTwLaOrrDsw6Qi4E=",
|
"narHash": "sha256-BOKCwOQQIP4p9z8DasT5r+qjri3x7sPCOq+FTjY8Z+o=",
|
||||||
"owner": "Mic92",
|
"owner": "Mic92",
|
||||||
"repo": "sops-nix",
|
"repo": "sops-nix",
|
||||||
"rev": "ab8d56e85b8be14cff9d93735951e30c3e86a437",
|
"rev": "9836912e37aef546029e48c8749834735a6b9dad",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -189,29 +138,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system_tools": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pyproject-build-systems": "pyproject-build-systems",
|
|
||||||
"pyproject-nix": "pyproject-nix",
|
|
||||||
"uv2nix": "uv2nix"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1760751967,
|
|
||||||
"narHash": "sha256-u/uciy9kpM/CBZKl05iAZRaOTwUHiuI0L/qbkk2mLUg=",
|
|
||||||
"owner": "RichieCahill",
|
|
||||||
"repo": "system_tools",
|
|
||||||
"rev": "a125c3e5c01cecbc3f2a842ffb1abb1210c35706",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "RichieCahill",
|
|
||||||
"repo": "system_tools",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"systems": {
|
"systems": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689347949,
|
"lastModified": 1689347949,
|
||||||
@@ -226,31 +152,6 @@
|
|||||||
"repo": "default-linux",
|
"repo": "default-linux",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"uv2nix": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"system_tools",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pyproject-nix": [
|
|
||||||
"system_tools",
|
|
||||||
"pyproject-nix"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1747441483,
|
|
||||||
"narHash": "sha256-W8BFXk5R0TuJcjIhcGoMpSOaIufGXpizK0pm+uTqynA=",
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "uv2nix",
|
|
||||||
"rev": "582024dc64663e9f88d467c2f7f7b20d278349de",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "uv2nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
@@ -31,11 +31,6 @@
|
|||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
system_tools = {
|
|
||||||
url = "github:RichieCahill/system_tools";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
|
|
||||||
sops-nix = {
|
sops-nix = {
|
||||||
url = "github:Mic92/sops-nix";
|
url = "github:Mic92/sops-nix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
@@ -59,6 +54,7 @@
|
|||||||
system:
|
system:
|
||||||
import nixpkgs {
|
import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
overlays = builtins.attrValues outputs.overlays;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
# When applied, the stable nixpkgs set (declared in the flake inputs) will be accessible through 'pkgs.stable'
|
# When applied, the stable nixpkgs set (declared in the flake inputs) will be accessible through 'pkgs.stable'
|
||||||
stable = final: _prev: {
|
stable = final: _prev: {
|
||||||
stable = import inputs.nixpkgs-stable {
|
stable = import inputs.nixpkgs-stable {
|
||||||
system = final.system;
|
system = final.stdenv.hostPlatform.system;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
# When applied, the master nixpkgs set (declared in the flake inputs) will be accessible through 'pkgs.master'
|
# When applied, the master nixpkgs set (declared in the flake inputs) will be accessible through 'pkgs.master'
|
||||||
master = final: _prev: {
|
master = final: _prev: {
|
||||||
master = import inputs.nixpkgs-master {
|
master = import inputs.nixpkgs-master {
|
||||||
system = final.system;
|
system = final.stdenv.hostPlatform.system;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
apscheduler
|
apscheduler
|
||||||
mypy
|
mypy
|
||||||
polars
|
polars
|
||||||
|
psycopg
|
||||||
pyfakefs
|
pyfakefs
|
||||||
pytest
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
@@ -29,6 +30,9 @@
|
|||||||
pytest-xdist
|
pytest-xdist
|
||||||
requests
|
requests
|
||||||
ruff
|
ruff
|
||||||
|
scalene
|
||||||
|
sqlalchemy
|
||||||
|
textual
|
||||||
typer
|
typer
|
||||||
types-requests
|
types-requests
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ lint.ignore = [
|
|||||||
"ERA001", # (perm) I don't care about print statements dir
|
"ERA001", # (perm) I don't care about print statements dir
|
||||||
]
|
]
|
||||||
|
|
||||||
|
"python/splendor/**" = [
|
||||||
|
"S311", # (perm) there is no security issue here
|
||||||
|
"T201", # (perm) I don't care about print statements dir
|
||||||
|
"PLR2004", # (temps) need to think about this
|
||||||
|
]
|
||||||
|
|
||||||
[tool.ruff.lint.pydocstyle]
|
[tool.ruff.lint.pydocstyle]
|
||||||
convention = "google"
|
convention = "google"
|
||||||
|
|
||||||
|
|||||||
59
python/database.py
Normal file
59
python/database.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
"""database."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
from sqlalchemy.exc import NoInspectionAvailable
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def safe_insert(orm_objects: Sequence[object], session: Session) -> list[tuple[Exception, object]]:
|
||||||
|
"""Safer insert at allows for partial rollbacks.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
orm_objects (Sequence[object]): Tables to insert.
|
||||||
|
session (Session): Database session.
|
||||||
|
"""
|
||||||
|
if unmapped := [orm_object for orm_object in orm_objects if not _is_mapped_instance(orm_object)]:
|
||||||
|
error = f"safe_insert expects ORM-mapped instances {unmapped}"
|
||||||
|
raise TypeError(error)
|
||||||
|
return _safe_insert(orm_objects, session)
|
||||||
|
|
||||||
|
|
||||||
|
def _safe_insert(objects: Sequence[object], session: Session) -> list[tuple[Exception, object]]:
|
||||||
|
exceptions: list[tuple[Exception, object]] = []
|
||||||
|
try:
|
||||||
|
session.add_all(objects)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
session.rollback()
|
||||||
|
|
||||||
|
objects_len = len(objects)
|
||||||
|
if objects_len == 1:
|
||||||
|
logger.exception(objects)
|
||||||
|
return [(error, objects[0])]
|
||||||
|
|
||||||
|
middle = objects_len // 2
|
||||||
|
exceptions.extend(_safe_insert(objects=objects[:middle], session=session))
|
||||||
|
exceptions.extend(_safe_insert(objects=objects[middle:], session=session))
|
||||||
|
return exceptions
|
||||||
|
|
||||||
|
|
||||||
|
def _is_mapped_instance(obj: object) -> bool:
|
||||||
|
"""Return True if `obj` is a SQLAlchemy ORM-mapped instance."""
|
||||||
|
try:
|
||||||
|
inspect(obj) # raises NoInspectionAvailable if not mapped
|
||||||
|
except NoInspectionAvailable:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
@@ -85,7 +85,7 @@ def get_material_resistivity(
|
|||||||
) -> float:
|
) -> float:
|
||||||
"""Get the resistivity of a material."""
|
"""Get the resistivity of a material."""
|
||||||
if not temperature:
|
if not temperature:
|
||||||
Temperature(20.0)
|
temperature = Temperature(20.0)
|
||||||
material_info = {
|
material_info = {
|
||||||
MaterialType.COPPER: (1.724e-8, 0.00393),
|
MaterialType.COPPER: (1.724e-8, 0.00393),
|
||||||
MaterialType.ALUMINUM: (2.908e-8, 0.00403),
|
MaterialType.ALUMINUM: (2.908e-8, 0.00403),
|
||||||
@@ -180,7 +180,7 @@ def max_wire_length(
|
|||||||
float: Maximum wire length in meters that maintains the specified voltage drop
|
float: Maximum wire length in meters that maintains the specified voltage drop
|
||||||
"""
|
"""
|
||||||
if not temperature:
|
if not temperature:
|
||||||
Temperature(100.0, unit=TemperatureUnit.FAHRENHEIT)
|
temperature = Temperature(100.0, unit=TemperatureUnit.FAHRENHEIT)
|
||||||
|
|
||||||
resistivity = get_material_resistivity(material, temperature)
|
resistivity = get_material_resistivity(material, temperature)
|
||||||
resistance_per_meter = resistivity / calculate_wire_area_m2(gauge)
|
resistance_per_meter = resistivity / calculate_wire_area_m2(gauge)
|
||||||
|
|||||||
1
python/splendor/.gitignore
vendored
Normal file
1
python/splendor/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
game_data/
|
||||||
1
python/splendor/__init__.py
Normal file
1
python/splendor/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
"""init."""
|
||||||
675
python/splendor/base.py
Normal file
675
python/splendor/base.py
Normal file
@@ -0,0 +1,675 @@
|
|||||||
|
"""Base logic for the Splendor game."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import TYPE_CHECKING, Literal, Protocol
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
GemColor = Literal["white", "blue", "green", "red", "black", "gold"]
|
||||||
|
|
||||||
|
GEM_COLORS: tuple[GemColor, ...] = (
|
||||||
|
"white",
|
||||||
|
"blue",
|
||||||
|
"green",
|
||||||
|
"red",
|
||||||
|
"black",
|
||||||
|
"gold",
|
||||||
|
)
|
||||||
|
BASE_COLORS: tuple[GemColor, ...] = (
|
||||||
|
"white",
|
||||||
|
"blue",
|
||||||
|
"green",
|
||||||
|
"red",
|
||||||
|
"black",
|
||||||
|
)
|
||||||
|
|
||||||
|
GEM_ORDER: list[GemColor] = list(GEM_COLORS)
|
||||||
|
GEM_INDEX: dict[GemColor, int] = {c: i for i, c in enumerate(GEM_ORDER)}
|
||||||
|
BASE_INDEX: dict[GemColor, int] = {c: i for i, c in enumerate(BASE_COLORS)}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class Card:
|
||||||
|
"""Development card: gives points + a permanent gem discount."""
|
||||||
|
|
||||||
|
tier: int
|
||||||
|
points: int
|
||||||
|
color: GemColor
|
||||||
|
cost: dict[GemColor, int]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class Noble:
|
||||||
|
"""Noble tile: gives points if you have enough bonuses."""
|
||||||
|
|
||||||
|
name: str
|
||||||
|
points: int
|
||||||
|
requirements: dict[GemColor, int]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PlayerState:
|
||||||
|
"""State of a player in the game."""
|
||||||
|
|
||||||
|
strategy: Strategy
|
||||||
|
tokens: dict[GemColor, int] = field(default_factory=lambda: dict.fromkeys(GEM_COLORS, 0))
|
||||||
|
discounts: dict[GemColor, int] = field(default_factory=lambda: dict.fromkeys(GEM_COLORS, 0))
|
||||||
|
cards: list[Card] = field(default_factory=list)
|
||||||
|
reserved: list[Card] = field(default_factory=list)
|
||||||
|
nobles: list[Noble] = field(default_factory=list)
|
||||||
|
card_score: int = 0
|
||||||
|
noble_score: int = 0
|
||||||
|
|
||||||
|
def total_tokens(self) -> int:
|
||||||
|
"""Total tokens in player's bank."""
|
||||||
|
return sum(self.tokens.values())
|
||||||
|
|
||||||
|
def add_noble(self, noble: Noble) -> None:
|
||||||
|
"""Add a noble to the player."""
|
||||||
|
self.nobles.append(noble)
|
||||||
|
self.noble_score = sum(noble.points for noble in self.nobles)
|
||||||
|
|
||||||
|
def add_card(self, card: Card) -> None:
|
||||||
|
"""Add a card to the player."""
|
||||||
|
self.cards.append(card)
|
||||||
|
self.card_score = sum(card.points for card in self.cards)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def score(self) -> int:
|
||||||
|
"""Total points in player's cards + nobles."""
|
||||||
|
return self.card_score + self.noble_score
|
||||||
|
|
||||||
|
def can_afford(self, card: Card) -> bool:
|
||||||
|
"""Check if player can afford card, using discounts + gold."""
|
||||||
|
missing = 0
|
||||||
|
gold = self.tokens["gold"]
|
||||||
|
|
||||||
|
for color, cost in card.cost.items():
|
||||||
|
missing += max(0, cost - self.discounts.get(color, 0) - self.tokens.get(color, 0))
|
||||||
|
if missing > gold:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def pay_for_card(self, card: Card) -> dict[GemColor, int]:
|
||||||
|
"""Pay tokens for card, move card to tableau, return payment for bank."""
|
||||||
|
if not self.can_afford(card):
|
||||||
|
msg = f"cannot afford card {card}"
|
||||||
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
payment: dict[GemColor, int] = dict.fromkeys(GEM_COLORS, 0)
|
||||||
|
gold_available = self.tokens["gold"]
|
||||||
|
|
||||||
|
for color in BASE_COLORS:
|
||||||
|
cost = card.cost.get(color, 0)
|
||||||
|
effective_cost = max(0, cost - self.discounts.get(color, 0))
|
||||||
|
|
||||||
|
use = min(self.tokens[color], effective_cost)
|
||||||
|
self.tokens[color] -= use
|
||||||
|
payment[color] += use
|
||||||
|
|
||||||
|
remaining = effective_cost - use
|
||||||
|
if remaining > 0:
|
||||||
|
use_gold = min(gold_available, remaining)
|
||||||
|
gold_available -= use_gold
|
||||||
|
self.tokens["gold"] -= use_gold
|
||||||
|
payment["gold"] += use_gold
|
||||||
|
|
||||||
|
self.add_card(card)
|
||||||
|
self.discounts[card.color] += 1
|
||||||
|
return payment
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_starting_tokens(player_count: int) -> dict[GemColor, int]:
|
||||||
|
"""get_default_starting_tokens."""
|
||||||
|
token_count = (player_count * player_count - 3 * player_count + 10) // 2
|
||||||
|
return {
|
||||||
|
"white": token_count,
|
||||||
|
"blue": token_count,
|
||||||
|
"green": token_count,
|
||||||
|
"red": token_count,
|
||||||
|
"black": token_count,
|
||||||
|
"gold": 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class GameConfig:
|
||||||
|
"""Game configuration: gems, bank, cards, nobles, etc."""
|
||||||
|
|
||||||
|
win_score: int = 15
|
||||||
|
table_cards_per_tier: int = 4
|
||||||
|
reserve_limit: int = 3
|
||||||
|
token_limit: int = 10
|
||||||
|
turn_limit: int = 1000
|
||||||
|
minimum_tokens_to_buy_2: int = 4
|
||||||
|
max_token_take: int = 3
|
||||||
|
|
||||||
|
cards: list[Card] = field(default_factory=list)
|
||||||
|
nobles: list[Noble] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
class GameState:
|
||||||
|
"""Game state: players, bank, decks, table, available nobles, etc."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: GameConfig,
|
||||||
|
players: list[PlayerState],
|
||||||
|
bank: dict[GemColor, int],
|
||||||
|
decks_by_tier: dict[int, list[Card]],
|
||||||
|
table_by_tier: dict[int, list[Card]],
|
||||||
|
available_nobles: list[Noble],
|
||||||
|
) -> None:
|
||||||
|
"""Game state."""
|
||||||
|
self.config = config
|
||||||
|
self.players = players
|
||||||
|
self.bank = bank
|
||||||
|
self.decks_by_tier = decks_by_tier
|
||||||
|
self.table_by_tier = table_by_tier
|
||||||
|
self.available_nobles = available_nobles
|
||||||
|
self.noble_min_requirements = 0
|
||||||
|
self.get_noble_min_requirements()
|
||||||
|
self.current_player_index = 0
|
||||||
|
self.finished = False
|
||||||
|
|
||||||
|
def get_noble_min_requirements(self) -> None:
|
||||||
|
"""Find the minimum requirement for all available nobles."""
|
||||||
|
test = 0
|
||||||
|
|
||||||
|
for noble in self.available_nobles:
|
||||||
|
test = max(test, min(foo for foo in noble.requirements.values()))
|
||||||
|
|
||||||
|
self.noble_min_requirements = test
|
||||||
|
|
||||||
|
def next_player(self) -> None:
|
||||||
|
"""Advance to the next player."""
|
||||||
|
self.current_player_index = (self.current_player_index + 1) % len(self.players)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_player(self) -> PlayerState:
|
||||||
|
"""Current player."""
|
||||||
|
return self.players[self.current_player_index]
|
||||||
|
|
||||||
|
def refill_table(self) -> None:
|
||||||
|
"""Refill face-up cards from decks."""
|
||||||
|
for tier, deck in self.decks_by_tier.items():
|
||||||
|
table = self.table_by_tier[tier]
|
||||||
|
while len(table) < self.config.table_cards_per_tier and deck:
|
||||||
|
table.append(deck.pop())
|
||||||
|
|
||||||
|
def check_winner_simple(self) -> PlayerState | None:
|
||||||
|
"""Simplified: end immediately when someone hits win_score."""
|
||||||
|
eligible = [player for player in self.players if player.score >= self.config.win_score]
|
||||||
|
if not eligible:
|
||||||
|
return None
|
||||||
|
eligible.sort(
|
||||||
|
key=lambda p: (p.score, -len(p.cards)),
|
||||||
|
reverse=True,
|
||||||
|
)
|
||||||
|
self.finished = True
|
||||||
|
return eligible[0]
|
||||||
|
|
||||||
|
|
||||||
|
class Action:
|
||||||
|
"""Marker protocol for actions."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class TakeDifferent(Action):
|
||||||
|
"""Take up to 3 different gem colors."""
|
||||||
|
|
||||||
|
colors: list[GemColor]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class TakeDouble(Action):
|
||||||
|
"""Take two of the same color."""
|
||||||
|
|
||||||
|
color: GemColor
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BuyCard(Action):
|
||||||
|
"""Buy a face-up card."""
|
||||||
|
|
||||||
|
tier: int
|
||||||
|
index: int
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BuyCardReserved(Action):
|
||||||
|
"""Buy a face-up card."""
|
||||||
|
|
||||||
|
index: int
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ReserveCard(Action):
|
||||||
|
"""Reserve a face-up card."""
|
||||||
|
|
||||||
|
tier: int
|
||||||
|
index: int | None = None
|
||||||
|
from_deck: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class Strategy(Protocol):
|
||||||
|
"""Implement this to make a bot or human controller."""
|
||||||
|
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
"""Initialize a strategy."""
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Return an Action, or None to concede/end."""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int,
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Called if player has more than token_limit tokens after an action.
|
||||||
|
|
||||||
|
Default: naive auto-discard.
|
||||||
|
"""
|
||||||
|
return auto_discard_tokens(player, excess)
|
||||||
|
|
||||||
|
def choose_noble(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState, # noqa: ARG002
|
||||||
|
nobles: list[Noble],
|
||||||
|
) -> Noble:
|
||||||
|
"""Called if player qualifies for multiple nobles. Default: first."""
|
||||||
|
return nobles[0]
|
||||||
|
|
||||||
|
|
||||||
|
def auto_discard_tokens(player: PlayerState, excess: int) -> dict[GemColor, int]:
|
||||||
|
"""Very dumb discard logic: discard from colors you have the most of."""
|
||||||
|
to_discard: dict[GemColor, int] = dict.fromkeys(GEM_COLORS, 0)
|
||||||
|
remaining = excess
|
||||||
|
while remaining > 0:
|
||||||
|
color = max(player.tokens, key=lambda c: player.tokens[c])
|
||||||
|
if player.tokens[color] == 0:
|
||||||
|
break
|
||||||
|
player.tokens[color] -= 1
|
||||||
|
to_discard[color] += 1
|
||||||
|
remaining -= 1
|
||||||
|
return to_discard
|
||||||
|
|
||||||
|
|
||||||
|
def enforce_token_limit(
|
||||||
|
game: GameState,
|
||||||
|
strategy: Strategy,
|
||||||
|
player: PlayerState,
|
||||||
|
) -> None:
|
||||||
|
"""If player has more than token_limit tokens, force discards."""
|
||||||
|
limit = game.config.token_limit
|
||||||
|
total = player.total_tokens()
|
||||||
|
if total <= limit:
|
||||||
|
return
|
||||||
|
excess = total - limit
|
||||||
|
discards = strategy.choose_discard(game, player, excess)
|
||||||
|
for color, amount in discards.items():
|
||||||
|
available = player.tokens[color]
|
||||||
|
to_remove = min(amount, available)
|
||||||
|
if to_remove <= 0:
|
||||||
|
continue
|
||||||
|
player.tokens[color] -= to_remove
|
||||||
|
game.bank[color] += to_remove
|
||||||
|
remaining = player.total_tokens() - limit
|
||||||
|
if remaining > 0:
|
||||||
|
auto = auto_discard_tokens(player, remaining)
|
||||||
|
for color, amount in auto.items():
|
||||||
|
game.bank[color] += amount
|
||||||
|
|
||||||
|
|
||||||
|
def _check_nobles_for_player(player: PlayerState, noble: Noble) -> bool:
|
||||||
|
# this rule is slower
|
||||||
|
for color, cost in noble.requirements.items(): # noqa: SIM110
|
||||||
|
if player.discounts[color] < cost:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def check_nobles_for_player(
|
||||||
|
game: GameState,
|
||||||
|
strategy: Strategy,
|
||||||
|
player: PlayerState,
|
||||||
|
) -> None:
|
||||||
|
"""Award at most one noble to player if they qualify."""
|
||||||
|
if game.noble_min_requirements > max(player.discounts.values()):
|
||||||
|
return
|
||||||
|
|
||||||
|
candidates = [noble for noble in game.available_nobles if _check_nobles_for_player(player, noble)]
|
||||||
|
|
||||||
|
if not candidates:
|
||||||
|
return
|
||||||
|
|
||||||
|
chosen = candidates[0] if len(candidates) == 1 else strategy.choose_noble(game, player, candidates)
|
||||||
|
|
||||||
|
if chosen not in game.available_nobles:
|
||||||
|
return
|
||||||
|
game.available_nobles.remove(chosen)
|
||||||
|
game.get_noble_min_requirements()
|
||||||
|
|
||||||
|
player.add_noble(chosen)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_take_different(game: GameState, strategy: Strategy, action: TakeDifferent) -> None:
|
||||||
|
"""Mutate game state according to action."""
|
||||||
|
player = game.current_player
|
||||||
|
|
||||||
|
colors = [color for color in action.colors if color in BASE_COLORS and game.bank[color] > 0]
|
||||||
|
if not (1 <= len(colors) <= game.config.max_token_take):
|
||||||
|
return
|
||||||
|
|
||||||
|
for color in colors:
|
||||||
|
game.bank[color] -= 1
|
||||||
|
player.tokens[color] += 1
|
||||||
|
|
||||||
|
enforce_token_limit(game, strategy, player)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_take_double(game: GameState, strategy: Strategy, action: TakeDouble) -> None:
|
||||||
|
"""Mutate game state according to action."""
|
||||||
|
player = game.current_player
|
||||||
|
color = action.color
|
||||||
|
if color not in BASE_COLORS:
|
||||||
|
return
|
||||||
|
if game.bank[color] < game.config.minimum_tokens_to_buy_2:
|
||||||
|
return
|
||||||
|
game.bank[color] -= 2
|
||||||
|
player.tokens[color] += 2
|
||||||
|
enforce_token_limit(game, strategy, player)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_buy_card(game: GameState, _strategy: Strategy, action: BuyCard) -> None:
|
||||||
|
"""Mutate game state according to action."""
|
||||||
|
player = game.current_player
|
||||||
|
|
||||||
|
row = game.table_by_tier.get(action.tier)
|
||||||
|
if row is None or not (0 <= action.index < len(row)):
|
||||||
|
return
|
||||||
|
card = row[action.index]
|
||||||
|
if not player.can_afford(card):
|
||||||
|
return
|
||||||
|
row.pop(action.index)
|
||||||
|
payment = player.pay_for_card(card)
|
||||||
|
for color, amount in payment.items():
|
||||||
|
game.bank[color] += amount
|
||||||
|
game.refill_table()
|
||||||
|
|
||||||
|
|
||||||
|
def apply_buy_card_reserved(game: GameState, _strategy: Strategy, action: BuyCardReserved) -> None:
|
||||||
|
"""Mutate game state according to action."""
|
||||||
|
player = game.current_player
|
||||||
|
if not (0 <= action.index < len(player.reserved)):
|
||||||
|
return
|
||||||
|
card = player.reserved[action.index]
|
||||||
|
if not player.can_afford(card):
|
||||||
|
return
|
||||||
|
player.reserved.pop(action.index)
|
||||||
|
payment = player.pay_for_card(card)
|
||||||
|
for color, amount in payment.items():
|
||||||
|
game.bank[color] += amount
|
||||||
|
|
||||||
|
|
||||||
|
def apply_reserve_card(game: GameState, strategy: Strategy, action: ReserveCard) -> None:
|
||||||
|
"""Mutate game state according to action."""
|
||||||
|
player = game.current_player
|
||||||
|
|
||||||
|
if len(player.reserved) >= game.config.reserve_limit:
|
||||||
|
return
|
||||||
|
|
||||||
|
card: Card | None = None
|
||||||
|
if action.from_deck:
|
||||||
|
deck = game.decks_by_tier.get(action.tier)
|
||||||
|
if deck:
|
||||||
|
card = deck.pop()
|
||||||
|
else:
|
||||||
|
row = game.table_by_tier.get(action.tier)
|
||||||
|
if row is None:
|
||||||
|
return
|
||||||
|
if action.index is None or not (0 <= action.index < len(row)):
|
||||||
|
return
|
||||||
|
card = row.pop(action.index)
|
||||||
|
game.refill_table()
|
||||||
|
|
||||||
|
if card is None:
|
||||||
|
return
|
||||||
|
player.reserved.append(card)
|
||||||
|
|
||||||
|
if game.bank["gold"] > 0:
|
||||||
|
game.bank["gold"] -= 1
|
||||||
|
player.tokens["gold"] += 1
|
||||||
|
enforce_token_limit(game, strategy, player)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_action(game: GameState, strategy: Strategy, action: Action) -> None:
|
||||||
|
"""Mutate game state according to action."""
|
||||||
|
actions = {
|
||||||
|
TakeDifferent: apply_take_different,
|
||||||
|
TakeDouble: apply_take_double,
|
||||||
|
BuyCard: apply_buy_card,
|
||||||
|
ReserveCard: apply_reserve_card,
|
||||||
|
BuyCardReserved: apply_buy_card_reserved,
|
||||||
|
}
|
||||||
|
action_func = actions.get(type(action))
|
||||||
|
if action_func is None:
|
||||||
|
msg = f"Unknown action type: {type(action)}"
|
||||||
|
raise ValueError(msg)
|
||||||
|
action_func(game, strategy, action)
|
||||||
|
|
||||||
|
|
||||||
|
# not sure how to simplify this yet
|
||||||
|
def get_legal_actions( # noqa: C901
|
||||||
|
game: GameState,
|
||||||
|
player: PlayerState | None = None,
|
||||||
|
) -> list[Action]:
|
||||||
|
"""Enumerate all syntactically legal actions for the given player.
|
||||||
|
|
||||||
|
This enforces:
|
||||||
|
- token-taking rules
|
||||||
|
- reserve limits
|
||||||
|
- affordability for buys
|
||||||
|
"""
|
||||||
|
if player is None:
|
||||||
|
player = game.players[game.current_player_index]
|
||||||
|
|
||||||
|
actions: list[Action] = []
|
||||||
|
|
||||||
|
colors_available = [c for c in BASE_COLORS if game.bank[c] > 0]
|
||||||
|
for r in (1, 2, 3):
|
||||||
|
actions.extend(TakeDifferent(colors=list(combo)) for combo in itertools.combinations(colors_available, r))
|
||||||
|
|
||||||
|
actions.extend(
|
||||||
|
TakeDouble(color=color) for color in BASE_COLORS if game.bank[color] >= game.config.minimum_tokens_to_buy_2
|
||||||
|
)
|
||||||
|
|
||||||
|
for tier, row in game.table_by_tier.items():
|
||||||
|
for idx, card in enumerate(row):
|
||||||
|
if player.can_afford(card):
|
||||||
|
actions.append(BuyCard(tier=tier, index=idx))
|
||||||
|
|
||||||
|
for idx, card in enumerate(player.reserved):
|
||||||
|
if player.can_afford(card):
|
||||||
|
actions.append(BuyCardReserved(index=idx))
|
||||||
|
|
||||||
|
if len(player.reserved) < game.config.reserve_limit:
|
||||||
|
for tier, row in game.table_by_tier.items():
|
||||||
|
for idx, _ in enumerate(row):
|
||||||
|
actions.append(
|
||||||
|
ReserveCard(tier=tier, index=idx, from_deck=False),
|
||||||
|
)
|
||||||
|
for tier, deck in game.decks_by_tier.items():
|
||||||
|
if deck:
|
||||||
|
actions.append(
|
||||||
|
ReserveCard(tier=tier, index=None, from_deck=True),
|
||||||
|
)
|
||||||
|
|
||||||
|
return actions
|
||||||
|
|
||||||
|
|
||||||
|
def create_random_cards_tier(
|
||||||
|
tier: int,
|
||||||
|
card_count: int,
|
||||||
|
cost_choices: list[int],
|
||||||
|
point_choices: list[int],
|
||||||
|
) -> list[Card]:
|
||||||
|
"""Create a random set of cards for a given tier."""
|
||||||
|
cards: list[Card] = []
|
||||||
|
|
||||||
|
for color in BASE_COLORS:
|
||||||
|
for _ in range(card_count):
|
||||||
|
cost = dict.fromkeys(GEM_COLORS, 0)
|
||||||
|
for c in BASE_COLORS:
|
||||||
|
if c == color:
|
||||||
|
continue
|
||||||
|
cost[c] = random.choice(cost_choices)
|
||||||
|
points = random.choice(point_choices)
|
||||||
|
cards.append(Card(tier=tier, points=points, color=color, cost=cost))
|
||||||
|
|
||||||
|
return cards
|
||||||
|
|
||||||
|
|
||||||
|
def create_random_cards() -> list[Card]:
|
||||||
|
"""Generate a generic but Splendor-ish set of cards.
|
||||||
|
|
||||||
|
This is not the official deck, but structured similarly enough for play.
|
||||||
|
"""
|
||||||
|
cards: list[Card] = []
|
||||||
|
cards.extend(
|
||||||
|
create_random_cards_tier(
|
||||||
|
tier=1,
|
||||||
|
card_count=5,
|
||||||
|
cost_choices=[0, 1, 1, 2],
|
||||||
|
point_choices=[0, 0, 1],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
cards.extend(
|
||||||
|
create_random_cards_tier(
|
||||||
|
tier=2,
|
||||||
|
card_count=4,
|
||||||
|
cost_choices=[2, 3, 4],
|
||||||
|
point_choices=[1, 2, 2, 3],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
cards.extend(
|
||||||
|
create_random_cards_tier(
|
||||||
|
tier=3,
|
||||||
|
card_count=3,
|
||||||
|
cost_choices=[4, 5, 6],
|
||||||
|
point_choices=[3, 4, 5],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
random.shuffle(cards)
|
||||||
|
return cards
|
||||||
|
|
||||||
|
|
||||||
|
def create_random_nobles() -> list[Noble]:
|
||||||
|
"""A small set of noble tiles, roughly Splendor-ish."""
|
||||||
|
nobles: list[Noble] = []
|
||||||
|
|
||||||
|
base_requirements: list[dict[GemColor, int]] = [
|
||||||
|
{"white": 3, "blue": 3, "green": 3},
|
||||||
|
{"blue": 3, "green": 3, "red": 3},
|
||||||
|
{"green": 3, "red": 3, "black": 3},
|
||||||
|
{"red": 3, "black": 3, "white": 3},
|
||||||
|
{"black": 3, "white": 3, "blue": 3},
|
||||||
|
{"white": 4, "blue": 4},
|
||||||
|
{"green": 4, "red": 4},
|
||||||
|
{"blue": 4, "black": 4},
|
||||||
|
]
|
||||||
|
|
||||||
|
for idx, req in enumerate(base_requirements, start=1):
|
||||||
|
nobles.append(
|
||||||
|
Noble(
|
||||||
|
name=f"Noble {idx}",
|
||||||
|
points=3,
|
||||||
|
requirements=dict(req.items()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return nobles
|
||||||
|
|
||||||
|
|
||||||
|
def load_nobles(file: Path) -> list[Noble]:
|
||||||
|
"""Load nobles from a file."""
|
||||||
|
nobles = json.loads(file.read_text())
|
||||||
|
return [Noble(**noble) for noble in nobles]
|
||||||
|
|
||||||
|
|
||||||
|
def load_cards(file: Path) -> list[Card]:
|
||||||
|
"""Load cards from a file."""
|
||||||
|
cards = json.loads(file.read_text())
|
||||||
|
return [Card(**card) for card in cards]
|
||||||
|
|
||||||
|
|
||||||
|
def new_game(
|
||||||
|
strategies: Sequence[Strategy],
|
||||||
|
config: GameConfig,
|
||||||
|
) -> GameState:
|
||||||
|
"""Create a new game state from a config + list of players."""
|
||||||
|
num_players = len(strategies)
|
||||||
|
bank = get_default_starting_tokens(num_players)
|
||||||
|
|
||||||
|
decks_by_tier: dict[int, list[Card]] = {1: [], 2: [], 3: []}
|
||||||
|
for card in config.cards:
|
||||||
|
decks_by_tier.setdefault(card.tier, []).append(card)
|
||||||
|
for deck in decks_by_tier.values():
|
||||||
|
random.shuffle(deck)
|
||||||
|
|
||||||
|
table_by_tier: dict[int, list[Card]] = {1: [], 2: [], 3: []}
|
||||||
|
players = [PlayerState(strategy=strategy) for strategy in strategies]
|
||||||
|
|
||||||
|
nobles = list(config.nobles)
|
||||||
|
random.shuffle(nobles)
|
||||||
|
nobles = nobles[: num_players + 1]
|
||||||
|
|
||||||
|
game = GameState(
|
||||||
|
config=config,
|
||||||
|
players=players,
|
||||||
|
bank=bank,
|
||||||
|
decks_by_tier=decks_by_tier,
|
||||||
|
table_by_tier=table_by_tier,
|
||||||
|
available_nobles=nobles,
|
||||||
|
)
|
||||||
|
game.refill_table()
|
||||||
|
return game
|
||||||
|
|
||||||
|
|
||||||
|
def run_game(game: GameState) -> tuple[PlayerState, int]:
|
||||||
|
"""Run a full game loop until someone wins or a player returns None."""
|
||||||
|
turn_count = 0
|
||||||
|
while not game.finished:
|
||||||
|
turn_count += 1
|
||||||
|
player = game.current_player
|
||||||
|
strategy = player.strategy
|
||||||
|
action = strategy.choose_action(game, player)
|
||||||
|
if action is None:
|
||||||
|
game.finished = True
|
||||||
|
break
|
||||||
|
|
||||||
|
apply_action(game, strategy, action)
|
||||||
|
check_nobles_for_player(game, strategy, player)
|
||||||
|
|
||||||
|
winner = game.check_winner_simple()
|
||||||
|
if winner is not None:
|
||||||
|
return winner, turn_count
|
||||||
|
|
||||||
|
game.next_player()
|
||||||
|
if turn_count >= game.config.turn_limit:
|
||||||
|
break
|
||||||
|
|
||||||
|
fallback = max(game.players, key=lambda player: player.score)
|
||||||
|
return fallback, turn_count
|
||||||
288
python/splendor/bot.py
Normal file
288
python/splendor/bot.py
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
"""Bot for Splendor game."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
from .base import (
|
||||||
|
BASE_COLORS,
|
||||||
|
Action,
|
||||||
|
BuyCard,
|
||||||
|
BuyCardReserved,
|
||||||
|
Card,
|
||||||
|
GameState,
|
||||||
|
GemColor,
|
||||||
|
PlayerState,
|
||||||
|
ReserveCard,
|
||||||
|
Strategy,
|
||||||
|
TakeDifferent,
|
||||||
|
TakeDouble,
|
||||||
|
auto_discard_tokens,
|
||||||
|
get_legal_actions,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def can_bot_afford(player: PlayerState, card: Card) -> bool:
|
||||||
|
"""Check if player can afford card, using discounts + gold."""
|
||||||
|
missing = 0
|
||||||
|
gold = player.tokens["gold"]
|
||||||
|
for color, cost in card.cost.items():
|
||||||
|
missing += max(0, cost - player.discounts.get(color, 0) - player.tokens.get(color, 0))
|
||||||
|
if missing > gold:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class RandomBot(Strategy):
|
||||||
|
"""Dumb bot that follows rules but doesn't think."""
|
||||||
|
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
"""Initialize the bot."""
|
||||||
|
super().__init__(name=name)
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Choose an action for the current player."""
|
||||||
|
affordable: list[tuple[int, int]] = []
|
||||||
|
for tier, row in game.table_by_tier.items():
|
||||||
|
for idx, card in enumerate(row):
|
||||||
|
if can_bot_afford(player, card):
|
||||||
|
affordable.append((tier, idx))
|
||||||
|
if affordable and random.random() < 0.5:
|
||||||
|
tier, idx = random.choice(affordable)
|
||||||
|
return BuyCard(tier=tier, index=idx)
|
||||||
|
|
||||||
|
if random.random() < 0.2:
|
||||||
|
tier = random.choice([1, 2, 3])
|
||||||
|
row = game.table_by_tier.get(tier, [])
|
||||||
|
if row:
|
||||||
|
idx = random.randrange(len(row))
|
||||||
|
return ReserveCard(tier=tier, index=idx, from_deck=False)
|
||||||
|
|
||||||
|
if random.random() < 0.5:
|
||||||
|
colors_for_double = [c for c in BASE_COLORS if game.bank[c] >= 4]
|
||||||
|
if colors_for_double:
|
||||||
|
return TakeDouble(color=random.choice(colors_for_double))
|
||||||
|
|
||||||
|
colors_for_diff = [c for c in BASE_COLORS if game.bank[c] > 0]
|
||||||
|
random.shuffle(colors_for_diff)
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int,
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Choose how many tokens to discard."""
|
||||||
|
return auto_discard_tokens(player, excess)
|
||||||
|
|
||||||
|
|
||||||
|
def check_cards_in_tier(row: list[Card], player: PlayerState) -> list[int]:
|
||||||
|
"""Check if player can afford card, using discounts + gold."""
|
||||||
|
return [index for index, card in enumerate(row) if can_bot_afford(player, card)]
|
||||||
|
|
||||||
|
|
||||||
|
class PersonalizedBot(Strategy):
|
||||||
|
"""PersonalizedBot."""
|
||||||
|
|
||||||
|
"""Dumb bot that follows rules but doesn't think."""
|
||||||
|
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
"""Initialize the bot."""
|
||||||
|
super().__init__(name=name)
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Choose an action for the current player."""
|
||||||
|
for tier in (1, 2, 3):
|
||||||
|
row = game.table_by_tier[tier]
|
||||||
|
if affordable := check_cards_in_tier(row, player):
|
||||||
|
index = random.choice(affordable)
|
||||||
|
return BuyCard(tier=tier, index=index)
|
||||||
|
|
||||||
|
colors_for_diff = [c for c in BASE_COLORS if game.bank[c] > 0]
|
||||||
|
random.shuffle(colors_for_diff)
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int,
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Choose how many tokens to discard."""
|
||||||
|
return auto_discard_tokens(player, excess)
|
||||||
|
|
||||||
|
|
||||||
|
class PersonalizedBot2(Strategy):
|
||||||
|
"""PersonalizedBot2."""
|
||||||
|
|
||||||
|
"""Dumb bot that follows rules but doesn't think."""
|
||||||
|
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
"""Initialize the bot."""
|
||||||
|
super().__init__(name=name)
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Choose an action for the current player."""
|
||||||
|
tiers = (1, 2, 3)
|
||||||
|
for tier in tiers:
|
||||||
|
row = game.table_by_tier[tier]
|
||||||
|
if affordable := check_cards_in_tier(row, player):
|
||||||
|
index = random.choice(affordable)
|
||||||
|
return BuyCard(tier=tier, index=index)
|
||||||
|
|
||||||
|
if affordable := check_cards_in_tier(player.reserved, player):
|
||||||
|
index = random.choice(affordable)
|
||||||
|
return BuyCardReserved(index=index)
|
||||||
|
|
||||||
|
colors_for_diff = [c for c in BASE_COLORS if game.bank[c] > 0]
|
||||||
|
if len(colors_for_diff) >= 3:
|
||||||
|
random.shuffle(colors_for_diff)
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
for tier in tiers:
|
||||||
|
len_deck = len(game.decks_by_tier[tier])
|
||||||
|
if len_deck:
|
||||||
|
return ReserveCard(tier=tier, index=None, from_deck=True)
|
||||||
|
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int,
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Choose how many tokens to discard."""
|
||||||
|
return auto_discard_tokens(player, excess)
|
||||||
|
|
||||||
|
|
||||||
|
def buy_card_reserved(player: PlayerState) -> Action | None:
|
||||||
|
"""Buy a card reserved."""
|
||||||
|
if affordable := check_cards_in_tier(player.reserved, player):
|
||||||
|
index = random.choice(affordable)
|
||||||
|
return BuyCardReserved(index=index)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def buy_card(game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Buy a card."""
|
||||||
|
for tier in (1, 2, 3):
|
||||||
|
row = game.table_by_tier[tier]
|
||||||
|
if affordable := check_cards_in_tier(row, player):
|
||||||
|
index = random.choice(affordable)
|
||||||
|
return BuyCard(tier=tier, index=index)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def take_tokens(game: GameState) -> Action | None:
|
||||||
|
"""Take tokens."""
|
||||||
|
colors_for_diff = [color for color in BASE_COLORS if game.bank[color] > 0]
|
||||||
|
if len(colors_for_diff) >= 3:
|
||||||
|
random.shuffle(colors_for_diff)
|
||||||
|
return TakeDifferent(colors=colors_for_diff[: game.config.max_token_take])
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class PersonalizedBot3(Strategy):
|
||||||
|
"""PersonalizedBot3."""
|
||||||
|
|
||||||
|
"""Dumb bot that follows rules but doesn't think."""
|
||||||
|
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
"""Initialize the bot."""
|
||||||
|
super().__init__(name=name)
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Choose an action for the current player."""
|
||||||
|
print(len(get_legal_actions(game, player)))
|
||||||
|
print(get_legal_actions(game, player))
|
||||||
|
if action := buy_card_reserved(player):
|
||||||
|
return action
|
||||||
|
if action := buy_card(game, player):
|
||||||
|
return action
|
||||||
|
|
||||||
|
colors_for_diff = [color for color in BASE_COLORS if game.bank[color] > 0]
|
||||||
|
if len(colors_for_diff) >= 3:
|
||||||
|
random.shuffle(colors_for_diff)
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
for tier in (1, 2, 3):
|
||||||
|
len_deck = len(game.decks_by_tier[tier])
|
||||||
|
if len_deck:
|
||||||
|
return ReserveCard(tier=tier, index=None, from_deck=True)
|
||||||
|
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int,
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Choose how many tokens to discard."""
|
||||||
|
return auto_discard_tokens(player, excess)
|
||||||
|
|
||||||
|
|
||||||
|
def estimate_value_of_card(game: GameState, player: PlayerState, color: GemColor) -> int:
|
||||||
|
"""Estimate value of a color in the player's bank."""
|
||||||
|
return game.bank[color] - player.discounts.get(color, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def estimate_value_of_token(game: GameState, player: PlayerState, color: GemColor) -> int:
|
||||||
|
"""Estimate value of a color in the player's bank."""
|
||||||
|
return game.bank[color] - player.discounts.get(color, 0)
|
||||||
|
|
||||||
|
|
||||||
|
class PersonalizedBot4(Strategy):
|
||||||
|
"""PersonalizedBot4."""
|
||||||
|
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
"""Initialize the bot."""
|
||||||
|
super().__init__(name=name)
|
||||||
|
|
||||||
|
def filter_actions(self, actions: list[Action]) -> list[Action]:
|
||||||
|
"""Filter actions to only take different."""
|
||||||
|
return [
|
||||||
|
action
|
||||||
|
for action in actions
|
||||||
|
if (isinstance(action, TakeDifferent) and len(action.colors) == 3) or not isinstance(action, TakeDifferent)
|
||||||
|
]
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None:
|
||||||
|
"""Choose an action for the current player."""
|
||||||
|
legal_actions = get_legal_actions(game, player)
|
||||||
|
print(len(legal_actions))
|
||||||
|
|
||||||
|
good_actions = self.filter_actions(legal_actions)
|
||||||
|
print(len(good_actions))
|
||||||
|
|
||||||
|
print(good_actions)
|
||||||
|
|
||||||
|
print(len(get_legal_actions(game, player)))
|
||||||
|
if action := buy_card_reserved(player):
|
||||||
|
return action
|
||||||
|
if action := buy_card(game, player):
|
||||||
|
return action
|
||||||
|
|
||||||
|
colors_for_diff = [color for color in BASE_COLORS if game.bank[color] > 0]
|
||||||
|
if len(colors_for_diff) >= 3:
|
||||||
|
random.shuffle(colors_for_diff)
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
for tier in (1, 2, 3):
|
||||||
|
len_deck = len(game.decks_by_tier[tier])
|
||||||
|
if len_deck:
|
||||||
|
return ReserveCard(tier=tier, index=None, from_deck=True)
|
||||||
|
|
||||||
|
return TakeDifferent(colors=colors_for_diff[:3])
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState, # noqa: ARG002
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int,
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Choose how many tokens to discard."""
|
||||||
|
return auto_discard_tokens(player, excess)
|
||||||
724
python/splendor/human.py
Normal file
724
python/splendor/human.py
Normal file
@@ -0,0 +1,724 @@
|
|||||||
|
"""Splendor game."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.containers import Horizontal, Vertical
|
||||||
|
from textual.widget import Widget
|
||||||
|
from textual.widgets import Footer, Header, Input, Static
|
||||||
|
|
||||||
|
from .base import (
|
||||||
|
BASE_COLORS,
|
||||||
|
GEM_COLORS,
|
||||||
|
Action,
|
||||||
|
BuyCard,
|
||||||
|
BuyCardReserved,
|
||||||
|
Card,
|
||||||
|
GameState,
|
||||||
|
GemColor,
|
||||||
|
Noble,
|
||||||
|
PlayerState,
|
||||||
|
ReserveCard,
|
||||||
|
Strategy,
|
||||||
|
TakeDifferent,
|
||||||
|
TakeDouble,
|
||||||
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Mapping
|
||||||
|
|
||||||
|
# Abbreviations used when rendering costs
|
||||||
|
COST_ABBR: dict[GemColor, str] = {
|
||||||
|
"white": "W",
|
||||||
|
"blue": "B",
|
||||||
|
"green": "G",
|
||||||
|
"red": "R",
|
||||||
|
"black": "K",
|
||||||
|
"gold": "O",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Abbreviations players can type on the command line
|
||||||
|
COLOR_ABBR_TO_FULL: dict[str, GemColor] = {
|
||||||
|
"w": "white",
|
||||||
|
"b": "blue",
|
||||||
|
"g": "green",
|
||||||
|
"r": "red",
|
||||||
|
"k": "black",
|
||||||
|
"o": "gold",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def parse_color_token(raw: str) -> GemColor:
|
||||||
|
"""Convert user input into a GemColor.
|
||||||
|
|
||||||
|
Supports:
|
||||||
|
- full names: white, blue, green, red, black, gold
|
||||||
|
- abbreviations: w, b, g, r, k, o
|
||||||
|
"""
|
||||||
|
key = raw.lower()
|
||||||
|
|
||||||
|
# full color names first
|
||||||
|
if key in BASE_COLORS:
|
||||||
|
return key # type: ignore[return-value]
|
||||||
|
|
||||||
|
# abbreviations
|
||||||
|
if key in COLOR_ABBR_TO_FULL:
|
||||||
|
return COLOR_ABBR_TO_FULL[key]
|
||||||
|
|
||||||
|
error = f"Unknown color: {raw}"
|
||||||
|
raise ValueError(error)
|
||||||
|
|
||||||
|
|
||||||
|
def format_cost(cost: Mapping[GemColor, int]) -> str:
|
||||||
|
"""Format a cost/requirements dict as colored tokens like 'B:2, R:1'.
|
||||||
|
|
||||||
|
Uses `color_token` internally so colors are guaranteed to match your bank.
|
||||||
|
"""
|
||||||
|
parts: list[str] = []
|
||||||
|
for color in GEM_COLORS:
|
||||||
|
n = cost.get(color, 0)
|
||||||
|
if not n:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# color_token gives us e.g. "[blue]blue: 3[/]"
|
||||||
|
token = color_token(color, n)
|
||||||
|
|
||||||
|
# Turn the leading color name into the abbreviation (blue: 3 → B:3)
|
||||||
|
# We only replace the first occurrence.
|
||||||
|
full = f"{color}:"
|
||||||
|
abbr = f"{COST_ABBR[color]}:"
|
||||||
|
token = token.replace(full, abbr, 1)
|
||||||
|
|
||||||
|
parts.append(token)
|
||||||
|
|
||||||
|
return ", ".join(parts) if parts else "-"
|
||||||
|
|
||||||
|
|
||||||
|
def format_card(card: Card) -> str:
|
||||||
|
"""Readable card line using dataclass fields instead of __str__."""
|
||||||
|
color_abbr = COST_ABBR[card.color]
|
||||||
|
header = f"T{card.tier} {color_abbr} P{card.points}"
|
||||||
|
cost_str = format_cost(card.cost)
|
||||||
|
return f"{header} ({cost_str})"
|
||||||
|
|
||||||
|
|
||||||
|
def format_noble(noble: Noble) -> str:
|
||||||
|
"""Readable noble line using dataclass fields instead of __str__."""
|
||||||
|
cost_str = format_cost(noble.requirements)
|
||||||
|
return f"{noble.name} +{noble.points} ({cost_str})"
|
||||||
|
|
||||||
|
|
||||||
|
def format_tokens(tokens: Mapping[GemColor, int]) -> str:
|
||||||
|
"""Colored 'color: n' list for a token dict."""
|
||||||
|
return " ".join(color_token(c, tokens.get(c, 0)) for c in GEM_COLORS)
|
||||||
|
|
||||||
|
|
||||||
|
def format_discounts(discounts: Mapping[GemColor, int]) -> str:
|
||||||
|
"""Colored discounts, skipping zeros."""
|
||||||
|
parts: list[str] = []
|
||||||
|
for c in GEM_COLORS:
|
||||||
|
n = discounts.get(c, 0)
|
||||||
|
if not n:
|
||||||
|
continue
|
||||||
|
abbr = COST_ABBR[c]
|
||||||
|
fg, bg = COLOR_STYLE[c]
|
||||||
|
parts.append(f"[{fg} on {bg}]{abbr}:{n}[/{fg} on {bg}]")
|
||||||
|
return ", ".join(parts) if parts else "-"
|
||||||
|
|
||||||
|
|
||||||
|
COLOR_STYLE: dict[GemColor, tuple[str, str]] = {
|
||||||
|
"white": ("black", "white"), # fg, bg
|
||||||
|
"blue": ("bright_white", "blue"),
|
||||||
|
"green": ("bright_white", "sea_green4"),
|
||||||
|
"red": ("white", "red3"),
|
||||||
|
"black": ("white", "grey0"),
|
||||||
|
"gold": ("black", "yellow3"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fmt_gem(color: GemColor) -> str:
|
||||||
|
"""Render gem name with fg/bg matching real token color."""
|
||||||
|
fg, bg = COLOR_STYLE[color]
|
||||||
|
return f"[{fg} on {bg}] {color} [/{fg} on {bg}]"
|
||||||
|
|
||||||
|
|
||||||
|
def fmt_number(value: int) -> str:
|
||||||
|
"""Return a Rich-markup colored 'value' string."""
|
||||||
|
return f"[bold cyan]{value}[/]"
|
||||||
|
|
||||||
|
|
||||||
|
def color_token(name: GemColor, amount: int) -> str:
|
||||||
|
"""Return a Rich-markup colored 'name: n' string."""
|
||||||
|
# Map Splendor colors -> terminal colors
|
||||||
|
color_map: Mapping[GemColor, str] = {
|
||||||
|
"white": "white",
|
||||||
|
"blue": "blue",
|
||||||
|
"green": "green",
|
||||||
|
"red": "red",
|
||||||
|
"black": "grey70", # 'black' is unreadable on dark backgrounds
|
||||||
|
"gold": "yellow",
|
||||||
|
}
|
||||||
|
style = color_map.get(name, "white")
|
||||||
|
return f"[{style}]{name}: {amount}[/]"
|
||||||
|
|
||||||
|
|
||||||
|
class Board(Widget):
|
||||||
|
"""Big board widget with the layout you sketched."""
|
||||||
|
|
||||||
|
def __init__(self, game: GameState, me: PlayerState, **kwargs: Any) -> None: # noqa: ANN401
|
||||||
|
"""Initialize the board widget."""
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.game = game
|
||||||
|
self.me = me
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
"""Compose the board widget."""
|
||||||
|
# Structure:
|
||||||
|
# ┌ bank row
|
||||||
|
# ├ middle row (tiers | nobles)
|
||||||
|
# └ players row
|
||||||
|
with Vertical(id="board_root"):
|
||||||
|
yield Static(id="bank_box")
|
||||||
|
with Horizontal(id="middle_row"):
|
||||||
|
with Vertical(id="tiers_box"):
|
||||||
|
yield Static(id="tier1_box")
|
||||||
|
yield Static(id="tier2_box")
|
||||||
|
yield Static(id="tier3_box")
|
||||||
|
yield Static(id="nobles_box")
|
||||||
|
yield Static(id="players_box")
|
||||||
|
|
||||||
|
def on_mount(self) -> None:
|
||||||
|
"""Refresh the board content."""
|
||||||
|
self.refresh_content()
|
||||||
|
|
||||||
|
def refresh_content(self) -> None:
|
||||||
|
"""Refresh the board content."""
|
||||||
|
self._render_bank()
|
||||||
|
self._render_tiers()
|
||||||
|
self._render_nobles()
|
||||||
|
self._render_players()
|
||||||
|
|
||||||
|
# --- sections ----------------------------------------------------
|
||||||
|
|
||||||
|
def _render_bank(self) -> None:
|
||||||
|
bank = self.game.bank
|
||||||
|
parts: list[str] = ["[b]Bank:[/b]"]
|
||||||
|
# One line, all tokens colored
|
||||||
|
parts.append(format_tokens(bank))
|
||||||
|
self.query_one("#bank_box", Static).update("\n".join(parts))
|
||||||
|
|
||||||
|
def _render_tiers(self) -> None:
|
||||||
|
for tier in (1, 2, 3):
|
||||||
|
box = self.query_one(f"#tier{tier}_box", Static)
|
||||||
|
cards: list[Card] = self.game.table_by_tier.get(tier, [])
|
||||||
|
lines: list[str] = [f"[b]Tier {tier} cards:[/b]"]
|
||||||
|
if not cards:
|
||||||
|
lines.append(" (none)")
|
||||||
|
else:
|
||||||
|
for idx, card in enumerate(cards):
|
||||||
|
lines.append(f" [{idx}] {format_card(card)}")
|
||||||
|
box.update("\n".join(lines))
|
||||||
|
|
||||||
|
def _render_nobles(self) -> None:
|
||||||
|
nobles_box = self.query_one("#nobles_box", Static)
|
||||||
|
lines: list[str] = ["[b]Nobles[/b]"]
|
||||||
|
if not self.game.available_nobles:
|
||||||
|
lines.append(" (none)")
|
||||||
|
else:
|
||||||
|
lines.extend(" - " + format_noble(noble) for noble in self.game.available_nobles)
|
||||||
|
nobles_box.update("\n".join(lines))
|
||||||
|
|
||||||
|
def _render_players(self) -> None:
|
||||||
|
players_box = self.query_one("#players_box", Static)
|
||||||
|
lines: list[str] = ["[b]Players:[/b]", ""]
|
||||||
|
for player in self.game.players:
|
||||||
|
mark = "*" if player is self.me else " "
|
||||||
|
token_str = format_tokens(player.tokens)
|
||||||
|
discount_str = format_discounts(player.discounts)
|
||||||
|
|
||||||
|
lines.append(
|
||||||
|
f"{mark} {player.name:10} Score={player.score:2d} Discounts={discount_str}",
|
||||||
|
)
|
||||||
|
lines.append(f" Tokens: {token_str}")
|
||||||
|
|
||||||
|
if player.nobles:
|
||||||
|
noble_names = ", ".join(n.name for n in player.nobles)
|
||||||
|
lines.append(f" Nobles: {noble_names}")
|
||||||
|
|
||||||
|
# Optional: show counts of cards / reserved
|
||||||
|
if player.cards:
|
||||||
|
lines.append(f" Cards: {len(player.cards)}")
|
||||||
|
if player.reserved:
|
||||||
|
lines.append(f" Reserved: {len(player.reserved)}")
|
||||||
|
|
||||||
|
lines.append("")
|
||||||
|
players_box.update("\n".join(lines))
|
||||||
|
|
||||||
|
|
||||||
|
class ActionApp(App[None]):
|
||||||
|
"""Textual app that asks for a single action command and returns an Action."""
|
||||||
|
|
||||||
|
CSS = """
|
||||||
|
Screen {
|
||||||
|
/* 3 rows: command zone, board, footer */
|
||||||
|
layout: grid;
|
||||||
|
grid-size: 1 3;
|
||||||
|
grid-rows: auto 1fr auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Top area with input + instructions */
|
||||||
|
#command_zone {
|
||||||
|
grid-columns: 1;
|
||||||
|
grid-rows: 1;
|
||||||
|
padding: 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Board sits in the middle row and can grow */
|
||||||
|
#board {
|
||||||
|
grid-columns: 1;
|
||||||
|
grid-rows: 2;
|
||||||
|
padding: 0 1 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Footer {
|
||||||
|
grid-columns: 1;
|
||||||
|
grid-rows: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input {
|
||||||
|
border: round $accent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* === Board layout === */
|
||||||
|
|
||||||
|
#board_root {
|
||||||
|
/* outer frame around the whole board area */
|
||||||
|
border: heavy white;
|
||||||
|
padding: 0 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bank row: full width */
|
||||||
|
#bank_box {
|
||||||
|
border: heavy white;
|
||||||
|
padding: 0 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Middle row: tiers (left) + nobles (right) */
|
||||||
|
#middle_row {
|
||||||
|
layout: horizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tiers_box {
|
||||||
|
border: heavy white;
|
||||||
|
padding: 0 1;
|
||||||
|
width: 70%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tier1_box,
|
||||||
|
#tier2_box,
|
||||||
|
#tier3_box {
|
||||||
|
border-bottom: heavy white;
|
||||||
|
padding: 0 0 1 0;
|
||||||
|
margin-bottom: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nobles_box {
|
||||||
|
border: heavy white;
|
||||||
|
padding: 0 1;
|
||||||
|
width: 30%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Players row: full width at bottom */
|
||||||
|
#players_box {
|
||||||
|
border: heavy white;
|
||||||
|
padding: 0 1;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, game: GameState, player: PlayerState) -> None:
|
||||||
|
"""Initialize the action app."""
|
||||||
|
super().__init__()
|
||||||
|
self.game = game
|
||||||
|
self.player = player
|
||||||
|
self.result: Action | None = None
|
||||||
|
self.message: str = ""
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
"""Compose the action app."""
|
||||||
|
# Row 1: input + Actions text
|
||||||
|
with Vertical(id="command_zone"):
|
||||||
|
yield Input(
|
||||||
|
placeholder="Enter command, e.g. '1 white blue red' or '1 w b r' or 'q'",
|
||||||
|
id="input_line",
|
||||||
|
)
|
||||||
|
yield Static("", id="prompt")
|
||||||
|
|
||||||
|
# Row 2: board
|
||||||
|
yield Board(self.game, self.player, id="board")
|
||||||
|
|
||||||
|
# Row 3: footer
|
||||||
|
yield Footer()
|
||||||
|
|
||||||
|
def on_mount(self) -> None:
|
||||||
|
"""Mount the action app."""
|
||||||
|
self._update_prompt()
|
||||||
|
self.query_one(Input).focus()
|
||||||
|
|
||||||
|
def _update_prompt(self) -> None:
|
||||||
|
lines: list[str] = []
|
||||||
|
lines.append("[bold underline]Actions:[/]")
|
||||||
|
lines.append(
|
||||||
|
" [bold green]1[/] <colors...> - Take up to 3 different gem colors "
|
||||||
|
"(e.g. [cyan]1 white blue red[/] or [cyan]1 w b r[/])",
|
||||||
|
)
|
||||||
|
lines.append(
|
||||||
|
f" [bold green]2[/] <color> - Take 2 of the same color (needs {fmt_number(4)} in bank, "
|
||||||
|
"e.g. [cyan]2 blue[/] or [cyan]2 b[/])",
|
||||||
|
)
|
||||||
|
lines.append(
|
||||||
|
" [bold green]3[/] <tier> <idx> - Buy a face-up card (e.g. [cyan]3 1 0[/] for tier 1, index 0)",
|
||||||
|
)
|
||||||
|
lines.append(" [bold green]4[/] <idx> - Buy a reserved card")
|
||||||
|
lines.append(" [bold green]5[/] <tier> <idx> - Reserve a face-up card")
|
||||||
|
lines.append(" [bold green]6[/] <tier> - Reserve top card of a deck")
|
||||||
|
lines.append(" [bold red]q[/] - Quit game")
|
||||||
|
if self.message:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"[bold red]Message:[/] {self.message}")
|
||||||
|
self.query_one("#prompt", Static).update("\n".join(lines))
|
||||||
|
|
||||||
|
def _cmd_1(self, parts: list[str]) -> str | None:
|
||||||
|
"""Take up to 3 different gem colors: 1 white blue red OR 1 w b r."""
|
||||||
|
color_names = parts[1:]
|
||||||
|
if not color_names:
|
||||||
|
return "Need at least one color (full name or abbreviation)."
|
||||||
|
colors: list[GemColor] = []
|
||||||
|
for name in color_names:
|
||||||
|
color = parse_color_token(name)
|
||||||
|
if self.game.bank[color] <= 0:
|
||||||
|
return f"No tokens left for color: {color}"
|
||||||
|
colors.append(color)
|
||||||
|
self.result = TakeDifferent(colors=colors[:3])
|
||||||
|
self.exit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _cmd_2(self, parts: list[str]) -> str | None:
|
||||||
|
"""Take two of the same color."""
|
||||||
|
if len(parts) < 2:
|
||||||
|
return "Usage: 2 <color>"
|
||||||
|
color = parse_color_token(parts[1])
|
||||||
|
if self.game.bank[color] < self.game.config.minimum_tokens_to_buy_2:
|
||||||
|
return "Bank must have at least 4 of that color."
|
||||||
|
self.result = TakeDouble(color=color)
|
||||||
|
self.exit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _cmd_3(self, parts: list[str]) -> str | None:
|
||||||
|
"""Buy face-up card."""
|
||||||
|
if len(parts) < 3:
|
||||||
|
return "Usage: 3 <tier> <index>"
|
||||||
|
tier = int(parts[1])
|
||||||
|
idx = int(parts[2])
|
||||||
|
self.result = BuyCard(tier=tier, index=idx)
|
||||||
|
self.exit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _cmd_4(self, parts: list[str]) -> str | None:
|
||||||
|
"""Buy reserved card."""
|
||||||
|
if len(parts) < 2:
|
||||||
|
return "Usage: 4 <reserved_index>"
|
||||||
|
idx = int(parts[1])
|
||||||
|
if not (0 <= idx < len(self.player.reserved)):
|
||||||
|
return "Reserved index out of range."
|
||||||
|
self.result = BuyCardReserved(tier=0, index=idx)
|
||||||
|
self.exit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _cmd_5(self, parts: list[str]) -> str | None:
|
||||||
|
"""Reserve face-up card."""
|
||||||
|
if len(parts) < 3:
|
||||||
|
return "Usage: 5 <tier> <index>"
|
||||||
|
tier = int(parts[1])
|
||||||
|
idx = int(parts[2])
|
||||||
|
self.result = ReserveCard(tier=tier, index=idx, from_deck=False)
|
||||||
|
self.exit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _cmd_6(self, parts: list[str]) -> str | None:
|
||||||
|
"""Reserve top of deck."""
|
||||||
|
if len(parts) < 2:
|
||||||
|
return "Usage: 6 <tier>"
|
||||||
|
tier = int(parts[1])
|
||||||
|
self.result = ReserveCard(tier=tier, index=None, from_deck=True)
|
||||||
|
self.exit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _unknown_cmd(self, _parts: list[str]) -> str:
|
||||||
|
return "Unknown command."
|
||||||
|
|
||||||
|
def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||||
|
"""Handle user input."""
|
||||||
|
text = (event.value or "").strip()
|
||||||
|
event.input.value = ""
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
|
if text.lower() in {"q", "quit", "0"}:
|
||||||
|
self.result = None
|
||||||
|
self.exit()
|
||||||
|
return
|
||||||
|
|
||||||
|
parts = text.split()
|
||||||
|
|
||||||
|
cmds = {
|
||||||
|
"1": self._cmd_1,
|
||||||
|
"2": self._cmd_2,
|
||||||
|
"3": self._cmd_3,
|
||||||
|
"4": self._cmd_4,
|
||||||
|
"5": self._cmd_5,
|
||||||
|
"6": self._cmd_6,
|
||||||
|
}
|
||||||
|
cmd = parts[0]
|
||||||
|
|
||||||
|
error = cmds.get(cmd, self._unknown_cmd)(parts)
|
||||||
|
|
||||||
|
if error:
|
||||||
|
self.message = error
|
||||||
|
self._update_prompt()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class DiscardApp(App[None]):
|
||||||
|
"""Textual app to choose discards when over token limit."""
|
||||||
|
|
||||||
|
CSS = """
|
||||||
|
Screen {
|
||||||
|
layout: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
#command_zone {
|
||||||
|
padding: 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#board {
|
||||||
|
padding: 0 1 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input {
|
||||||
|
border: round $accent;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, game: GameState, player: PlayerState) -> None:
|
||||||
|
"""Initialize the discard app."""
|
||||||
|
super().__init__()
|
||||||
|
self.game = game
|
||||||
|
self.player = player
|
||||||
|
self.discards: dict[GemColor, int] = dict.fromkeys(GEM_COLORS, 0)
|
||||||
|
self.message: str = ""
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult: # type: ignore[override]
|
||||||
|
"""Compose the discard app."""
|
||||||
|
yield Header(show_clock=False)
|
||||||
|
|
||||||
|
with Vertical(id="command_zone"):
|
||||||
|
yield Input(
|
||||||
|
placeholder="Enter color to discard, e.g. 'blue' or 'b'",
|
||||||
|
id="input_line",
|
||||||
|
)
|
||||||
|
yield Static("", id="prompt")
|
||||||
|
|
||||||
|
# Board directly under the command zone
|
||||||
|
yield Board(self.game, self.player, id="board")
|
||||||
|
|
||||||
|
yield Footer()
|
||||||
|
|
||||||
|
def on_mount(self) -> None: # type: ignore[override]
|
||||||
|
"""Mount the discard app."""
|
||||||
|
self._update_prompt()
|
||||||
|
self.query_one(Input).focus()
|
||||||
|
|
||||||
|
def _remaining_to_discard(self) -> int:
|
||||||
|
return self.player.total_tokens() - sum(self.discards.values()) - self.game.config.token_limit
|
||||||
|
|
||||||
|
def _update_prompt(self) -> None:
|
||||||
|
remaining = max(self._remaining_to_discard(), 0)
|
||||||
|
lines: list[str] = []
|
||||||
|
lines.append(
|
||||||
|
"You must discard "
|
||||||
|
f"{fmt_number(remaining)} token(s) "
|
||||||
|
f"to get down to {fmt_number(self.game.config.token_limit)}.",
|
||||||
|
)
|
||||||
|
disc_str = ", ".join(f"{fmt_gem(c)}={fmt_number(self.discards[c])}" for c in GEM_COLORS)
|
||||||
|
lines.append(f"Current planned discards: {{ {disc_str} }}")
|
||||||
|
lines.append(
|
||||||
|
"Type a color name or abbreviation (e.g. 'blue' or 'b') to discard one token.",
|
||||||
|
)
|
||||||
|
if self.message:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"[bold red]Message:[/] {self.message}")
|
||||||
|
self.query_one("#prompt", Static).update("\n".join(lines))
|
||||||
|
|
||||||
|
def on_input_submitted(self, event: Input.Submitted) -> None: # type: ignore[override]
|
||||||
|
"""Handle user input."""
|
||||||
|
raw = (event.value or "").strip()
|
||||||
|
event.input.value = ""
|
||||||
|
if not raw:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
color = parse_color_token(raw)
|
||||||
|
except ValueError:
|
||||||
|
self.message = f"Unknown color: {raw}"
|
||||||
|
self._update_prompt()
|
||||||
|
return
|
||||||
|
|
||||||
|
available = self.player.tokens[color] - self.discards[color]
|
||||||
|
if available <= 0:
|
||||||
|
self.message = f"No more {color} tokens available to discard."
|
||||||
|
self._update_prompt()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.discards[color] += 1
|
||||||
|
if self._remaining_to_discard() <= 0:
|
||||||
|
self.exit()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.message = ""
|
||||||
|
self._update_prompt()
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Noble choice app
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class NobleChoiceApp(App[None]):
|
||||||
|
"""Textual app to choose one noble."""
|
||||||
|
|
||||||
|
CSS = """
|
||||||
|
Screen {
|
||||||
|
layout: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
#command_zone {
|
||||||
|
padding: 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#board {
|
||||||
|
padding: 0 1 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input {
|
||||||
|
border: round $accent;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
game: GameState,
|
||||||
|
player: PlayerState,
|
||||||
|
nobles: list[Noble],
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the noble choice app."""
|
||||||
|
super().__init__()
|
||||||
|
self.game = game
|
||||||
|
self.player = player
|
||||||
|
self.nobles = nobles
|
||||||
|
self.result: Noble | None = None
|
||||||
|
self.message: str = ""
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult: # type: ignore[override]
|
||||||
|
"""Compose the noble choice app."""
|
||||||
|
yield Header(show_clock=False)
|
||||||
|
|
||||||
|
with Vertical(id="command_zone"):
|
||||||
|
yield Input(
|
||||||
|
placeholder="Enter noble index, e.g. '0'",
|
||||||
|
id="input_line",
|
||||||
|
)
|
||||||
|
yield Static("", id="prompt")
|
||||||
|
|
||||||
|
# Board directly under the command zone
|
||||||
|
yield Board(self.game, self.player, id="board")
|
||||||
|
|
||||||
|
yield Footer()
|
||||||
|
|
||||||
|
def on_mount(self) -> None: # type: ignore[override]
|
||||||
|
"""Mount the noble choice app."""
|
||||||
|
self._update_prompt()
|
||||||
|
self.query_one(Input).focus()
|
||||||
|
|
||||||
|
def _update_prompt(self) -> None:
|
||||||
|
lines: list[str] = []
|
||||||
|
lines.append("[bold underline]You qualify for nobles:[/]")
|
||||||
|
for i, noble in enumerate(self.nobles):
|
||||||
|
lines.append(f" [bright_cyan]{i})[/] {format_noble(noble)}")
|
||||||
|
lines.append("Enter the index of the noble you want.")
|
||||||
|
if self.message:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"[bold red]Message:[/] {self.message}")
|
||||||
|
self.query_one("#prompt", Static).update("\n".join(lines))
|
||||||
|
|
||||||
|
def on_input_submitted(self, event: Input.Submitted) -> None: # type: ignore[override]
|
||||||
|
"""Handle user input."""
|
||||||
|
raw = (event.value or "").strip()
|
||||||
|
event.input.value = ""
|
||||||
|
if not raw:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
idx = int(raw)
|
||||||
|
except ValueError:
|
||||||
|
self.message = "Please enter a valid integer index."
|
||||||
|
self._update_prompt()
|
||||||
|
return
|
||||||
|
if not (0 <= idx < len(self.nobles)):
|
||||||
|
self.message = "Index out of range."
|
||||||
|
self._update_prompt()
|
||||||
|
return
|
||||||
|
self.result = self.nobles[idx]
|
||||||
|
self.exit()
|
||||||
|
|
||||||
|
|
||||||
|
class TuiHuman(Strategy):
|
||||||
|
"""Textual-based human player Strategy with colorful board."""
|
||||||
|
|
||||||
|
def choose_action(
|
||||||
|
self,
|
||||||
|
game: GameState,
|
||||||
|
player: PlayerState,
|
||||||
|
) -> Action | None:
|
||||||
|
"""Choose an action for the player."""
|
||||||
|
if not sys.stdout.isatty():
|
||||||
|
return None
|
||||||
|
app = ActionApp(game, player)
|
||||||
|
app.run()
|
||||||
|
return app.result
|
||||||
|
|
||||||
|
def choose_discard(
|
||||||
|
self,
|
||||||
|
game: GameState,
|
||||||
|
player: PlayerState,
|
||||||
|
excess: int, # noqa: ARG002
|
||||||
|
) -> dict[GemColor, int]:
|
||||||
|
"""Choose tokens to discard."""
|
||||||
|
if not sys.stdout.isatty():
|
||||||
|
return dict.fromkeys(GEM_COLORS, 0)
|
||||||
|
app = DiscardApp(game, player)
|
||||||
|
app.run()
|
||||||
|
return app.discards
|
||||||
|
|
||||||
|
def choose_noble(
|
||||||
|
self,
|
||||||
|
game: GameState,
|
||||||
|
player: PlayerState,
|
||||||
|
nobles: list[Noble],
|
||||||
|
) -> Noble:
|
||||||
|
"""Choose a noble for the player."""
|
||||||
|
if not sys.stdout.isatty():
|
||||||
|
return nobles[0]
|
||||||
|
app = NobleChoiceApp(game, player, nobles)
|
||||||
|
app.run()
|
||||||
|
return app.result
|
||||||
19
python/splendor/main.py
Normal file
19
python/splendor/main.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
"""Main entry point for Splendor game."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from .base import new_game, run_game
|
||||||
|
from .bot import RandomBot
|
||||||
|
from .human import TuiHuman
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""Main entry point."""
|
||||||
|
human = TuiHuman()
|
||||||
|
bot = RandomBot()
|
||||||
|
game_state = new_game(["You", "Bot A"])
|
||||||
|
run_game(game_state, [human, bot])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
111
python/splendor/public_state.py
Normal file
111
python/splendor/public_state.py
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
"""Public state for RL/search."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from .base import (
|
||||||
|
BASE_COLORS,
|
||||||
|
BASE_INDEX,
|
||||||
|
GEM_ORDER,
|
||||||
|
Card,
|
||||||
|
GameState,
|
||||||
|
Noble,
|
||||||
|
PlayerState,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class ObsCard:
|
||||||
|
"""Numeric-ish card view for RL/search."""
|
||||||
|
|
||||||
|
tier: int
|
||||||
|
points: int
|
||||||
|
color_index: int
|
||||||
|
cost: list[int]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class ObsNoble:
|
||||||
|
"""Numeric-ish noble view for RL/search."""
|
||||||
|
|
||||||
|
points: int
|
||||||
|
requirements: list[int]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class ObsPlayer:
|
||||||
|
"""Numeric-ish player view for RL/search."""
|
||||||
|
|
||||||
|
tokens: list[int]
|
||||||
|
discounts: list[int]
|
||||||
|
score: int
|
||||||
|
cards: list[ObsCard]
|
||||||
|
reserved: list[ObsCard]
|
||||||
|
nobles: list[ObsNoble]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class Observation:
|
||||||
|
"""Full public state for RL/search."""
|
||||||
|
|
||||||
|
current_player: int
|
||||||
|
bank: list[int]
|
||||||
|
players: list[ObsPlayer]
|
||||||
|
table_by_tier: dict[int, list[ObsCard]]
|
||||||
|
decks_remaining: dict[int, int]
|
||||||
|
available_nobles: list[ObsNoble]
|
||||||
|
|
||||||
|
|
||||||
|
def _encode_card(card: Card) -> ObsCard:
|
||||||
|
color_index = BASE_INDEX.get(card.color, -1)
|
||||||
|
cost_vec = [card.cost.get(c, 0) for c in BASE_COLORS]
|
||||||
|
return ObsCard(
|
||||||
|
tier=card.tier,
|
||||||
|
points=card.points,
|
||||||
|
color_index=color_index,
|
||||||
|
cost=cost_vec,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _encode_noble(noble: Noble) -> ObsNoble:
|
||||||
|
req_vec = [noble.requirements.get(c, 0) for c in BASE_COLORS]
|
||||||
|
return ObsNoble(
|
||||||
|
points=noble.points,
|
||||||
|
requirements=req_vec,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _encode_player(player: PlayerState) -> ObsPlayer:
|
||||||
|
tokens_vec = [player.tokens[c] for c in GEM_ORDER]
|
||||||
|
discounts_vec = [player.discounts[c] for c in GEM_ORDER]
|
||||||
|
cards_enc = [_encode_card(c) for c in player.cards]
|
||||||
|
reserved_enc = [_encode_card(c) for c in player.reserved]
|
||||||
|
nobles_enc = [_encode_noble(n) for n in player.nobles]
|
||||||
|
return ObsPlayer(
|
||||||
|
tokens=tokens_vec,
|
||||||
|
discounts=discounts_vec,
|
||||||
|
score=player.score,
|
||||||
|
cards=cards_enc,
|
||||||
|
reserved=reserved_enc,
|
||||||
|
nobles=nobles_enc,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def to_observation(game: GameState) -> Observation:
|
||||||
|
"""Create a structured observation of the full public state."""
|
||||||
|
bank_vec = [game.bank[c] for c in GEM_ORDER]
|
||||||
|
players_enc = [_encode_player(p) for p in game.players]
|
||||||
|
table_enc: dict[int, list[ObsCard]] = {
|
||||||
|
tier: [_encode_card(c) for c in row] for tier, row in game.table_by_tier.items()
|
||||||
|
}
|
||||||
|
decks_remaining = {tier: len(deck) for tier, deck in game.decks_by_tier.items()}
|
||||||
|
nobles_enc = [_encode_noble(n) for n in game.available_nobles]
|
||||||
|
return Observation(
|
||||||
|
current_player=game.current_player_index,
|
||||||
|
bank=bank_vec,
|
||||||
|
players=players_enc,
|
||||||
|
table_by_tier=table_enc,
|
||||||
|
decks_remaining=decks_remaining,
|
||||||
|
available_nobles=nobles_enc,
|
||||||
|
)
|
||||||
36
python/splendor/sim.py
Normal file
36
python/splendor/sim.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
"""Simulate a step in the game."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
|
from .base import Action, GameState, PlayerState, apply_action, check_nobles_for_player
|
||||||
|
from .bot import RandomBot
|
||||||
|
|
||||||
|
|
||||||
|
class SimStrategy(RandomBot):
|
||||||
|
"""Strategy used in simulate_step.
|
||||||
|
|
||||||
|
We never call choose_action here (caller chooses actions),
|
||||||
|
but we reuse discard/noble-selection logic.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def choose_action(self, game: GameState, player: PlayerState) -> Action | None: # noqa: ARG002
|
||||||
|
"""Choose an action for the current player."""
|
||||||
|
msg = "SimStrategy.choose_action should not be used in simulate_step"
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def simulate_step(game: GameState, action: Action) -> GameState:
|
||||||
|
"""Return a deep-copied next state after applying action for the current player.
|
||||||
|
|
||||||
|
Useful for tree search / MCTS:
|
||||||
|
|
||||||
|
next_state = simulate_step(state, action)
|
||||||
|
"""
|
||||||
|
next_state = copy.deepcopy(game)
|
||||||
|
sim_strategy = SimStrategy()
|
||||||
|
apply_action(next_state, sim_strategy, action)
|
||||||
|
check_nobles_for_player(next_state, sim_strategy, next_state.current_player)
|
||||||
|
next_state.next_player()
|
||||||
|
return next_state
|
||||||
50
python/splendor/simulat.py
Normal file
50
python/splendor/simulat.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"""Simulator for Splendor game."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
|
from statistics import mean
|
||||||
|
|
||||||
|
from .base import GameConfig, load_cards, load_nobles, new_game, run_game
|
||||||
|
from .bot import PersonalizedBot4, RandomBot
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""Main entry point."""
|
||||||
|
turn_limit = 1000
|
||||||
|
good_games = 0
|
||||||
|
games = 1
|
||||||
|
winners: dict[str, list] = defaultdict(list)
|
||||||
|
game_data = Path(__file__).parent / "game_data"
|
||||||
|
|
||||||
|
cards = load_cards(game_data / "cards/default.json")
|
||||||
|
nobles = load_nobles(game_data / "nobles/default.json")
|
||||||
|
|
||||||
|
for _ in range(games):
|
||||||
|
bot_a = RandomBot("bot_a")
|
||||||
|
bot_b = RandomBot("bot_b")
|
||||||
|
bot_c = RandomBot("bot_c")
|
||||||
|
bot_d = PersonalizedBot4("my_bot")
|
||||||
|
config = GameConfig(
|
||||||
|
cards=cards,
|
||||||
|
nobles=nobles,
|
||||||
|
turn_limit=turn_limit,
|
||||||
|
)
|
||||||
|
players = (bot_a, bot_b, bot_c, bot_d)
|
||||||
|
game_state = new_game(players, config)
|
||||||
|
winner, turns = run_game(game_state)
|
||||||
|
if turns < turn_limit:
|
||||||
|
good_games += 1
|
||||||
|
winners[winner.strategy.name].append(turns)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"out of {games} {turn_limit} turn games with {len(players)}"
|
||||||
|
f"random bots there where {good_games} games where a bot won"
|
||||||
|
)
|
||||||
|
for name, turns in winners.items():
|
||||||
|
print(f"{name} won {len(turns)} games in {mean(turns):.2f} turns")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
nix
|
nix
|
||||||
home-manager
|
home-manager
|
||||||
git
|
git
|
||||||
|
my_python
|
||||||
|
|
||||||
ssh-to-age
|
ssh-to-age
|
||||||
gnupg
|
gnupg
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
|
{ inputs, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/richie
|
"${inputs.self}/users/richie"
|
||||||
../../users/gaming
|
"${inputs.self}/users/gaming"
|
||||||
../../common/global
|
"${inputs.self}/common/global"
|
||||||
../../common/optional/desktop.nix
|
"${inputs.self}/common/optional/desktop.nix"
|
||||||
../../common/optional/docker.nix
|
"${inputs.self}/common/optional/docker.nix"
|
||||||
../../common/optional/scanner.nix
|
"${inputs.self}/common/optional/scanner.nix"
|
||||||
../../common/optional/steam.nix
|
"${inputs.self}/common/optional/steam.nix"
|
||||||
../../common/optional/syncthing_base.nix
|
"${inputs.self}/common/optional/syncthing_base.nix"
|
||||||
../../common/optional/systemd-boot.nix
|
"${inputs.self}/common/optional/systemd-boot.nix"
|
||||||
../../common/optional/update.nix
|
"${inputs.self}/common/optional/update.nix"
|
||||||
../../common/optional/yubikey.nix
|
"${inputs.self}/common/optional/yubikey.nix"
|
||||||
../../common/optional/zerotier.nix
|
"${inputs.self}/common/optional/zerotier.nix"
|
||||||
../../common/optional/nvidia.nix
|
"${inputs.self}/common/optional/nvidia.nix"
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
./syncthing.nix
|
./syncthing.nix
|
||||||
./llms.nix
|
./llms.nix
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
"Qihoo360-Light-R1-32B"
|
"Qihoo360-Light-R1-32B"
|
||||||
];
|
];
|
||||||
models = "/zfs/models";
|
models = "/zfs/models";
|
||||||
acceleration = "cuda";
|
|
||||||
openFirewall = true;
|
openFirewall = true;
|
||||||
};
|
};
|
||||||
# open-webui = {
|
# open-webui = {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{ inputs, ... }:
|
{ inputs, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/richie
|
"${inputs.self}/users/richie"
|
||||||
../../common/global
|
"${inputs.self}/common/global"
|
||||||
../../common/optional/docker.nix
|
"${inputs.self}/common/optional/docker.nix"
|
||||||
../../common/optional/ssh_decrypt.nix
|
"${inputs.self}/common/optional/ssh_decrypt.nix"
|
||||||
../../common/optional/syncthing_base.nix
|
"${inputs.self}/common/optional/syncthing_base.nix"
|
||||||
../../common/optional/systemd-boot.nix
|
"${inputs.self}/common/optional/systemd-boot.nix"
|
||||||
../../common/optional/update.nix
|
"${inputs.self}/common/optional/update.nix"
|
||||||
../../common/optional/zerotier.nix
|
"${inputs.self}/common/optional/zerotier.nix"
|
||||||
./docker
|
./docker
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
./programs.nix
|
./programs.nix
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
"192.168.95.35"
|
"192.168.95.35"
|
||||||
"127.0.0.1"
|
"127.0.0.1"
|
||||||
];
|
];
|
||||||
use_x_forwarded_for = true;
|
|
||||||
};
|
};
|
||||||
homeassistant = {
|
homeassistant = {
|
||||||
time_zone = "America/New_York";
|
time_zone = "America/New_York";
|
||||||
@@ -60,16 +59,21 @@
|
|||||||
};
|
};
|
||||||
extraPackages =
|
extraPackages =
|
||||||
python3Packages: with python3Packages; [
|
python3Packages: with python3Packages; [
|
||||||
pymodbus # for modbus
|
aioesphomeapi # for esphome
|
||||||
|
aiounifi # for ubiquiti integration
|
||||||
|
bleak-esphome # for esphome
|
||||||
|
esphome-dashboard-api # for esphome
|
||||||
|
forecast-solar # for solar forecast
|
||||||
gtts # not sure what wants this
|
gtts # not sure what wants this
|
||||||
|
ical # for todo
|
||||||
jellyfin-apiclient-python # for jellyfin
|
jellyfin-apiclient-python # for jellyfin
|
||||||
paho-mqtt # for mqtt
|
paho-mqtt # for mqtt
|
||||||
psycopg2 # for postgresql
|
psycopg2 # for postgresql
|
||||||
forecast-solar # for solar forecast
|
|
||||||
aioesphomeapi # for esphome
|
|
||||||
esphome-dashboard-api # for esphome
|
|
||||||
py-improv-ble-client # for esphome
|
py-improv-ble-client # for esphome
|
||||||
bleak-esphome # for esphome
|
pymodbus # for modbus
|
||||||
|
pyopenweathermap # for weather
|
||||||
|
uiprotect # for ubiquiti integration
|
||||||
|
unifi-discovery # for ubiquiti integration
|
||||||
];
|
];
|
||||||
extraComponents = [ "isal" ];
|
extraComponents = [ "isal" ];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,45 +1,7 @@
|
|||||||
template:
|
|
||||||
- sensor:
|
|
||||||
# Battery 0
|
|
||||||
- name: "JK0 charge power W"
|
|
||||||
unique_id: jk0_charge_power_w
|
|
||||||
unit_of_measurement: W
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
state: >
|
|
||||||
{% set p = states('sensor.batteries_jk0_power')|float(0) %}
|
|
||||||
{{ max(0, p) }}
|
|
||||||
- name: "JK0 discharge power W"
|
|
||||||
unique_id: jk0_discharge_power_w
|
|
||||||
unit_of_measurement: W
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
state: >
|
|
||||||
{% set p = states('sensor.batteries_jk0_power')|float(0) %}
|
|
||||||
{{ max(0, -p) }}
|
|
||||||
|
|
||||||
# Battery 1
|
|
||||||
- name: "JK1 charge power W"
|
|
||||||
unique_id: jk1_charge_power_w
|
|
||||||
unit_of_measurement: W
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
state: >
|
|
||||||
{% set p = states('sensor.batteries_jk1_power')|float(0) %}
|
|
||||||
{{ max(0, p) }}
|
|
||||||
- name: "JK1 discharge power W"
|
|
||||||
unique_id: jk1_discharge_power_w
|
|
||||||
unit_of_measurement: W
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
state: >
|
|
||||||
{% set p = states('sensor.batteries_jk1_power')|float(0) %}
|
|
||||||
{{ max(0, -p) }}
|
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
# Battery 0
|
# Battery 0
|
||||||
- platform: integration
|
- platform: integration
|
||||||
source: sensor.jk0_charge_power_w
|
source: sensor.batteries_jk0_charging_power
|
||||||
name: "JK0 energy in"
|
name: "JK0 energy in"
|
||||||
unique_id: jk0_energy_in_kwh
|
unique_id: jk0_energy_in_kwh
|
||||||
unit_prefix: k
|
unit_prefix: k
|
||||||
@@ -48,7 +10,7 @@ sensor:
|
|||||||
max_sub_interval:
|
max_sub_interval:
|
||||||
minutes: 5
|
minutes: 5
|
||||||
- platform: integration
|
- platform: integration
|
||||||
source: sensor.jk0_discharge_power_w
|
source: sensor.batteries_jk0_discharging_power
|
||||||
name: "JK0 energy out"
|
name: "JK0 energy out"
|
||||||
unique_id: jk0_energy_out_kwh
|
unique_id: jk0_energy_out_kwh
|
||||||
unit_prefix: k
|
unit_prefix: k
|
||||||
@@ -59,7 +21,7 @@ sensor:
|
|||||||
|
|
||||||
# Battery 1
|
# Battery 1
|
||||||
- platform: integration
|
- platform: integration
|
||||||
source: sensor.jk1_charge_power_w
|
source: sensor.battery1_jk1_charging_power
|
||||||
name: "JK1 energy in"
|
name: "JK1 energy in"
|
||||||
unique_id: jk1_energy_in_kwh
|
unique_id: jk1_energy_in_kwh
|
||||||
unit_prefix: k
|
unit_prefix: k
|
||||||
@@ -68,7 +30,7 @@ sensor:
|
|||||||
max_sub_interval:
|
max_sub_interval:
|
||||||
minutes: 5
|
minutes: 5
|
||||||
- platform: integration
|
- platform: integration
|
||||||
source: sensor.jk1_discharge_power_w
|
source: sensor.battery1_jk1_discharging_power
|
||||||
name: "JK1 energy out"
|
name: "JK1 energy out"
|
||||||
unique_id: jk1_energy_out_kwh
|
unique_id: jk1_energy_out_kwh
|
||||||
unit_prefix: k
|
unit_prefix: k
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ modbus:
|
|||||||
|
|
||||||
# GPS
|
# GPS
|
||||||
- name: GPS Latitude
|
- name: GPS Latitude
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2800
|
address: 2800
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: int32
|
data_type: int32
|
||||||
@@ -87,7 +87,7 @@ modbus:
|
|||||||
unique_id: gps_latitude
|
unique_id: gps_latitude
|
||||||
|
|
||||||
- name: GPS Longitude
|
- name: GPS Longitude
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2802
|
address: 2802
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: int32
|
data_type: int32
|
||||||
@@ -97,7 +97,7 @@ modbus:
|
|||||||
unique_id: gps_longitude
|
unique_id: gps_longitude
|
||||||
|
|
||||||
- name: GPS Course
|
- name: GPS Course
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2804
|
address: 2804
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: uint16
|
data_type: uint16
|
||||||
@@ -108,7 +108,7 @@ modbus:
|
|||||||
unique_id: gps_course
|
unique_id: gps_course
|
||||||
|
|
||||||
- name: GPS Speed
|
- name: GPS Speed
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2805
|
address: 2805
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: uint16
|
data_type: uint16
|
||||||
@@ -119,7 +119,7 @@ modbus:
|
|||||||
unique_id: gps_speed
|
unique_id: gps_speed
|
||||||
|
|
||||||
- name: GPS Fix
|
- name: GPS Fix
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2806
|
address: 2806
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: uint16
|
data_type: uint16
|
||||||
@@ -128,7 +128,7 @@ modbus:
|
|||||||
unique_id: gps_fix
|
unique_id: gps_fix
|
||||||
|
|
||||||
- name: GPS Satellites
|
- name: GPS Satellites
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2807
|
address: 2807
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: uint16
|
data_type: uint16
|
||||||
@@ -137,7 +137,7 @@ modbus:
|
|||||||
unique_id: gps_satellites
|
unique_id: gps_satellites
|
||||||
|
|
||||||
- name: GPS Altitude
|
- name: GPS Altitude
|
||||||
slave: 100
|
slave: 1
|
||||||
address: 2808
|
address: 2808
|
||||||
input_type: holding
|
input_type: holding
|
||||||
data_type: int32
|
data_type: int32
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
|
{ inputs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/richie
|
"${inputs.self}/users/richie"
|
||||||
../../users/math
|
"${inputs.self}/users/math"
|
||||||
../../users/dov
|
"${inputs.self}/users/dov"
|
||||||
../../common/global
|
"${inputs.self}/common/global"
|
||||||
../../common/optional/docker.nix
|
"${inputs.self}/common/optional/docker.nix"
|
||||||
../../common/optional/ssh_decrypt.nix
|
"${inputs.self}/common/optional/ssh_decrypt.nix"
|
||||||
../../common/optional/syncthing_base.nix
|
"${inputs.self}/common/optional/syncthing_base.nix"
|
||||||
../../common/optional/update.nix
|
"${inputs.self}/common/optional/update.nix"
|
||||||
../../common/optional/zerotier.nix
|
"${inputs.self}/common/optional/zerotier.nix"
|
||||||
./docker
|
./docker
|
||||||
./services
|
./services
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
./networking.nix
|
./networking.nix
|
||||||
./nvidia.nix
|
|
||||||
./programs.nix
|
./programs.nix
|
||||||
./runners
|
./runners
|
||||||
./syncthing.nix
|
./syncthing.nix
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
{
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
|
|
||||||
# environment.systemPackages = with pkgs; [ php.withExtensions ({ all, ... }: [ all.pdo_pgsql ]) ];
|
|
||||||
|
|
||||||
services.httpd = {
|
|
||||||
enable = true;
|
|
||||||
adminAddr = "webmaster@localhost";
|
|
||||||
|
|
||||||
enablePHP = true;
|
|
||||||
phpPackage = pkgs.php.withExtensions (
|
|
||||||
{ enabled, all }:
|
|
||||||
enabled
|
|
||||||
++ [
|
|
||||||
all.pdo
|
|
||||||
all.pdo_pgsql
|
|
||||||
]
|
|
||||||
);
|
|
||||||
extraModules = [ "rewrite" ];
|
|
||||||
virtualHosts.great_cloud_of_witnesses = {
|
|
||||||
hostName = "localhost";
|
|
||||||
listen = [
|
|
||||||
{
|
|
||||||
ip = "*";
|
|
||||||
port = 8092;
|
|
||||||
}
|
|
||||||
|
|
||||||
];
|
|
||||||
documentRoot = "${vars.services}/great_cloud_of_witnesses";
|
|
||||||
extraConfig = ''
|
|
||||||
<Directory "${vars.services}/great_cloud_of_witnesses">
|
|
||||||
AllowOverride All
|
|
||||||
Require all granted
|
|
||||||
</Directory>
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
sops.secrets.gcw_password = {
|
|
||||||
sopsFile = ../../../users/secrets.yaml;
|
|
||||||
neededForUsers = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
users = {
|
|
||||||
users.gcw = {
|
|
||||||
isSystemUser = true;
|
|
||||||
hashedPasswordFile = config.sops.secrets.gcw_password.path;
|
|
||||||
group = "gcw";
|
|
||||||
};
|
|
||||||
groups.gcw = { };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
networking.firewall = {
|
|
||||||
allowedTCPPorts = [
|
|
||||||
6882
|
|
||||||
8081
|
|
||||||
8118
|
|
||||||
];
|
|
||||||
allowedUDPPorts = [ 6882 ];
|
|
||||||
};
|
|
||||||
virtualisation.oci-containers.containers.qbitvpn = {
|
|
||||||
image = "binhex/arch-qbittorrentvpn:5.0.3-1-01";
|
|
||||||
devices = [ "/dev/net/tun:/dev/net/tun" ];
|
|
||||||
extraOptions = [ "--cap-add=NET_ADMIN" ];
|
|
||||||
ports = [
|
|
||||||
"6882:6881"
|
|
||||||
"6882:6881/udp"
|
|
||||||
"8081:8081"
|
|
||||||
"8118:8118"
|
|
||||||
];
|
|
||||||
volumes = [
|
|
||||||
"${vars.docker_configs}/qbitvpn:/config"
|
|
||||||
"${vars.qbitvpn}:/data"
|
|
||||||
"${vars.qbitvpn_scratch}:/data/incomplete"
|
|
||||||
"/etc/localtime:/etc/localtime:ro"
|
|
||||||
];
|
|
||||||
environment = {
|
|
||||||
WEBUI_PORT = "8081";
|
|
||||||
PUID = "600";
|
|
||||||
PGID = "100";
|
|
||||||
VPN_ENABLED = "yes";
|
|
||||||
VPN_CLIENT = "openvpn";
|
|
||||||
STRICT_PORT_FORWARD = "yes";
|
|
||||||
ENABLE_PRIVOXY = "yes";
|
|
||||||
LAN_NETWORK = "192.168.90.0/24";
|
|
||||||
NAME_SERVERS = "1.1.1.1,1.0.0.1";
|
|
||||||
UMASK = "000";
|
|
||||||
DEBUG = "false";
|
|
||||||
DELUGE_DAEMON_LOG_LEVEL = "debug";
|
|
||||||
DELUGE_WEB_LOG_LEVEL = "debug";
|
|
||||||
};
|
|
||||||
environmentFiles = [ "${vars.secrets}/docker/qbitvpn" ];
|
|
||||||
autoStart = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -61,31 +61,7 @@ in
|
|||||||
"luks-root-pool-wwn-0x55cd2e4150f01556-part2" =
|
"luks-root-pool-wwn-0x55cd2e4150f01556-part2" =
|
||||||
makeLuksSSD "/dev/disk/by-id/wwn-0x55cd2e4150f01556-part2";
|
makeLuksSSD "/dev/disk/by-id/wwn-0x55cd2e4150f01556-part2";
|
||||||
|
|
||||||
# Media pool
|
|
||||||
"luks-media_pool-nvme-INTEL_SSDPEK1A118GA_BTOC14120V2J118B-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPEK1A118GA_BTOC14120V2J118B-part1";
|
|
||||||
"luks-media_pool-nvme-INTEL_SSDPEK1A118GA_BTOC14120WAG118B-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPEK1A118GA_BTOC14120WAG118B-part1";
|
|
||||||
"luks-media_pool-nvme-INTEL_SSDPE2ME012T4_CVMD5130000G1P2HGN-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPE2ME012T4_CVMD5130000G1P2HGN-part1";
|
|
||||||
"luks-media_pool-nvme-INTEL_SSDPE2ME012T4_CVMD5130000U1P2HGN-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPE2ME012T4_CVMD5130000U1P2HGN-part1";
|
|
||||||
|
|
||||||
# Scratch pool
|
|
||||||
"luks-scratch-pool-ata-CT480BX500SSD1_2314E6C3C01C-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/ata-CT480BX500SSD1_2314E6C3C01C-part1";
|
|
||||||
"luks-scratch-pool-ata-CT480BX500SSD1_2314E6C3C01E-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/ata-CT480BX500SSD1_2314E6C3C01E-part1";
|
|
||||||
|
|
||||||
# Storage pool
|
# Storage pool
|
||||||
"luks-storage_pool-nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834822N-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834822N-part1";
|
|
||||||
"luks-storage_pool-nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834817F-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834817F-part1";
|
|
||||||
"luks-storage_pool-nvme-INTEL_MEMPEK1W016GA_PHBT828104DF016D-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_MEMPEK1W016GA_PHBT828104DF016D-part1";
|
|
||||||
"luks-storage_pool-nvme-INTEL_MEMPEK1W016GA_PHBT828105A8016D-part1" =
|
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_MEMPEK1W016GA_PHBT828105A8016D-part1";
|
|
||||||
"luks-storage_pool-wwn-0x5000cca23bc438dd-part1" =
|
"luks-storage_pool-wwn-0x5000cca23bc438dd-part1" =
|
||||||
makeLuksDevice "/dev/disk/by-id/wwn-0x5000cca23bc438dd-part1";
|
makeLuksDevice "/dev/disk/by-id/wwn-0x5000cca23bc438dd-part1";
|
||||||
"luks-storage_pool-wwn-0x5000cca23bd035f5-part1" =
|
"luks-storage_pool-wwn-0x5000cca23bd035f5-part1" =
|
||||||
|
|||||||
@@ -2,31 +2,71 @@
|
|||||||
networking = {
|
networking = {
|
||||||
hostName = "jeeves";
|
hostName = "jeeves";
|
||||||
hostId = "0e15ce35";
|
hostId = "0e15ce35";
|
||||||
firewall.enable = true;
|
firewall = {
|
||||||
|
enable = true;
|
||||||
|
interfaces.br-nix-builder = {
|
||||||
|
allowedTCPPorts = [ ];
|
||||||
|
allowedUDPPorts = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
useNetworkd = true;
|
useNetworkd = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.network = {
|
systemd.network = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
wait-online = {
|
||||||
|
enable = false;
|
||||||
|
anyInterface = true;
|
||||||
|
};
|
||||||
|
netdevs = {
|
||||||
|
"20-br-nix-builder" = {
|
||||||
|
netdevConfig = {
|
||||||
|
Kind = "bridge";
|
||||||
|
Name = "br-nix-builder";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
"30-internet-vlan" = {
|
||||||
|
netdevConfig = {
|
||||||
|
Kind = "vlan";
|
||||||
|
Name = "internet-vlan";
|
||||||
|
};
|
||||||
|
vlanConfig.Id = 100;
|
||||||
|
};
|
||||||
|
};
|
||||||
networks = {
|
networks = {
|
||||||
"10-1GB_Primary" = {
|
"10-1GB_Primary" = {
|
||||||
matchConfig.Name = "enp98s0f0";
|
matchConfig.Name = "enp97s0f1";
|
||||||
address = [ "192.168.99.14/24" ];
|
address = [ "192.168.99.14/24" ];
|
||||||
routes = [ { Gateway = "192.168.99.1"; } ];
|
routes = [ { Gateway = "192.168.99.1"; } ];
|
||||||
|
vlan = [ "internet-vlan" ];
|
||||||
linkConfig.RequiredForOnline = "routable";
|
linkConfig.RequiredForOnline = "routable";
|
||||||
};
|
};
|
||||||
"10-1GB_Secondary" = {
|
"50-internet-vlan" = {
|
||||||
matchConfig.Name = "enp98s0f1";
|
matchConfig.Name = "internet-vlan";
|
||||||
DHCP = "yes";
|
bridge = [ "br-nix-builder" ];
|
||||||
|
linkConfig.RequiredForOnline = "no";
|
||||||
};
|
};
|
||||||
"10-10GB_Primary" = {
|
"60-br-nix-builder" = {
|
||||||
matchConfig.Name = "enp97s0f0np0";
|
matchConfig.Name = "br-nix-builder";
|
||||||
DHCP = "yes";
|
bridgeConfig = { };
|
||||||
linkConfig.RequiredForOnline = "routable";
|
address = [ "192.168.3.10/24" ];
|
||||||
};
|
routingPolicyRules = [
|
||||||
"10-10GB_Secondary" = {
|
{
|
||||||
matchConfig.Name = "enp97s0f1np1";
|
From = "192.168.3.0/24";
|
||||||
DHCP = "yes";
|
Table = 100;
|
||||||
|
Priority = 100;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
routes = [
|
||||||
|
{
|
||||||
|
Gateway = "192.168.3.1";
|
||||||
|
Table = 100;
|
||||||
|
GatewayOnLink = false;
|
||||||
|
Metric = 2048;
|
||||||
|
PreferredSource = "192.168.3.10";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
linkConfig.RequiredForOnline = "no";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
nixpkgs.config.cudaSupport = true;
|
|
||||||
|
|
||||||
services.xserver.videoDrivers = [ "nvidia" ];
|
|
||||||
hardware = {
|
|
||||||
nvidia = {
|
|
||||||
modesetting.enable = true;
|
|
||||||
powerManagement.enable = true;
|
|
||||||
package = config.boot.kernelPackages.nvidiaPackages.beta;
|
|
||||||
nvidiaSettings = true;
|
|
||||||
open = false;
|
|
||||||
};
|
|
||||||
nvidia-container-toolkit.enable = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -16,11 +16,20 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
services.nix_builder.containers = {
|
services.nix_builder.containers = {
|
||||||
nix-builder-0.enable = true;
|
nix-builder-00.enable = true;
|
||||||
nix-builder-1.enable = true;
|
nix-builder-01.enable = true;
|
||||||
nix-builder-2.enable = true;
|
nix-builder-02.enable = true;
|
||||||
nix-builder-3.enable = true;
|
nix-builder-03.enable = true;
|
||||||
nix-builder-4.enable = true;
|
nix-builder-04.enable = true;
|
||||||
nix-builder-5.enable = true;
|
nix-builder-05.enable = true;
|
||||||
|
nix-builder-06.enable = true;
|
||||||
|
nix-builder-07.enable = true;
|
||||||
|
nix-builder-08.enable = true;
|
||||||
|
nix-builder-09.enable = true;
|
||||||
|
nix-builder-10.enable = true;
|
||||||
|
nix-builder-11.enable = true;
|
||||||
|
nix-builder-12.enable = true;
|
||||||
|
nix-builder-13.enable = true;
|
||||||
|
nix-builder-14.enable = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,106 +6,130 @@
|
|||||||
}:
|
}:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
vars = import ../vars.nix;
|
vars = import ../vars.nix;
|
||||||
|
cfg = config.services.nix_builder;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.nix_builder.containers = mkOption {
|
options.services.nix_builder = {
|
||||||
type = types.attrsOf (
|
bridgeName = mkOption {
|
||||||
types.submodule (
|
type = types.str;
|
||||||
{ name, ... }:
|
default = "br-nix-builder";
|
||||||
{
|
description = "Bridge name for the builder containers.";
|
||||||
options.enable = mkEnableOption "GitHub runner container";
|
};
|
||||||
}
|
|
||||||
)
|
containers = mkOption {
|
||||||
);
|
type = types.attrsOf (
|
||||||
default = { };
|
types.submodule (
|
||||||
description = "GitHub runner container configurations";
|
{ name, ... }:
|
||||||
|
{
|
||||||
|
options.enable = mkEnableOption "GitHub runner container";
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
|
description = "GitHub runner container configurations";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config.containers = mapAttrs (
|
config = {
|
||||||
name: cfg:
|
containers = mapAttrs (
|
||||||
mkIf cfg.enable {
|
name: containerCfg:
|
||||||
autoStart = true;
|
mkIf containerCfg.enable {
|
||||||
bindMounts = {
|
autoStart = true;
|
||||||
"/storage" = {
|
privateNetwork = true;
|
||||||
mountPoint = "/zfs/media/github-runners/${name}";
|
hostBridge = cfg.bridgeName;
|
||||||
isReadOnly = false;
|
ephemeral = true;
|
||||||
|
bindMounts = {
|
||||||
|
storage = {
|
||||||
|
hostPath = "/zfs/media/github-runners/${name}";
|
||||||
|
mountPoint = "/zfs/media/github-runners/${name}";
|
||||||
|
isReadOnly = false;
|
||||||
|
};
|
||||||
|
host-nix = {
|
||||||
|
mountPoint = "/host-nix/var/nix/daemon-socket";
|
||||||
|
hostPath = "/nix/var/nix/daemon-socket";
|
||||||
|
isReadOnly = false;
|
||||||
|
};
|
||||||
|
pat = {
|
||||||
|
hostPath = "${vars.secrets}/services/github-runners/runner_pat";
|
||||||
|
mountPoint = "${vars.secrets}/services/github-runners/runner_pat";
|
||||||
|
isReadOnly = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
"/secrets".mountPoint = "${vars.secrets}/services/github-runners/${name}";
|
config =
|
||||||
"ssh-keys".mountPoint = "${vars.secrets}/services/github-runners/id_ed25519_github-runners";
|
{
|
||||||
};
|
config,
|
||||||
config =
|
pkgs,
|
||||||
{
|
lib,
|
||||||
config,
|
...
|
||||||
pkgs,
|
}:
|
||||||
lib,
|
{
|
||||||
...
|
networking = {
|
||||||
}:
|
useDHCP = lib.mkDefault true;
|
||||||
{
|
interfaces.eth0.useDHCP = true;
|
||||||
nix.settings = {
|
# Ensure containers don't inherit the host's stub resolver (127.0.0.53) which was causing issues
|
||||||
trusted-substituters = [
|
useHostResolvConf = false;
|
||||||
"https://cache.nixos.org"
|
|
||||||
"https://cache.tmmworkshop.com"
|
|
||||||
"https://nix-community.cachix.org"
|
|
||||||
];
|
|
||||||
substituters = [
|
|
||||||
"https://cache.nixos.org/?priority=2&want-mass-query=true"
|
|
||||||
"https://cache.tmmworkshop.com/?priority=2&want-mass-query=true"
|
|
||||||
"https://nix-community.cachix.org/?priority=10&want-mass-query=true"
|
|
||||||
];
|
|
||||||
trusted-public-keys = [
|
|
||||||
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
|
||||||
"cache.tmmworkshop.com:jHffkpgbmEdstQPoihJPYW9TQe6jnQbWR2LqkNGV3iA="
|
|
||||||
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
|
||||||
];
|
|
||||||
experimental-features = [
|
|
||||||
"flakes"
|
|
||||||
"nix-command"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
programs.ssh.extraConfig = ''
|
|
||||||
Host jeeves
|
|
||||||
Port 629
|
|
||||||
User github-runners
|
|
||||||
HostName jeeves
|
|
||||||
IdentityFile ${vars.secrets}/services/github-runners/id_ed25519_github-runners
|
|
||||||
StrictHostKeyChecking no
|
|
||||||
UserKnownHostsFile /dev/null
|
|
||||||
'';
|
|
||||||
nixpkgs = {
|
|
||||||
overlays = builtins.attrValues outputs.overlays;
|
|
||||||
config.allowUnfree = true;
|
|
||||||
};
|
|
||||||
services.github-runners.${name} = {
|
|
||||||
enable = true;
|
|
||||||
replace = true;
|
|
||||||
workDir = "/zfs/media/github-runners/${name}";
|
|
||||||
url = "https://github.com/RichieCahill/dotfiles";
|
|
||||||
extraLabels = [ "nixos" ];
|
|
||||||
tokenFile = "${vars.secrets}/services/github-runners/${name}";
|
|
||||||
user = "github-runners";
|
|
||||||
group = "github-runners";
|
|
||||||
extraPackages = with pkgs; [
|
|
||||||
nixfmt-rfc-style
|
|
||||||
nixos-rebuild
|
|
||||||
openssh
|
|
||||||
treefmt
|
|
||||||
my_python
|
|
||||||
];
|
|
||||||
};
|
|
||||||
users = {
|
|
||||||
users.github-runners = {
|
|
||||||
shell = pkgs.bash;
|
|
||||||
isSystemUser = true;
|
|
||||||
group = "github-runners";
|
|
||||||
uid = 601;
|
|
||||||
};
|
};
|
||||||
groups.github-runners.gid = 601;
|
nix.settings = {
|
||||||
|
trusted-substituters = [
|
||||||
|
"https://cache.nixos.org"
|
||||||
|
"https://cache.tmmworkshop.com"
|
||||||
|
"https://nix-community.cachix.org"
|
||||||
|
];
|
||||||
|
substituters = [
|
||||||
|
"https://cache.nixos.org/?priority=2&want-mass-query=true"
|
||||||
|
"https://cache.tmmworkshop.com/?priority=2&want-mass-query=true"
|
||||||
|
"https://nix-community.cachix.org/?priority=10&want-mass-query=true"
|
||||||
|
];
|
||||||
|
trusted-public-keys = [
|
||||||
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||||
|
"cache.tmmworkshop.com:jHffkpgbmEdstQPoihJPYW9TQe6jnQbWR2LqkNGV3iA="
|
||||||
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
|
];
|
||||||
|
experimental-features = [
|
||||||
|
"flakes"
|
||||||
|
"nix-command"
|
||||||
|
];
|
||||||
|
sandbox = true;
|
||||||
|
allowed-users = [ "github-runners" ];
|
||||||
|
trusted-users = [
|
||||||
|
"root"
|
||||||
|
"github-runners"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
nixpkgs = {
|
||||||
|
overlays = builtins.attrValues outputs.overlays;
|
||||||
|
config.allowUnfree = true;
|
||||||
|
};
|
||||||
|
services.github-runners.${name} = {
|
||||||
|
enable = true;
|
||||||
|
replace = true;
|
||||||
|
workDir = "/zfs/media/github-runners/${name}";
|
||||||
|
url = "https://github.com/RichieCahill/dotfiles";
|
||||||
|
extraLabels = [ "nixos" ];
|
||||||
|
tokenFile = "${vars.secrets}/services/github-runners/runner_pat";
|
||||||
|
user = "github-runners";
|
||||||
|
group = "github-runners";
|
||||||
|
extraPackages = with pkgs; [
|
||||||
|
nixfmt-rfc-style
|
||||||
|
nixos-rebuild
|
||||||
|
treefmt
|
||||||
|
my_python
|
||||||
|
];
|
||||||
|
};
|
||||||
|
users = {
|
||||||
|
users.github-runners = {
|
||||||
|
shell = pkgs.bash;
|
||||||
|
isSystemUser = true;
|
||||||
|
group = "github-runners";
|
||||||
|
uid = 601;
|
||||||
|
};
|
||||||
|
groups.github-runners.gid = 601;
|
||||||
|
};
|
||||||
|
system.stateVersion = "24.05";
|
||||||
};
|
};
|
||||||
system.stateVersion = "24.11";
|
}
|
||||||
};
|
) cfg.containers;
|
||||||
}
|
};
|
||||||
) config.services.nix_builder.containers;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,31 +12,30 @@ sudo zpool add storage -o ashift=12 special mirror
|
|||||||
sudo zpool add storage -o ashift=12 logs mirror
|
sudo zpool add storage -o ashift=12 logs mirror
|
||||||
|
|
||||||
# scratch
|
# scratch
|
||||||
sudo zpool create -o ashift=12 -O acltype=posixacl -O atime=off -O dnodesize=auto -O xattr=sa -O compression=zstd -m /zfs/scratch scratch
|
sudo zpool create scratch -o ashift=12 -O acltype=posixacl -O atime=off -O dnodesize=auto -O xattr=sa -O compression=zstd -O encryption=aes-256-gcm -O keyformat=hex -O keylocation=file:///key -m /zfs/scratch
|
||||||
|
|
||||||
# media datasets
|
# media datasets
|
||||||
sudo zfs create -o compression=zstd-9 media/docker
|
sudo zfs create media/secure -o encryption=aes-256-gcm -o keyformat=hex -o keylocation=file:///root/zfs.key
|
||||||
sudo zfs create -o compression=zstd-9 -o sync=disabled media/github-runners
|
sudo zfs create media/secure/docker -o compression=zstd-9
|
||||||
sudo zfs create -o copies=3 media/notes
|
sudo zfs create media/secure/github-runners -o compression=zstd-9 -o sync=disabled
|
||||||
sudo zfs create -o compression=zstd-9 media/plex
|
sudo zfs create media/secure/home_assistant -o compression=zstd-19
|
||||||
sudo zfs create -o compression=zstd-9 media/services
|
sudo zfs create media/secure/notes -o copies=2
|
||||||
sudo zfs create -o compression=zstd-19 media/home_assistant
|
sudo zfs create media/secure/postgres -o recordsize=16k -o primarycache=metadata
|
||||||
sudo zfs create -o exec=off media/share
|
sudo zfs create media/secure/services -o compression=zstd-9
|
||||||
sudo zfs create -o recordsize=16k -o primarycache=metadata -o mountpoint=/zfs/media/database/postgres media/postgres
|
sudo zfs create media/secure/share -o mountpoint=/zfs/media/share -o exec=off
|
||||||
|
|
||||||
# scratch datasets
|
# scratch datasets
|
||||||
sudo zfs create -o recordsize=16k -o sync=disabled scratch/qbitvpn
|
sudo zfs create scratch/kafka -o mountpoint=/zfs/scratch/kafka -o recordsize=1M
|
||||||
sudo zfs create -o recordsize=16k -o sync=disabled scratch/transmission
|
sudo zfs create scratch/transmission -o mountpoint=/zfs/scratch/transmission -o recordsize=16k -o sync=disabled
|
||||||
sudo zfs create -o recordsize=1M scratch/kafka
|
|
||||||
|
|
||||||
# storage datasets
|
# storage datasets
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 storage/archive
|
sudo zfs create storage/ollama -o recordsize=1M -o compression=zstd-19 -o sync=disabled
|
||||||
sudo zfs create -o compression=zstd-19 storage/main
|
sudo zfs create storage/secure -o encryption=aes-256-gcm -o keyformat=hex -o keylocation=file:///root/zfs.key
|
||||||
sudo zfs create -o recordsize=16K -o compression=zstd-19 -o copies=2 storage/photos
|
sudo zfs create storage/secure/archive -o recordsize=1M -o compression=zstd-19
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 storage/plex
|
sudo zfs create storage/secure/library -o recordsize=1M -o compression=zstd-19
|
||||||
sudo zfs create -o compression=zstd-19 -o copies=3 storage/secrets
|
sudo zfs create storage/secure/main -o compression=zstd-19
|
||||||
sudo zfs create -o compression=zstd-19 storage/syncthing
|
sudo zfs create storage/secure/photos -o recordsize=16K -o compression=zstd-19 -o copies=2
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-9 -o exec=off -o sync=disabled storage/qbitvpn
|
sudo zfs create storage/secure/plex -o recordsize=1M -o compression=zstd-19
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-9 -o exec=off -o sync=disabled storage/transmission
|
sudo zfs create storage/secure/secrets -o compression=zstd-19 -o copies=3
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 storage/library
|
sudo zfs create storage/secure/syncthing -o compression=zstd-19
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 -o sync=disabled storage/ollama
|
sudo zfs create storage/secure/transmission -o recordsize=1M -o compression=zstd-9 -o exec=off -o sync=disabled
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
systemd.services.filebrowser = {
|
|
||||||
description = "filebrowser";
|
|
||||||
after = [ "network.target" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "simple";
|
|
||||||
User = "richie";
|
|
||||||
Group = "users";
|
|
||||||
ExecStart = "${pkgs.filebrowser}/bin/filebrowser --root=/zfs --address=0.0.0.0 --database=${vars.docker_configs}/filebrowser/filebrowser.db";
|
|
||||||
Restart = "on-failure";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
46
systems/jeeves/services/gitea.nix
Normal file
46
systems/jeeves/services/gitea.nix
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
networking.firewall.allowedTCPPorts = [ 6443 ];
|
||||||
|
|
||||||
|
services.gitea = {
|
||||||
|
enable = true;
|
||||||
|
appName = "TMM Workshop";
|
||||||
|
stateDir = "${vars.services}/gitea/";
|
||||||
|
lfs.enable = true;
|
||||||
|
database = {
|
||||||
|
type = "postgres";
|
||||||
|
name = "gitea";
|
||||||
|
user = "gitea";
|
||||||
|
socket = "/run/postgresql";
|
||||||
|
port = 5432;
|
||||||
|
createDatabase = false;
|
||||||
|
};
|
||||||
|
settings = {
|
||||||
|
service.DISABLE_REGISTRATION = true;
|
||||||
|
server = {
|
||||||
|
DOMAIN = "tmmworkshop.com";
|
||||||
|
ROOT_URL = "https://gitea.tmmworkshop.com/";
|
||||||
|
HTTP_PORT = 6443;
|
||||||
|
SSH_PORT = 2223;
|
||||||
|
SSH_LISTEN_PORT = 2224;
|
||||||
|
START_SSH_SERVER = true;
|
||||||
|
PUBLIC_URL_DETECTION = "auto";
|
||||||
|
};
|
||||||
|
repository = {
|
||||||
|
ENABLE_PUSH_CREATE_USER = true;
|
||||||
|
DEFAULT_MERGE_STYLE = "rebase-merge";
|
||||||
|
};
|
||||||
|
log = {
|
||||||
|
LEVEL = "Trace";
|
||||||
|
ENABLE_SSH_LOG = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.gitea = {
|
||||||
|
requires = [ "docker.service" ];
|
||||||
|
after = [ "docker.service" ];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -27,21 +27,21 @@ frontend ContentSwitching
|
|||||||
# tmmworkshop.com
|
# tmmworkshop.com
|
||||||
acl host_audiobookshelf hdr(host) -i audiobookshelf.tmmworkshop.com
|
acl host_audiobookshelf hdr(host) -i audiobookshelf.tmmworkshop.com
|
||||||
acl host_cache hdr(host) -i cache.tmmworkshop.com
|
acl host_cache hdr(host) -i cache.tmmworkshop.com
|
||||||
acl host_filebrowser hdr(host) -i filebrowser.tmmworkshop.com
|
|
||||||
acl host_homeassistant hdr(host) -i homeassistant.tmmworkshop.com
|
acl host_homeassistant hdr(host) -i homeassistant.tmmworkshop.com
|
||||||
acl host_jellyfin hdr(host) -i jellyfin.tmmworkshop.com
|
acl host_jellyfin hdr(host) -i jellyfin.tmmworkshop.com
|
||||||
acl host_share hdr(host) -i share.tmmworkshop.com
|
acl host_share hdr(host) -i share.tmmworkshop.com
|
||||||
acl host_gcw hdr(host) -i gcw.tmmworkshop.com
|
acl host_gcw hdr(host) -i gcw.tmmworkshop.com
|
||||||
acl host_n8n hdr(host) -i n8n.tmmworkshop.com
|
acl host_n8n hdr(host) -i n8n.tmmworkshop.com
|
||||||
|
acl host_gitea hdr(host) -i gitea.tmmworkshop.com
|
||||||
|
|
||||||
use_backend audiobookshelf_nodes if host_audiobookshelf
|
use_backend audiobookshelf_nodes if host_audiobookshelf
|
||||||
use_backend cache_nodes if host_cache
|
use_backend cache_nodes if host_cache
|
||||||
use_backend filebrowser_nodes if host_filebrowser
|
|
||||||
use_backend homeassistant_nodes if host_homeassistant
|
use_backend homeassistant_nodes if host_homeassistant
|
||||||
use_backend jellyfin if host_jellyfin
|
use_backend jellyfin if host_jellyfin
|
||||||
use_backend share_nodes if host_share
|
use_backend share_nodes if host_share
|
||||||
use_backend gcw_nodes if host_gcw
|
use_backend gcw_nodes if host_gcw
|
||||||
use_backend n8n if host_n8n
|
use_backend n8n if host_n8n
|
||||||
|
use_backend gitea if host_gitea
|
||||||
|
|
||||||
backend audiobookshelf_nodes
|
backend audiobookshelf_nodes
|
||||||
mode http
|
mode http
|
||||||
@@ -51,10 +51,6 @@ backend cache_nodes
|
|||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:5000
|
server server 127.0.0.1:5000
|
||||||
|
|
||||||
backend filebrowser_nodes
|
|
||||||
mode http
|
|
||||||
server server 127.0.0.1:8080
|
|
||||||
|
|
||||||
backend homeassistant_nodes
|
backend homeassistant_nodes
|
||||||
mode http
|
mode http
|
||||||
server server 192.168.90.35:8123
|
server server 192.168.90.35:8123
|
||||||
@@ -77,3 +73,7 @@ backend gcw_nodes
|
|||||||
backend n8n
|
backend n8n
|
||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:5678
|
server server 127.0.0.1:5678
|
||||||
|
|
||||||
|
backend gitea
|
||||||
|
mode http
|
||||||
|
server server 127.0.0.1:6443
|
||||||
@@ -68,7 +68,7 @@ in
|
|||||||
jellyfin-apiclient-python
|
jellyfin-apiclient-python
|
||||||
psycopg2
|
psycopg2
|
||||||
pymetno
|
pymetno
|
||||||
pyownet
|
aio-ownet
|
||||||
rokuecp
|
rokuecp
|
||||||
uiprotect
|
uiprotect
|
||||||
wakeonlan
|
wakeonlan
|
||||||
|
|||||||
@@ -9,13 +9,25 @@ in
|
|||||||
host = "0.0.0.0";
|
host = "0.0.0.0";
|
||||||
loadModels = [
|
loadModels = [
|
||||||
"codellama:7b"
|
"codellama:7b"
|
||||||
|
"deepscaler:1.5b"
|
||||||
"deepseek-r1:14b"
|
"deepseek-r1:14b"
|
||||||
"deepseek-r1:32b"
|
"deepseek-r1:32b"
|
||||||
"deepseek-r1:8b"
|
"deepseek-r1:8b"
|
||||||
|
"devstral-small-2:24b"
|
||||||
|
"functiongemma:270m"
|
||||||
"gemma3:12b"
|
"gemma3:12b"
|
||||||
"gemma3:27b"
|
"gemma3:27b"
|
||||||
"gpt-oss:120b"
|
"gpt-oss:120b"
|
||||||
"gpt-oss:20b"
|
"gpt-oss:20b"
|
||||||
|
"llama3.1:70b"
|
||||||
|
"llama3.1:8b"
|
||||||
|
"llama3.2:1b"
|
||||||
|
"llama3.2:3b"
|
||||||
|
"magistral:24b"
|
||||||
|
"ministral-3:14b"
|
||||||
|
"nemotron-3-nano:30b"
|
||||||
|
"qwen3-coder:30b"
|
||||||
|
"qwen3-vl:32b"
|
||||||
"qwen3:14b"
|
"qwen3:14b"
|
||||||
"qwen3:30b"
|
"qwen3:30b"
|
||||||
];
|
];
|
||||||
|
|||||||
16
systems/jeeves/services/open_webui.nix
Normal file
16
systems/jeeves/services/open_webui.nix
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
services.open-webui = {
|
||||||
|
stateDir = "${vars.services}/open_webui/";
|
||||||
|
enable = true;
|
||||||
|
openFirewall = true;
|
||||||
|
environment = {
|
||||||
|
ANONYMIZED_TELEMETRY = "False";
|
||||||
|
DO_NOT_TRACK = "True";
|
||||||
|
SCARF_NO_ANALYTICS = "True";
|
||||||
|
OLLAMA_API_BASE_URL = "http://127.0.0.1:11434";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -28,25 +28,7 @@ in
|
|||||||
|
|
||||||
#type database DBuser origin-address auth-method
|
#type database DBuser origin-address auth-method
|
||||||
local hass hass trust
|
local hass hass trust
|
||||||
|
local gitea gitea trust
|
||||||
# ipv4
|
|
||||||
host hass hass 192.168.90.1/24 trust
|
|
||||||
host hass hass 127.0.0.1/32 trust
|
|
||||||
|
|
||||||
# ipv6
|
|
||||||
host hass hass ::1/128 trust
|
|
||||||
|
|
||||||
# megan
|
|
||||||
host megan megan 192.168.90.1/24 trust
|
|
||||||
host megan megan 127.0.0.1/32 trust
|
|
||||||
|
|
||||||
host gcw megan 192.168.90.1/24 trust
|
|
||||||
host gcw megan 127.0.0.1/32 trust
|
|
||||||
|
|
||||||
# gcw
|
|
||||||
local gcw gcw trust
|
|
||||||
host gcw gcw 192.168.90.1/24 trust
|
|
||||||
host gcw gcw 127.0.0.1/32 trust
|
|
||||||
|
|
||||||
# math
|
# math
|
||||||
local postgres math trust
|
local postgres math trust
|
||||||
@@ -97,17 +79,7 @@ in
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "megan";
|
name = "gitea";
|
||||||
ensureDBOwnership = true;
|
|
||||||
ensureClauses = {
|
|
||||||
login = true;
|
|
||||||
createrole = true;
|
|
||||||
createdb = true;
|
|
||||||
replication = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "gcw";
|
|
||||||
ensureDBOwnership = true;
|
ensureDBOwnership = true;
|
||||||
ensureClauses = {
|
ensureClauses = {
|
||||||
login = true;
|
login = true;
|
||||||
@@ -128,12 +100,9 @@ in
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
ensureDatabases = [
|
ensureDatabases = [
|
||||||
"gcw"
|
|
||||||
"hass"
|
"hass"
|
||||||
|
"gitea"
|
||||||
"math"
|
"math"
|
||||||
"megan"
|
|
||||||
"mxr_dev"
|
|
||||||
"mxr_prod"
|
|
||||||
"n8n"
|
"n8n"
|
||||||
"richie"
|
"richie"
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
inputs,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
|
inputs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@@ -22,10 +22,13 @@ in
|
|||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
description = "validates startup";
|
description = "validates startup";
|
||||||
path = [ pkgs.zfs ];
|
path = [ pkgs.zfs ];
|
||||||
|
environment = {
|
||||||
|
PYTHONPATH = "${inputs.self}/";
|
||||||
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
EnvironmentFile = "${vars.secrets}/services/server-validation";
|
EnvironmentFile = "${vars.secrets}/services/server-validation";
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "${inputs.system_tools.packages.x86_64-linux.default}/bin/validate_system '${./validate_system.toml}'";
|
ExecStart = "${pkgs.my_python}/bin/python -m python.system_tests.validate_system '${./validate_system.toml}'";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ services = [
|
|||||||
"audiobookshelf",
|
"audiobookshelf",
|
||||||
"cloud_flare_tunnel",
|
"cloud_flare_tunnel",
|
||||||
"haproxy",
|
"haproxy",
|
||||||
"docker-qbitvpn",
|
|
||||||
"docker",
|
"docker",
|
||||||
"filebrowser",
|
|
||||||
"home-assistant",
|
"home-assistant",
|
||||||
"jellyfin",
|
"jellyfin",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -64,24 +64,12 @@ hourly = 12
|
|||||||
daily = 14
|
daily = 14
|
||||||
monthly = 2
|
monthly = 2
|
||||||
|
|
||||||
["scratch/qbitvpn"]
|
|
||||||
15_min = 0
|
|
||||||
hourly = 0
|
|
||||||
daily = 0
|
|
||||||
monthly = 0
|
|
||||||
|
|
||||||
["scratch/transmission"]
|
["scratch/transmission"]
|
||||||
15_min = 0
|
15_min = 0
|
||||||
hourly = 0
|
hourly = 0
|
||||||
daily = 0
|
daily = 0
|
||||||
monthly = 0
|
monthly = 0
|
||||||
|
|
||||||
["storage/qbitvpn"]
|
|
||||||
15_min = 0
|
|
||||||
hourly = 0
|
|
||||||
daily = 0
|
|
||||||
monthly = 0
|
|
||||||
|
|
||||||
["storage/transmission"]
|
["storage/transmission"]
|
||||||
15_min = 0
|
15_min = 0
|
||||||
hourly = 0
|
hourly = 0
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ in
|
|||||||
docker_configs = "${zfs_media}/docker/configs";
|
docker_configs = "${zfs_media}/docker/configs";
|
||||||
home_assistant = "${zfs_media}/home_assistant";
|
home_assistant = "${zfs_media}/home_assistant";
|
||||||
notes = "${zfs_media}/notes";
|
notes = "${zfs_media}/notes";
|
||||||
qbitvpn = "${zfs_storage}/qbitvpn";
|
|
||||||
qbitvpn_scratch = "${zfs_scratch}/qbitvpn";
|
|
||||||
secrets = "${zfs_storage}/secrets";
|
secrets = "${zfs_storage}/secrets";
|
||||||
services = "${zfs_media}/services";
|
services = "${zfs_media}/services";
|
||||||
share = "${zfs_media}/share";
|
share = "${zfs_media}/share";
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{ inputs, ... }:
|
{ inputs, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/elise
|
"${inputs.self}/users/elise"
|
||||||
../../users/richie
|
"${inputs.self}/users/richie"
|
||||||
../../common/global
|
"${inputs.self}/common/global"
|
||||||
../../common/optional/desktop.nix
|
"${inputs.self}/common/optional/desktop.nix"
|
||||||
../../common/optional/steam.nix
|
"${inputs.self}/common/optional/steam.nix"
|
||||||
../../common/optional/systemd-boot.nix
|
"${inputs.self}/common/optional/systemd-boot.nix"
|
||||||
../../common/optional/update.nix
|
"${inputs.self}/common/optional/update.nix"
|
||||||
../../common/optional/zerotier.nix
|
"${inputs.self}/common/optional/zerotier.nix"
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
|
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
{ inputs, ... }:
|
{ inputs, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/richie
|
"${inputs.self}/users/richie"
|
||||||
../../common/global
|
"${inputs.self}/common/global"
|
||||||
../../common/optional/desktop.nix
|
"${inputs.self}/common/optional/desktop.nix"
|
||||||
../../common/optional/docker.nix
|
"${inputs.self}/common/optional/docker.nix"
|
||||||
../../common/optional/steam.nix
|
"${inputs.self}/common/optional/steam.nix"
|
||||||
../../common/optional/syncthing_base.nix
|
"${inputs.self}/common/optional/syncthing_base.nix"
|
||||||
../../common/optional/systemd-boot.nix
|
"${inputs.self}/common/optional/systemd-boot.nix"
|
||||||
../../common/optional/yubikey.nix
|
"${inputs.self}/common/optional/yubikey.nix"
|
||||||
../../common/optional/zerotier.nix
|
"${inputs.self}/common/optional/zerotier.nix"
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
./llms.nix
|
./llms.nix
|
||||||
./syncthing.nix
|
./syncthing.nix
|
||||||
|
./qmk.nix
|
||||||
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
|
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
34
systems/rhapsody-in-green/qmk.nix
Normal file
34
systems/rhapsody-in-green/qmk.nix
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
qmk
|
||||||
|
vial
|
||||||
|
];
|
||||||
|
|
||||||
|
services = {
|
||||||
|
udev = {
|
||||||
|
packages = [ pkgs.qmk-udev-rules ];
|
||||||
|
extraRules = ''
|
||||||
|
# Keychron keyboards
|
||||||
|
KERNEL=="hidraw*", ATTRS{idVendor}=="3434", MODE="0660", GROUP="plugdev"
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="3434", MODE="0660", GROUP="plugdev"
|
||||||
|
|
||||||
|
# Some boards use 32f0 as vendor id
|
||||||
|
KERNEL=="hidraw*", ATTRS{idVendor}=="32f0", MODE="0660", GROUP="plugdev"
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="32f0", MODE="0660", GROUP="plugdev"
|
||||||
|
|
||||||
|
# Keychron HID device permissions
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="3434", MODE="0660", GROUP="plugdev"
|
||||||
|
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="3434", MODE="0660", GROUP="plugdev"
|
||||||
|
KERNEL=="hidraw*", ATTRS{idVendor}=="32f0", MODE="0660", GROUP="plugdev"
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="32f0", MODE="0660", GROUP="plugdev"
|
||||||
|
|
||||||
|
|
||||||
|
# Keychron / QMK common bootloaders
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="df11", MODE="0660", GROUP="plugdev"
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="03eb", MODE="0660", GROUP="plugdev"
|
||||||
|
SUBSYSTEM=="usb", ATTR{idVendor}=="16c0", MODE="0660", GROUP="plugdev"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
258
temp_flake.lock
258
temp_flake.lock
@@ -1,258 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"firefox-addons": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"dir": "pkgs/firefox-addons",
|
|
||||||
"lastModified": 1757649814,
|
|
||||||
"narHash": "sha256-VjtA+fqkraKHbGzjKJBPfDj+SXysXiR4SrghTr10HoY=",
|
|
||||||
"owner": "rycee",
|
|
||||||
"repo": "nur-expressions",
|
|
||||||
"rev": "789920825fc982a93a2bf91a714367fa8f7ea0a6",
|
|
||||||
"type": "gitlab"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"dir": "pkgs/firefox-addons",
|
|
||||||
"owner": "rycee",
|
|
||||||
"repo": "nur-expressions",
|
|
||||||
"type": "gitlab"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"home-manager": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1757698511,
|
|
||||||
"narHash": "sha256-UqHHGydF/q3jfYXCpvYLA0TWtvByOp1NwOKCUjhYmPs=",
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "home-manager",
|
|
||||||
"rev": "a3fcc92180c7462082cd849498369591dfb20855",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "home-manager",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixos-hardware": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1757103352,
|
|
||||||
"narHash": "sha256-PtT7ix43ss8PONJ1VJw3f6t2yAoGH+q462Sn8lrmWmk=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixos-hardware",
|
|
||||||
"rev": "11b2a10c7be726321bb854403fdeec391e798bf0",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "master",
|
|
||||||
"repo": "nixos-hardware",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1757487488,
|
|
||||||
"narHash": "sha256-zwE/e7CuPJUWKdvvTCB7iunV4E/+G0lKfv4kk/5Izdg=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "ab0f3607a6c7486ea22229b92ed2d355f1482ee0",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs-master": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1757720853,
|
|
||||||
"narHash": "sha256-VBS5+YKIT8Aj81ZW+8Bg9MuYoI6OqO6HSrwG4dpHpW4=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "2ca437b4796d049192eb30576a50fef139038c09",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "master",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs-stable": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1735563628,
|
|
||||||
"narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-24.05",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pyproject-build-systems": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"system_tools",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pyproject-nix": [
|
|
||||||
"system_tools",
|
|
||||||
"pyproject-nix"
|
|
||||||
],
|
|
||||||
"uv2nix": [
|
|
||||||
"system_tools",
|
|
||||||
"uv2nix"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1744599653,
|
|
||||||
"narHash": "sha256-nysSwVVjG4hKoOjhjvE6U5lIKA8sEr1d1QzEfZsannU=",
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "build-system-pkgs",
|
|
||||||
"rev": "7dba6dbc73120e15b558754c26024f6c93015dd7",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "build-system-pkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pyproject-nix": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"system_tools",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1746540146,
|
|
||||||
"narHash": "sha256-QxdHGNpbicIrw5t6U3x+ZxeY/7IEJ6lYbvsjXmcxFIM=",
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "pyproject.nix",
|
|
||||||
"rev": "e09c10c24ebb955125fda449939bfba664c467fd",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "pyproject.nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"firefox-addons": "firefox-addons",
|
|
||||||
"home-manager": "home-manager",
|
|
||||||
"nixos-hardware": "nixos-hardware",
|
|
||||||
"nixpkgs": "nixpkgs",
|
|
||||||
"nixpkgs-master": "nixpkgs-master",
|
|
||||||
"nixpkgs-stable": "nixpkgs-stable",
|
|
||||||
"sops-nix": "sops-nix",
|
|
||||||
"system_tools": "system_tools",
|
|
||||||
"systems": "systems"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sops-nix": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1757503115,
|
|
||||||
"narHash": "sha256-S9F6bHUBh+CFEUalv/qxNImRapCxvSnOzWBUZgK1zDU=",
|
|
||||||
"owner": "Mic92",
|
|
||||||
"repo": "sops-nix",
|
|
||||||
"rev": "0bf793823386187dff101ee2a9d4ed26de8bbf8c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "Mic92",
|
|
||||||
"repo": "sops-nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"system_tools": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pyproject-build-systems": "pyproject-build-systems",
|
|
||||||
"pyproject-nix": "pyproject-nix",
|
|
||||||
"uv2nix": "uv2nix"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1757910132,
|
|
||||||
"narHash": "sha256-6r45DD/tMN+hYgnMc2/c82Z0bb1A7FnI/nvU8kZf/Us=",
|
|
||||||
"owner": "RichieCahill",
|
|
||||||
"repo": "system_tools",
|
|
||||||
"rev": "d63c486fe3b76c24b2ed2fff33d6f54c847b50e8",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "RichieCahill",
|
|
||||||
"repo": "system_tools",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"systems": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1689347949,
|
|
||||||
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default-linux",
|
|
||||||
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default-linux",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uv2nix": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"system_tools",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pyproject-nix": [
|
|
||||||
"system_tools",
|
|
||||||
"pyproject-nix"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1747441483,
|
|
||||||
"narHash": "sha256-W8BFXk5R0TuJcjIhcGoMpSOaIufGXpizK0pm+uTqynA=",
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "uv2nix",
|
|
||||||
"rev": "582024dc64663e9f88d467c2f7f7b20d278349de",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "pyproject-nix",
|
|
||||||
"repo": "uv2nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
||||||
67
tests/test_databasse.py
Normal file
67
tests/test_databasse.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
"""test_database."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from sqlalchemy import Integer, String, create_engine, select
|
||||||
|
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column, sessionmaker
|
||||||
|
|
||||||
|
from python.database import safe_insert
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Generator
|
||||||
|
|
||||||
|
|
||||||
|
class TestingBase(DeclarativeBase):
|
||||||
|
"""TestingBase."""
|
||||||
|
|
||||||
|
|
||||||
|
class Item(TestingBase):
|
||||||
|
"""Item."""
|
||||||
|
|
||||||
|
__tablename__ = "items"
|
||||||
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
name: Mapped[str] = mapped_column(String(50), nullable=False, unique=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def session() -> Generator[Session]:
|
||||||
|
"""Fresh in-memory DB + tables for each test."""
|
||||||
|
engine = create_engine("sqlite+pysqlite:///:memory:", echo=False, future=True)
|
||||||
|
TestingBase.metadata.create_all(engine)
|
||||||
|
with sessionmaker(bind=engine, expire_on_commit=False, future=True)() as s:
|
||||||
|
yield s
|
||||||
|
|
||||||
|
|
||||||
|
def test_partial_failure_unique_constraint(session: Session) -> None:
|
||||||
|
"""Duplicate name should fail only for the conflicting row; others commit."""
|
||||||
|
objs = [Item(name="a"), Item(name="b"), Item(name="a"), Item(name="c")]
|
||||||
|
failures = safe_insert(objs, session)
|
||||||
|
|
||||||
|
assert len(failures) == 1
|
||||||
|
exc, failed_obj = failures[0]
|
||||||
|
assert isinstance(exc, Exception)
|
||||||
|
assert isinstance(failed_obj, Item)
|
||||||
|
assert failed_obj.name == "a"
|
||||||
|
|
||||||
|
rows = session.scalars(select(Item.name)).all()
|
||||||
|
assert sorted(rows) == ["a", "b", "c"]
|
||||||
|
assert rows.count("a") == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_all_good_inserts(session: Session) -> None:
|
||||||
|
"""No failures when all rows are valid."""
|
||||||
|
objs = [Item(name="x"), Item(name="y")]
|
||||||
|
failures = safe_insert(objs, session)
|
||||||
|
assert failures == []
|
||||||
|
|
||||||
|
rows = session.scalars(select(Item.name).where(Item.name.in_(("x", "y")))).all()
|
||||||
|
assert sorted(rows) == ["x", "y"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_unmapped_object_raises(session: Session) -> None:
|
||||||
|
"""Non-ORM instances should raise TypeError immediately."""
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
safe_insert([object()], session)
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
{
|
{
|
||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
userEmail = "dov.kruger@gmail.com";
|
settings = {
|
||||||
userName = "Dov Kruger";
|
user = {
|
||||||
extraConfig = {
|
email = "dov.kruger@gmail.com";
|
||||||
|
name = "Dov Kruger";
|
||||||
|
};
|
||||||
pull.rebase = true;
|
pull.rebase = true;
|
||||||
color.ui = true;
|
color.ui = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
{
|
{
|
||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
userEmail = "DumbPuppy208@gmail.com";
|
settings = {
|
||||||
userName = "Elise Corvidae";
|
user = {
|
||||||
extraConfig = {
|
email = "DumbPuppy208@gmail.com";
|
||||||
|
name = "Elise Corvidae";
|
||||||
|
};
|
||||||
pull.rebase = true;
|
pull.rebase = true;
|
||||||
color.ui = true;
|
color.ui = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ pkgs, inputs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
# cli
|
# cli
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
{
|
{
|
||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
userEmail = "matthew.michal11@gmail.com";
|
settings = {
|
||||||
userName = "Matthew Michal";
|
user = {
|
||||||
extraConfig = {
|
email = "matthew.michal11@gmail.com";
|
||||||
|
name = "Matthew Michal";
|
||||||
|
};
|
||||||
pull.rebase = true;
|
pull.rebase = true;
|
||||||
color.ui = true;
|
color.ui = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
sops.secrets.megan_password = {
|
|
||||||
sopsFile = ../secrets.yaml;
|
|
||||||
neededForUsers = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
users = {
|
|
||||||
users.megan = {
|
|
||||||
isNormalUser = true;
|
|
||||||
hashedPasswordFile = "${config.sops.secrets.megan_password.path}";
|
|
||||||
|
|
||||||
shell = pkgs.zsh;
|
|
||||||
group = "megan";
|
|
||||||
extraGroups = [
|
|
||||||
"audio"
|
|
||||||
"video"
|
|
||||||
"users"
|
|
||||||
];
|
|
||||||
uid = 1101;
|
|
||||||
};
|
|
||||||
|
|
||||||
groups.megan.gid = 1101;
|
|
||||||
};
|
|
||||||
home-manager.users.megan = import ./systems/${config.networking.hostName}.nix;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
imports = [
|
|
||||||
./direnv.nix
|
|
||||||
./git.nix
|
|
||||||
./zsh.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
programs.starship.enable = true;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
|
|
||||||
programs.direnv = {
|
|
||||||
enable = true;
|
|
||||||
enableZshIntegration = true;
|
|
||||||
nix-direnv.enable = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
programs.git = {
|
|
||||||
enable = true;
|
|
||||||
userEmail = "mousikos112@gmail.com";
|
|
||||||
userName = "megan";
|
|
||||||
extraConfig = {
|
|
||||||
pull.rebase = true;
|
|
||||||
color.ui = true;
|
|
||||||
};
|
|
||||||
lfs.enable = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
{
|
|
||||||
programs.zsh = {
|
|
||||||
enable = true;
|
|
||||||
syntaxHighlighting.enable = true;
|
|
||||||
history.size = 10000;
|
|
||||||
oh-my-zsh = {
|
|
||||||
enable = true;
|
|
||||||
plugins = [
|
|
||||||
"git"
|
|
||||||
"docker"
|
|
||||||
"docker-compose"
|
|
||||||
"colored-man-pages"
|
|
||||||
"rust"
|
|
||||||
"systemd"
|
|
||||||
"tmux"
|
|
||||||
"ufw"
|
|
||||||
"z"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
shellAliases = {
|
|
||||||
"lrt" = "eza --icons -lsnew";
|
|
||||||
"ls" = "eza";
|
|
||||||
"ll" = "eza --long --group";
|
|
||||||
"la" = "eza --all";
|
|
||||||
|
|
||||||
"rspace" = "'for f in *\ *; do mv \"$f\" \"\${f// /_}\"; done'";
|
|
||||||
"rebuild" = "sudo nixos-rebuild switch --flake /home/richie/dotfiles#$HOST";
|
|
||||||
"nix-test" = "nixos-rebuild test --flake /home/richie/dotfiles";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
./cli
|
|
||||||
./programs.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
programs = {
|
|
||||||
home-manager.enable = true;
|
|
||||||
git.enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
home = {
|
|
||||||
username = "megan";
|
|
||||||
homeDirectory = "/home/${config.home.username}";
|
|
||||||
stateVersion = "24.05";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
home.packages = with pkgs; [
|
|
||||||
# cli
|
|
||||||
bat
|
|
||||||
btop
|
|
||||||
eza
|
|
||||||
fd
|
|
||||||
ffmpegthumbnailer
|
|
||||||
fzf
|
|
||||||
git
|
|
||||||
gnupg
|
|
||||||
imagemagick
|
|
||||||
jq
|
|
||||||
ncdu
|
|
||||||
neofetch
|
|
||||||
ouch
|
|
||||||
p7zip
|
|
||||||
poppler
|
|
||||||
rar
|
|
||||||
ripgrep
|
|
||||||
starship
|
|
||||||
tmux
|
|
||||||
unzip
|
|
||||||
yazi
|
|
||||||
zoxide
|
|
||||||
# system info
|
|
||||||
hwloc
|
|
||||||
lynis
|
|
||||||
pciutils
|
|
||||||
smartmontools
|
|
||||||
usbutils
|
|
||||||
# networking
|
|
||||||
iperf3
|
|
||||||
nmap
|
|
||||||
wget
|
|
||||||
# python
|
|
||||||
poetry
|
|
||||||
ruff
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
imports = [
|
|
||||||
../home/global.nix
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -41,6 +41,7 @@ in
|
|||||||
"scanner"
|
"scanner"
|
||||||
"transmission"
|
"transmission"
|
||||||
"uaccess"
|
"uaccess"
|
||||||
|
"uucp"
|
||||||
"wireshark"
|
"wireshark"
|
||||||
];
|
];
|
||||||
uid = 1000;
|
uid = 1000;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
{
|
{
|
||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
userEmail = "Richie@tmmworkshop.com";
|
settings = {
|
||||||
userName = "Richie Cahill";
|
user = {
|
||||||
extraConfig = {
|
email = "Richie@tmmworkshop.com";
|
||||||
|
name = "Richie Cahill";
|
||||||
|
};
|
||||||
pull.rebase = true;
|
pull.rebase = true;
|
||||||
color.ui = true;
|
color.ui = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,23 +9,25 @@
|
|||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
candy-icons
|
candy-icons
|
||||||
chromium
|
chromium
|
||||||
discord-canary
|
|
||||||
gimp
|
gimp
|
||||||
gparted
|
|
||||||
jetbrains.datagrip
|
|
||||||
mediainfo
|
mediainfo
|
||||||
nemo
|
|
||||||
nemo-fileroller
|
|
||||||
obs-studio
|
obs-studio
|
||||||
obsidian
|
obsidian
|
||||||
prismlauncher
|
prismlauncher
|
||||||
proxychains
|
|
||||||
prusa-slicer
|
prusa-slicer
|
||||||
signal-desktop
|
|
||||||
sweet-nova
|
sweet-nova
|
||||||
util-linux
|
util-linux
|
||||||
vlc
|
vlc
|
||||||
|
# comms
|
||||||
|
discord-canary
|
||||||
|
signal-desktop
|
||||||
zoom-us
|
zoom-us
|
||||||
|
# dev tools
|
||||||
|
claude-code
|
||||||
|
gparted
|
||||||
|
jetbrains.datagrip
|
||||||
|
master.antigravity-fhs
|
||||||
|
proxychains
|
||||||
# games
|
# games
|
||||||
dwarf-fortress
|
dwarf-fortress
|
||||||
tower-pixel-dungeon
|
tower-pixel-dungeon
|
||||||
|
|||||||
@@ -88,5 +88,6 @@
|
|||||||
"redhat.telemetry.enabled": true,
|
"redhat.telemetry.enabled": true,
|
||||||
"gitlens.plusFeatures.enabled": false,
|
"gitlens.plusFeatures.enabled": false,
|
||||||
// new
|
// new
|
||||||
"hediet.vscode-drawio.resizeImages": null
|
"hediet.vscode-drawio.resizeImages": null,
|
||||||
|
"hediet.vscode-drawio.appearance": "automatic"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ pkgs, inputs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
# cli
|
# cli
|
||||||
@@ -58,6 +58,5 @@
|
|||||||
nix-tree
|
nix-tree
|
||||||
nixfmt-rfc-style
|
nixfmt-rfc-style
|
||||||
treefmt
|
treefmt
|
||||||
inputs.system_tools.packages.x86_64-linux.default
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user