mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-21 14:49:10 -04:00
Compare commits
1 Commits
feature/li
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
| c64d8da490 |
10
.github/workflows/build_systems.yml
vendored
10
.github/workflows/build_systems.yml
vendored
@@ -1,11 +1,9 @@
|
|||||||
name: build_systems
|
name: build_jeeves
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
schedule:
|
|
||||||
- cron: "0 22 * * *"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -15,14 +13,10 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
system:
|
system:
|
||||||
- "bob"
|
- "bob"
|
||||||
- "brain"
|
|
||||||
- "jeeves"
|
- "jeeves"
|
||||||
- "leviathan"
|
- "muninn"
|
||||||
- "rhapsody-in-green"
|
- "rhapsody-in-green"
|
||||||
continue-on-error: true
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- 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
|
|
||||||
run: nix copy --to ssh://jeeves .#nixosConfigurations.${{ matrix.system }}.config.system.build.toplevel
|
|
||||||
|
|||||||
29
.github/workflows/merge_flake_lock_update.yml
vendored
29
.github/workflows/merge_flake_lock_update.yml
vendored
@@ -1,29 +0,0 @@
|
|||||||
name: merge_flake_lock_update
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 2 * * 6"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
merge:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: merge_flake_lock_update
|
|
||||||
run: |
|
|
||||||
pr_number=$(gh pr list --state open --author RichieCahill --label flake_lock_update --json number --jq '.[0].number')
|
|
||||||
echo "pr_number=$pr_number" >> $GITHUB_ENV
|
|
||||||
if [ -n "$pr_number" ]; then
|
|
||||||
gh pr merge "$pr_number" --rebase
|
|
||||||
else
|
|
||||||
echo "No open PR found with label flake_lock_update"
|
|
||||||
fi
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
|
|
||||||
19
.github/workflows/pytest.yml
vendored
19
.github/workflows/pytest.yml
vendored
@@ -1,19 +0,0 @@
|
|||||||
name: pytest
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
merge_group:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
pytest:
|
|
||||||
runs-on: self-hosted
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Run tests
|
|
||||||
run: pytest tests
|
|
||||||
15
.github/workflows/treefmt.yml
vendored
15
.github/workflows/treefmt.yml
vendored
@@ -1,15 +0,0 @@
|
|||||||
name: treefmt
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
treefmt:
|
|
||||||
name: nix fmt
|
|
||||||
runs-on: self-hosted
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: runs treefmt
|
|
||||||
run: "treefmt --ci"
|
|
||||||
4
.github/workflows/update-flake-lock.yml
vendored
4
.github/workflows/update-flake-lock.yml
vendored
@@ -2,7 +2,7 @@ name: update-flake-lock
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 0 * * 6"
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lockfile:
|
lockfile:
|
||||||
@@ -15,9 +15,7 @@ jobs:
|
|||||||
- name: Update flake.lock
|
- name: Update flake.lock
|
||||||
uses: DeterminateSystems/update-flake-lock@main
|
uses: DeterminateSystems/update-flake-lock@main
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
|
|
||||||
pr-title: "Update flake.lock"
|
pr-title: "Update flake.lock"
|
||||||
pr-labels: |
|
pr-labels: |
|
||||||
dependencies
|
dependencies
|
||||||
automated
|
automated
|
||||||
flake_lock_update
|
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -162,6 +162,4 @@ cython_debug/
|
|||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
test.*
|
test.*
|
||||||
|
secrets.*
|
||||||
# syncthing
|
|
||||||
.stfolder
|
|
||||||
|
|||||||
22
.sops.yaml
22
.sops.yaml
@@ -1,22 +0,0 @@
|
|||||||
# Generate AGE keys from SSH keys with:
|
|
||||||
# ssh-keygen -A
|
|
||||||
# nix-shell -p ssh-to-age --run 'cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age'
|
|
||||||
keys:
|
|
||||||
- &admin_richie age1u8zj599elqqvcmhxn8zuwrufsz8w8w366d3ayrljjejljt2q45kq8mxw9c # cspell:disable-line
|
|
||||||
|
|
||||||
- &system_bob age1q47vup0tjhulkg7d6xwmdsgrw64h4ax3la3evzqpxyy4adsmk9fs56qz3y # cspell:disable-line
|
|
||||||
- &system_brain age1jhf7vm0005j60mjq63696frrmjhpy8kpc2d66mw044lqap5mjv4snmwvwm # cspell:disable-line
|
|
||||||
- &system_jeeves age13lmqgc3jvkyah5e3vcwmj4s5wsc2akctcga0lpc0x8v8du3fxprqp4ldkv # cspell:disable-line
|
|
||||||
- &system_leviathan age1l272y8udvg60z7edgje42fu49uwt4x2gxn5zvywssnv9h2krms8s094m4k # cspell:disable-line
|
|
||||||
- &system_rhapsody age1ufnewppysaq2wwcl4ugngjz8pfzc5a35yg7luq0qmuqvctajcycs5lf6k4 # cspell:disable-line
|
|
||||||
|
|
||||||
creation_rules:
|
|
||||||
- path_regex: users/secrets\.yaml$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin_richie
|
|
||||||
- *system_bob
|
|
||||||
- *system_brain
|
|
||||||
- *system_jeeves
|
|
||||||
- *system_leviathan
|
|
||||||
- *system_rhapsody
|
|
||||||
71
.vscode/settings.json
vendored
71
.vscode/settings.json
vendored
@@ -2,15 +2,11 @@
|
|||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"aboutwelcome",
|
"aboutwelcome",
|
||||||
"acltype",
|
"acltype",
|
||||||
"addopts",
|
|
||||||
"addstr",
|
"addstr",
|
||||||
"advplyr",
|
"advplyr",
|
||||||
"ahci",
|
"ahci",
|
||||||
"aioesphomeapi",
|
"aioesphomeapi",
|
||||||
"aiounifi",
|
|
||||||
"alsa",
|
"alsa",
|
||||||
"apiclient",
|
|
||||||
"apscheduler",
|
|
||||||
"archlinux",
|
"archlinux",
|
||||||
"ashift",
|
"ashift",
|
||||||
"asrouter",
|
"asrouter",
|
||||||
@@ -21,45 +17,36 @@
|
|||||||
"auditd",
|
"auditd",
|
||||||
"autofetch",
|
"autofetch",
|
||||||
"autologin",
|
"autologin",
|
||||||
"automations",
|
|
||||||
"autopull",
|
"autopull",
|
||||||
"autotrim",
|
"autotrim",
|
||||||
"autoupdate",
|
|
||||||
"azuretools",
|
"azuretools",
|
||||||
"bantime",
|
"bantime",
|
||||||
"bazarr",
|
"bazarr",
|
||||||
"bgwriter",
|
|
||||||
"binhex",
|
"binhex",
|
||||||
"bitwarden",
|
"bitwarden",
|
||||||
"blkdiscard",
|
"blkdiscard",
|
||||||
"breakpad",
|
"breakpad",
|
||||||
|
"bredr",
|
||||||
"btop",
|
"btop",
|
||||||
"cachix",
|
"cachix",
|
||||||
"canmount",
|
"canmount",
|
||||||
"captivedetect",
|
"captivedetect",
|
||||||
"cgroupdriver",
|
"cgroupdriver",
|
||||||
"charliermarsh",
|
"charliermarsh",
|
||||||
"Checkpointing",
|
|
||||||
"cloudflared",
|
"cloudflared",
|
||||||
"codellama",
|
|
||||||
"codezombiech",
|
"codezombiech",
|
||||||
"compactmode",
|
"compactmode",
|
||||||
"Compat",
|
"Compat",
|
||||||
"contentblocking",
|
"contentblocking",
|
||||||
"cookiebanners",
|
"cookiebanners",
|
||||||
"createdb",
|
|
||||||
"createrole",
|
|
||||||
"crlite",
|
"crlite",
|
||||||
"cryptsetup",
|
"cryptsetup",
|
||||||
"cuda",
|
|
||||||
"darkreader",
|
"darkreader",
|
||||||
"datagrip",
|
|
||||||
"datareporting",
|
"datareporting",
|
||||||
"davidanson",
|
"davidanson",
|
||||||
"dconf",
|
"dconf",
|
||||||
"dearrow",
|
"dearrow",
|
||||||
"debugpy",
|
"debugpy",
|
||||||
"deepseek",
|
|
||||||
"dialout",
|
"dialout",
|
||||||
"diffie",
|
"diffie",
|
||||||
"direnv",
|
"direnv",
|
||||||
@@ -67,16 +54,12 @@
|
|||||||
"dnodesize",
|
"dnodesize",
|
||||||
"dotfiles",
|
"dotfiles",
|
||||||
"drawio",
|
"drawio",
|
||||||
"duckdns",
|
|
||||||
"eamodio",
|
"eamodio",
|
||||||
"ehci",
|
|
||||||
"emerg",
|
|
||||||
"endlessh",
|
"endlessh",
|
||||||
"errorlens",
|
"errorlens",
|
||||||
"esbenp",
|
"esbenp",
|
||||||
"esphome",
|
"esphome",
|
||||||
"extest",
|
"extest",
|
||||||
"fadvise",
|
|
||||||
"fastforwardteam",
|
"fastforwardteam",
|
||||||
"FASTFOX",
|
"FASTFOX",
|
||||||
"ffmpegthumbnailer",
|
"ffmpegthumbnailer",
|
||||||
@@ -88,7 +71,6 @@
|
|||||||
"fmask",
|
"fmask",
|
||||||
"fontconfig",
|
"fontconfig",
|
||||||
"formfill",
|
"formfill",
|
||||||
"forwardfor",
|
|
||||||
"foxundermoon",
|
"foxundermoon",
|
||||||
"FULLSCREEN",
|
"FULLSCREEN",
|
||||||
"fwupd",
|
"fwupd",
|
||||||
@@ -101,7 +83,6 @@
|
|||||||
"globalprivacycontrol",
|
"globalprivacycontrol",
|
||||||
"gparted",
|
"gparted",
|
||||||
"gtts",
|
"gtts",
|
||||||
"gutenprint",
|
|
||||||
"hass",
|
"hass",
|
||||||
"healthreport",
|
"healthreport",
|
||||||
"Heatsink",
|
"Heatsink",
|
||||||
@@ -111,30 +92,24 @@
|
|||||||
"hmac",
|
"hmac",
|
||||||
"homeassistant",
|
"homeassistant",
|
||||||
"HPKP",
|
"HPKP",
|
||||||
"hplip",
|
|
||||||
"htmlaboutaddons",
|
"htmlaboutaddons",
|
||||||
"httpchk",
|
|
||||||
"hurlenko",
|
"hurlenko",
|
||||||
"hwloc",
|
"hwloc",
|
||||||
"ignorelist",
|
|
||||||
"INITDB",
|
"INITDB",
|
||||||
"iocharset",
|
"iocharset",
|
||||||
"ioit",
|
"ioit",
|
||||||
"iperf",
|
"iperf",
|
||||||
"isal",
|
"isal",
|
||||||
"jellyfin",
|
|
||||||
"jnoortheen",
|
"jnoortheen",
|
||||||
"jsbc",
|
"jsbc",
|
||||||
"kagi",
|
"kagi",
|
||||||
"kuma",
|
"kuma",
|
||||||
"lazer",
|
|
||||||
"levelname",
|
"levelname",
|
||||||
"libglvnd",
|
"libglvnd",
|
||||||
"libmysqlclient",
|
"libmysqlclient",
|
||||||
"libsodium",
|
"libsodium",
|
||||||
"libssh",
|
"libssh",
|
||||||
"libvirtd",
|
"libvirtd",
|
||||||
"llms",
|
|
||||||
"localtime",
|
"localtime",
|
||||||
"louislam",
|
"louislam",
|
||||||
"lsnew",
|
"lsnew",
|
||||||
@@ -142,24 +117,18 @@
|
|||||||
"lynis",
|
"lynis",
|
||||||
"mangohud",
|
"mangohud",
|
||||||
"markdownlint",
|
"markdownlint",
|
||||||
"maxconn",
|
|
||||||
"maxpages",
|
|
||||||
"maxretry",
|
"maxretry",
|
||||||
"maxtime",
|
"maxtime",
|
||||||
"mechatroner",
|
"mechatroner",
|
||||||
"mediainfo",
|
"mediainfo",
|
||||||
"mixtral",
|
|
||||||
"mklabel",
|
"mklabel",
|
||||||
"mkpart",
|
"mkpart",
|
||||||
"modbus",
|
|
||||||
"modbuss",
|
|
||||||
"modesetting",
|
"modesetting",
|
||||||
"mountpoint",
|
"mountpoint",
|
||||||
"mountpoints",
|
"mountpoints",
|
||||||
"mousewheel",
|
"mousewheel",
|
||||||
"mqtt",
|
|
||||||
"mtxr",
|
"mtxr",
|
||||||
"mypy",
|
"muninn",
|
||||||
"ncdu",
|
"ncdu",
|
||||||
"nemo",
|
"nemo",
|
||||||
"neofetch",
|
"neofetch",
|
||||||
@@ -169,30 +138,22 @@
|
|||||||
"Networkd",
|
"Networkd",
|
||||||
"networkmanager",
|
"networkmanager",
|
||||||
"newtabpage",
|
"newtabpage",
|
||||||
"nixfmt",
|
|
||||||
"nixos",
|
"nixos",
|
||||||
"nixpkgs",
|
"nixpkgs",
|
||||||
"nmap",
|
"nmap",
|
||||||
"noauto",
|
"noauto",
|
||||||
"nodev",
|
|
||||||
"noecho",
|
"noecho",
|
||||||
"nonsponsored",
|
"nonsponsored",
|
||||||
"Noto",
|
"Noto",
|
||||||
"nprt",
|
|
||||||
"nvme",
|
"nvme",
|
||||||
"OCSP",
|
"OCSP",
|
||||||
"oderwat",
|
"oderwat",
|
||||||
"ollama",
|
|
||||||
"ondemand",
|
|
||||||
"oneshot",
|
"oneshot",
|
||||||
"openwakeword",
|
|
||||||
"optimise",
|
"optimise",
|
||||||
"optoutstudies",
|
"optoutstudies",
|
||||||
"overalljails",
|
"overalljails",
|
||||||
"overscroll",
|
"overscroll",
|
||||||
"overseerr",
|
"overseerr",
|
||||||
"paho",
|
|
||||||
"partitionwise",
|
|
||||||
"pbmode",
|
"pbmode",
|
||||||
"pciutils",
|
"pciutils",
|
||||||
"pcscd",
|
"pcscd",
|
||||||
@@ -200,17 +161,16 @@
|
|||||||
"peerconnection",
|
"peerconnection",
|
||||||
"PESKYFOX",
|
"PESKYFOX",
|
||||||
"PGID",
|
"PGID",
|
||||||
|
"photoprism",
|
||||||
"pipewire",
|
"pipewire",
|
||||||
"pkgs",
|
"pkgs",
|
||||||
"plugdev",
|
"plugdev",
|
||||||
"poppler",
|
"poppler",
|
||||||
"posixacl",
|
"posixacl",
|
||||||
"powertop",
|
|
||||||
"primarycache",
|
"primarycache",
|
||||||
"prismlauncher",
|
"prismlauncher",
|
||||||
"privatebrowsing",
|
"privatebrowsing",
|
||||||
"PRIVOXY",
|
"PRIVOXY",
|
||||||
"protontricks",
|
|
||||||
"prowlarr",
|
"prowlarr",
|
||||||
"proxychains",
|
"proxychains",
|
||||||
"prusa",
|
"prusa",
|
||||||
@@ -218,15 +178,8 @@
|
|||||||
"PUID",
|
"PUID",
|
||||||
"pulseaudio",
|
"pulseaudio",
|
||||||
"punycode",
|
"punycode",
|
||||||
"pychromecast",
|
|
||||||
"pydocstyle",
|
|
||||||
"pyfakefs",
|
|
||||||
"pylance",
|
"pylance",
|
||||||
"pylint",
|
|
||||||
"pymetno",
|
"pymetno",
|
||||||
"pymodbus",
|
|
||||||
"pyownet",
|
|
||||||
"pytest",
|
|
||||||
"qbit",
|
"qbit",
|
||||||
"qbittorrent",
|
"qbittorrent",
|
||||||
"qbittorrentvpn",
|
"qbittorrentvpn",
|
||||||
@@ -234,16 +187,12 @@
|
|||||||
"quicksuggest",
|
"quicksuggest",
|
||||||
"radarr",
|
"radarr",
|
||||||
"readahead",
|
"readahead",
|
||||||
"receiveencrypted",
|
|
||||||
"recordsize",
|
|
||||||
"Redistributable",
|
"Redistributable",
|
||||||
"referer",
|
"referer",
|
||||||
"REFERERS",
|
"REFERERS",
|
||||||
"relatime",
|
"relatime",
|
||||||
"Rhosts",
|
"Rhosts",
|
||||||
"ripgrep",
|
"ripgrep",
|
||||||
"roboto",
|
|
||||||
"rokuecp",
|
|
||||||
"routable",
|
"routable",
|
||||||
"rspace",
|
"rspace",
|
||||||
"rtkit",
|
"rtkit",
|
||||||
@@ -265,7 +214,6 @@
|
|||||||
"sponsorblock",
|
"sponsorblock",
|
||||||
"sqltools",
|
"sqltools",
|
||||||
"ssdp",
|
"ssdp",
|
||||||
"SSHOPTS",
|
|
||||||
"stdenv",
|
"stdenv",
|
||||||
"subresource",
|
"subresource",
|
||||||
"substituters",
|
"substituters",
|
||||||
@@ -273,25 +221,19 @@
|
|||||||
"sysstat",
|
"sysstat",
|
||||||
"tabmanager",
|
"tabmanager",
|
||||||
"tamasfe",
|
"tamasfe",
|
||||||
"TCPIP",
|
|
||||||
"testdisk",
|
|
||||||
"tiktok",
|
"tiktok",
|
||||||
"timonwong",
|
"timonwong",
|
||||||
"titlebar",
|
|
||||||
"tmmworkshop",
|
"tmmworkshop",
|
||||||
"Tmpfs",
|
"Tmpfs",
|
||||||
"topsites",
|
"topsites",
|
||||||
"topstories",
|
"topstories",
|
||||||
"treefmt",
|
"torrenting",
|
||||||
"twimg",
|
"twimg",
|
||||||
"typer",
|
|
||||||
"uaccess",
|
"uaccess",
|
||||||
"ublock",
|
"ublock",
|
||||||
"uiprotect",
|
|
||||||
"uitour",
|
"uitour",
|
||||||
"unrar",
|
"unrar",
|
||||||
"unsubmitted",
|
"unsubmitted",
|
||||||
"uptimekuma",
|
|
||||||
"urlbar",
|
"urlbar",
|
||||||
"urlclassifier",
|
"urlclassifier",
|
||||||
"usbhid",
|
"usbhid",
|
||||||
@@ -300,20 +242,15 @@
|
|||||||
"usernamehw",
|
"usernamehw",
|
||||||
"userprefs",
|
"userprefs",
|
||||||
"vfat",
|
"vfat",
|
||||||
"victron",
|
|
||||||
"virt",
|
"virt",
|
||||||
"virtualisation",
|
"virtualisation",
|
||||||
"vpnpromourl",
|
"vpnpromourl",
|
||||||
"wakeonlan",
|
|
||||||
"webchannel",
|
"webchannel",
|
||||||
"WEBRTC",
|
"WEBRTC",
|
||||||
"WEBUI",
|
"WEBUI",
|
||||||
"wireplumber",
|
|
||||||
"wireshark",
|
"wireshark",
|
||||||
"Workqueues",
|
"Workqueues",
|
||||||
"xattr",
|
"xattr",
|
||||||
"xcursorgen",
|
|
||||||
"xdist",
|
|
||||||
"xhci",
|
"xhci",
|
||||||
"yazi",
|
"yazi",
|
||||||
"yubikey",
|
"yubikey",
|
||||||
|
|||||||
6
build.sh
Normal file
6
build.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
nixos-rebuild build --flake /home/richie/projects/dotfiles#bob
|
||||||
|
nixos-rebuild build --flake /home/richie/projects/dotfiles#jeeves
|
||||||
|
nixos-rebuild build --flake /home/richie/projects/dotfiles#muninn
|
||||||
|
nixos-rebuild build --flake /home/richie/projects/dotfiles#rhapsody-in-green
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
inputs.sops-nix.nixosModules.sops
|
|
||||||
./fail2ban.nix
|
./fail2ban.nix
|
||||||
./fonts.nix
|
./fonts.nix
|
||||||
./libs.nix
|
./libs.nix
|
||||||
@@ -23,7 +22,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;
|
||||||
};
|
};
|
||||||
|
|
||||||
hardware.enableRedistributableFirmware = true;
|
hardware.enableRedistributableFirmware = true;
|
||||||
@@ -31,41 +30,23 @@
|
|||||||
home-manager = {
|
home-manager = {
|
||||||
useGlobalPkgs = true;
|
useGlobalPkgs = true;
|
||||||
useUserPackages = true;
|
useUserPackages = true;
|
||||||
extraSpecialArgs = { inherit inputs outputs; };
|
extraSpecialArgs = {inherit inputs outputs;};
|
||||||
backupFileExtension = "backup";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
nixpkgs = {
|
nixpkgs = {
|
||||||
overlays = builtins.attrValues outputs.overlays;
|
overlays = builtins.attrValues outputs.overlays;
|
||||||
config.allowUnfree = true;
|
config = {
|
||||||
};
|
allowUnfree = true;
|
||||||
|
|
||||||
services = {
|
|
||||||
# firmware update
|
|
||||||
fwupd.enable = true;
|
|
||||||
|
|
||||||
snapshot_manager.enable = lib.mkDefault true;
|
|
||||||
|
|
||||||
zfs = {
|
|
||||||
trim.enable = lib.mkDefault true;
|
|
||||||
autoScrub.enable = lib.mkDefault true;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
powerManagement.powertop.enable = lib.mkDefault true;
|
services.fwupd.enable = true;
|
||||||
|
|
||||||
programs.zsh.enable = true;
|
programs.zsh.enable = true;
|
||||||
|
|
||||||
security = {
|
security.auditd.enable = lib.mkDefault true;
|
||||||
auditd.enable = lib.mkDefault true;
|
|
||||||
sudo-rs = {
|
|
||||||
enable = true;
|
|
||||||
execWheelOnly = true;
|
|
||||||
};
|
|
||||||
sudo.enable = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
users.mutableUsers = lib.mkDefault false;
|
users.mutableUsers = lib.mkDefault true;
|
||||||
|
|
||||||
zramSwap = {
|
zramSwap = {
|
||||||
enable = lib.mkDefault true;
|
enable = lib.mkDefault true;
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
{ lib, pkgs, ... }:
|
{ lib, pkgs, ... }:
|
||||||
let
|
|
||||||
libPath = pkgs.lib.makeLibraryPath [
|
|
||||||
pkgs.zlib
|
|
||||||
pkgs.stdenv.cc.cc.lib
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
programs.nix-ld = {
|
programs.nix-ld = {
|
||||||
enable = lib.mkDefault true;
|
enable = lib.mkDefault true;
|
||||||
@@ -21,7 +15,6 @@ in
|
|||||||
libxml2
|
libxml2
|
||||||
openssl
|
openssl
|
||||||
stdenv.cc.cc
|
stdenv.cc.cc
|
||||||
stdenv.cc.cc.lib
|
|
||||||
systemd
|
systemd
|
||||||
util-linux
|
util-linux
|
||||||
xz
|
xz
|
||||||
@@ -30,9 +23,4 @@ in
|
|||||||
zstd
|
zstd
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
environment = {
|
|
||||||
sessionVariables.LD_LIBRARY_PATH = lib.mkDefault libPath;
|
|
||||||
variables.LD_LIBRARY_PATH = lib.mkDefault libPath;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
console.keyMap = lib.mkDefault "us";
|
console.keyMap = lib.mkDefault "us";
|
||||||
|
|
||||||
i18n = {
|
i18n = {
|
||||||
defaultLocale = lib.mkDefault "en_US.UTF-8";
|
defaultLocale = lib.mkDefault "en_US.utf8";
|
||||||
|
supportedLocales = lib.mkDefault [ "en_US.UTF-8/UTF-8" ];
|
||||||
extraLocaleSettings = lib.mkDefault {
|
extraLocaleSettings = lib.mkDefault {
|
||||||
LC_ADDRESS = "en_US.UTF-8";
|
LC_ADDRESS = "en_US.UTF-8";
|
||||||
LC_IDENTIFICATION = "en_US.UTF-8";
|
LC_IDENTIFICATION = "en_US.UTF-8";
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
inputs,
|
inputs,
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}: let
|
||||||
let
|
|
||||||
flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs;
|
flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs;
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
nix = {
|
nix = {
|
||||||
settings = {
|
settings = {
|
||||||
trusted-users = [
|
trusted-users = [
|
||||||
@@ -15,14 +13,17 @@ in
|
|||||||
];
|
];
|
||||||
trusted-substituters = [
|
trusted-substituters = [
|
||||||
"https://cache.nixos.org"
|
"https://cache.nixos.org"
|
||||||
|
"https://cache.tmmworkshop.com"
|
||||||
"https://nix-community.cachix.org"
|
"https://nix-community.cachix.org"
|
||||||
];
|
];
|
||||||
substituters = [
|
substituters = [
|
||||||
"https://cache.nixos.org/?priority=2&want-mass-query=true"
|
"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"
|
"https://nix-community.cachix.org/?priority=10&want-mass-query=true"
|
||||||
];
|
];
|
||||||
trusted-public-keys = [
|
trusted-public-keys = [
|
||||||
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||||
|
"cache.tmmworkshop.com:jHffkpgbmEdstQPoihJPYW9TQe6jnQbWR2LqkNGV3iA="
|
||||||
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
];
|
];
|
||||||
auto-optimise-store = lib.mkDefault true;
|
auto-optimise-store = lib.mkDefault true;
|
||||||
@@ -36,7 +37,7 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
# Add each flake input as a registry and nix_path
|
# Add each flake input as a registry and nix_path
|
||||||
registry = lib.mapAttrs (_: flake: { inherit flake; }) flakeInputs;
|
registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs;
|
||||||
nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs;
|
nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
{
|
{
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
git
|
git
|
||||||
my_python
|
python313
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,37 @@
|
|||||||
{
|
{ inputs, pkgs, lib, config, ... }:
|
||||||
inputs,
|
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
cfg = config.services.snapshot_manager;
|
cfg = config.services.snapshot_manager;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
services.snapshot_manager = {
|
services.snapshot_manager = {
|
||||||
enable = lib.mkEnableOption "ZFS snapshot manager";
|
enable = lib.mkOption {
|
||||||
|
default = true;
|
||||||
|
example = true;
|
||||||
|
description = "Whether to enable k3s-net.";
|
||||||
|
type = lib.types.bool;
|
||||||
|
};
|
||||||
path = lib.mkOption {
|
path = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
|
description = "Path that needs to be updated via git pull";
|
||||||
default = ./snapshot_config.toml;
|
default = ./snapshot_config.toml;
|
||||||
description = "Path to the snapshot_manager TOML config.";
|
|
||||||
};
|
|
||||||
EnvironmentFile = lib.mkOption {
|
|
||||||
type = lib.types.nullOr (lib.types.coercedTo lib.types.path toString lib.types.str);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Single environment file for the service (e.g. /etc/snapshot-manager/env).
|
|
||||||
Use a leading "-" to ignore if missing (systemd feature).
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
systemd = {
|
systemd = {
|
||||||
services.snapshot_manager = {
|
services."snapshot_manager" = {
|
||||||
description = "ZFS Snapshot Manager";
|
description = "ZFS Snapshot Manager";
|
||||||
requires = [ "zfs-import.target" ];
|
requires = [ "zfs-import.target" ];
|
||||||
after = [ "zfs-import.target" ];
|
after = [ "zfs-import.target" ];
|
||||||
path = [ pkgs.zfs ];
|
path = [ pkgs.zfs ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "${
|
ExecStart = "${inputs.system_tools.packages.x86_64-linux.default}/bin/snapshot_manager --config-file='${cfg.path}'";
|
||||||
inputs.system_tools.packages.${pkgs.system}.default
|
|
||||||
}/bin/snapshot_manager ${lib.escapeShellArg cfg.path}";
|
|
||||||
}
|
|
||||||
// lib.optionalAttrs (cfg.EnvironmentFile != null) {
|
|
||||||
EnvironmentFile = cfg.EnvironmentFile;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
timers.snapshot_manager = {
|
timers."snapshot_manager" = {
|
||||||
wantedBy = [ "timers.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
OnBootSec = "15m";
|
OnBootSec = "15m";
|
||||||
@@ -55,4 +41,4 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -67,5 +67,5 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ 22 ];
|
networking.firewall.allowedTCPPorts = [ 22 ];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,10 @@
|
|||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
boot = {
|
boot = {
|
||||||
kernelPackages = pkgs.linuxPackages_6_17;
|
kernelPackages = pkgs.linuxPackages_6_12;
|
||||||
zfs.package = pkgs.zfs_2_3;
|
zfs.package = pkgs.zfs;
|
||||||
};
|
};
|
||||||
|
|
||||||
hardware.bluetooth = {
|
|
||||||
enable = true;
|
|
||||||
powerOnBoot = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
# rtkit is optional but recommended for pipewire
|
|
||||||
security.rtkit.enable = true;
|
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
displayManager.sddm = {
|
displayManager.sddm = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@@ -29,8 +21,6 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pulseaudio.enable = false;
|
|
||||||
|
|
||||||
pipewire = {
|
pipewire = {
|
||||||
enable = true;
|
enable = true;
|
||||||
alsa.enable = true;
|
alsa.enable = true;
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
services.printing = {
|
|
||||||
enable = true;
|
|
||||||
drivers = with pkgs; [
|
|
||||||
gutenprint
|
|
||||||
hplip
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -10,9 +10,6 @@
|
|||||||
authorizedKeys = config.users.users.richie.openssh.authorizedKeys.keys;
|
authorizedKeys = config.users.users.richie.openssh.authorizedKeys.keys;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
availableKernelModules = [
|
availableKernelModules = [ "igb" ];
|
||||||
"igb"
|
|
||||||
"r8152"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [mangohud steam-run];
|
||||||
mangohud
|
|
||||||
steam-run
|
|
||||||
];
|
|
||||||
hardware.steam-hardware.enable = true;
|
hardware.steam-hardware.enable = true;
|
||||||
|
|
||||||
programs = {
|
programs = {
|
||||||
@@ -14,7 +11,7 @@
|
|||||||
remotePlay.openFirewall = true;
|
remotePlay.openFirewall = true;
|
||||||
localNetworkGameTransfers.openFirewall = true;
|
localNetworkGameTransfers.openFirewall = true;
|
||||||
protontricks.enable = true;
|
protontricks.enable = true;
|
||||||
extraCompatPackages = with pkgs; [ proton-ge-bin ];
|
extraCompatPackages = with pkgs; [proton-ge-bin];
|
||||||
extest.enable = true;
|
extest.enable = true;
|
||||||
};
|
};
|
||||||
gamescope = {
|
gamescope = {
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
{ lib, ... }:
|
|
||||||
{
|
{
|
||||||
services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
user = "richie";
|
user = "richie";
|
||||||
overrideDevices = true;
|
overrideDevices = true;
|
||||||
overrideFolders = lib.mkDefault true;
|
overrideFolders = true;
|
||||||
dataDir = "/home/richie/Syncthing";
|
dataDir = "/home/richie/Syncthing";
|
||||||
configDir = "/home/richie/.config/syncthing";
|
configDir = "/home/richie/.config/syncthing";
|
||||||
settings.devices = {
|
settings = {
|
||||||
bob.id = "CJIAPEJ-VO74RR4-F75VU6M-QNZAMYG-FYUJG7Y-6AT62HJ-355PRPL-PJFETAZ"; # cspell:disable-line
|
devices = {
|
||||||
brain.id = "SSCGIPI-IV3VYKB-TRNIJE3-COV4T2H-CDBER7F-I2CGHYA-NWOEUDU-3T5QAAN"; # cspell:disable-line
|
phone.id = "LTGPLAE-M4ZDJTM-TZ3DJGY-SLLAVWF-CQDVEVS-RGCS75T-GAPZYK3-KUM6LA5"; # cspell:disable-line
|
||||||
ipad.id = "KI76T3X-SFUGV2L-VSNYTKR-TSIUV5L-SHWD3HE-GQRGRCN-GY4UFMD-CW6Z6AX"; # cspell:disable-line
|
jeeves.id = "ICRHXZW-ECYJCUZ-I4CZ64R-3XRK7CG-LL2HAAK-FGOHD22-BQA4AI6-5OAL6AG"; # cspell:disable-line
|
||||||
jeeves.id = "ICRHXZW-ECYJCUZ-I4CZ64R-3XRK7CG-LL2HAAK-FGOHD22-BQA4AI6-5OAL6AG"; # cspell:disable-line
|
ipad.id = "KI76T3X-SFUGV2L-VSNYTKR-TSIUV5L-SHWD3HE-GQRGRCN-GY4UFMD-CW6Z6AX"; # cspell:disable-line
|
||||||
phone.id = "TBRULKD-7DZPGGZ-F6LLB7J-MSO54AY-7KLPBIN-QOFK6PX-W2HBEWI-PHM2CQI"; # cspell:disable-line
|
bob.id = "CJIAPEJ-VO74RR4-F75VU6M-QNZAMYG-FYUJG7Y-6AT62HJ-355PRPL-PJFETAZ"; # cspell:disable-line
|
||||||
rhapsody-in-green.id = "ASL3KC4-3XEN6PA-7BQBRKE-A7JXLI6-DJT43BY-Q4WPOER-7UALUAZ-VTPQ6Q4"; # cspell:disable-line
|
rhapsody-in-green.id = "ASL3KC4-3XEN6PA-7BQBRKE-A7JXLI6-DJT43BY-Q4WPOER-7UALUAZ-VTPQ6Q4"; # cspell:disable-line
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
nix.settings = {
|
|
||||||
trusted-substituters = [ "http://cache.tmmworkshop.com" ];
|
|
||||||
substituters = [ "http://cache.tmmworkshop.com/?priority=1&want-mass-query=true" ];
|
|
||||||
trusted-public-keys = [ "cache.tmmworkshop.com:jHffkpgbmEdstQPoihJPYW9TQe6jnQbWR2LqkNGV3iA=" ];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,32 @@
|
|||||||
|
{ lib, pkgs, ... }:
|
||||||
{
|
{
|
||||||
|
systemd = {
|
||||||
|
services."autopull@dotfiles" = {
|
||||||
|
requires = [ "multi-user.target" ];
|
||||||
|
after = [ "multi-user.target" ];
|
||||||
|
description = "Pull the latest data for dotfiles";
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "root";
|
||||||
|
WorkingDirectory = /root/dotfiles;
|
||||||
|
ExecStart = "${pkgs.git}/bin/git pull --all --prune";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
timers."autopull@dotfiles" = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnBootSec = "1h";
|
||||||
|
OnUnitActiveSec = "1h";
|
||||||
|
Unit = "autopull@dotfiles.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
system.autoUpgrade = {
|
system.autoUpgrade = {
|
||||||
enable = true;
|
enable = lib.mkDefault true;
|
||||||
flags = [ "--accept-flake-config" ];
|
flags = [ "--accept-flake-config" ];
|
||||||
randomizedDelaySec = "1h";
|
randomizedDelaySec = "1h";
|
||||||
persistent = true;
|
persistent = true;
|
||||||
flake = "github:RichieCahill/dotfiles";
|
flake = "github:RAD-Development/nix-dotfiles";
|
||||||
allowReboot = true;
|
|
||||||
dates = "Sat *-*-* 06:00:00";
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
source "https://rubygems.org"
|
|
||||||
|
|
||||||
# The github-pages gem pins all compatible versions of Jekyll and its plugins
|
|
||||||
gem "github-pages", group: :jekyll_plugins
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
title: "Richie Cahill"
|
|
||||||
description: "ALL THE CHAOS THAT I CANT DO AT WORK"
|
|
||||||
baseurl: "/dotfiles"
|
|
||||||
url: "https://richiecahill.github.io"
|
|
||||||
|
|
||||||
remote_theme: pages-themes/hacker@v0.2.0
|
|
||||||
plugins:
|
|
||||||
- jekyll-feed
|
|
||||||
- jekyll-remote-theme
|
|
||||||
- jekyll-seo-tag
|
|
||||||
- jekyll-sitemap
|
|
||||||
- jekyll-paginate
|
|
||||||
|
|
||||||
paginate: 5
|
|
||||||
paginate_path: "/page:num"
|
|
||||||
|
|
||||||
author:
|
|
||||||
name: "Richie Cahill"
|
|
||||||
email: "richie@tmmworkshop.com"
|
|
||||||
|
|
||||||
social_links:
|
|
||||||
github: "RichieCahill"
|
|
||||||
website: "https://tmmworkshop.com"
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# The MONOREPO experiment
|
|
||||||
|
|
||||||
Im testing a [MONOREPO](https://en.wikipedia.org/wiki/Monorepo) because Phil said this was a bad idea. To that i say hold my beer.
|
|
||||||
|
|
||||||
In all seriousness, I Think that for a small dev team/solo dev. The simplicity is worth higher barer to entry. One of my most annoying processes was updating my system tools. I had to build my update in a feature branch and then merge it into my main branch. then go to my dotfiles create a feature branch update the system tools merge it into main.
|
|
||||||
|
|
||||||
It will be starting with my Nix Dotfiles Python tools and now my blog.
|
|
||||||
|
|
||||||
I will be reaching ot to phil on 2030-10-31 and 2035-10-31 to give him updates on the progress.
|
|
||||||
|
|
||||||
Known Issues:
|
|
||||||
|
|
||||||
- the python tests are running on the current derivation not the one the derivation im updating to.
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
layout: default
|
|
||||||
title: "Welcome"
|
|
||||||
---
|
|
||||||
|
|
||||||
Welcome to my build logs, notes, and experiments.
|
|
||||||
|
|
||||||
You can read my latest posts below
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
{% for post in site.posts %}
|
|
||||||
<li>
|
|
||||||
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
|
|
||||||
<small>— {{ post.date | date: "%Y-%m-%d" }}</small>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
3
esphome/.gitignore
vendored
3
esphome/.gitignore
vendored
@@ -1,3 +0,0 @@
|
|||||||
# esphome
|
|
||||||
/.esphome/
|
|
||||||
/secrets.yaml
|
|
||||||
@@ -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"
|
|
||||||
File diff suppressed because one or more lines are too long
283
flake.lock
generated
283
flake.lock
generated
@@ -2,17 +2,18 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"firefox-addons": {
|
"firefox-addons": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "pkgs/firefox-addons",
|
"dir": "pkgs/firefox-addons",
|
||||||
"lastModified": 1760673822,
|
"lastModified": 1735099403,
|
||||||
"narHash": "sha256-h+liPhhMw1yYvkDGLHzQJQShQs+yLjNgjfAyZX+sRrM=",
|
"narHash": "sha256-22NF70bxkMY7/IY2NG0pC7WzgJ0bI67FGSUP37d2mQ8=",
|
||||||
"owner": "rycee",
|
"owner": "rycee",
|
||||||
"repo": "nur-expressions",
|
"repo": "nur-expressions",
|
||||||
"rev": "5cca27f1bb30a26140d0cf60ab34daa45b4fa11f",
|
"rev": "5b2c380332cf5a3022fde931d0346e2b868b544e",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -22,6 +23,55 @@
|
|||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-compat": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1717312683,
|
||||||
|
"narHash": "sha256-FrlieJH50AuvagamEvWMIE6D2OAnERuDboFDYAED/dE=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "38fd3954cf65ce6faf3d0d45cd26059e059f07ea",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1629284811,
|
||||||
|
"narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "c5d161cc0af116a2e17f54316f0bf43f0819785c",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils_2": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"home-manager": {
|
"home-manager": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
@@ -29,11 +79,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760662441,
|
"lastModified": 1735053786,
|
||||||
"narHash": "sha256-mlDqR1Ntgs9uYYEAUR1IhamKBO0lxoNS4zGLzEZaY0A=",
|
"narHash": "sha256-Gm+0DcbUS338vvkwyYWms5jsWlx8z8MeQBzcnIDuIkw=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "722792af097dff5790f1a66d271a47759f477755",
|
"rev": "35b98d20ca8f4ca1f6a2c30b8a2c8bb305a36d84",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -42,13 +92,58 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nix-github-actions": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"system_tools",
|
||||||
|
"poetry2nix",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1729742964,
|
||||||
|
"narHash": "sha256-B4mzTcQ0FZHdpeWcpDYPERtyjJd/NIuaQ9+BV1h+MpA=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nix-github-actions",
|
||||||
|
"rev": "e04df33f62cdcf93d73e9a04142464753a16db67",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nix-github-actions",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixos-cosmic": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"nixpkgs-stable": "nixpkgs-stable",
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1735090583,
|
||||||
|
"narHash": "sha256-Tm+BsKXJS/EdJd9DvLxDbw+chPI1o7A9RHKIFxho36I=",
|
||||||
|
"owner": "lilyinstarlight",
|
||||||
|
"repo": "nixos-cosmic",
|
||||||
|
"rev": "847b93e3b63bcea9a477dd86bb4b56ce7e051f0e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "lilyinstarlight",
|
||||||
|
"repo": "nixos-cosmic",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixos-hardware": {
|
"nixos-hardware": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760106635,
|
"lastModified": 1734954597,
|
||||||
"narHash": "sha256-2GoxVaKWTHBxRoeUYSjv0AfSOx4qw5CWSFz2b+VolKU=",
|
"narHash": "sha256-QIhd8/0x30gEv8XEE1iAnrdMlKuQ0EzthfDR7Hwl+fk=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixos-hardware",
|
"repo": "nixos-hardware",
|
||||||
"rev": "9ed85f8afebf2b7478f25db0a98d0e782c0ed903",
|
"rev": "def1d472c832d77885f174089b0d34854b007198",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -60,11 +155,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760524057,
|
"lastModified": 1734649271,
|
||||||
"narHash": "sha256-EVAqOteLBFmd7pKkb0+FIUyzTF61VKi7YmvP1tw4nEw=",
|
"narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "544961dfcce86422ba200ed9a0b00dd4b1486ec5",
|
"rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -76,11 +171,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-master": {
|
"nixpkgs-master": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760751316,
|
"lastModified": 1735170897,
|
||||||
"narHash": "sha256-1296zQfPiLZNrLKzX1t+kunadeI/mH82hKze3voduEI=",
|
"narHash": "sha256-O1OXa12dHaObowGsfiM8pgphWfSXJj5v8sTxFoPXR0A=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d85429339c0bcf0428084fe1306c970aed364417",
|
"rev": "138326d6e9841ab9e6161730d40e09cedd670c40",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -92,11 +187,27 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-stable": {
|
"nixpkgs-stable": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735563628,
|
"lastModified": 1734875076,
|
||||||
"narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=",
|
"narHash": "sha256-Pzyb+YNG5u3zP79zoi8HXYMs15Q5dfjDgwCdUI5B0nY=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "1807c2b91223227ad5599d7067a61665c52d1295",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-24.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-stable_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1734835170,
|
||||||
|
"narHash": "sha256-JG6n9tQET7ZLjvwjH9BdYE6pES/Alcduxv2FDXliuBM=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798",
|
"rev": "6df924734e1b626efd70925545de844b1c25246f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -106,53 +217,31 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pyproject-build-systems": {
|
"poetry2nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": [
|
||||||
|
"system_tools",
|
||||||
|
"flake-utils"
|
||||||
|
],
|
||||||
|
"nix-github-actions": "nix-github-actions",
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"system_tools",
|
"system_tools",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"pyproject-nix": [
|
"systems": "systems_2",
|
||||||
"system_tools",
|
"treefmt-nix": "treefmt-nix"
|
||||||
"pyproject-nix"
|
|
||||||
],
|
|
||||||
"uv2nix": [
|
|
||||||
"system_tools",
|
|
||||||
"uv2nix"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1744599653,
|
"lastModified": 1731205797,
|
||||||
"narHash": "sha256-nysSwVVjG4hKoOjhjvE6U5lIKA8sEr1d1QzEfZsannU=",
|
"narHash": "sha256-F7N1mxH1VrkVNHR3JGNMRvp9+98KYO4b832KS8Gl2xI=",
|
||||||
"owner": "pyproject-nix",
|
"owner": "nix-community",
|
||||||
"repo": "build-system-pkgs",
|
"repo": "poetry2nix",
|
||||||
"rev": "7dba6dbc73120e15b558754c26024f6c93015dd7",
|
"rev": "f554d27c1544d9c56e5f1f8e2b8aff399803674e",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "pyproject-nix",
|
"owner": "nix-community",
|
||||||
"repo": "build-system-pkgs",
|
"repo": "poetry2nix",
|
||||||
"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"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -160,50 +249,50 @@
|
|||||||
"inputs": {
|
"inputs": {
|
||||||
"firefox-addons": "firefox-addons",
|
"firefox-addons": "firefox-addons",
|
||||||
"home-manager": "home-manager",
|
"home-manager": "home-manager",
|
||||||
|
"nixos-cosmic": "nixos-cosmic",
|
||||||
"nixos-hardware": "nixos-hardware",
|
"nixos-hardware": "nixos-hardware",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"nixpkgs-master": "nixpkgs-master",
|
"nixpkgs-master": "nixpkgs-master",
|
||||||
"nixpkgs-stable": "nixpkgs-stable",
|
"nixpkgs-stable": "nixpkgs-stable_2",
|
||||||
"sops-nix": "sops-nix",
|
|
||||||
"system_tools": "system_tools",
|
"system_tools": "system_tools",
|
||||||
"systems": "systems"
|
"systems": "systems_3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sops-nix": {
|
"rust-overlay": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
|
"nixos-cosmic",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760393368,
|
"lastModified": 1735007320,
|
||||||
"narHash": "sha256-8mN3kqyqa2PKY0wwZ2UmMEYMcxvNTwLaOrrDsw6Qi4E=",
|
"narHash": "sha256-NdhUgB9BkLGW9I+Q1GyUUCc3CbDgsg7HLWjG7WZBR5Q=",
|
||||||
"owner": "Mic92",
|
"owner": "oxalica",
|
||||||
"repo": "sops-nix",
|
"repo": "rust-overlay",
|
||||||
"rev": "ab8d56e85b8be14cff9d93735951e30c3e86a437",
|
"rev": "fb5fdba697ee9a2391ca9ceea3b853b4e3ce37a5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "Mic92",
|
"owner": "oxalica",
|
||||||
"repo": "sops-nix",
|
"repo": "rust-overlay",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system_tools": {
|
"system_tools": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils_2",
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"pyproject-build-systems": "pyproject-build-systems",
|
"poetry2nix": "poetry2nix"
|
||||||
"pyproject-nix": "pyproject-nix",
|
|
||||||
"uv2nix": "uv2nix"
|
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760751967,
|
"lastModified": 1733083480,
|
||||||
"narHash": "sha256-u/uciy9kpM/CBZKl05iAZRaOTwUHiuI0L/qbkk2mLUg=",
|
"narHash": "sha256-B13faNyBbA3MeI7Jp6pFVbp58rI2Rx5Uvd83csW2p48=",
|
||||||
"owner": "RichieCahill",
|
"owner": "RichieCahill",
|
||||||
"repo": "system_tools",
|
"repo": "system_tools",
|
||||||
"rev": "a125c3e5c01cecbc3f2a842ffb1abb1210c35706",
|
"rev": "bc357d8fabd83c1423611829091e5b1d86dd913c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -213,6 +302,35 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "systems",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems_3": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689347949,
|
"lastModified": 1689347949,
|
||||||
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
||||||
@@ -227,28 +345,25 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"uv2nix": {
|
"treefmt-nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"system_tools",
|
"system_tools",
|
||||||
|
"poetry2nix",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
|
||||||
"pyproject-nix": [
|
|
||||||
"system_tools",
|
|
||||||
"pyproject-nix"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1747441483,
|
"lastModified": 1730120726,
|
||||||
"narHash": "sha256-W8BFXk5R0TuJcjIhcGoMpSOaIufGXpizK0pm+uTqynA=",
|
"narHash": "sha256-LqHYIxMrl/1p3/kvm2ir925tZ8DkI0KA10djk8wecSk=",
|
||||||
"owner": "pyproject-nix",
|
"owner": "numtide",
|
||||||
"repo": "uv2nix",
|
"repo": "treefmt-nix",
|
||||||
"rev": "582024dc64663e9f88d467c2f7f7b20d278349de",
|
"rev": "9ef337e492a5555d8e17a51c911ff1f02635be15",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "pyproject-nix",
|
"owner": "numtide",
|
||||||
"repo": "uv2nix",
|
"repo": "treefmt-nix",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
101
flake.nix
101
flake.nix
@@ -4,12 +4,14 @@
|
|||||||
nixConfig = {
|
nixConfig = {
|
||||||
extra-substituters = [
|
extra-substituters = [
|
||||||
"https://cache.nixos.org/?priority=2&want-mass-query=true"
|
"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"
|
"https://nix-community.cachix.org/?priority=10&want-mass-query=true"
|
||||||
];
|
];
|
||||||
extra-trusted-public-keys = [
|
extra-trusted-public-keys = [
|
||||||
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" # cspell:disable-line
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||||
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" # cspell:disable-line
|
"cache.tmmworkshop.com:jHffkpgbmEdstQPoihJPYW9TQe6jnQbWR2LqkNGV3iA="
|
||||||
"cache-nix-dot:Od9KN34LXc6Lu7y1ozzV1kIXZa8coClozgth/SYE7dU=" # cspell:disable-line
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
|
"cache-nix-dot:Od9KN34LXc6Lu7y1ozzV1kIXZa8coClozgth/SYE7dU="
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,71 +38,54 @@
|
|||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
sops-nix = {
|
nixos-cosmic = {
|
||||||
url = "github:Mic92/sops-nix";
|
url = "github:lilyinstarlight/nixos-cosmic";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = {
|
||||||
{
|
self,
|
||||||
self,
|
nixpkgs,
|
||||||
nixpkgs,
|
home-manager,
|
||||||
home-manager,
|
systems,
|
||||||
systems,
|
nixos-cosmic,
|
||||||
sops-nix,
|
...
|
||||||
...
|
} @ inputs: let
|
||||||
}@inputs:
|
inherit (self) outputs;
|
||||||
let
|
lib = nixpkgs.lib // home-manager.lib;
|
||||||
inherit (self) outputs;
|
forEachSystem = f: lib.genAttrs (import systems) (system: f pkgsFor.${system});
|
||||||
lib = nixpkgs.lib // home-manager.lib;
|
pkgsFor = lib.genAttrs (import systems) (
|
||||||
forEachSystem = f: lib.genAttrs (import systems) (system: f pkgsFor.${system});
|
system:
|
||||||
pkgsFor = lib.genAttrs (import systems) (
|
|
||||||
system:
|
|
||||||
import nixpkgs {
|
import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
in
|
in {
|
||||||
{
|
inherit lib;
|
||||||
inherit lib;
|
overlays = import ./overlays {inherit inputs outputs;};
|
||||||
overlays = import ./overlays { inherit inputs outputs; };
|
|
||||||
|
|
||||||
devShells = forEachSystem (pkgs: import ./shell.nix { inherit pkgs; });
|
devShells = forEachSystem (pkgs: import ./shell.nix {inherit pkgs;});
|
||||||
formatter = forEachSystem (pkgs: pkgs.treefmt);
|
formatter = forEachSystem (pkgs: pkgs.alejandra);
|
||||||
|
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
bob = lib.nixosSystem {
|
bob = lib.nixosSystem {
|
||||||
modules = [
|
modules = [./systems/bob];
|
||||||
./systems/bob
|
specialArgs = {inherit inputs outputs;};
|
||||||
];
|
};
|
||||||
specialArgs = { inherit inputs outputs; };
|
jeeves = lib.nixosSystem {
|
||||||
};
|
modules = [./systems/jeeves];
|
||||||
brain = lib.nixosSystem {
|
specialArgs = {inherit inputs outputs;};
|
||||||
modules = [
|
};
|
||||||
./systems/brain
|
rhapsody-in-green = lib.nixosSystem {
|
||||||
];
|
modules = [./systems/rhapsody-in-green];
|
||||||
specialArgs = { inherit inputs outputs; };
|
specialArgs = {inherit inputs outputs;};
|
||||||
};
|
};
|
||||||
jeeves = lib.nixosSystem {
|
muninn = lib.nixosSystem {
|
||||||
modules = [
|
modules = [./systems/muninn];
|
||||||
./systems/jeeves
|
specialArgs = {inherit inputs outputs;};
|
||||||
];
|
|
||||||
specialArgs = { inherit inputs outputs; };
|
|
||||||
};
|
|
||||||
rhapsody-in-green = lib.nixosSystem {
|
|
||||||
modules = [
|
|
||||||
./systems/rhapsody-in-green
|
|
||||||
];
|
|
||||||
specialArgs = { inherit inputs outputs; };
|
|
||||||
};
|
|
||||||
leviathan = lib.nixosSystem {
|
|
||||||
modules = [
|
|
||||||
./systems/leviathan
|
|
||||||
];
|
|
||||||
specialArgs = { inherit inputs outputs; };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{ inputs, ... }:
|
{inputs, ...}: {
|
||||||
{
|
|
||||||
# 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 {
|
||||||
@@ -14,24 +13,4 @@
|
|||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
python-env = final: _prev: {
|
|
||||||
my_python = final.python313.withPackages (
|
|
||||||
ps: with ps; [
|
|
||||||
apprise
|
|
||||||
apscheduler
|
|
||||||
mypy
|
|
||||||
polars
|
|
||||||
pyfakefs
|
|
||||||
pytest
|
|
||||||
pytest-cov
|
|
||||||
pytest-mock
|
|
||||||
pytest-xdist
|
|
||||||
requests
|
|
||||||
ruff
|
|
||||||
typer
|
|
||||||
types-requests
|
|
||||||
]
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
[project]
|
|
||||||
name = "system_tools"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = ""
|
|
||||||
authors = [{ name = "Richie Cahill", email = "richie@tmmworkshop.com" }]
|
|
||||||
requires-python = "~=3.13.0"
|
|
||||||
readme = "README.md"
|
|
||||||
license = "MIT"
|
|
||||||
# these dependencies are a best effort and aren't guaranteed to work
|
|
||||||
dependencies = ["apprise", "apscheduler", "polars", "requests", "typer"]
|
|
||||||
|
|
||||||
[dependency-groups]
|
|
||||||
dev = [
|
|
||||||
"mypy",
|
|
||||||
"pyfakefs",
|
|
||||||
"pytest-cov",
|
|
||||||
"pytest-mock",
|
|
||||||
"pytest-xdist",
|
|
||||||
"pytest",
|
|
||||||
"ruff",
|
|
||||||
"types-requests",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.ruff]
|
|
||||||
|
|
||||||
target-version = "py313"
|
|
||||||
|
|
||||||
line-length = 120
|
|
||||||
|
|
||||||
lint.select = ["ALL"]
|
|
||||||
lint.ignore = [
|
|
||||||
"G004", # (PERM) This is a performers nit
|
|
||||||
"COM812", # (TEMP) conflicts when used with the formatter
|
|
||||||
"ISC001", # (TEMP) conflicts when used with the formatter
|
|
||||||
"S603", # (PERM) This is known to cause a false positive
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.ruff.lint.per-file-ignores]
|
|
||||||
|
|
||||||
"tests/**" = [
|
|
||||||
"S101", # (perm) pytest needs asserts
|
|
||||||
]
|
|
||||||
"python/random/**" = [
|
|
||||||
"T201", # (perm) I don't care about print statements dir
|
|
||||||
]
|
|
||||||
"python/testing/**" = [
|
|
||||||
"T201", # (perm) I don't care about print statements dir
|
|
||||||
"ERA001", # (perm) I don't care about print statements dir
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.ruff.lint.pydocstyle]
|
|
||||||
convention = "google"
|
|
||||||
|
|
||||||
[tool.ruff.lint.flake8-builtins]
|
|
||||||
builtins-ignorelist = ["id"]
|
|
||||||
|
|
||||||
[tool.ruff.lint.pylint]
|
|
||||||
max-args = 9
|
|
||||||
|
|
||||||
[tool.coverage.run]
|
|
||||||
source = ["system_tools"]
|
|
||||||
|
|
||||||
[tool.coverage.report]
|
|
||||||
exclude_lines = [
|
|
||||||
"pragma: no cover",
|
|
||||||
"if TYPE_CHECKING:",
|
|
||||||
"raise NotImplementedError",
|
|
||||||
"if __name__ == \"__main__\":",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
|
||||||
addopts = "-n auto -ra"
|
|
||||||
# --cov=system_tools --cov-report=term-missing --cov-report=xml --cov-report=html --cov-branch
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""Server Tools."""
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
"""common."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
from datetime import UTC, datetime
|
|
||||||
from os import getenv
|
|
||||||
from subprocess import PIPE, Popen
|
|
||||||
|
|
||||||
from apprise import Apprise
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def configure_logger(level: str = "INFO") -> None:
|
|
||||||
"""Configure the logger.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
level (str, optional): The logging level. Defaults to "INFO".
|
|
||||||
"""
|
|
||||||
logging.basicConfig(
|
|
||||||
level=level,
|
|
||||||
datefmt="%Y-%m-%dT%H:%M:%S%z",
|
|
||||||
format="%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s",
|
|
||||||
handlers=[logging.StreamHandler(sys.stdout)],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def bash_wrapper(command: str) -> tuple[str, int]:
|
|
||||||
"""Execute a bash command and capture the output.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
command (str): The bash command to be executed.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Tuple[str, int]: A tuple containing the output of the command (stdout) as a string,
|
|
||||||
the error output (stderr) as a string (optional), and the return code as an integer.
|
|
||||||
"""
|
|
||||||
# This is a acceptable risk
|
|
||||||
process = Popen(command.split(), stdout=PIPE, stderr=PIPE)
|
|
||||||
output, error = process.communicate()
|
|
||||||
if error:
|
|
||||||
logger.error(f"{error=}")
|
|
||||||
return error.decode(), process.returncode
|
|
||||||
|
|
||||||
return output.decode(), process.returncode
|
|
||||||
|
|
||||||
|
|
||||||
def signal_alert(body: str, title: str = "") -> None:
|
|
||||||
"""Send a signal alert.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
body (str): The body of the alert.
|
|
||||||
title (str, optional): The title of the alert. Defaults to "".
|
|
||||||
"""
|
|
||||||
apprise_client = Apprise()
|
|
||||||
|
|
||||||
from_phone = getenv("SIGNAL_ALERT_FROM_PHONE")
|
|
||||||
to_phone = getenv("SIGNAL_ALERT_TO_PHONE")
|
|
||||||
if not from_phone or not to_phone:
|
|
||||||
logger.info("SIGNAL_ALERT_FROM_PHONE or SIGNAL_ALERT_TO_PHONE not set")
|
|
||||||
return
|
|
||||||
|
|
||||||
apprise_client.add(f"signal://localhost:8989/{from_phone}/{to_phone}")
|
|
||||||
|
|
||||||
apprise_client.notify(title=title, body=body)
|
|
||||||
|
|
||||||
|
|
||||||
def utcnow() -> datetime:
|
|
||||||
"""Get the current UTC time."""
|
|
||||||
return datetime.now(tz=UTC)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""installer."""
|
|
||||||
@@ -1,308 +0,0 @@
|
|||||||
"""Install NixOS on a ZFS pool."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import curses
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
from os import getenv
|
|
||||||
from pathlib import Path
|
|
||||||
from random import getrandbits
|
|
||||||
from subprocess import PIPE, Popen, run
|
|
||||||
from time import sleep
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from python.common import configure_logger
|
|
||||||
from python.installer.tui import draw_menu
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from collections.abc import Sequence
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def bash_wrapper(command: str) -> str:
|
|
||||||
"""Execute a bash command and capture the output.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
command (str): The bash command to be executed.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Tuple[str, int]: A tuple containing the output of the command (stdout) as a string,
|
|
||||||
the error output (stderr) as a string (optional), and the return code as an integer.
|
|
||||||
"""
|
|
||||||
logger.debug(f"running {command=}")
|
|
||||||
# This is a acceptable risk
|
|
||||||
process = Popen(command.split(), stdout=PIPE, stderr=PIPE)
|
|
||||||
output, _ = process.communicate()
|
|
||||||
if process.returncode != 0:
|
|
||||||
error = f"Failed to run command {command=} return code {process.returncode=}"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
|
|
||||||
return output.decode()
|
|
||||||
|
|
||||||
|
|
||||||
def partition_disk(disk: str, swap_size: int, reserve: int = 0) -> None:
|
|
||||||
"""Partition a disk.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
disk (str): The disk to partition.
|
|
||||||
swap_size (int): The size of the swap partition in GB.
|
|
||||||
minimum value is 1.
|
|
||||||
reserve (int, optional): The size of the reserve partition in GB. Defaults to 0.
|
|
||||||
minimum value is 0.
|
|
||||||
"""
|
|
||||||
logger.info(f"partitioning {disk=}")
|
|
||||||
swap_size = max(swap_size, 1)
|
|
||||||
reserve = max(reserve, 0)
|
|
||||||
|
|
||||||
bash_wrapper(f"blkdiscard -f {disk}")
|
|
||||||
|
|
||||||
if reserve > 0:
|
|
||||||
msg = f"Creating swap partition on {disk=} with size {swap_size=}GiB and reserve {reserve=}GiB"
|
|
||||||
logger.info(msg)
|
|
||||||
|
|
||||||
swap_start = swap_size + reserve
|
|
||||||
swap_partition = f"mkpart swap -{swap_start}GiB -{reserve}GiB "
|
|
||||||
else:
|
|
||||||
logger.info(f"Creating swap partition on {disk=} with size {swap_size=}GiB")
|
|
||||||
swap_start = swap_size
|
|
||||||
swap_partition = f"mkpart swap -{swap_start}GiB 100% "
|
|
||||||
|
|
||||||
logger.debug(f"{swap_partition=}")
|
|
||||||
|
|
||||||
create_partitions = (
|
|
||||||
f"parted --script --align=optimal {disk} -- "
|
|
||||||
"mklabel gpt "
|
|
||||||
"mkpart EFI 1MiB 4GiB "
|
|
||||||
f"mkpart root_pool 4GiB -{swap_start}GiB "
|
|
||||||
f"{swap_partition}"
|
|
||||||
"set 1 esp on"
|
|
||||||
)
|
|
||||||
bash_wrapper(create_partitions)
|
|
||||||
|
|
||||||
logger.info(f"{disk=} successfully partitioned")
|
|
||||||
|
|
||||||
|
|
||||||
def create_zfs_pool(pool_disks: Sequence[str], mnt_dir: str) -> None:
|
|
||||||
"""Create a ZFS pool.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pool_disks (Sequence[str]): A tuple of disks to use for the pool.
|
|
||||||
mnt_dir (str): The mount directory.
|
|
||||||
"""
|
|
||||||
if len(pool_disks) <= 0:
|
|
||||||
error = "disks must be a tuple of at least length 1"
|
|
||||||
raise ValueError(error)
|
|
||||||
|
|
||||||
zpool_create = (
|
|
||||||
"zpool create "
|
|
||||||
"-o ashift=12 "
|
|
||||||
"-o autotrim=on "
|
|
||||||
f"-R {mnt_dir} "
|
|
||||||
"-O acltype=posixacl "
|
|
||||||
"-O canmount=off "
|
|
||||||
"-O dnodesize=auto "
|
|
||||||
"-O normalization=formD "
|
|
||||||
"-O relatime=on "
|
|
||||||
"-O xattr=sa "
|
|
||||||
"-O mountpoint=legacy "
|
|
||||||
"-O compression=zstd "
|
|
||||||
"-O atime=off "
|
|
||||||
"root_pool "
|
|
||||||
)
|
|
||||||
if len(pool_disks) == 1:
|
|
||||||
zpool_create += pool_disks[0]
|
|
||||||
else:
|
|
||||||
zpool_create += "mirror "
|
|
||||||
zpool_create += " ".join(pool_disks)
|
|
||||||
|
|
||||||
bash_wrapper(zpool_create)
|
|
||||||
zpools = bash_wrapper("zpool list -o name")
|
|
||||||
if "root_pool" not in zpools.splitlines():
|
|
||||||
logger.critical("Failed to create root_pool")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def create_zfs_datasets() -> None:
|
|
||||||
"""Create ZFS datasets."""
|
|
||||||
bash_wrapper("zfs create -o canmount=noauto -o reservation=10G root_pool/root")
|
|
||||||
bash_wrapper("zfs create root_pool/home")
|
|
||||||
bash_wrapper("zfs create root_pool/var -o reservation=1G")
|
|
||||||
bash_wrapper("zfs create -o compression=zstd-9 -o reservation=10G root_pool/nix")
|
|
||||||
datasets = bash_wrapper("zfs list -o name")
|
|
||||||
|
|
||||||
expected_datasets = {
|
|
||||||
"root_pool/root",
|
|
||||||
"root_pool/home",
|
|
||||||
"root_pool/var",
|
|
||||||
"root_pool/nix",
|
|
||||||
}
|
|
||||||
missing_datasets = expected_datasets.difference(datasets.splitlines())
|
|
||||||
if missing_datasets:
|
|
||||||
logger.critical(f"Failed to create pools {missing_datasets}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def get_cpu_manufacturer() -> str:
|
|
||||||
"""Get the CPU manufacturer."""
|
|
||||||
output = bash_wrapper("cat /proc/cpuinfo")
|
|
||||||
|
|
||||||
id_vendor = {"AuthenticAMD": "amd", "GenuineIntel": "intel"}
|
|
||||||
|
|
||||||
for line in output.splitlines():
|
|
||||||
if "vendor_id" in line:
|
|
||||||
return id_vendor[line.split(": ")[1].strip()]
|
|
||||||
|
|
||||||
error = "Failed to get CPU manufacturer"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
|
|
||||||
|
|
||||||
def get_boot_drive_id(disk: str) -> str:
|
|
||||||
"""Get the boot drive ID."""
|
|
||||||
output = bash_wrapper(f"lsblk -o UUID {disk}-part1")
|
|
||||||
return output.splitlines()[1]
|
|
||||||
|
|
||||||
|
|
||||||
def create_nix_hardware_file(mnt_dir: str, disks: Sequence[str], encrypt: str | None) -> None:
|
|
||||||
"""Create a NixOS hardware file."""
|
|
||||||
cpu_manufacturer = get_cpu_manufacturer()
|
|
||||||
|
|
||||||
devices = ""
|
|
||||||
if encrypt:
|
|
||||||
disk = disks[0]
|
|
||||||
|
|
||||||
devices = (
|
|
||||||
f' luks.devices."luks-root-pool-{disk.split("/")[-1]}-part2"'
|
|
||||||
"= {\n"
|
|
||||||
f' device = "{disk}-part2";\n'
|
|
||||||
" bypassWorkqueues = true;\n"
|
|
||||||
" allowDiscards = true;\n"
|
|
||||||
" };\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
host_id = format(getrandbits(32), "08x")
|
|
||||||
|
|
||||||
nix_hardware = (
|
|
||||||
"{ config, lib, modulesPath, ... }:\n"
|
|
||||||
"{\n"
|
|
||||||
' imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];\n\n'
|
|
||||||
" boot = {\n"
|
|
||||||
" initrd = {\n"
|
|
||||||
' availableKernelModules = [ \n "ahci"\n "ehci_pci"\n "nvme"\n "sd_mod"\n'
|
|
||||||
' "usb_storage"\n "usbhid"\n "xhci_pci"\n ];\n'
|
|
||||||
" kernelModules = [ ];\n"
|
|
||||||
f" {devices}"
|
|
||||||
" };\n"
|
|
||||||
f' kernelModules = [ "kvm-{cpu_manufacturer}" ];\n'
|
|
||||||
" extraModulePackages = [ ];\n"
|
|
||||||
" };\n\n"
|
|
||||||
" fileSystems = {\n"
|
|
||||||
' "/" = lib.mkDefault {\n device = "root_pool/root";\n fsType = "zfs";\n };\n\n'
|
|
||||||
' "/home" = {\n device = "root_pool/home";\n fsType = "zfs";\n };\n\n'
|
|
||||||
' "/var" = {\n device = "root_pool/var";\n fsType = "zfs";\n };\n\n'
|
|
||||||
' "/nix" = {\n device = "root_pool/nix";\n fsType = "zfs";\n };\n\n'
|
|
||||||
' "/boot" = {\n'
|
|
||||||
f' device = "/dev/disk/by-uuid/{get_boot_drive_id(disks[0])}";\n'
|
|
||||||
' fsType = "vfat";\n options = [\n "fmask=0077"\n'
|
|
||||||
' "dmask=0077"\n ];\n };\n };\n\n'
|
|
||||||
" swapDevices = [ ];\n\n"
|
|
||||||
" networking.useDHCP = lib.mkDefault true;\n\n"
|
|
||||||
' nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";\n'
|
|
||||||
f" hardware.cpu.{cpu_manufacturer}.updateMicrocode = "
|
|
||||||
"lib.mkDefault config.hardware.enableRedistributableFirmware;\n"
|
|
||||||
f' networking.hostId = "{host_id}";\n'
|
|
||||||
"}\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
Path(f"{mnt_dir}/etc/nixos/hardware-configuration.nix").write_text(nix_hardware)
|
|
||||||
|
|
||||||
|
|
||||||
def install_nixos(mnt_dir: str, disks: Sequence[str], encrypt: str | None) -> None:
|
|
||||||
"""Install NixOS."""
|
|
||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/root {mnt_dir}")
|
|
||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/home {mnt_dir}/home")
|
|
||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/var {mnt_dir}/var")
|
|
||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/nix {mnt_dir}/nix")
|
|
||||||
|
|
||||||
for disk in disks:
|
|
||||||
bash_wrapper(f"mkfs.vfat -n EFI {disk}-part1")
|
|
||||||
|
|
||||||
# set up mirroring afterwards if more than one disk
|
|
||||||
boot_partition = (
|
|
||||||
f"mount -t vfat -o fmask=0077,dmask=0077,iocharset=iso8859-1,X-mount.mkdir {disks[0]}-part1 {mnt_dir}/boot"
|
|
||||||
)
|
|
||||||
bash_wrapper(boot_partition)
|
|
||||||
|
|
||||||
bash_wrapper(f"nixos-generate-config --root {mnt_dir}")
|
|
||||||
|
|
||||||
create_nix_hardware_file(mnt_dir, disks, encrypt)
|
|
||||||
|
|
||||||
run(("nixos-install", "--root", mnt_dir), check=True)
|
|
||||||
|
|
||||||
|
|
||||||
def installer(
|
|
||||||
disks: Sequence[str],
|
|
||||||
swap_size: int,
|
|
||||||
reserve: int,
|
|
||||||
encrypt_key: str | None,
|
|
||||||
) -> None:
|
|
||||||
"""Main."""
|
|
||||||
logger.info("Starting installation")
|
|
||||||
|
|
||||||
for disk in disks:
|
|
||||||
partition_disk(disk, swap_size, reserve)
|
|
||||||
|
|
||||||
test = Popen(("printf", f"'{encrypt_key}'"), stdout=PIPE)
|
|
||||||
if encrypt_key:
|
|
||||||
sleep(1)
|
|
||||||
for command in (
|
|
||||||
f"cryptsetup luksFormat --type luks2 {disk}-part2 -",
|
|
||||||
f"cryptsetup luksOpen {disk}-part2 luks-root-pool-{disk.split('/')[-1]}-part2 -",
|
|
||||||
):
|
|
||||||
run(command, check=True, stdin=test.stdout)
|
|
||||||
|
|
||||||
mnt_dir = "/tmp/nix_install" # noqa: S108
|
|
||||||
|
|
||||||
Path(mnt_dir).mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
if encrypt_key:
|
|
||||||
pool_disks = [f"/dev/mapper/luks-root-pool-{disk.split('/')[-1]}-part2" for disk in disks]
|
|
||||||
else:
|
|
||||||
pool_disks = [f"{disk}-part2" for disk in disks]
|
|
||||||
|
|
||||||
create_zfs_pool(pool_disks, mnt_dir)
|
|
||||||
|
|
||||||
create_zfs_datasets()
|
|
||||||
|
|
||||||
install_nixos(mnt_dir, disks, encrypt_key)
|
|
||||||
|
|
||||||
logger.info("Installation complete")
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""Main."""
|
|
||||||
configure_logger("DEBUG")
|
|
||||||
|
|
||||||
state = curses.wrapper(draw_menu)
|
|
||||||
|
|
||||||
encrypt_key = getenv("ENCRYPT_KEY")
|
|
||||||
|
|
||||||
logger.info("installing_nixos")
|
|
||||||
logger.info(f"disks: {state.selected_device_ids}")
|
|
||||||
logger.info(f"swap_size: {state.swap_size}")
|
|
||||||
logger.info(f"reserve: {state.reserve_size}")
|
|
||||||
logger.info(f"encrypted: {bool(encrypt_key)}")
|
|
||||||
|
|
||||||
sleep(3)
|
|
||||||
|
|
||||||
installer(
|
|
||||||
disks=state.get_selected_devices(),
|
|
||||||
swap_size=state.swap_size,
|
|
||||||
reserve=state.reserve_size,
|
|
||||||
encrypt_key=encrypt_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,498 +0,0 @@
|
|||||||
"""TUI module."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import curses
|
|
||||||
import logging
|
|
||||||
from collections import defaultdict
|
|
||||||
from subprocess import PIPE, Popen
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def bash_wrapper(command: str) -> str:
|
|
||||||
"""Execute a bash command and capture the output.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
command (str): The bash command to be executed.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Tuple[str, int]: A tuple containing the output of the command (stdout) as a string,
|
|
||||||
the error output (stderr) as a string (optional), and the return code as an integer.
|
|
||||||
"""
|
|
||||||
logger.debug(f"running {command=}")
|
|
||||||
# This is a acceptable risk
|
|
||||||
process = Popen(command.split(), stdout=PIPE, stderr=PIPE)
|
|
||||||
output, _ = process.communicate()
|
|
||||||
if process.returncode != 0:
|
|
||||||
error = f"Failed to run command {command=} return code {process.returncode=}"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
|
|
||||||
return output.decode()
|
|
||||||
|
|
||||||
|
|
||||||
class Cursor:
|
|
||||||
"""Cursor class."""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Initialize the Cursor class."""
|
|
||||||
self.x_position = 0
|
|
||||||
self.y_position = 0
|
|
||||||
self.height = 0
|
|
||||||
self.width = 0
|
|
||||||
|
|
||||||
def set_height(self, height: int) -> None:
|
|
||||||
"""Set height."""
|
|
||||||
self.height = height
|
|
||||||
|
|
||||||
def set_width(self, width: int) -> None:
|
|
||||||
"""Set width."""
|
|
||||||
self.width = width
|
|
||||||
|
|
||||||
def x_bounce_check(self, cursor: int) -> int:
|
|
||||||
"""X bounce check."""
|
|
||||||
cursor = max(0, cursor)
|
|
||||||
return min(self.width - 1, cursor)
|
|
||||||
|
|
||||||
def y_bounce_check(self, cursor: int) -> int:
|
|
||||||
"""Y bounce check."""
|
|
||||||
cursor = max(0, cursor)
|
|
||||||
return min(self.height - 1, cursor)
|
|
||||||
|
|
||||||
def set_x(self, x: int) -> None:
|
|
||||||
"""Set x."""
|
|
||||||
self.x_position = self.x_bounce_check(x)
|
|
||||||
|
|
||||||
def set_y(self, y: int) -> None:
|
|
||||||
"""Set y."""
|
|
||||||
self.y_position = self.y_bounce_check(y)
|
|
||||||
|
|
||||||
def get_x(self) -> int:
|
|
||||||
"""Get x."""
|
|
||||||
return self.x_position
|
|
||||||
|
|
||||||
def get_y(self) -> int:
|
|
||||||
"""Get y."""
|
|
||||||
return self.y_position
|
|
||||||
|
|
||||||
def move_up(self) -> None:
|
|
||||||
"""Move up."""
|
|
||||||
self.set_y(self.y_position - 1)
|
|
||||||
|
|
||||||
def move_down(self) -> None:
|
|
||||||
"""Move down."""
|
|
||||||
self.set_y(self.y_position + 1)
|
|
||||||
|
|
||||||
def move_left(self) -> None:
|
|
||||||
"""Move left."""
|
|
||||||
self.set_x(self.x_position - 1)
|
|
||||||
|
|
||||||
def move_right(self) -> None:
|
|
||||||
"""Move right."""
|
|
||||||
self.set_x(self.x_position + 1)
|
|
||||||
|
|
||||||
def navigation(self, key: int) -> None:
|
|
||||||
"""Navigation.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
key (int): The key.
|
|
||||||
"""
|
|
||||||
action = {
|
|
||||||
curses.KEY_DOWN: self.move_down,
|
|
||||||
curses.KEY_UP: self.move_up,
|
|
||||||
curses.KEY_RIGHT: self.move_right,
|
|
||||||
curses.KEY_LEFT: self.move_left,
|
|
||||||
}
|
|
||||||
|
|
||||||
action.get(key, lambda: None)()
|
|
||||||
|
|
||||||
|
|
||||||
class State:
|
|
||||||
"""State class to store the state of the program."""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Initialize the State class."""
|
|
||||||
self.key = 0
|
|
||||||
self.cursor = Cursor()
|
|
||||||
|
|
||||||
self.swap_size = 0
|
|
||||||
self.show_swap_input = False
|
|
||||||
|
|
||||||
self.reserve_size = 0
|
|
||||||
self.show_reserve_input = False
|
|
||||||
|
|
||||||
self.selected_device_ids: set[str] = set()
|
|
||||||
|
|
||||||
def get_selected_devices(self) -> tuple[str, ...]:
|
|
||||||
"""Get selected devices."""
|
|
||||||
return tuple(self.selected_device_ids)
|
|
||||||
|
|
||||||
|
|
||||||
def get_device(raw_device: str) -> dict[str, str]:
|
|
||||||
"""Get a device.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
raw_device (str): The raw device.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict[str, str]: The device.
|
|
||||||
"""
|
|
||||||
raw_device_components = raw_device.split(" ")
|
|
||||||
return {thing.split("=")[0].lower(): thing.split("=")[1].strip('"') for thing in raw_device_components}
|
|
||||||
|
|
||||||
|
|
||||||
def get_devices() -> list[dict[str, str]]:
|
|
||||||
"""Get a list of devices."""
|
|
||||||
# --bytes
|
|
||||||
raw_devices = bash_wrapper("lsblk --paths --pairs").splitlines()
|
|
||||||
return [get_device(raw_device) for raw_device in raw_devices]
|
|
||||||
|
|
||||||
|
|
||||||
def set_color() -> None:
|
|
||||||
"""Set the color."""
|
|
||||||
curses.start_color()
|
|
||||||
curses.use_default_colors()
|
|
||||||
for i in range(curses.COLORS):
|
|
||||||
curses.init_pair(i + 1, i, -1)
|
|
||||||
|
|
||||||
|
|
||||||
def debug_menu(std_screen: curses.window, key: int) -> None:
|
|
||||||
"""Debug menu.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): The curses window.
|
|
||||||
key (int): The key.
|
|
||||||
"""
|
|
||||||
height, width = std_screen.getmaxyx()
|
|
||||||
std_screen.addstr(height - 4, 0, f"Width: {width}, Height: {height}", curses.color_pair(5))
|
|
||||||
|
|
||||||
key_pressed = f"Last key pressed: {key}"[: width - 1]
|
|
||||||
if key == 0:
|
|
||||||
key_pressed = "No key press detected..."[: width - 1]
|
|
||||||
std_screen.addstr(height - 3, 0, key_pressed)
|
|
||||||
|
|
||||||
for i in range(8):
|
|
||||||
std_screen.addstr(height - 2, i * 3, f"{i}██", curses.color_pair(i))
|
|
||||||
|
|
||||||
|
|
||||||
def get_text_input(std_screen: curses.window, prompt: str, y: int, x: int) -> str:
|
|
||||||
"""Get text input.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): The curses window.
|
|
||||||
prompt (str): The prompt.
|
|
||||||
y (int): The y position.
|
|
||||||
x (int): The x position.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: The input string.
|
|
||||||
"""
|
|
||||||
esc_key = 27
|
|
||||||
curses.echo()
|
|
||||||
std_screen.addstr(y, x, prompt)
|
|
||||||
input_str = ""
|
|
||||||
while True:
|
|
||||||
key = std_screen.getch()
|
|
||||||
if key == ord("\n"):
|
|
||||||
break
|
|
||||||
if key == esc_key:
|
|
||||||
input_str = ""
|
|
||||||
break
|
|
||||||
if key in (curses.KEY_BACKSPACE, ord("\b"), 127):
|
|
||||||
input_str = input_str[:-1]
|
|
||||||
std_screen.addstr(y, x + len(prompt), input_str + " ")
|
|
||||||
else:
|
|
||||||
input_str += chr(key)
|
|
||||||
std_screen.refresh()
|
|
||||||
curses.noecho()
|
|
||||||
return input_str
|
|
||||||
|
|
||||||
|
|
||||||
def swap_size_input(
|
|
||||||
std_screen: curses.window,
|
|
||||||
state: State,
|
|
||||||
swap_offset: int,
|
|
||||||
) -> State:
|
|
||||||
"""Reserve size input.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): The curses window.
|
|
||||||
state (State): The state object.
|
|
||||||
swap_offset (int): The swap offset.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
State: The updated state object.
|
|
||||||
"""
|
|
||||||
swap_size_text = "Swap size (GB): "
|
|
||||||
std_screen.addstr(swap_offset, 0, f"{swap_size_text}{state.swap_size}")
|
|
||||||
if state.key == ord("\n") and state.cursor.get_y() == swap_offset:
|
|
||||||
state.show_swap_input = True
|
|
||||||
|
|
||||||
if state.show_swap_input:
|
|
||||||
swap_size_str = get_text_input(std_screen, swap_size_text, swap_offset, 0)
|
|
||||||
try:
|
|
||||||
state.swap_size = int(swap_size_str)
|
|
||||||
state.show_swap_input = False
|
|
||||||
except ValueError:
|
|
||||||
std_screen.addstr(swap_offset, 0, "Invalid input. Press any key to continue.")
|
|
||||||
std_screen.getch()
|
|
||||||
state.show_swap_input = False
|
|
||||||
|
|
||||||
return state
|
|
||||||
|
|
||||||
|
|
||||||
def reserve_size_input(
|
|
||||||
std_screen: curses.window,
|
|
||||||
state: State,
|
|
||||||
reserve_offset: int,
|
|
||||||
) -> State:
|
|
||||||
"""Reserve size input.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): The curses window.
|
|
||||||
state (State): The state object.
|
|
||||||
reserve_offset (int): The reserve offset.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
State: The updated state object.
|
|
||||||
"""
|
|
||||||
reserve_size_text = "reserve size (GB): "
|
|
||||||
std_screen.addstr(reserve_offset, 0, f"{reserve_size_text}{state.reserve_size}")
|
|
||||||
if state.key == ord("\n") and state.cursor.get_y() == reserve_offset:
|
|
||||||
state.show_reserve_input = True
|
|
||||||
|
|
||||||
if state.show_reserve_input:
|
|
||||||
reserve_size_str = get_text_input(std_screen, reserve_size_text, reserve_offset, 0)
|
|
||||||
try:
|
|
||||||
state.reserve_size = int(reserve_size_str)
|
|
||||||
state.show_reserve_input = False
|
|
||||||
except ValueError:
|
|
||||||
std_screen.addstr(reserve_offset, 0, "Invalid input. Press any key to continue.")
|
|
||||||
std_screen.getch()
|
|
||||||
state.show_reserve_input = False
|
|
||||||
|
|
||||||
return state
|
|
||||||
|
|
||||||
|
|
||||||
def status_bar(
|
|
||||||
std_screen: curses.window,
|
|
||||||
cursor: Cursor,
|
|
||||||
width: int,
|
|
||||||
height: int,
|
|
||||||
) -> None:
|
|
||||||
"""Draw the status bar.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): The curses window.
|
|
||||||
cursor (Cursor): The cursor.
|
|
||||||
width (int): The width.
|
|
||||||
height (int): The height.
|
|
||||||
"""
|
|
||||||
std_screen.attron(curses.A_REVERSE)
|
|
||||||
std_screen.attron(curses.color_pair(3))
|
|
||||||
|
|
||||||
status_bar = f"Press 'q' to exit | STATUS BAR | Pos: {cursor.get_x()}, {cursor.get_y()}"
|
|
||||||
std_screen.addstr(height - 1, 0, status_bar)
|
|
||||||
std_screen.addstr(height - 1, len(status_bar), " " * (width - len(status_bar) - 1))
|
|
||||||
|
|
||||||
std_screen.attroff(curses.color_pair(3))
|
|
||||||
std_screen.attroff(curses.A_REVERSE)
|
|
||||||
|
|
||||||
|
|
||||||
def get_device_id_mapping() -> dict[str, set[str]]:
|
|
||||||
"""Get a list of device ids.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[str]: the list of device ids
|
|
||||||
"""
|
|
||||||
device_ids = bash_wrapper("find /dev/disk/by-id -type l").splitlines()
|
|
||||||
|
|
||||||
device_id_mapping: dict[str, set[str]] = defaultdict(set)
|
|
||||||
|
|
||||||
for device_id in device_ids:
|
|
||||||
device = bash_wrapper(f"readlink -f {device_id}").strip()
|
|
||||||
device_id_mapping[device].add(device_id)
|
|
||||||
|
|
||||||
return device_id_mapping
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_device_menu_padding(devices: list[dict[str, str]], column: str, padding: int = 0) -> int:
|
|
||||||
"""Calculate the device menu padding.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
devices (list[dict[str, str]]): The devices.
|
|
||||||
column (str): The column.
|
|
||||||
padding (int, optional): The padding. Defaults to 0.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: The calculated padding.
|
|
||||||
"""
|
|
||||||
return max(len(device[column]) for device in devices) + padding
|
|
||||||
|
|
||||||
|
|
||||||
def draw_device_ids(
|
|
||||||
state: State,
|
|
||||||
row_number: int,
|
|
||||||
menu_start_x: int,
|
|
||||||
std_screen: curses.window,
|
|
||||||
menu_width: list[int],
|
|
||||||
device_ids: set[str],
|
|
||||||
) -> tuple[State, int]:
|
|
||||||
"""Draw device IDs.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
state (State): The state object.
|
|
||||||
row_number (int): The row number.
|
|
||||||
menu_start_x (int): The menu start x.
|
|
||||||
std_screen (curses.window): The curses window.
|
|
||||||
menu_width (list[int]): The menu width.
|
|
||||||
device_ids (set[str]): The device IDs.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
tuple[State, int]: The updated state object and the row number.
|
|
||||||
"""
|
|
||||||
for device_id in sorted(device_ids):
|
|
||||||
row_number = row_number + 1
|
|
||||||
if row_number == state.cursor.get_y() and state.cursor.get_x() in menu_width:
|
|
||||||
std_screen.attron(curses.A_BOLD)
|
|
||||||
if state.key == ord(" "):
|
|
||||||
if device_id not in state.selected_device_ids:
|
|
||||||
state.selected_device_ids.add(device_id)
|
|
||||||
else:
|
|
||||||
state.selected_device_ids.remove(device_id)
|
|
||||||
|
|
||||||
if device_id in state.selected_device_ids:
|
|
||||||
std_screen.attron(curses.color_pair(7))
|
|
||||||
|
|
||||||
std_screen.addstr(row_number, menu_start_x, f" {device_id}")
|
|
||||||
|
|
||||||
std_screen.attroff(curses.color_pair(7))
|
|
||||||
std_screen.attroff(curses.A_BOLD)
|
|
||||||
|
|
||||||
return state, row_number
|
|
||||||
|
|
||||||
|
|
||||||
def draw_device_menu(
|
|
||||||
std_screen: curses.window,
|
|
||||||
devices: list[dict[str, str]],
|
|
||||||
device_id_mapping: dict[str, set[str]],
|
|
||||||
state: State,
|
|
||||||
menu_start_y: int = 0,
|
|
||||||
menu_start_x: int = 0,
|
|
||||||
) -> tuple[State, int]:
|
|
||||||
"""Draw the device menu and handle user input.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
devices (list[dict[str, str]]): the list of devices to draw
|
|
||||||
device_id_mapping (dict[str, set[str]]): the list of device ids to draw
|
|
||||||
state (State): the state object to update
|
|
||||||
menu_start_y (int, optional): the y position to start drawing the menu. Defaults to 0.
|
|
||||||
menu_start_x (int, optional): the x position to start drawing the menu. Defaults to 0.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
State: the updated state object
|
|
||||||
"""
|
|
||||||
padding = 2
|
|
||||||
|
|
||||||
name_padding = calculate_device_menu_padding(devices, "name", padding)
|
|
||||||
size_padding = calculate_device_menu_padding(devices, "size", padding)
|
|
||||||
type_padding = calculate_device_menu_padding(devices, "type", padding)
|
|
||||||
mountpoints_padding = calculate_device_menu_padding(devices, "mountpoints", padding)
|
|
||||||
|
|
||||||
device_header = (
|
|
||||||
f"{'Name':{name_padding}}{'Size':{size_padding}}{'Type':{type_padding}}{'Mountpoints':{mountpoints_padding}}"
|
|
||||||
)
|
|
||||||
|
|
||||||
menu_width = list(range(menu_start_x, len(device_header) + menu_start_x))
|
|
||||||
|
|
||||||
std_screen.addstr(menu_start_y, menu_start_x, device_header, curses.color_pair(5))
|
|
||||||
devises_list_start = menu_start_y + 1
|
|
||||||
|
|
||||||
row_number = devises_list_start
|
|
||||||
|
|
||||||
for device in devices:
|
|
||||||
row_number = row_number + 1
|
|
||||||
device_name = device["name"]
|
|
||||||
device_row = (
|
|
||||||
f"{device_name:{name_padding}}"
|
|
||||||
f"{device['size']:{size_padding}}"
|
|
||||||
f"{device['type']:{type_padding}}"
|
|
||||||
f"{device['mountpoints']:{mountpoints_padding}}"
|
|
||||||
)
|
|
||||||
std_screen.addstr(row_number, menu_start_x, device_row)
|
|
||||||
|
|
||||||
state, row_number = draw_device_ids(
|
|
||||||
state=state,
|
|
||||||
row_number=row_number,
|
|
||||||
menu_start_x=menu_start_x,
|
|
||||||
std_screen=std_screen,
|
|
||||||
menu_width=menu_width,
|
|
||||||
device_ids=device_id_mapping[device_name],
|
|
||||||
)
|
|
||||||
|
|
||||||
return state, row_number
|
|
||||||
|
|
||||||
|
|
||||||
def draw_menu(std_screen: curses.window) -> State:
|
|
||||||
"""Draw the menu and handle user input.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
State: the state object
|
|
||||||
"""
|
|
||||||
# Clear and refresh the screen for a blank canvas
|
|
||||||
std_screen.clear()
|
|
||||||
std_screen.refresh()
|
|
||||||
|
|
||||||
set_color()
|
|
||||||
|
|
||||||
state = State()
|
|
||||||
|
|
||||||
devices = get_devices()
|
|
||||||
|
|
||||||
device_id_mapping = get_device_id_mapping()
|
|
||||||
|
|
||||||
# Loop where k is the last character pressed
|
|
||||||
while state.key != ord("q"):
|
|
||||||
std_screen.clear()
|
|
||||||
height, width = std_screen.getmaxyx()
|
|
||||||
|
|
||||||
state.cursor.set_height(height)
|
|
||||||
state.cursor.set_width(width)
|
|
||||||
|
|
||||||
state.cursor.navigation(state.key)
|
|
||||||
|
|
||||||
state, device_menu_size = draw_device_menu(
|
|
||||||
std_screen=std_screen,
|
|
||||||
state=state,
|
|
||||||
devices=devices,
|
|
||||||
device_id_mapping=device_id_mapping,
|
|
||||||
)
|
|
||||||
|
|
||||||
swap_offset = device_menu_size + 2
|
|
||||||
|
|
||||||
swap_size_input(
|
|
||||||
std_screen=std_screen,
|
|
||||||
state=state,
|
|
||||||
swap_offset=swap_offset,
|
|
||||||
)
|
|
||||||
reserve_size_input(
|
|
||||||
std_screen=std_screen,
|
|
||||||
state=state,
|
|
||||||
reserve_offset=swap_offset + 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
status_bar(std_screen, state.cursor, width, height)
|
|
||||||
|
|
||||||
debug_menu(std_screen, state.key)
|
|
||||||
|
|
||||||
std_screen.move(state.cursor.get_y(), state.cursor.get_x())
|
|
||||||
|
|
||||||
std_screen.refresh()
|
|
||||||
|
|
||||||
state.key = std_screen.getch()
|
|
||||||
|
|
||||||
return state
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
"""Thing."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import logging
|
|
||||||
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from multiprocessing import cpu_count
|
|
||||||
from typing import TYPE_CHECKING, Any, Literal, TypeVar
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from collections.abc import Callable, Mapping, Sequence
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
R = TypeVar("R")
|
|
||||||
|
|
||||||
modes = Literal["normal", "early_error"]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class ExecutorResults[R]:
|
|
||||||
"""Dataclass to store the results and exceptions of the parallel execution."""
|
|
||||||
|
|
||||||
results: list[R]
|
|
||||||
exceptions: list[BaseException]
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
"""Return a string representation of the object."""
|
|
||||||
return f"results={self.results} exceptions={self.exceptions}"
|
|
||||||
|
|
||||||
|
|
||||||
def _parallelize_base[R](
|
|
||||||
executor_type: type[ThreadPoolExecutor | ProcessPoolExecutor],
|
|
||||||
func: Callable[..., R],
|
|
||||||
kwargs_list: Sequence[Mapping[str, Any]],
|
|
||||||
max_workers: int | None,
|
|
||||||
progress_tracker: int | None,
|
|
||||||
mode: modes,
|
|
||||||
) -> ExecutorResults:
|
|
||||||
total_work = len(kwargs_list)
|
|
||||||
|
|
||||||
with executor_type(max_workers=max_workers) as executor:
|
|
||||||
futures = [executor.submit(func, **kwarg) for kwarg in kwargs_list]
|
|
||||||
|
|
||||||
results = []
|
|
||||||
exceptions = []
|
|
||||||
for index, future in enumerate(futures, 1):
|
|
||||||
if exception := future.exception():
|
|
||||||
logger.error(f"{future} raised {exception.__class__.__name__}")
|
|
||||||
exceptions.append(exception)
|
|
||||||
if mode == "early_error":
|
|
||||||
executor.shutdown(wait=False)
|
|
||||||
raise exception
|
|
||||||
continue
|
|
||||||
|
|
||||||
results.append(future.result())
|
|
||||||
|
|
||||||
if progress_tracker and index % progress_tracker == 0:
|
|
||||||
logger.info(f"Progress: {index}/{total_work}")
|
|
||||||
|
|
||||||
return ExecutorResults(results, exceptions)
|
|
||||||
|
|
||||||
|
|
||||||
def parallelize_thread[R](
|
|
||||||
func: Callable[..., R],
|
|
||||||
kwargs_list: Sequence[Mapping[str, Any]],
|
|
||||||
max_workers: int | None = None,
|
|
||||||
progress_tracker: int | None = None,
|
|
||||||
mode: modes = "normal",
|
|
||||||
) -> ExecutorResults:
|
|
||||||
"""Generic function to run a function with multiple arguments in threads.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
func (Callable[..., R]): Function to run in threads.
|
|
||||||
kwargs_list (Sequence[Mapping[str, Any]]): List of dictionaries with the arguments for the function.
|
|
||||||
max_workers (int, optional): Number of workers to use. Defaults to 8.
|
|
||||||
progress_tracker (int, optional): Number of tasks to complete before logging progress.
|
|
||||||
mode (modes, optional): Mode to use. Defaults to "normal".
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
tuple[list[R], list[Exception]]: List with the results and a list with the exceptions.
|
|
||||||
"""
|
|
||||||
return _parallelize_base(
|
|
||||||
executor_type=ThreadPoolExecutor,
|
|
||||||
func=func,
|
|
||||||
kwargs_list=kwargs_list,
|
|
||||||
max_workers=max_workers,
|
|
||||||
progress_tracker=progress_tracker,
|
|
||||||
mode=mode,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parallelize_process[R](
|
|
||||||
func: Callable[..., R],
|
|
||||||
kwargs_list: Sequence[Mapping[str, Any]],
|
|
||||||
max_workers: int | None = None,
|
|
||||||
progress_tracker: int | None = None,
|
|
||||||
mode: modes = "normal",
|
|
||||||
) -> ExecutorResults:
|
|
||||||
"""Generic function to run a function with multiple arguments in process.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
func (Callable[..., R]): Function to run in process.
|
|
||||||
kwargs_list (Sequence[Mapping[str, Any]]): List of dictionaries with the arguments for the function.
|
|
||||||
max_workers (int, optional): Number of workers to use. Defaults to 4.
|
|
||||||
progress_tracker (int, optional): Number of tasks to complete before logging progress.
|
|
||||||
mode (modes, optional): Mode to use. Defaults to "normal".
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
tuple[list[R], list[Exception]]: List with the results and a list with the exceptions.
|
|
||||||
"""
|
|
||||||
if max_workers and max_workers > cpu_count():
|
|
||||||
error = f"max_workers must be less than or equal to {cpu_count()}"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
|
|
||||||
return process_executor_unchecked(
|
|
||||||
func=func,
|
|
||||||
kwargs_list=kwargs_list,
|
|
||||||
max_workers=max_workers,
|
|
||||||
progress_tracker=progress_tracker,
|
|
||||||
mode=mode,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def process_executor_unchecked[R](
|
|
||||||
func: Callable[..., R],
|
|
||||||
kwargs_list: Sequence[Mapping[str, Any]],
|
|
||||||
max_workers: int | None,
|
|
||||||
progress_tracker: int | None,
|
|
||||||
mode: modes = "normal",
|
|
||||||
) -> ExecutorResults:
|
|
||||||
"""Generic function to run a function with multiple arguments in parallel.
|
|
||||||
|
|
||||||
Note: this function does not check if the number of workers is greater than the number of CPUs.
|
|
||||||
This can cause the system to become unresponsive.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
func (Callable[..., R]): Function to run in parallel.
|
|
||||||
kwargs_list (Sequence[Mapping[str, Any]]): List of dictionaries with the arguments for the function.
|
|
||||||
max_workers (int, optional): Number of workers to use. Defaults to 8.
|
|
||||||
progress_tracker (int, optional): Number of tasks to complete before logging progress.
|
|
||||||
mode (modes, optional): Mode to use. Defaults to "normal".
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
tuple[list[R], list[Exception]]: List with the results and a list with the exceptions.
|
|
||||||
"""
|
|
||||||
return _parallelize_base(
|
|
||||||
executor_type=ProcessPoolExecutor,
|
|
||||||
func=func,
|
|
||||||
kwargs_list=kwargs_list,
|
|
||||||
max_workers=max_workers,
|
|
||||||
progress_tracker=progress_tracker,
|
|
||||||
mode=mode,
|
|
||||||
)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""init."""
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
"""capasitor."""
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_capacitor_capacity(voltage: float, farads: float) -> float:
|
|
||||||
"""Calculate capacitor capacity."""
|
|
||||||
joules = (farads * voltage**2) // 2
|
|
||||||
return joules // 3600
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_pack_capacity(cells: int, cell_voltage: float, farads: float) -> float:
|
|
||||||
"""Calculate pack capacity."""
|
|
||||||
return calculate_capacitor_capacity(cells * cell_voltage, farads / cells)
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_pack_capacity2(cells: int, cell_voltage: float, farads: float, cell_cost: float) -> tuple[float, float]:
|
|
||||||
"""Calculate pack capacity."""
|
|
||||||
capacitor_capacity = calculate_capacitor_capacity(cells * cell_voltage, farads / cells)
|
|
||||||
return capacitor_capacity, cell_cost * cells
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""Main."""
|
|
||||||
watt_hours = calculate_pack_capacity(cells=10, cell_voltage=2.7, farads=500)
|
|
||||||
print(f"{watt_hours=}")
|
|
||||||
print(f"{watt_hours*16=}")
|
|
||||||
watt_hours = calculate_pack_capacity(cells=1, cell_voltage=2.7, farads=5000)
|
|
||||||
print(f"{watt_hours=}")
|
|
||||||
|
|
||||||
watt_hours, cost = calculate_pack_capacity2(
|
|
||||||
cells=10,
|
|
||||||
cell_voltage=2.7,
|
|
||||||
farads=3000,
|
|
||||||
cell_cost=11.60,
|
|
||||||
)
|
|
||||||
print(f"{watt_hours=}")
|
|
||||||
print(f"{cost=}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
"""thing."""
|
|
||||||
|
|
||||||
|
|
||||||
def caculat_batry_specs(
|
|
||||||
cell_amp_hour: int,
|
|
||||||
cell_voltage: float,
|
|
||||||
cells_per_pack: int,
|
|
||||||
packs: int,
|
|
||||||
) -> tuple[float, float]:
|
|
||||||
"""Caculat battry specs."""
|
|
||||||
pack_voltage = cell_voltage * cells_per_pack
|
|
||||||
|
|
||||||
pack_watt_hours = pack_voltage * cell_amp_hour
|
|
||||||
|
|
||||||
battry_capacity = pack_watt_hours * packs
|
|
||||||
return (
|
|
||||||
battry_capacity,
|
|
||||||
pack_voltage,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
battry_capacity, pack_voltage = caculat_batry_specs(300, 3.2, 8, 2)
|
|
||||||
print(f"{battry_capacity=} {pack_voltage=}")
|
|
||||||
cost = 1700
|
|
||||||
print(f"$/kWh {cost / battry_capacity}")
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
"""voltage_drop."""
|
|
||||||
|
|
||||||
import math
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
class TemperatureUnit(Enum):
|
|
||||||
"""Temperature unit."""
|
|
||||||
|
|
||||||
CELSIUS = "c"
|
|
||||||
FAHRENHEIT = "f"
|
|
||||||
KELVIN = "k"
|
|
||||||
|
|
||||||
|
|
||||||
class Temperature:
|
|
||||||
"""Temperature."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
temperature: float,
|
|
||||||
unit: TemperatureUnit = TemperatureUnit.CELSIUS,
|
|
||||||
) -> None:
|
|
||||||
"""__init__."""
|
|
||||||
unit_modifier = {
|
|
||||||
TemperatureUnit.CELSIUS: 1,
|
|
||||||
TemperatureUnit.FAHRENHEIT: 0.5556,
|
|
||||||
TemperatureUnit.KELVIN: 1.8,
|
|
||||||
}
|
|
||||||
self.temperature = temperature * unit_modifier[unit]
|
|
||||||
|
|
||||||
def __float__(self) -> float:
|
|
||||||
"""Return the temperature in degrees Celsius."""
|
|
||||||
return self.temperature
|
|
||||||
|
|
||||||
|
|
||||||
class LengthUnit(Enum):
|
|
||||||
"""Length unit."""
|
|
||||||
|
|
||||||
METERS = "m"
|
|
||||||
FEET = "ft"
|
|
||||||
INCHES = "in"
|
|
||||||
|
|
||||||
|
|
||||||
class Length:
|
|
||||||
"""Length."""
|
|
||||||
|
|
||||||
def __init__(self, length: float, unit: LengthUnit) -> None:
|
|
||||||
"""__init__."""
|
|
||||||
self.meters = self._convert_to_meters(length, unit)
|
|
||||||
|
|
||||||
def _convert_to_meters(self, length: float, unit: LengthUnit) -> float:
|
|
||||||
thing = {
|
|
||||||
LengthUnit.METERS: 1,
|
|
||||||
LengthUnit.FEET: 0.3048,
|
|
||||||
LengthUnit.INCHES: 0.0254,
|
|
||||||
}
|
|
||||||
test = thing.get(unit)
|
|
||||||
if test:
|
|
||||||
return length * test
|
|
||||||
error = f"Unsupported unit: {unit}"
|
|
||||||
raise ValueError(error)
|
|
||||||
|
|
||||||
def __float__(self) -> float:
|
|
||||||
"""Return the length in meters."""
|
|
||||||
return self.meters
|
|
||||||
|
|
||||||
def feet(self) -> float:
|
|
||||||
"""Return the length in feet."""
|
|
||||||
return self.meters * 3.2808
|
|
||||||
|
|
||||||
|
|
||||||
class MaterialType(Enum):
|
|
||||||
"""Material type."""
|
|
||||||
|
|
||||||
COPPER = "copper"
|
|
||||||
ALUMINUM = "aluminum"
|
|
||||||
CCA = "cca"
|
|
||||||
SILVER = "silver"
|
|
||||||
GOLD = "gold"
|
|
||||||
|
|
||||||
|
|
||||||
def get_material_resistivity(
|
|
||||||
material: MaterialType,
|
|
||||||
temperature: Temperature | None = None,
|
|
||||||
) -> float:
|
|
||||||
"""Get the resistivity of a material."""
|
|
||||||
if not temperature:
|
|
||||||
Temperature(20.0)
|
|
||||||
material_info = {
|
|
||||||
MaterialType.COPPER: (1.724e-8, 0.00393),
|
|
||||||
MaterialType.ALUMINUM: (2.908e-8, 0.00403),
|
|
||||||
MaterialType.CCA: (2.577e-8, 0.00397),
|
|
||||||
MaterialType.SILVER: (1.632e-8, 0.00380),
|
|
||||||
MaterialType.GOLD: (2.503e-8, 0.00340),
|
|
||||||
}
|
|
||||||
|
|
||||||
base_resistivity, temp_coefficient = material_info[material]
|
|
||||||
return base_resistivity * (1 + temp_coefficient * float(temperature))
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_awg_diameter_mm(gauge: int) -> float:
|
|
||||||
"""Calculate wire diameter in millimeters for a given AWG gauge."""
|
|
||||||
return round(0.127 * 92 ** ((36 - gauge) / 39), 3)
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_wire_area_m2(gauge: int) -> float:
|
|
||||||
"""Calculate the area of a wire in square meters.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
float: The area of the wire in square meters
|
|
||||||
"""
|
|
||||||
return math.pi * (calculate_awg_diameter_mm(gauge) / 2000) ** 2
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_resistance_per_meter(gauge: int) -> float:
|
|
||||||
"""Calculate the resistance per meter of a wire.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
float: The resistance per meter of the wire
|
|
||||||
"""
|
|
||||||
return get_material_resistivity(MaterialType.COPPER) / calculate_wire_area_m2(gauge)
|
|
||||||
|
|
||||||
|
|
||||||
def voltage_drop(
|
|
||||||
gauge: int,
|
|
||||||
material: MaterialType,
|
|
||||||
length: Length,
|
|
||||||
current_a: float,
|
|
||||||
) -> float:
|
|
||||||
"""Calculate the voltage drop of a wire.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
|
||||||
material (MaterialType): The type of conductor material (e.g., copper, aluminum)
|
|
||||||
length (Length): The length of the wire in meters
|
|
||||||
current_a (float): The current flowing through the wire in amperes
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
float: The voltage drop of the wire in volts
|
|
||||||
"""
|
|
||||||
resistivity = get_material_resistivity(material)
|
|
||||||
resistance_per_meter = resistivity / calculate_wire_area_m2(gauge)
|
|
||||||
total_resistance = resistance_per_meter * float(length) * 2 # round-trip
|
|
||||||
return total_resistance * current_a
|
|
||||||
|
|
||||||
|
|
||||||
print(
|
|
||||||
voltage_drop(
|
|
||||||
gauge=10,
|
|
||||||
material=MaterialType.CCA,
|
|
||||||
length=Length(length=20, unit=LengthUnit.FEET),
|
|
||||||
current_a=20,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def max_wire_length(
|
|
||||||
gauge: int,
|
|
||||||
material: MaterialType,
|
|
||||||
current_amps: float,
|
|
||||||
voltage_drop: float = 0.3,
|
|
||||||
temperature: Temperature | None = None,
|
|
||||||
) -> Length:
|
|
||||||
"""Calculate the maximum allowable wire length based on voltage drop criteria.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
|
||||||
material (MaterialType): The type of conductor material (e.g., copper, aluminum)
|
|
||||||
current_amps (float): The current flowing through the wire in amperes
|
|
||||||
voltage_drop (float, optional): Maximum allowable voltage drop as a decimal (default 0.1 or 10%)
|
|
||||||
temperature (Temperature | None, optional): The temperature of the wire. Defaults to None.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
float: Maximum wire length in meters that maintains the specified voltage drop
|
|
||||||
"""
|
|
||||||
if not temperature:
|
|
||||||
Temperature(100.0, unit=TemperatureUnit.FAHRENHEIT)
|
|
||||||
|
|
||||||
resistivity = get_material_resistivity(material, temperature)
|
|
||||||
resistance_per_meter = resistivity / calculate_wire_area_m2(gauge)
|
|
||||||
# V = IR, solve for length where V is the allowed voltage drop
|
|
||||||
return Length(
|
|
||||||
voltage_drop / (current_amps * resistance_per_meter),
|
|
||||||
LengthUnit.METERS,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
print(max_wire_length(gauge=10, material=MaterialType.CCA, current_amps=20).feet())
|
|
||||||
print(max_wire_length(gauge=10, material=MaterialType.CCA, current_amps=10).feet())
|
|
||||||
print(max_wire_length(gauge=10, material=MaterialType.CCA, current_amps=5).feet())
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""system_tests."""
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
"""Validate Jeeves."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import logging
|
|
||||||
from copy import copy
|
|
||||||
from re import search
|
|
||||||
from time import sleep
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from python.common import bash_wrapper
|
|
||||||
from python.zfs import Zpool
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from collections.abc import Sequence
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def zpool_tests(pool_names: Sequence[str], zpool_capacity_threshold: int = 90) -> list[str] | None:
|
|
||||||
"""Check the zpool health and capacity.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pool_names (Sequence[str]): A list of pool names to test.
|
|
||||||
zpool_capacity_threshold (int, optional): The threshold for the zpool capacity. Defaults to 90.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[str] | None: A list of errors if any.
|
|
||||||
"""
|
|
||||||
logger.info("Testing zpool")
|
|
||||||
|
|
||||||
errors: list[str] = []
|
|
||||||
for pool_name in pool_names:
|
|
||||||
pool = Zpool(pool_name)
|
|
||||||
if pool.health != "ONLINE":
|
|
||||||
errors.append(f"{pool.name} is {pool.health}")
|
|
||||||
if pool.capacity >= zpool_capacity_threshold:
|
|
||||||
errors.append(f"{pool.name} is low on space")
|
|
||||||
|
|
||||||
upgrade_status, _ = bash_wrapper("zpool upgrade")
|
|
||||||
if not search(r"Every feature flags pool has all supported and requested features enabled.", upgrade_status):
|
|
||||||
errors.append("ZPool out of date run `sudo zpool upgrade -a`")
|
|
||||||
|
|
||||||
return errors
|
|
||||||
|
|
||||||
|
|
||||||
def systemd_tests(
|
|
||||||
service_names: Sequence[str],
|
|
||||||
max_retries: int = 30,
|
|
||||||
retry_delay_secs: int = 1,
|
|
||||||
retryable_statuses: Sequence[str] | None = None,
|
|
||||||
valid_statuses: Sequence[str] | None = None,
|
|
||||||
) -> list[str] | None:
|
|
||||||
"""Tests a systemd services.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
service_names (Sequence[str]): A list of service names to test.
|
|
||||||
max_retries (int, optional): The maximum number of retries. Defaults to 30.
|
|
||||||
minimum value is 1.
|
|
||||||
retry_delay_secs (int, optional): The delay between retries in seconds. Defaults to 1.
|
|
||||||
minimum value is 1.
|
|
||||||
retryable_statuses (Sequence[str] | None, optional): A list of retryable statuses. Defaults to None.
|
|
||||||
valid_statuses (Sequence[str] | None, optional): A list of valid statuses. Defaults to None.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[str] | None: A list of errors if any.
|
|
||||||
"""
|
|
||||||
logger.info("Testing systemd service")
|
|
||||||
|
|
||||||
max_retries = max(max_retries, 1)
|
|
||||||
retry_delay_secs = max(retry_delay_secs, 1)
|
|
||||||
last_try = max_retries - 1
|
|
||||||
|
|
||||||
if retryable_statuses is None:
|
|
||||||
retryable_statuses = ("inactive\n", "activating\n")
|
|
||||||
|
|
||||||
if valid_statuses is None:
|
|
||||||
valid_statuses = ("active\n",)
|
|
||||||
|
|
||||||
service_names_set = set(service_names)
|
|
||||||
|
|
||||||
errors: set[str] = set()
|
|
||||||
for retry in range(max_retries):
|
|
||||||
if not service_names_set:
|
|
||||||
break
|
|
||||||
logger.info(f"Testing systemd service in {retry + 1} of {max_retries}")
|
|
||||||
service_names_to_test = copy(service_names_set)
|
|
||||||
for service_name in service_names_to_test:
|
|
||||||
service_status, _ = bash_wrapper(f"systemctl is-active {service_name}")
|
|
||||||
if service_status in valid_statuses:
|
|
||||||
service_names_set.remove(service_name)
|
|
||||||
continue
|
|
||||||
if service_status in retryable_statuses and retry < last_try:
|
|
||||||
continue
|
|
||||||
errors.add(f"{service_name} is {service_status.strip()}")
|
|
||||||
|
|
||||||
sleep(retry_delay_secs)
|
|
||||||
|
|
||||||
return list(errors)
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
"""Validate {server_name}."""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
import tomllib
|
|
||||||
from os import environ
|
|
||||||
from pathlib import Path
|
|
||||||
from socket import gethostname
|
|
||||||
|
|
||||||
import typer
|
|
||||||
|
|
||||||
from python.common import configure_logger, signal_alert
|
|
||||||
from python.system_tests.components import systemd_tests, zpool_tests
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def load_config_data(config_file: Path) -> dict[str, list[str]]:
|
|
||||||
"""Load a TOML configuration file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
config_file (Path): The path to the configuration file.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: The configuration data.
|
|
||||||
"""
|
|
||||||
return tomllib.loads(config_file.read_text())
|
|
||||||
|
|
||||||
|
|
||||||
def main(config_file: Path) -> None:
|
|
||||||
"""Main."""
|
|
||||||
configure_logger(level=environ.get("LOG_LEVEL", "INFO"))
|
|
||||||
|
|
||||||
server_name = gethostname()
|
|
||||||
logger.info(f"Starting {server_name} validation")
|
|
||||||
|
|
||||||
config_data = load_config_data(config_file)
|
|
||||||
|
|
||||||
errors: list[str] = []
|
|
||||||
try:
|
|
||||||
if config_data.get("zpools") and (zpool_errors := zpool_tests(config_data["zpools"])):
|
|
||||||
errors.extend(zpool_errors)
|
|
||||||
|
|
||||||
if config_data.get("services") and (systemd_errors := systemd_tests(config_data["services"])):
|
|
||||||
errors.extend(systemd_errors)
|
|
||||||
|
|
||||||
except Exception as error:
|
|
||||||
logger.exception(f"{server_name} validation failed")
|
|
||||||
errors.append(f"{server_name} validation failed: {error}")
|
|
||||||
|
|
||||||
if errors:
|
|
||||||
logger.error(f"{server_name} validation failed: \n{'\n'.join(errors)}")
|
|
||||||
signal_alert(f"{server_name} validation failed {errors}")
|
|
||||||
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
logger.info(f"{server_name} validation passed")
|
|
||||||
|
|
||||||
|
|
||||||
def cli() -> None:
|
|
||||||
"""CLI."""
|
|
||||||
typer.run(main)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
cli()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""init."""
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""init."""
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
"""Bar."""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def bar() -> None:
|
|
||||||
"""Bar."""
|
|
||||||
logger.debug(f"bar {__name__}")
|
|
||||||
logger.debug("bar")
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
"""configure_logger."""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def configure_logger(level: str = "INFO", test: str | None = None) -> None:
|
|
||||||
"""Configure the logger.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
level (str, optional): The logging level. Defaults to "INFO".
|
|
||||||
test (str | None, optional): The test name. Defaults to None.
|
|
||||||
"""
|
|
||||||
logging.basicConfig(
|
|
||||||
level=level,
|
|
||||||
datefmt="%Y-%m-%dT%H:%M:%S%z",
|
|
||||||
format="%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s" # this is nesiseary
|
|
||||||
f" {test}",
|
|
||||||
handlers=[logging.StreamHandler(sys.stdout)],
|
|
||||||
)
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
"""foo."""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from python.testing.logging.bar import bar
|
|
||||||
from python.testing.logging.configure_logger import configure_logger
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def foo() -> None:
|
|
||||||
"""Foo."""
|
|
||||||
configure_logger("DEBUG", "FOO")
|
|
||||||
logger.debug(f"foo {__name__}")
|
|
||||||
logger.debug("foo")
|
|
||||||
|
|
||||||
bar()
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
"""main."""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from python.testing.logging.bar import bar
|
|
||||||
from python.testing.logging.configure_logger import configure_logger
|
|
||||||
from python.testing.logging.foo import foo
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""Main."""
|
|
||||||
configure_logger("DEBUG")
|
|
||||||
# handler = logging.StreamHandler()
|
|
||||||
|
|
||||||
# Create and attach a formatter
|
|
||||||
# formatter = logging.Formatter(
|
|
||||||
# "%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s FOO"
|
|
||||||
# )
|
|
||||||
# handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
# Attach handler to logger
|
|
||||||
# foo_logger = logging.getLogger("python.testing.logging.foo")
|
|
||||||
# foo_logger.addHandler(handler)
|
|
||||||
# foo_logger.propagate = True
|
|
||||||
logger.debug("main")
|
|
||||||
foo()
|
|
||||||
bar()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
"""Server Tools."""
|
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
"""snapshot_manager."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
import tomllib
|
|
||||||
from functools import cache
|
|
||||||
from pathlib import Path # noqa: TC003 This is required for the typer CLI
|
|
||||||
from re import compile as re_compile
|
|
||||||
from re import search
|
|
||||||
|
|
||||||
import typer
|
|
||||||
|
|
||||||
from python.common import configure_logger, signal_alert, utcnow
|
|
||||||
from python.zfs import Dataset, get_datasets
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def main(config_file: Path) -> None:
|
|
||||||
"""Main."""
|
|
||||||
configure_logger(level="DEBUG")
|
|
||||||
logger.info("Starting snapshot_manager")
|
|
||||||
|
|
||||||
try:
|
|
||||||
time_stamp = get_time_stamp()
|
|
||||||
|
|
||||||
for dataset in get_datasets():
|
|
||||||
status = dataset.create_snapshot(time_stamp)
|
|
||||||
logger.debug(f"{status=}")
|
|
||||||
if status != "snapshot created":
|
|
||||||
msg = f"{dataset.name} failed to create snapshot {time_stamp}"
|
|
||||||
logger.error(msg)
|
|
||||||
signal_alert(msg)
|
|
||||||
continue
|
|
||||||
|
|
||||||
get_snapshots_to_delete(dataset, get_count_lookup(config_file, dataset.name))
|
|
||||||
except Exception:
|
|
||||||
logger.exception("snapshot_manager failed")
|
|
||||||
signal_alert("snapshot_manager failed")
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
logger.info("snapshot_manager completed")
|
|
||||||
|
|
||||||
|
|
||||||
def get_count_lookup(config_file: Path, dataset_name: str) -> dict[str, int]:
|
|
||||||
"""Get the count lookup.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
config_file (Path): The path to the configuration file.
|
|
||||||
dataset_name (str): The name of the dataset.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict[str, int]: The count lookup.
|
|
||||||
"""
|
|
||||||
config_data = load_config_data(config_file)
|
|
||||||
|
|
||||||
return config_data.get(dataset_name, get_default_config(config_data))
|
|
||||||
|
|
||||||
|
|
||||||
def get_default_config(config_data: dict[str, dict[str, int]]) -> dict[str, int]:
|
|
||||||
"""Get the default configuration.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
config_data (dict[str, dict[str, int]]): The configuration data.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict[str, int]: The default configuration.
|
|
||||||
"""
|
|
||||||
return config_data.get(
|
|
||||||
"default",
|
|
||||||
{"15_min": 4, "hourly": 12, "daily": 0, "monthly": 0},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def load_config_data(config_file: Path) -> dict[str, dict[str, int]]:
|
|
||||||
"""Load a TOML configuration file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
config_file (Path): The path to the configuration file.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: The configuration data.
|
|
||||||
"""
|
|
||||||
return tomllib.loads(config_file.read_text())
|
|
||||||
|
|
||||||
|
|
||||||
def get_snapshots_to_delete(
|
|
||||||
dataset: Dataset,
|
|
||||||
count_lookup: dict[str, int],
|
|
||||||
) -> None:
|
|
||||||
"""Get snapshots to delete.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
dataset (Dataset): the dataset
|
|
||||||
count_lookup (dict[str, int]): the count lookup
|
|
||||||
"""
|
|
||||||
snapshots = dataset.get_snapshots()
|
|
||||||
|
|
||||||
if not snapshots:
|
|
||||||
logger.info(f"{dataset.name} has no snapshots")
|
|
||||||
return
|
|
||||||
|
|
||||||
filters = (
|
|
||||||
("15_min", re_compile(r"auto_\d{10}(?:15|30|45)")),
|
|
||||||
("hourly", re_compile(r"auto_\d{8}(?!00)\d{2}00")),
|
|
||||||
("daily", re_compile(r"auto_\d{6}(?!01)\d{2}0000")),
|
|
||||||
("monthly", re_compile(r"auto_\d{6}010000")),
|
|
||||||
)
|
|
||||||
|
|
||||||
for filter_name, snapshot_filter in filters:
|
|
||||||
logger.debug(f"{filter_name=}\n{snapshot_filter=}")
|
|
||||||
|
|
||||||
filtered_snapshots = sorted(snapshot.name for snapshot in snapshots if search(snapshot_filter, snapshot.name))
|
|
||||||
|
|
||||||
logger.debug(f"{filtered_snapshots=}")
|
|
||||||
|
|
||||||
snapshots_wanted = count_lookup[filter_name]
|
|
||||||
snapshots_being_deleted = filtered_snapshots[:-snapshots_wanted] if snapshots_wanted > 0 else filtered_snapshots
|
|
||||||
|
|
||||||
logger.info(f"{snapshots_being_deleted} are being deleted")
|
|
||||||
for snapshot in snapshots_being_deleted:
|
|
||||||
if error := dataset.delete_snapshot(snapshot):
|
|
||||||
error_message = f"{dataset.name}@{snapshot} failed to delete: {error}"
|
|
||||||
signal_alert(error_message)
|
|
||||||
logger.error(error_message)
|
|
||||||
|
|
||||||
|
|
||||||
def get_time_stamp() -> str:
|
|
||||||
"""Get the time stamp."""
|
|
||||||
now = utcnow()
|
|
||||||
nearest_15_min = now.replace(minute=(now.minute - (now.minute % 15)))
|
|
||||||
return nearest_15_min.strftime("auto_%Y%m%d%H%M")
|
|
||||||
|
|
||||||
|
|
||||||
def cli() -> None:
|
|
||||||
"""CLI."""
|
|
||||||
typer.run(main)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
cli()
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
"""init."""
|
|
||||||
|
|
||||||
from python.zfs.dataset import Dataset, Snapshot, get_datasets
|
|
||||||
from python.zfs.zpool import Zpool
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"Dataset",
|
|
||||||
"Snapshot",
|
|
||||||
"Zpool",
|
|
||||||
"get_datasets",
|
|
||||||
]
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
"""dataset."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
from datetime import UTC, datetime
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from python.common import bash_wrapper
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _zfs_list(zfs_list: str) -> dict[str, Any]:
|
|
||||||
"""Check the version of zfs."""
|
|
||||||
raw_zfs_list_data, _ = bash_wrapper(zfs_list)
|
|
||||||
|
|
||||||
zfs_list_data = json.loads(raw_zfs_list_data)
|
|
||||||
|
|
||||||
vers_major = zfs_list_data["output_version"]["vers_major"]
|
|
||||||
vers_minor = zfs_list_data["output_version"]["vers_minor"]
|
|
||||||
command = zfs_list_data["output_version"]["command"]
|
|
||||||
|
|
||||||
if vers_major != 0 or vers_minor != 1 or command != "zfs list":
|
|
||||||
error = f"Datasets are not in the correct format {vers_major=} {vers_minor=} {command=}"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
|
|
||||||
return zfs_list_data
|
|
||||||
|
|
||||||
|
|
||||||
class Snapshot:
|
|
||||||
"""Snapshot."""
|
|
||||||
|
|
||||||
def __init__(self, snapshot_data: dict[str, Any]) -> None:
|
|
||||||
"""__init__."""
|
|
||||||
properties = snapshot_data["properties"]
|
|
||||||
self.createtxg = int(snapshot_data["createtxg"])
|
|
||||||
self.creation = datetime.fromtimestamp(int(properties["creation"]["value"]), tz=UTC)
|
|
||||||
self.defer_destroy = properties["defer_destroy"]["value"]
|
|
||||||
self.guid = int(properties["guid"]["value"])
|
|
||||||
self.name = snapshot_data["name"].split("@")[1]
|
|
||||||
self.objsetid = int(properties["objsetid"]["value"])
|
|
||||||
self.referenced = int(properties["referenced"]["value"])
|
|
||||||
self.used = int(properties["used"]["value"])
|
|
||||||
self.userrefs = int(properties["userrefs"]["value"])
|
|
||||||
self.version = int(properties["version"]["value"])
|
|
||||||
self.written = int(properties["written"]["value"])
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
"""__repr__."""
|
|
||||||
return f"name={self.name} used={self.used} refer={self.referenced}"
|
|
||||||
|
|
||||||
|
|
||||||
class Dataset:
|
|
||||||
"""Dataset."""
|
|
||||||
|
|
||||||
def __init__(self, name: str) -> None:
|
|
||||||
"""__init__."""
|
|
||||||
dataset_data = _zfs_list(f"zfs list {name} -pHj -o all")
|
|
||||||
|
|
||||||
properties = dataset_data["datasets"][name]["properties"]
|
|
||||||
|
|
||||||
self.aclinherit = properties["aclinherit"]["value"]
|
|
||||||
self.aclmode = properties["aclmode"]["value"]
|
|
||||||
self.acltype = properties["acltype"]["value"]
|
|
||||||
self.available = int(properties["available"]["value"])
|
|
||||||
self.canmount = properties["canmount"]["value"]
|
|
||||||
self.checksum = properties["checksum"]["value"]
|
|
||||||
self.clones = properties["clones"]["value"]
|
|
||||||
self.compression = properties["compression"]["value"]
|
|
||||||
self.copies = int(properties["copies"]["value"])
|
|
||||||
self.createtxg = int(properties["createtxg"]["value"])
|
|
||||||
self.creation = datetime.fromtimestamp(int(properties["creation"]["value"]), tz=UTC)
|
|
||||||
self.dedup = properties["dedup"]["value"]
|
|
||||||
self.devices = properties["devices"]["value"]
|
|
||||||
self.encryption = properties["encryption"]["value"]
|
|
||||||
self.exec = properties["exec"]["value"]
|
|
||||||
self.filesystem_limit = properties["filesystem_limit"]["value"]
|
|
||||||
self.guid = int(properties["guid"]["value"])
|
|
||||||
self.keystatus = properties["keystatus"]["value"]
|
|
||||||
self.logbias = properties["logbias"]["value"]
|
|
||||||
self.mlslabel = properties["mlslabel"]["value"]
|
|
||||||
self.mounted = properties["mounted"]["value"]
|
|
||||||
self.mountpoint = properties["mountpoint"]["value"]
|
|
||||||
self.name = name
|
|
||||||
self.quota = int(properties["quota"]["value"])
|
|
||||||
self.readonly = properties["readonly"]["value"]
|
|
||||||
self.recordsize = int(properties["recordsize"]["value"])
|
|
||||||
self.redundant_metadata = properties["redundant_metadata"]["value"]
|
|
||||||
self.referenced = int(properties["referenced"]["value"])
|
|
||||||
self.refquota = int(properties["refquota"]["value"])
|
|
||||||
self.refreservation = int(properties["refreservation"]["value"])
|
|
||||||
self.reservation = int(properties["reservation"]["value"])
|
|
||||||
self.setuid = properties["setuid"]["value"]
|
|
||||||
self.sharenfs = properties["sharenfs"]["value"]
|
|
||||||
self.snapdir = properties["snapdir"]["value"]
|
|
||||||
self.snapshot_limit = properties["snapshot_limit"]["value"]
|
|
||||||
self.sync = properties["sync"]["value"]
|
|
||||||
self.used = int(properties["used"]["value"])
|
|
||||||
self.usedbychildren = int(properties["usedbychildren"]["value"])
|
|
||||||
self.usedbydataset = int(properties["usedbydataset"]["value"])
|
|
||||||
self.usedbysnapshots = int(properties["usedbysnapshots"]["value"])
|
|
||||||
self.version = int(properties["version"]["value"])
|
|
||||||
self.volmode = properties["volmode"]["value"]
|
|
||||||
self.volsize = properties["volsize"]["value"]
|
|
||||||
self.vscan = properties["vscan"]["value"]
|
|
||||||
self.written = int(properties["written"]["value"])
|
|
||||||
self.xattr = properties["xattr"]["value"]
|
|
||||||
|
|
||||||
def get_snapshots(self) -> list[Snapshot] | None:
|
|
||||||
"""Get all snapshots from zfs and process then is test dicts of sets."""
|
|
||||||
snapshots_data = _zfs_list(f"zfs list -t snapshot -pHj {self.name} -o all")
|
|
||||||
|
|
||||||
return [Snapshot(properties) for properties in snapshots_data["datasets"].values()]
|
|
||||||
|
|
||||||
def create_snapshot(self, snapshot_name: str) -> str:
|
|
||||||
"""Creates a zfs snapshot.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
snapshot_name (str): a snapshot name
|
|
||||||
"""
|
|
||||||
logger.debug(f"Creating {self.name}@{snapshot_name}")
|
|
||||||
_, return_code = bash_wrapper(f"zfs snapshot {self.name}@{snapshot_name}")
|
|
||||||
if return_code == 0:
|
|
||||||
return "snapshot created"
|
|
||||||
|
|
||||||
if snapshots := self.get_snapshots():
|
|
||||||
snapshot_names = {snapshot.name for snapshot in snapshots}
|
|
||||||
if snapshot_name in snapshot_names:
|
|
||||||
return f"Snapshot {snapshot_name} already exists for {self.name}"
|
|
||||||
|
|
||||||
return f"Failed to create snapshot {snapshot_name} for {self.name}"
|
|
||||||
|
|
||||||
def delete_snapshot(self, snapshot_name: str) -> str | None:
|
|
||||||
"""Deletes a zfs snapshot.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
snapshot_name (str): a snapshot name
|
|
||||||
"""
|
|
||||||
logger.debug(f"deleting {self.name}@{snapshot_name}")
|
|
||||||
msg, return_code = bash_wrapper(f"zfs destroy {self.name}@{snapshot_name}")
|
|
||||||
if return_code != 0:
|
|
||||||
if msg.startswith(f"cannot destroy '{self.name}@{snapshot_name}': snapshot has dependent clones"):
|
|
||||||
return "snapshot has dependent clones"
|
|
||||||
error = f"Failed to delete snapshot {snapshot_name=} for {self.name}"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
"""__repr__."""
|
|
||||||
return (
|
|
||||||
f"{self.aclinherit=}\n"
|
|
||||||
f"{self.aclmode=}\n"
|
|
||||||
f"{self.acltype=}\n"
|
|
||||||
f"{self.available=}\n"
|
|
||||||
f"{self.canmount=}\n"
|
|
||||||
f"{self.checksum=}\n"
|
|
||||||
f"{self.clones=}\n"
|
|
||||||
f"{self.compression=}\n"
|
|
||||||
f"{self.copies=}\n"
|
|
||||||
f"{self.createtxg=}\n"
|
|
||||||
f"{self.creation=}\n"
|
|
||||||
f"{self.dedup=}\n"
|
|
||||||
f"{self.devices=}\n"
|
|
||||||
f"{self.encryption=}\n"
|
|
||||||
f"{self.exec=}\n"
|
|
||||||
f"{self.filesystem_limit=}\n"
|
|
||||||
f"{self.guid=}\n"
|
|
||||||
f"{self.keystatus=}\n"
|
|
||||||
f"{self.logbias=}\n"
|
|
||||||
f"{self.mlslabel=}\n"
|
|
||||||
f"{self.mounted=}\n"
|
|
||||||
f"{self.mountpoint=}\n"
|
|
||||||
f"{self.name=}\n"
|
|
||||||
f"{self.quota=}\n"
|
|
||||||
f"{self.readonly=}\n"
|
|
||||||
f"{self.recordsize=}\n"
|
|
||||||
f"{self.redundant_metadata=}\n"
|
|
||||||
f"{self.referenced=}\n"
|
|
||||||
f"{self.refquota=}\n"
|
|
||||||
f"{self.refreservation=}\n"
|
|
||||||
f"{self.reservation=}\n"
|
|
||||||
f"{self.setuid=}\n"
|
|
||||||
f"{self.sharenfs=}\n"
|
|
||||||
f"{self.snapdir=}\n"
|
|
||||||
f"{self.snapshot_limit=}\n"
|
|
||||||
f"{self.sync=}\n"
|
|
||||||
f"{self.used=}\n"
|
|
||||||
f"{self.usedbychildren=}\n"
|
|
||||||
f"{self.usedbydataset=}\n"
|
|
||||||
f"{self.usedbysnapshots=}\n"
|
|
||||||
f"{self.version=}\n"
|
|
||||||
f"{self.volmode=}\n"
|
|
||||||
f"{self.volsize=}\n"
|
|
||||||
f"{self.vscan=}\n"
|
|
||||||
f"{self.written=}\n"
|
|
||||||
f"{self.xattr=}\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_datasets() -> list[Dataset]:
|
|
||||||
"""Get zfs list.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[Dataset]: A list of zfs datasets.
|
|
||||||
"""
|
|
||||||
logger.info("Getting zfs list")
|
|
||||||
|
|
||||||
dataset_names, _ = bash_wrapper("zfs list -Hp -t filesystem -o name")
|
|
||||||
|
|
||||||
cleaned_datasets = dataset_names.strip().split("\n")
|
|
||||||
|
|
||||||
return [Dataset(dataset_name) for dataset_name in cleaned_datasets if "/" in dataset_name]
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
"""test."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from python.common import bash_wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def _zpool_list(zfs_list: str) -> dict[str, Any]:
|
|
||||||
"""Check the version of zfs."""
|
|
||||||
raw_zfs_list_data, _ = bash_wrapper(zfs_list)
|
|
||||||
|
|
||||||
zfs_list_data = json.loads(raw_zfs_list_data)
|
|
||||||
|
|
||||||
vers_major = zfs_list_data["output_version"]["vers_major"]
|
|
||||||
vers_minor = zfs_list_data["output_version"]["vers_minor"]
|
|
||||||
command = zfs_list_data["output_version"]["command"]
|
|
||||||
|
|
||||||
if vers_major != 0 or vers_minor != 1 or command != "zpool list":
|
|
||||||
error = f"Datasets are not in the correct format {vers_major=} {vers_minor=} {command=}"
|
|
||||||
raise RuntimeError(error)
|
|
||||||
|
|
||||||
return zfs_list_data
|
|
||||||
|
|
||||||
|
|
||||||
class Zpool:
|
|
||||||
"""Zpool."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
) -> None:
|
|
||||||
"""__init__."""
|
|
||||||
zpool_data = _zpool_list(f"zpool list {name} -pHj -o all")
|
|
||||||
|
|
||||||
properties = zpool_data["pools"][name]["properties"]
|
|
||||||
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
self.allocated = int(properties["allocated"]["value"])
|
|
||||||
self.altroot = properties["altroot"]["value"]
|
|
||||||
self.ashift = int(properties["ashift"]["value"])
|
|
||||||
self.autoexpand = properties["autoexpand"]["value"]
|
|
||||||
self.autoreplace = properties["autoreplace"]["value"]
|
|
||||||
self.autotrim = properties["autotrim"]["value"]
|
|
||||||
self.capacity = int(properties["capacity"]["value"])
|
|
||||||
self.comment = properties["comment"]["value"]
|
|
||||||
self.dedupratio = properties["dedupratio"]["value"]
|
|
||||||
self.delegation = properties["delegation"]["value"]
|
|
||||||
self.expandsize = properties["expandsize"]["value"]
|
|
||||||
self.failmode = properties["failmode"]["value"]
|
|
||||||
self.fragmentation = int(properties["fragmentation"]["value"])
|
|
||||||
self.free = properties["free"]["value"]
|
|
||||||
self.freeing = int(properties["freeing"]["value"])
|
|
||||||
self.guid = int(properties["guid"]["value"])
|
|
||||||
self.health = properties["health"]["value"]
|
|
||||||
self.leaked = int(properties["leaked"]["value"])
|
|
||||||
self.readonly = properties["readonly"]["value"]
|
|
||||||
self.size = int(properties["size"]["value"])
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
"""__repr__."""
|
|
||||||
return (
|
|
||||||
f"{self.name=}\n"
|
|
||||||
f"{self.allocated=}\n"
|
|
||||||
f"{self.altroot=}\n"
|
|
||||||
f"{self.ashift=}\n"
|
|
||||||
f"{self.autoexpand=}\n"
|
|
||||||
f"{self.autoreplace=}\n"
|
|
||||||
f"{self.autotrim=}\n"
|
|
||||||
f"{self.capacity=}\n"
|
|
||||||
f"{self.comment=}\n"
|
|
||||||
f"{self.dedupratio=}\n"
|
|
||||||
f"{self.delegation=}\n"
|
|
||||||
f"{self.expandsize=}\n"
|
|
||||||
f"{self.failmode=}\n"
|
|
||||||
f"{self.fragmentation=}\n"
|
|
||||||
f"{self.freeing=}\n"
|
|
||||||
f"{self.guid=}\n"
|
|
||||||
f"{self.health=}\n"
|
|
||||||
f"{self.leaked=}\n"
|
|
||||||
f"{self.readonly=}\n"
|
|
||||||
f"{self.size=}"
|
|
||||||
)
|
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
{
|
{pkgs ? import <nixpkgs> {}, ...}: {
|
||||||
pkgs ? import <nixpkgs> { },
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
NIX_CONFIG = "extra-experimental-features = nix-command flakes ca-derivations";
|
NIX_CONFIG = "extra-experimental-features = nix-command flakes ca-derivations";
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/richie
|
../../users/richie
|
||||||
../../users/gaming
|
|
||||||
../../common/global
|
../../common/global
|
||||||
../../common/optional/desktop.nix
|
../../common/optional/desktop.nix
|
||||||
../../common/optional/docker.nix
|
../../common/optional/docker.nix
|
||||||
@@ -9,13 +8,11 @@
|
|||||||
../../common/optional/steam.nix
|
../../common/optional/steam.nix
|
||||||
../../common/optional/syncthing_base.nix
|
../../common/optional/syncthing_base.nix
|
||||||
../../common/optional/systemd-boot.nix
|
../../common/optional/systemd-boot.nix
|
||||||
../../common/optional/update.nix
|
|
||||||
../../common/optional/yubikey.nix
|
../../common/optional/yubikey.nix
|
||||||
../../common/optional/zerotier.nix
|
../../common/optional/zerotier.nix
|
||||||
../../common/optional/nvidia.nix
|
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
|
./nvidia.nix
|
||||||
./syncthing.nix
|
./syncthing.nix
|
||||||
./llms.nix
|
|
||||||
];
|
];
|
||||||
|
|
||||||
networking = {
|
networking = {
|
||||||
@@ -25,19 +22,28 @@
|
|||||||
networkmanager.enable = true;
|
networkmanager.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
services = {
|
hardware = {
|
||||||
displayManager = {
|
pulseaudio.enable = false;
|
||||||
|
bluetooth = {
|
||||||
enable = true;
|
enable = true;
|
||||||
autoLogin = {
|
powerOnBoot = true;
|
||||||
user = "gaming";
|
|
||||||
enable = true;
|
|
||||||
};
|
|
||||||
defaultSession = "plasma";
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
security.rtkit.enable = true;
|
||||||
|
|
||||||
|
services = {
|
||||||
|
|
||||||
openssh.ports = [ 262 ];
|
openssh.ports = [ 262 ];
|
||||||
|
|
||||||
snapshot_manager.path = ./snapshot_config.toml;
|
printing.enable = true;
|
||||||
|
|
||||||
|
snapshot_manager.enable = true;
|
||||||
|
|
||||||
|
zfs = {
|
||||||
|
trim.enable = true;
|
||||||
|
autoScrub.enable = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
system.stateVersion = "24.05";
|
system.stateVersion = "24.05";
|
||||||
|
|||||||
@@ -26,9 +26,6 @@
|
|||||||
device = "/dev/disk/by-id/nvme-Samsung_SSD_990_PRO_with_Heatsink_1TB_S73JNJ0X114418B-part2";
|
device = "/dev/disk/by-id/nvme-Samsung_SSD_990_PRO_with_Heatsink_1TB_S73JNJ0X114418B-part2";
|
||||||
bypassWorkqueues = true;
|
bypassWorkqueues = true;
|
||||||
allowDiscards = true;
|
allowDiscards = true;
|
||||||
keyFileSize = 4096;
|
|
||||||
keyFile = "/dev/disk/by-id/usb-Samsung_Flash_Drive_FIT_0374620080067131-0:0";
|
|
||||||
fallbackToPassword = true;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
kernelModules = [ "kvm-amd" ];
|
kernelModules = [ "kvm-amd" ];
|
||||||
@@ -51,11 +48,6 @@
|
|||||||
fsType = "zfs";
|
fsType = "zfs";
|
||||||
};
|
};
|
||||||
|
|
||||||
"/zfs/models" = {
|
|
||||||
device = "root_pool/models";
|
|
||||||
fsType = "zfs";
|
|
||||||
};
|
|
||||||
|
|
||||||
"/boot" = {
|
"/boot" = {
|
||||||
device = "/dev/disk/by-uuid/609D-FF29";
|
device = "/dev/disk/by-uuid/609D-FF29";
|
||||||
fsType = "vfat";
|
fsType = "vfat";
|
||||||
@@ -72,4 +64,4 @@
|
|||||||
|
|
||||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||||
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||||
}
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
services = {
|
|
||||||
ollama = {
|
|
||||||
user = "ollama";
|
|
||||||
enable = true;
|
|
||||||
loadModels = [
|
|
||||||
"codellama:7b"
|
|
||||||
"deepseek-r1:8b"
|
|
||||||
"deepseek-r1:14b"
|
|
||||||
"deepseek-r1:32b"
|
|
||||||
"llama3.2:3b"
|
|
||||||
"llama2-uncensored:7b"
|
|
||||||
"mistral-nemo:12b"
|
|
||||||
"dolphin-mixtral:8x7b"
|
|
||||||
"qwq:32b"
|
|
||||||
"Qihoo360-Light-R1-32B"
|
|
||||||
];
|
|
||||||
models = "/zfs/models";
|
|
||||||
acceleration = "cuda";
|
|
||||||
openFirewall = true;
|
|
||||||
};
|
|
||||||
# open-webui = {
|
|
||||||
# enable = true;
|
|
||||||
# openFirewall = true;
|
|
||||||
# host = "0.0.0.0";
|
|
||||||
# };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
nixpkgs.config.cudaSupport = true;
|
|
||||||
|
|
||||||
services.xserver.videoDrivers = [ "nvidia" ];
|
services.xserver.videoDrivers = [ "nvidia" ];
|
||||||
hardware = {
|
hardware = {
|
||||||
nvidia = {
|
nvidia = {
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
["default"]
|
|
||||||
15_min = 8
|
|
||||||
hourly = 24
|
|
||||||
daily = 0
|
|
||||||
monthly = 0
|
|
||||||
|
|
||||||
["root_pool/home"]
|
|
||||||
15_min = 8
|
|
||||||
hourly = 12
|
|
||||||
daily = 1
|
|
||||||
monthly = 0
|
|
||||||
|
|
||||||
["root_pool/root"]
|
|
||||||
15_min = 8
|
|
||||||
hourly = 24
|
|
||||||
daily = 0
|
|
||||||
monthly = 0
|
|
||||||
|
|
||||||
["root_pool/nix"]
|
|
||||||
15_min = 4
|
|
||||||
hourly = 0
|
|
||||||
daily = 0
|
|
||||||
monthly = 0
|
|
||||||
|
|
||||||
["root_pool/models"]
|
|
||||||
15_min = 4
|
|
||||||
hourly = 24
|
|
||||||
daily = 0
|
|
||||||
monthly = 0
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
services.syncthing.settings.folders = {
|
services.syncthing.settings.folders = {
|
||||||
"dotfiles" = {
|
"notes" = {
|
||||||
path = "/home/richie/dotfiles";
|
id = "l62ul-lpweo"; # cspell:disable-line
|
||||||
|
path = "/home/richie/notes";
|
||||||
devices = [
|
devices = [
|
||||||
"brain"
|
|
||||||
"jeeves"
|
"jeeves"
|
||||||
"rhapsody-in-green"
|
"rhapsody-in-green"
|
||||||
];
|
];
|
||||||
@@ -13,9 +13,8 @@
|
|||||||
id = "4ckma-gtshs"; # cspell:disable-line
|
id = "4ckma-gtshs"; # cspell:disable-line
|
||||||
path = "/home/richie/important";
|
path = "/home/richie/important";
|
||||||
devices = [
|
devices = [
|
||||||
"brain"
|
|
||||||
"jeeves"
|
|
||||||
"phone"
|
"phone"
|
||||||
|
"jeeves"
|
||||||
"rhapsody-in-green"
|
"rhapsody-in-green"
|
||||||
];
|
];
|
||||||
fsWatcherEnabled = true;
|
fsWatcherEnabled = true;
|
||||||
@@ -31,5 +30,29 @@
|
|||||||
];
|
];
|
||||||
fsWatcherEnabled = true;
|
fsWatcherEnabled = true;
|
||||||
};
|
};
|
||||||
|
"projects" = {
|
||||||
|
id = "vyma6-lqqrz"; # cspell:disable-line
|
||||||
|
path = "/home/richie/projects";
|
||||||
|
devices = [
|
||||||
|
"jeeves"
|
||||||
|
"rhapsody-in-green"
|
||||||
|
];
|
||||||
|
fsWatcherEnabled = true;
|
||||||
|
};
|
||||||
|
"temp" = {
|
||||||
|
id = "bob_temp";
|
||||||
|
path = "/home/richie/temp";
|
||||||
|
devices = [
|
||||||
|
"jeeves"
|
||||||
|
];
|
||||||
|
fsWatcherEnabled = true;
|
||||||
|
};
|
||||||
|
"vault" = {
|
||||||
|
path = "/home/richie/vault";
|
||||||
|
devices = [
|
||||||
|
"rhapsody-in-green"
|
||||||
|
];
|
||||||
|
fsWatcherEnabled = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
../../users/richie
|
|
||||||
../../common/global
|
|
||||||
../../common/optional/docker.nix
|
|
||||||
../../common/optional/ssh_decrypt.nix
|
|
||||||
../../common/optional/syncthing_base.nix
|
|
||||||
../../common/optional/systemd-boot.nix
|
|
||||||
../../common/optional/update.nix
|
|
||||||
../../common/optional/zerotier.nix
|
|
||||||
./docker
|
|
||||||
./hardware.nix
|
|
||||||
./programs.nix
|
|
||||||
./services
|
|
||||||
./syncthing.nix
|
|
||||||
inputs.nixos-hardware.nixosModules.framework-11th-gen-intel
|
|
||||||
];
|
|
||||||
|
|
||||||
networking = {
|
|
||||||
hostName = "brain";
|
|
||||||
hostId = "93a06c6e";
|
|
||||||
firewall.enable = true;
|
|
||||||
networkmanager.enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
hardware.bluetooth = {
|
|
||||||
enable = true;
|
|
||||||
powerOnBoot = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
services = {
|
|
||||||
openssh.ports = [ 129 ];
|
|
||||||
|
|
||||||
smartd.enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
system.stateVersion = "25.05";
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{ lib, ... }:
|
|
||||||
{
|
|
||||||
imports =
|
|
||||||
let
|
|
||||||
files = builtins.attrNames (builtins.readDir ./.);
|
|
||||||
nixFiles = builtins.filter (name: lib.hasSuffix ".nix" name && name != "default.nix") files;
|
|
||||||
in
|
|
||||||
map (file: ./. + "/${file}") nixFiles;
|
|
||||||
|
|
||||||
virtualisation.oci-containers.backend = "docker";
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# docker_networks
|
|
||||||
|
|
||||||
docker network create -d bridge web
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
environment.systemPackages = with pkgs; [
|
|
||||||
filebot
|
|
||||||
docker-compose
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{ lib, ... }:
|
|
||||||
{
|
|
||||||
imports =
|
|
||||||
let
|
|
||||||
files = builtins.attrNames (builtins.readDir ./.);
|
|
||||||
nixFiles = builtins.filter (name: lib.hasSuffix ".nix" name && name != "default.nix") files;
|
|
||||||
in
|
|
||||||
map (file: ./. + "/${file}") nixFiles;
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
{
|
|
||||||
users = {
|
|
||||||
users.hass = {
|
|
||||||
isSystemUser = true;
|
|
||||||
group = "hass";
|
|
||||||
};
|
|
||||||
groups.hass = { };
|
|
||||||
};
|
|
||||||
|
|
||||||
services = {
|
|
||||||
home-assistant = {
|
|
||||||
enable = true;
|
|
||||||
openFirewall = true;
|
|
||||||
config = {
|
|
||||||
http = {
|
|
||||||
server_port = 8123;
|
|
||||||
server_host = [
|
|
||||||
"192.168.90.35"
|
|
||||||
"192.168.95.35"
|
|
||||||
"127.0.0.1"
|
|
||||||
];
|
|
||||||
use_x_forwarded_for = true;
|
|
||||||
};
|
|
||||||
homeassistant = {
|
|
||||||
time_zone = "America/New_York";
|
|
||||||
unit_system = "us_customary";
|
|
||||||
temperature_unit = "F";
|
|
||||||
packages = {
|
|
||||||
victron_modbuss = "!include ${./home_assistant/victron_modbuss.yaml}";
|
|
||||||
battery_sensors = "!include ${./home_assistant/battery_sensors.yaml}";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
recorder = {
|
|
||||||
db_url = "postgresql://@/hass";
|
|
||||||
auto_purge = true;
|
|
||||||
purge_keep_days = 3650;
|
|
||||||
db_retry_wait = 15;
|
|
||||||
};
|
|
||||||
assist_pipeline = { };
|
|
||||||
backup = { };
|
|
||||||
bluetooth = { };
|
|
||||||
config = { };
|
|
||||||
dhcp = { };
|
|
||||||
energy = { };
|
|
||||||
history = { };
|
|
||||||
homeassistant_alerts = { };
|
|
||||||
image_upload = { };
|
|
||||||
logbook = { };
|
|
||||||
media_source = { };
|
|
||||||
mobile_app = { };
|
|
||||||
ssdp = { };
|
|
||||||
sun = { };
|
|
||||||
webhook = { };
|
|
||||||
cloud = { };
|
|
||||||
zeroconf = { };
|
|
||||||
automation = "!include automations.yaml";
|
|
||||||
script = "!include scripts.yaml";
|
|
||||||
scene = "!include scenes.yaml";
|
|
||||||
group = "!include groups.yaml";
|
|
||||||
};
|
|
||||||
extraPackages =
|
|
||||||
python3Packages: with python3Packages; [
|
|
||||||
pymodbus # for modbus
|
|
||||||
gtts # not sure what wants this
|
|
||||||
jellyfin-apiclient-python # for jellyfin
|
|
||||||
paho-mqtt # for mqtt
|
|
||||||
psycopg2 # for postgresql
|
|
||||||
forecast-solar # for solar forecast
|
|
||||||
aioesphomeapi # for esphome
|
|
||||||
esphome-dashboard-api # for esphome
|
|
||||||
py-improv-ble-client # for esphome
|
|
||||||
bleak-esphome # for esphome
|
|
||||||
];
|
|
||||||
extraComponents = [ "isal" ];
|
|
||||||
};
|
|
||||||
esphome = {
|
|
||||||
enable = true;
|
|
||||||
openFirewall = true;
|
|
||||||
address = "192.168.90.35";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
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:
|
|
||||||
# Battery 0
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.jk0_charge_power_w
|
|
||||||
name: "JK0 energy in"
|
|
||||||
unique_id: jk0_energy_in_kwh
|
|
||||||
unit_prefix: k
|
|
||||||
method: trapezoidal
|
|
||||||
round: 3
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.jk0_discharge_power_w
|
|
||||||
name: "JK0 energy out"
|
|
||||||
unique_id: jk0_energy_out_kwh
|
|
||||||
unit_prefix: k
|
|
||||||
method: trapezoidal
|
|
||||||
round: 3
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
|
|
||||||
# Battery 1
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.jk1_charge_power_w
|
|
||||||
name: "JK1 energy in"
|
|
||||||
unique_id: jk1_energy_in_kwh
|
|
||||||
unit_prefix: k
|
|
||||||
method: trapezoidal
|
|
||||||
round: 3
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.jk1_discharge_power_w
|
|
||||||
name: "JK1 energy out"
|
|
||||||
unique_id: jk1_energy_out_kwh
|
|
||||||
unit_prefix: k
|
|
||||||
method: trapezoidal
|
|
||||||
round: 3
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
|
|
||||||
utility_meter:
|
|
||||||
# Battery 0
|
|
||||||
jk0_energy_in_daily:
|
|
||||||
source: sensor.jk0_energy_in
|
|
||||||
name: "JK0 Energy In Daily"
|
|
||||||
cycle: daily
|
|
||||||
jk0_energy_out_daily:
|
|
||||||
source: sensor.jk0_energy_out
|
|
||||||
name: "JK0 Energy Out Daily"
|
|
||||||
cycle: daily
|
|
||||||
|
|
||||||
# Battery 1
|
|
||||||
jk1_energy_in_daily:
|
|
||||||
source: sensor.jk1_energy_in
|
|
||||||
name: "JK1 Energy In Daily"
|
|
||||||
cycle: daily
|
|
||||||
jk1_energy_out_daily:
|
|
||||||
source: sensor.jk1_energy_out
|
|
||||||
name: "JK1 Energy Out Daily"
|
|
||||||
cycle: daily
|
|
||||||
@@ -1,347 +0,0 @@
|
|||||||
modbus:
|
|
||||||
- name: victron_gx
|
|
||||||
type: tcp
|
|
||||||
host: 192.168.103.30
|
|
||||||
port: 502
|
|
||||||
timeout: 3
|
|
||||||
delay: 2
|
|
||||||
sensors:
|
|
||||||
# ---- SOLAR CHARGER (Unit ID 226) ----
|
|
||||||
- name: Solar Voltage
|
|
||||||
slave: 226
|
|
||||||
address: 776
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.01
|
|
||||||
precision: 2
|
|
||||||
unit_of_measurement: "V"
|
|
||||||
device_class: voltage
|
|
||||||
state_class: measurement
|
|
||||||
|
|
||||||
- name: Solar Amperage
|
|
||||||
slave: 226
|
|
||||||
address: 777
|
|
||||||
input_type: holding
|
|
||||||
data_type: int16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 1
|
|
||||||
unit_of_measurement: "A"
|
|
||||||
device_class: current
|
|
||||||
state_class: measurement
|
|
||||||
|
|
||||||
- name: Solar Wattage
|
|
||||||
slave: 226
|
|
||||||
address: 789
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.1
|
|
||||||
unit_of_measurement: "W"
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
|
|
||||||
- name: Solar Yield Today
|
|
||||||
slave: 226
|
|
||||||
address: 784
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 3
|
|
||||||
unit_of_measurement: "kWh"
|
|
||||||
device_class: energy
|
|
||||||
state_class: total
|
|
||||||
|
|
||||||
# DC system
|
|
||||||
- name: DC Voltage
|
|
||||||
slave: 100
|
|
||||||
address: 840
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 2
|
|
||||||
unit_of_measurement: "V"
|
|
||||||
device_class: voltage
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: dc_voltage
|
|
||||||
|
|
||||||
- name: DC Wattage
|
|
||||||
slave: 100
|
|
||||||
address: 860
|
|
||||||
input_type: holding
|
|
||||||
data_type: int16
|
|
||||||
scale: 1
|
|
||||||
precision: 0
|
|
||||||
unit_of_measurement: "W"
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: dc_wattage
|
|
||||||
|
|
||||||
# GPS
|
|
||||||
- name: GPS Latitude
|
|
||||||
slave: 100
|
|
||||||
address: 2800
|
|
||||||
input_type: holding
|
|
||||||
data_type: int32
|
|
||||||
scale: 0.0000001
|
|
||||||
precision: 7
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_latitude
|
|
||||||
|
|
||||||
- name: GPS Longitude
|
|
||||||
slave: 100
|
|
||||||
address: 2802
|
|
||||||
input_type: holding
|
|
||||||
data_type: int32
|
|
||||||
scale: 0.0000001
|
|
||||||
precision: 7
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_longitude
|
|
||||||
|
|
||||||
- name: GPS Course
|
|
||||||
slave: 100
|
|
||||||
address: 2804
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.01
|
|
||||||
precision: 2
|
|
||||||
unit_of_measurement: "°"
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_course
|
|
||||||
|
|
||||||
- name: GPS Speed
|
|
||||||
slave: 100
|
|
||||||
address: 2805
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.01
|
|
||||||
precision: 2
|
|
||||||
unit_of_measurement: "m/s"
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_speed
|
|
||||||
|
|
||||||
- name: GPS Fix
|
|
||||||
slave: 100
|
|
||||||
address: 2806
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_fix
|
|
||||||
|
|
||||||
- name: GPS Satellites
|
|
||||||
slave: 100
|
|
||||||
address: 2807
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_satellites
|
|
||||||
|
|
||||||
- name: GPS Altitude
|
|
||||||
slave: 100
|
|
||||||
address: 2808
|
|
||||||
input_type: holding
|
|
||||||
data_type: int32
|
|
||||||
scale: 0.16
|
|
||||||
precision: 1
|
|
||||||
unit_of_measurement: "m"
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: gps_altitude
|
|
||||||
|
|
||||||
# ---- CHARGER (Unit ID 223) ----
|
|
||||||
- name: Charger Output 1 Voltage
|
|
||||||
slave: 223
|
|
||||||
address: 2307
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 0.01
|
|
||||||
precision: 2
|
|
||||||
unit_of_measurement: "V"
|
|
||||||
device_class: voltage
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_output_1_voltage
|
|
||||||
|
|
||||||
- name: Charger Output 1 Current
|
|
||||||
slave: 223
|
|
||||||
address: 2308
|
|
||||||
input_type: holding
|
|
||||||
data_type: int16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 1
|
|
||||||
unit_of_measurement: "A"
|
|
||||||
device_class: current
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_output_1_current
|
|
||||||
|
|
||||||
- name: Charger Output 1 Temperature
|
|
||||||
slave: 223
|
|
||||||
address: 2309
|
|
||||||
input_type: holding
|
|
||||||
data_type: int16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 1
|
|
||||||
unit_of_measurement: "°C"
|
|
||||||
device_class: temperature
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_output_1_temperature
|
|
||||||
|
|
||||||
- name: Charger AC Current
|
|
||||||
slave: 223
|
|
||||||
address: 2314
|
|
||||||
input_type: holding
|
|
||||||
data_type: int16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 1
|
|
||||||
unit_of_measurement: "A"
|
|
||||||
device_class: current
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_ac_current
|
|
||||||
|
|
||||||
- name: Charger AC Current Limit
|
|
||||||
slave: 223
|
|
||||||
address: 2316
|
|
||||||
input_type: holding
|
|
||||||
data_type: int16
|
|
||||||
scale: 0.1
|
|
||||||
precision: 1
|
|
||||||
unit_of_measurement: "A"
|
|
||||||
device_class: current
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_ac_current_limit
|
|
||||||
|
|
||||||
- name: Charger On Off Raw
|
|
||||||
slave: 223
|
|
||||||
address: 2317
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_on_off_raw
|
|
||||||
|
|
||||||
- name: Charger Charge State Raw
|
|
||||||
slave: 223
|
|
||||||
address: 2318
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_charge_state_raw
|
|
||||||
|
|
||||||
- name: Charger Error Code
|
|
||||||
slave: 223
|
|
||||||
address: 2319
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_error_code
|
|
||||||
|
|
||||||
- name: Charger Relay State
|
|
||||||
slave: 223
|
|
||||||
address: 2320
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_relay_state
|
|
||||||
|
|
||||||
- name: Charger Low Voltage Alarm
|
|
||||||
slave: 223
|
|
||||||
address: 2321
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_low_voltage_alarm
|
|
||||||
|
|
||||||
- name: Charger High Voltage Alarm
|
|
||||||
slave: 223
|
|
||||||
address: 2322
|
|
||||||
input_type: holding
|
|
||||||
data_type: uint16
|
|
||||||
scale: 1
|
|
||||||
state_class: measurement
|
|
||||||
unique_id: charger_high_voltage_alarm
|
|
||||||
|
|
||||||
template:
|
|
||||||
- sensor:
|
|
||||||
- name: Charger On Off
|
|
||||||
state: >-
|
|
||||||
{% set v = states('sensor.charger_on_off_raw')|int %}
|
|
||||||
{{ {0:'Off',1:'On',2:'Error',3:'Unavailable'}.get(v, 'Unknown') }}
|
|
||||||
|
|
||||||
- name: Charger Charge State
|
|
||||||
state: >-
|
|
||||||
{% set v = states('sensor.charger_charge_state_raw')|int %}
|
|
||||||
{{ {
|
|
||||||
0:'Off',1:'Low Power',2:'Fault',3:'Bulk',4:'Absorption',5:'Float',
|
|
||||||
6:'Storage',7:'Equalize/Manual',8:'External Control'
|
|
||||||
}.get(v,'Unknown') }}
|
|
||||||
|
|
||||||
- name: "Charger DC Wattage"
|
|
||||||
unique_id: charger_dc_wattage
|
|
||||||
unit_of_measurement: "W"
|
|
||||||
device_class: power
|
|
||||||
state_class: measurement
|
|
||||||
state: >-
|
|
||||||
{% set v = states('sensor.charger_output_1_voltage')|float(0) %}
|
|
||||||
{% set a = states('sensor.charger_output_1_current')|float(0) %}
|
|
||||||
{{ (v * a) | round(1) }}
|
|
||||||
|
|
||||||
- binary_sensor:
|
|
||||||
- name: Charger Low Voltage Alarm Active
|
|
||||||
state: "{{ states('sensor.charger_low_voltage_alarm')|int == 2 }}"
|
|
||||||
- name: Charger High Voltage Alarm Active
|
|
||||||
state: "{{ states('sensor.charger_high_voltage_alarm')|int == 2 }}"
|
|
||||||
|
|
||||||
sensor:
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.dc_wattage
|
|
||||||
name: DC System Energy
|
|
||||||
unit_prefix: k
|
|
||||||
round: 2
|
|
||||||
method: trapezoidal
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.solar_wattage
|
|
||||||
name: Solar Yield
|
|
||||||
unit_prefix: k
|
|
||||||
round: 2
|
|
||||||
method: trapezoidal
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
|
|
||||||
- platform: integration
|
|
||||||
source: sensor.charger_dc_wattage
|
|
||||||
name: DC Charger Energy
|
|
||||||
unit_prefix: k
|
|
||||||
round: 2
|
|
||||||
method: trapezoidal
|
|
||||||
max_sub_interval:
|
|
||||||
minutes: 5
|
|
||||||
|
|
||||||
utility_meter:
|
|
||||||
dc_load_energy_daily:
|
|
||||||
source: sensor.dc_system_energy
|
|
||||||
cycle: daily
|
|
||||||
|
|
||||||
dc_load_energy_monthly:
|
|
||||||
source: sensor.dc_system_energy
|
|
||||||
cycle: monthly
|
|
||||||
|
|
||||||
solar_yield_daily:
|
|
||||||
source: sensor.solar_yield
|
|
||||||
cycle: daily
|
|
||||||
|
|
||||||
solar_yield_monthly:
|
|
||||||
source: sensor.solar_yield
|
|
||||||
cycle: monthly
|
|
||||||
|
|
||||||
charger_dc_wattage_daily:
|
|
||||||
source: sensor.dc_charger_energy
|
|
||||||
cycle: daily
|
|
||||||
|
|
||||||
charger_dc_wattage_monthly:
|
|
||||||
source: sensor.dc_charger_energy
|
|
||||||
cycle: monthly
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
services.jellyfin = {
|
|
||||||
enable = true;
|
|
||||||
openFirewall = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
networking.firewall.allowedTCPPorts = [ 5432 ];
|
|
||||||
|
|
||||||
services.postgresql = {
|
|
||||||
enable = true;
|
|
||||||
package = pkgs.postgresql_17_jit;
|
|
||||||
enableTCPIP = true;
|
|
||||||
enableJIT = true;
|
|
||||||
|
|
||||||
authentication = pkgs.lib.mkOverride 10 ''
|
|
||||||
|
|
||||||
# admins
|
|
||||||
local all postgres trust
|
|
||||||
host all postgres 127.0.0.1/32 trust
|
|
||||||
host all postgres ::1/128 trust
|
|
||||||
|
|
||||||
local all richie trust
|
|
||||||
host all richie 127.0.0.1/32 trust
|
|
||||||
host all richie ::1/128 trust
|
|
||||||
host all richie 192.168.90.1/24 trust
|
|
||||||
host all richie 192.168.99.1/24 trust
|
|
||||||
|
|
||||||
#type database DBuser origin-address auth-method
|
|
||||||
local hass hass 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
|
|
||||||
'';
|
|
||||||
|
|
||||||
identMap = ''
|
|
||||||
# ArbitraryMapName systemUser DBUser
|
|
||||||
superuser_map root postgres
|
|
||||||
superuser_map postgres postgres
|
|
||||||
# Let other names login as themselves
|
|
||||||
superuser_map richie postgres
|
|
||||||
superuser_map hass hass
|
|
||||||
'';
|
|
||||||
ensureUsers = [
|
|
||||||
{
|
|
||||||
name = "postgres";
|
|
||||||
ensureClauses = {
|
|
||||||
superuser = true;
|
|
||||||
login = true;
|
|
||||||
createrole = true;
|
|
||||||
createdb = true;
|
|
||||||
replication = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "richie";
|
|
||||||
ensureDBOwnership = true;
|
|
||||||
ensureClauses = {
|
|
||||||
superuser = true;
|
|
||||||
login = true;
|
|
||||||
createrole = true;
|
|
||||||
createdb = true;
|
|
||||||
replication = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "hass";
|
|
||||||
ensureDBOwnership = true;
|
|
||||||
ensureClauses = {
|
|
||||||
login = true;
|
|
||||||
createrole = true;
|
|
||||||
createdb = true;
|
|
||||||
replication = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
ensureDatabases = [
|
|
||||||
"hass"
|
|
||||||
"richie"
|
|
||||||
];
|
|
||||||
# Thank you NotAShelf
|
|
||||||
# https://github.com/NotAShelf/nyx/blob/d407b4d6e5ab7f60350af61a3d73a62a5e9ac660/modules/core/roles/server/system/services/databases/postgresql.nix#L74
|
|
||||||
settings = {
|
|
||||||
# Connectivity;
|
|
||||||
max_connections = 100;
|
|
||||||
superuser_reserved_connections = 3;
|
|
||||||
|
|
||||||
# Memory Settings;
|
|
||||||
shared_buffers = "1024 MB";
|
|
||||||
work_mem = "32 MB";
|
|
||||||
maintenance_work_mem = "320 MB";
|
|
||||||
huge_pages = "off";
|
|
||||||
effective_cache_size = "2 GB";
|
|
||||||
effective_io_concurrency = 100; # concurrent IO only really activated if OS supports posix_fadvise function;
|
|
||||||
random_page_cost = 1.25; # speed of random disk access relative to sequential access (1.0);
|
|
||||||
|
|
||||||
# Monitoring;
|
|
||||||
shared_preload_libraries = "pg_stat_statements,auto_explain"; # per statement resource usage stats & log explain statements for slow queries
|
|
||||||
track_io_timing = "on"; # measure exact block IO times;
|
|
||||||
track_functions = "pl"; # track execution times of pl-language procedures if any;
|
|
||||||
# Replication;
|
|
||||||
wal_level = "replica"; # consider using at least "replica";
|
|
||||||
max_wal_senders = 0;
|
|
||||||
synchronous_commit = "on";
|
|
||||||
|
|
||||||
# Checkpointing: ;
|
|
||||||
checkpoint_timeout = "15 min";
|
|
||||||
checkpoint_completion_target = 0.9;
|
|
||||||
max_wal_size = "1024 MB";
|
|
||||||
min_wal_size = "512 MB";
|
|
||||||
|
|
||||||
# WAL writing;
|
|
||||||
wal_compression = "on";
|
|
||||||
wal_buffers = -1; # auto-tuned by Postgres till maximum of segment size (16MB by default);
|
|
||||||
wal_writer_delay = "200ms";
|
|
||||||
wal_writer_flush_after = "1MB";
|
|
||||||
|
|
||||||
# Background writer;
|
|
||||||
bgwriter_delay = "200ms";
|
|
||||||
bgwriter_lru_maxpages = 100;
|
|
||||||
bgwriter_lru_multiplier = 2.0;
|
|
||||||
bgwriter_flush_after = 0;
|
|
||||||
|
|
||||||
# Parallel queries: ;
|
|
||||||
max_worker_processes = 6;
|
|
||||||
max_parallel_workers_per_gather = 3;
|
|
||||||
max_parallel_maintenance_workers = 3;
|
|
||||||
max_parallel_workers = 6;
|
|
||||||
parallel_leader_participation = "on";
|
|
||||||
|
|
||||||
# Advanced features ;
|
|
||||||
enable_partitionwise_join = "on";
|
|
||||||
enable_partitionwise_aggregate = "on";
|
|
||||||
jit = "on";
|
|
||||||
|
|
||||||
jit_above_cost = 100000;
|
|
||||||
jit_inline_above_cost = 150000;
|
|
||||||
jit_optimize_above_cost = 500000;
|
|
||||||
|
|
||||||
# log slow queries
|
|
||||||
log_min_duration_statement = 100;
|
|
||||||
"auto_explain.log_min_duration" = 100;
|
|
||||||
|
|
||||||
# logging configuration
|
|
||||||
log_connections = true;
|
|
||||||
log_statement = "ddl";
|
|
||||||
logging_collector = true;
|
|
||||||
log_disconnections = true;
|
|
||||||
log_rotation_age = "14d";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
networking.firewall.allowedTCPPorts = [ 8384 ];
|
|
||||||
|
|
||||||
services.syncthing = {
|
|
||||||
overrideFolders = false;
|
|
||||||
guiAddress = "192.168.90.35:8384";
|
|
||||||
settings = {
|
|
||||||
"dotfiles" = {
|
|
||||||
path = "/home/richie/dotfiles";
|
|
||||||
devices = [
|
|
||||||
"bob"
|
|
||||||
"jeeves"
|
|
||||||
"rhapsody-in-green"
|
|
||||||
];
|
|
||||||
fsWatcherEnabled = true;
|
|
||||||
};
|
|
||||||
"important" = {
|
|
||||||
id = "4ckma-gtshs"; # cspell:disable-line
|
|
||||||
path = "/home/richie/important";
|
|
||||||
devices = [
|
|
||||||
"bob"
|
|
||||||
"jeeves"
|
|
||||||
"phone"
|
|
||||||
"rhapsody-in-green"
|
|
||||||
];
|
|
||||||
fsWatcherEnabled = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -4,35 +4,55 @@ in
|
|||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../users/richie
|
../../users/richie
|
||||||
../../users/math
|
|
||||||
../../users/dov
|
|
||||||
../../common/global
|
../../common/global
|
||||||
../../common/optional/docker.nix
|
../../common/optional/docker.nix
|
||||||
../../common/optional/ssh_decrypt.nix
|
../../common/optional/ssh_decrypt.nix
|
||||||
../../common/optional/syncthing_base.nix
|
../../common/optional/syncthing_base.nix
|
||||||
../../common/optional/update.nix
|
|
||||||
../../common/optional/zerotier.nix
|
../../common/optional/zerotier.nix
|
||||||
./docker
|
./docker
|
||||||
./services
|
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
|
./home_assistant.nix
|
||||||
./networking.nix
|
./networking.nix
|
||||||
./nvidia.nix
|
|
||||||
./programs.nix
|
./programs.nix
|
||||||
./runners
|
./runner.nix
|
||||||
|
./services.nix
|
||||||
./syncthing.nix
|
./syncthing.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
boot.zfs.extraPools = [
|
||||||
|
"media"
|
||||||
|
"storage"
|
||||||
|
"torrenting"
|
||||||
|
];
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
openssh.ports = [ 629 ];
|
openssh.ports = [ 629 ];
|
||||||
|
|
||||||
|
nix-serve = {
|
||||||
|
enable = true;
|
||||||
|
secretKeyFile = "${vars.storage_secrets}/services/nix-cache/cache-priv-key.pem";
|
||||||
|
openFirewall = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
plex = {
|
||||||
|
enable = true;
|
||||||
|
dataDir = vars.media_plex;
|
||||||
|
openFirewall = true;
|
||||||
|
};
|
||||||
|
|
||||||
smartd.enable = true;
|
smartd.enable = true;
|
||||||
|
|
||||||
snapshot_manager = {
|
snapshot_manager = {
|
||||||
|
enable = true;
|
||||||
path = ./snapshot_config.toml;
|
path = ./snapshot_config.toml;
|
||||||
EnvironmentFile = "${vars.secrets}/services/snapshot_manager";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
zerotierone.joinNetworks = [ "a09acf02330d37b9" ];
|
sysstat.enable = true;
|
||||||
|
|
||||||
|
zfs = {
|
||||||
|
trim.enable = true;
|
||||||
|
autoScrub.enable = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
system.stateVersion = "24.05";
|
system.stateVersion = "24.05";
|
||||||
|
|||||||
19
systems/jeeves/docker/audiobookshelf.nix
Normal file
19
systems/jeeves/docker/audiobookshelf.nix
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
virtualisation.oci-containers.containers.audiobookshelf = {
|
||||||
|
image = "ghcr.io/advplyr/audiobookshelf:latest";
|
||||||
|
volumes = [
|
||||||
|
"${vars.media_docker_configs}/audiobookshelf:/config"
|
||||||
|
"${vars.media_docker_configs}/audiobookshelf:/metadata"
|
||||||
|
"${vars.storage_library}/audiobooks:/audiobooks"
|
||||||
|
"${vars.storage_library}/books:/books"
|
||||||
|
];
|
||||||
|
environment = {
|
||||||
|
TZ = "America/New_York";
|
||||||
|
};
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
autoStart = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
15
systems/jeeves/docker/filebrowser.nix
Normal file
15
systems/jeeves/docker/filebrowser.nix
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
virtualisation.oci-containers.containers.filebrowser = {
|
||||||
|
image = "hurlenko/filebrowser:latest";
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
volumes = [
|
||||||
|
"/zfs:/data"
|
||||||
|
"${vars.media_docker_configs}/filebrowser:/config"
|
||||||
|
];
|
||||||
|
autoStart = true;
|
||||||
|
user = "1000:users";
|
||||||
|
};
|
||||||
|
}
|
||||||
12
systems/jeeves/docker/grafana.nix
Normal file
12
systems/jeeves/docker/grafana.nix
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
virtualisation.oci-containers.containers.grafana = {
|
||||||
|
image = "grafana/grafana-enterprise:latest";
|
||||||
|
volumes = [ "${vars.media_docker_configs}/grafana:/var/lib/grafana" ];
|
||||||
|
user = "600:600";
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
autoStart = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -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 = { };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -21,59 +21,51 @@ defaults
|
|||||||
|
|
||||||
#Application Setup
|
#Application Setup
|
||||||
frontend ContentSwitching
|
frontend ContentSwitching
|
||||||
bind *:80 v4v6
|
bind *:80
|
||||||
bind *:443 v4v6 ssl crt /zfs/storage/secrets/docker/cloudflare.pem
|
bind *:443 ssl crt /etc/ssl/certs/cloudflare.pem
|
||||||
mode http
|
mode http
|
||||||
# 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_filebrowser hdr(host) -i filebrowser.tmmworkshop.com
|
||||||
|
acl host_grafana hdr(host) -i grafana.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_photoprism hdr(host) -i photoprism.tmmworkshop.com
|
||||||
acl host_share hdr(host) -i share.tmmworkshop.com
|
acl host_uptime_kuma hdr(host) -i uptimekuma-jeeves.tmmworkshop.com
|
||||||
acl host_gcw hdr(host) -i gcw.tmmworkshop.com
|
|
||||||
acl host_n8n hdr(host) -i n8n.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 filebrowser_nodes if host_filebrowser
|
||||||
|
use_backend grafana_nodes if host_grafana
|
||||||
use_backend homeassistant_nodes if host_homeassistant
|
use_backend homeassistant_nodes if host_homeassistant
|
||||||
use_backend jellyfin if host_jellyfin
|
use_backend photoprism_nodes if host_photoprism
|
||||||
use_backend share_nodes if host_share
|
use_backend uptime_kuma_nodes if host_uptime_kuma
|
||||||
use_backend gcw_nodes if host_gcw
|
|
||||||
use_backend n8n if host_n8n
|
|
||||||
|
|
||||||
backend audiobookshelf_nodes
|
backend audiobookshelf_nodes
|
||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:8000
|
server server audiobookshelf:80
|
||||||
|
|
||||||
backend cache_nodes
|
backend cache_nodes
|
||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:5000
|
server server 192.168.90.40:5000
|
||||||
|
|
||||||
|
backend grafana_nodes
|
||||||
|
mode http
|
||||||
|
server server grafana:3000
|
||||||
|
|
||||||
backend filebrowser_nodes
|
backend filebrowser_nodes
|
||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:8080
|
server server filebrowser:8080
|
||||||
|
|
||||||
backend homeassistant_nodes
|
backend homeassistant_nodes
|
||||||
mode http
|
mode http
|
||||||
server server 192.168.90.35:8123
|
server server 192.168.95.14:8123
|
||||||
|
|
||||||
backend jellyfin
|
backend photoprism_nodes
|
||||||
option httpchk
|
|
||||||
option forwardfor
|
|
||||||
http-check send meth GET uri /health
|
|
||||||
http-check expect string Healthy
|
|
||||||
server jellyfin 127.0.0.1:8096
|
|
||||||
|
|
||||||
backend share_nodes
|
|
||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:8091
|
server server photoprism:2342
|
||||||
|
|
||||||
backend gcw_nodes
|
backend uptime_kuma_nodes
|
||||||
mode http
|
mode http
|
||||||
server server 127.0.0.1:8092
|
server server uptime_kuma:3001
|
||||||
|
|
||||||
backend n8n
|
|
||||||
mode http
|
|
||||||
server server 127.0.0.1:5678
|
|
||||||
53
systems/jeeves/docker/photoprism.nix
Normal file
53
systems/jeeves/docker/photoprism.nix
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
virtualisation.oci-containers.containers.photoprism = {
|
||||||
|
image = "photoprism/photoprism:latest";
|
||||||
|
volumes = [
|
||||||
|
"${vars.media_docker_configs}/photoprism:/photoprism/storage"
|
||||||
|
"${vars.storage_photos}/originals:/photoprism/originals"
|
||||||
|
"${vars.storage_photos}/import:/photoprism/import"
|
||||||
|
];
|
||||||
|
environment = {
|
||||||
|
PHOTOPRISM_ADMIN_USER="admin";
|
||||||
|
PHOTOPRISM_AUTH_MODE="password";
|
||||||
|
PHOTOPRISM_DISABLE_TLS="false";
|
||||||
|
PHOTOPRISM_DEFAULT_TLS="true";
|
||||||
|
PHOTOPRISM_ORIGINALS_LIMIT="30000";
|
||||||
|
PHOTOPRISM_HTTP_COMPRESSION="gzip";
|
||||||
|
PHOTOPRISM_LOG_LEVEL="info";
|
||||||
|
PHOTOPRISM_READONLY="false";
|
||||||
|
PHOTOPRISM_EXPERIMENTAL="false";
|
||||||
|
PHOTOPRISM_DISABLE_CHOWN="false";
|
||||||
|
PHOTOPRISM_DISABLE_WEBDAV="false";
|
||||||
|
PHOTOPRISM_DISABLE_SETTINGS="false";
|
||||||
|
PHOTOPRISM_DISABLE_TENSORFLOW="false";
|
||||||
|
PHOTOPRISM_DISABLE_FACES="false";
|
||||||
|
PHOTOPRISM_DISABLE_CLASSIFICATION="false";
|
||||||
|
PHOTOPRISM_DISABLE_VECTORS="false";
|
||||||
|
PHOTOPRISM_DISABLE_RAW="false";
|
||||||
|
PHOTOPRISM_RAW_PRESETS="false";
|
||||||
|
PHOTOPRISM_SIDECAR_YAML="true";
|
||||||
|
PHOTOPRISM_BACKUP_ALBUMS="true";
|
||||||
|
PHOTOPRISM_BACKUP_DATABASE="true";
|
||||||
|
PHOTOPRISM_BACKUP_SCHEDULE="daily";
|
||||||
|
PHOTOPRISM_INDEX_SCHEDULE="";
|
||||||
|
PHOTOPRISM_AUTO_INDEX="300";
|
||||||
|
PHOTOPRISM_AUTO_IMPORT= "-1";
|
||||||
|
PHOTOPRISM_DETECT_NSFW="false";
|
||||||
|
PHOTOPRISM_UPLOAD_NSFW="true";
|
||||||
|
PHOTOPRISM_DATABASE_DRIVER="sqlite";
|
||||||
|
PHOTOPRISM_SITE_CAPTION="AI-Powered Photos App";
|
||||||
|
PHOTOPRISM_SITE_DESCRIPTION="";
|
||||||
|
PHOTOPRISM_SITE_AUTHOR="";
|
||||||
|
PHOTOPRISM_UID="600";
|
||||||
|
PHOTOPRISM_GID="600";
|
||||||
|
# PHOTOPRISM_UMASK: 0000
|
||||||
|
};
|
||||||
|
environmentFiles = ["${vars.storage_secrets}/docker/photoprism"];
|
||||||
|
autoStart = true;
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
32
systems/jeeves/docker/postgresql.nix
Normal file
32
systems/jeeves/docker/postgresql.nix
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
users = {
|
||||||
|
users.postgres = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = "postgres";
|
||||||
|
uid = 999;
|
||||||
|
};
|
||||||
|
groups.postgres = {
|
||||||
|
gid = 999;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
virtualisation.oci-containers.containers = {
|
||||||
|
postgres = {
|
||||||
|
image = "postgres:17";
|
||||||
|
ports = [ "5432:5432" ];
|
||||||
|
volumes = [ "${vars.media_database}/postgres:/var/lib/postgresql/data" ];
|
||||||
|
environment = {
|
||||||
|
POSTGRES_USER = "admin";
|
||||||
|
POSTGRES_DB = "archive";
|
||||||
|
POSTGRES_INITDB_ARGS = "--auth-host=scram-sha-256";
|
||||||
|
};
|
||||||
|
environmentFiles = [ "${vars.storage_secrets}/docker/postgres" ];
|
||||||
|
autoStart = true;
|
||||||
|
user = "postgres:postgres";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
29
systems/jeeves/docker/qbit.nix
Normal file
29
systems/jeeves/docker/qbit.nix
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
networking.firewall = {
|
||||||
|
allowedTCPPorts = [ 6881 8082 29432 ];
|
||||||
|
allowedUDPPorts = [ 6881 29432 ];
|
||||||
|
};
|
||||||
|
virtualisation.oci-containers.containers.qbit = {
|
||||||
|
image = "ghcr.io/linuxserver/qbittorrent:5.0.2";
|
||||||
|
ports = [
|
||||||
|
"6881:6881"
|
||||||
|
"6881:6881/udp"
|
||||||
|
"8082:8082"
|
||||||
|
"29432:29432"
|
||||||
|
];
|
||||||
|
volumes = [
|
||||||
|
"${vars.media_docker_configs}/qbit:/config"
|
||||||
|
"${vars.torrenting_qbit}:/data"
|
||||||
|
];
|
||||||
|
environment = {
|
||||||
|
PUID = "600";
|
||||||
|
PGID = "100";
|
||||||
|
TZ = "America/New_York";
|
||||||
|
WEBUI_PORT = "8082";
|
||||||
|
};
|
||||||
|
autoStart = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -3,11 +3,7 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
networking.firewall = {
|
networking.firewall = {
|
||||||
allowedTCPPorts = [
|
allowedTCPPorts = [ 6882 8081 8118 ];
|
||||||
6882
|
|
||||||
8081
|
|
||||||
8118
|
|
||||||
];
|
|
||||||
allowedUDPPorts = [ 6882 ];
|
allowedUDPPorts = [ 6882 ];
|
||||||
};
|
};
|
||||||
virtualisation.oci-containers.containers.qbitvpn = {
|
virtualisation.oci-containers.containers.qbitvpn = {
|
||||||
@@ -21,9 +17,8 @@ in
|
|||||||
"8118:8118"
|
"8118:8118"
|
||||||
];
|
];
|
||||||
volumes = [
|
volumes = [
|
||||||
"${vars.docker_configs}/qbitvpn:/config"
|
"${vars.media_docker_configs}/qbitvpn:/config"
|
||||||
"${vars.qbitvpn}:/data"
|
"${vars.torrenting_qbitvpn}:/data"
|
||||||
"${vars.qbitvpn_scratch}:/data/incomplete"
|
|
||||||
"/etc/localtime:/etc/localtime:ro"
|
"/etc/localtime:/etc/localtime:ro"
|
||||||
];
|
];
|
||||||
environment = {
|
environment = {
|
||||||
@@ -41,7 +36,7 @@ in
|
|||||||
DELUGE_DAEMON_LOG_LEVEL = "debug";
|
DELUGE_DAEMON_LOG_LEVEL = "debug";
|
||||||
DELUGE_WEB_LOG_LEVEL = "debug";
|
DELUGE_WEB_LOG_LEVEL = "debug";
|
||||||
};
|
};
|
||||||
environmentFiles = [ "${vars.secrets}/docker/qbitvpn" ];
|
environmentFiles = ["${vars.storage_secrets}/docker/qbitvpn"];
|
||||||
autoStart = true;
|
autoStart = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
39
systems/jeeves/docker/reverse_proxy.nix
Normal file
39
systems/jeeves/docker/reverse_proxy.nix
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
virtualisation.oci-containers.containers = {
|
||||||
|
haproxy = {
|
||||||
|
image = "haproxy:latest";
|
||||||
|
user = "600:600";
|
||||||
|
environment = {
|
||||||
|
TZ = "Etc/EST";
|
||||||
|
};
|
||||||
|
volumes = [
|
||||||
|
"${vars.storage_secrets}/docker/cloudflare.pem:/etc/ssl/certs/cloudflare.pem"
|
||||||
|
"${./haproxy.cfg}:/usr/local/etc/haproxy/haproxy.cfg"
|
||||||
|
];
|
||||||
|
dependsOn = [
|
||||||
|
"audiobookshelf"
|
||||||
|
"filebrowser"
|
||||||
|
"grafana"
|
||||||
|
"photoprism"
|
||||||
|
"uptime_kuma"
|
||||||
|
];
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
autoStart = true;
|
||||||
|
};
|
||||||
|
cloud_flare_tunnel = {
|
||||||
|
image = "cloudflare/cloudflared:latest";
|
||||||
|
user = "600:600";
|
||||||
|
cmd = [
|
||||||
|
"tunnel"
|
||||||
|
"run"
|
||||||
|
];
|
||||||
|
environmentFiles = ["${vars.storage_secrets}/docker/cloud_flare_tunnel"];
|
||||||
|
dependsOn = [ "haproxy" ];
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
autoStart = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
virtualisation.oci-containers.containers.share = {
|
|
||||||
image = "ubuntu/apache2:2.4-22.04_beta";
|
|
||||||
ports = [ "8091:80" ];
|
|
||||||
volumes = [
|
|
||||||
"${../../../common/docker_templates}/file_server/sites/:/etc/apache2/sites-enabled/"
|
|
||||||
"${vars.share}:/data"
|
|
||||||
];
|
|
||||||
extraOptions = [ "--network=web" ];
|
|
||||||
autoStart = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
networking.firewall.allowedTCPPorts = [
|
|
||||||
8989
|
|
||||||
];
|
|
||||||
virtualisation.oci-containers.containers.signal_cli_rest_api = {
|
|
||||||
image = "bbernhard/signal-cli-rest-api:latest";
|
|
||||||
ports = [
|
|
||||||
"8989:8080"
|
|
||||||
];
|
|
||||||
volumes = [
|
|
||||||
"${vars.docker_configs}/signal-cli-config:/home/.local/share/signal-cli"
|
|
||||||
];
|
|
||||||
environment = {
|
|
||||||
MODE = "json-rpc";
|
|
||||||
};
|
|
||||||
autoStart = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
16
systems/jeeves/docker/uptime_kuma.nix
Normal file
16
systems/jeeves/docker/uptime_kuma.nix
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
let
|
||||||
|
vars = import ../vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
virtualisation.oci-containers.containers = {
|
||||||
|
uptime_kuma = {
|
||||||
|
image = "louislam/uptime-kuma:latest";
|
||||||
|
volumes = [
|
||||||
|
"${vars.media_docker_configs}/uptime_kuma:/app/data"
|
||||||
|
"/var/run/docker.sock:/var/run/docker.sock"
|
||||||
|
];
|
||||||
|
extraOptions = [ "--network=web" ];
|
||||||
|
autoStart = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,26 +1,6 @@
|
|||||||
|
{ config, lib, modulesPath, ... }:
|
||||||
{
|
{
|
||||||
config,
|
imports =[ (modulesPath + "/installer/scan/not-detected.nix") ];
|
||||||
lib,
|
|
||||||
modulesPath,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
makeLuksDevice = device: {
|
|
||||||
inherit device;
|
|
||||||
keyFileSize = 4096;
|
|
||||||
keyFile = "/dev/disk/by-id/usb-XIAO_USB_Drive_24587CE29074-0:0";
|
|
||||||
fallbackToPassword = true;
|
|
||||||
};
|
|
||||||
makeLuksSSD =
|
|
||||||
device:
|
|
||||||
(makeLuksDevice device)
|
|
||||||
// {
|
|
||||||
bypassWorkqueues = true;
|
|
||||||
allowDiscards = true;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
|
|
||||||
|
|
||||||
boot = {
|
boot = {
|
||||||
loader = {
|
loader = {
|
||||||
@@ -56,51 +36,77 @@ in
|
|||||||
luks.devices = {
|
luks.devices = {
|
||||||
# cspell:disable
|
# cspell:disable
|
||||||
# Root pool
|
# Root pool
|
||||||
"luks-root-pool-wwn-0x55cd2e4150f01519-part2" =
|
"luks-root-pool-wwn-0x55cd2e4150f01519-part2" = {
|
||||||
makeLuksSSD "/dev/disk/by-id/wwn-0x55cd2e4150f01519-part2";
|
device = "/dev/disk/by-id/wwn-0x55cd2e4150f01519-part2";
|
||||||
"luks-root-pool-wwn-0x55cd2e4150f01556-part2" =
|
bypassWorkqueues = true;
|
||||||
makeLuksSSD "/dev/disk/by-id/wwn-0x55cd2e4150f01556-part2";
|
allowDiscards = true;
|
||||||
|
};
|
||||||
|
"luks-root-pool-wwn-0x55cd2e4150f01556-part2" = {
|
||||||
|
device = "/dev/disk/by-id/wwn-0x55cd2e4150f01556-part2";
|
||||||
|
bypassWorkqueues = true;
|
||||||
|
allowDiscards = true;
|
||||||
|
};
|
||||||
# Media pool
|
# Media pool
|
||||||
"luks-media_pool-nvme-INTEL_SSDPEK1A118GA_BTOC14120V2J118B-part1" =
|
"luks-media_pool-nvme-INTEL_SSDPEK1A118GA_BTOC14120V2J118B-part1" = {
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPEK1A118GA_BTOC14120V2J118B-part1";
|
device = "/dev/disk/by-id/nvme-INTEL_SSDPEK1A118GA_BTOC14120V2J118B-part1";
|
||||||
"luks-media_pool-nvme-INTEL_SSDPEK1A118GA_BTOC14120WAG118B-part1" =
|
bypassWorkqueues = true;
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPEK1A118GA_BTOC14120WAG118B-part1";
|
allowDiscards = true;
|
||||||
"luks-media_pool-nvme-INTEL_SSDPE2ME012T4_CVMD5130000G1P2HGN-part1" =
|
};
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPE2ME012T4_CVMD5130000G1P2HGN-part1";
|
"luks-media_pool-nvme-INTEL_SSDPEK1A118GA_BTOC14120WAG118B-part1" = {
|
||||||
"luks-media_pool-nvme-INTEL_SSDPE2ME012T4_CVMD5130000U1P2HGN-part1" =
|
device = "/dev/disk/by-id/nvme-INTEL_SSDPEK1A118GA_BTOC14120WAG118B-part1";
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_SSDPE2ME012T4_CVMD5130000U1P2HGN-part1";
|
bypassWorkqueues = true;
|
||||||
|
allowDiscards = true;
|
||||||
# Scratch pool
|
};
|
||||||
"luks-scratch-pool-ata-CT480BX500SSD1_2314E6C3C01C-part1" =
|
"luks-media_pool-nvme-INTEL_SSDPE2ME012T4_CVMD5130000G1P2HGN-part1" = {
|
||||||
makeLuksSSD "/dev/disk/by-id/ata-CT480BX500SSD1_2314E6C3C01C-part1";
|
device = "/dev/disk/by-id/nvme-INTEL_SSDPE2ME012T4_CVMD5130000G1P2HGN-part1";
|
||||||
"luks-scratch-pool-ata-CT480BX500SSD1_2314E6C3C01E-part1" =
|
bypassWorkqueues = true;
|
||||||
makeLuksSSD "/dev/disk/by-id/ata-CT480BX500SSD1_2314E6C3C01E-part1";
|
allowDiscards = true;
|
||||||
|
};
|
||||||
|
"luks-media_pool-nvme-INTEL_SSDPE2ME012T4_CVMD5130000U1P2HGN-part1" = {
|
||||||
|
device = "/dev/disk/by-id/nvme-INTEL_SSDPE2ME012T4_CVMD5130000U1P2HGN-part1";
|
||||||
|
bypassWorkqueues = true;
|
||||||
|
allowDiscards = true;
|
||||||
|
};
|
||||||
# Storage pool
|
# Storage pool
|
||||||
"luks-storage_pool-nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834822N-part1" =
|
"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";
|
device = "/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" =
|
bypassWorkqueues = true;
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834817F-part1";
|
allowDiscards = true;
|
||||||
"luks-storage_pool-nvme-INTEL_MEMPEK1W016GA_PHBT828104DF016D-part1" =
|
};
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_MEMPEK1W016GA_PHBT828104DF016D-part1";
|
"luks-storage_pool-nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834817F-part1" = {
|
||||||
"luks-storage_pool-nvme-INTEL_MEMPEK1W016GA_PHBT828105A8016D-part1" =
|
device = "/dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_2TB_S6S2NS0T834817F-part1";
|
||||||
makeLuksSSD "/dev/disk/by-id/nvme-INTEL_MEMPEK1W016GA_PHBT828105A8016D-part1";
|
bypassWorkqueues = true;
|
||||||
"luks-storage_pool-wwn-0x5000cca23bc438dd-part1" =
|
allowDiscards = true;
|
||||||
makeLuksDevice "/dev/disk/by-id/wwn-0x5000cca23bc438dd-part1";
|
};
|
||||||
"luks-storage_pool-wwn-0x5000cca23bd035f5-part1" =
|
"luks-storage_pool-nvme-INTEL_MEMPEK1W016GA_PHBT828104DF016D-part1" = {
|
||||||
makeLuksDevice "/dev/disk/by-id/wwn-0x5000cca23bd035f5-part1";
|
device = "/dev/disk/by-id/nvme-INTEL_MEMPEK1W016GA_PHBT828104DF016D-part1";
|
||||||
"luks-storage_pool-wwn-0x5000cca23bd00ad6-part1" =
|
bypassWorkqueues = true;
|
||||||
makeLuksDevice "/dev/disk/by-id/wwn-0x5000cca23bd00ad6-part1";
|
allowDiscards = true;
|
||||||
|
};
|
||||||
|
"luks-storage_pool-nvme-INTEL_MEMPEK1W016GA_PHBT828105A8016D-part1" = {
|
||||||
|
device = "/dev/disk/by-id/nvme-INTEL_MEMPEK1W016GA_PHBT828105A8016D-part1";
|
||||||
|
bypassWorkqueues = true;
|
||||||
|
allowDiscards = true;
|
||||||
|
};
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bc438dd-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bc438dd-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bd035f5-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bd035f5-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bd00ad6-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bd00ad6-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bcf313e-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bcf313e-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bcdf3b8-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bcdf3b8-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bd02746-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bd02746-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bcf9f89-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bcf9f89-part1";
|
||||||
|
"luks-storage_pool-wwn-0x5000cca23bd00ae9-part1".device = "/dev/disk/by-id/wwn-0x5000cca23bd00ae9-part1";
|
||||||
|
# Torrenting pool
|
||||||
|
"luks-torrenting_pool-wwn-0x500a0751e6c3c01e-part1" = {
|
||||||
|
device = "/dev/disk/by-id/wwn-0x500a0751e6c3c01e-part1";
|
||||||
|
bypassWorkqueues = true;
|
||||||
|
allowDiscards = true;
|
||||||
|
};
|
||||||
|
"luks-torrenting_pool-wwn-0x5000cca264f080a3-part1".device = "/dev/disk/by-id/wwn-0x5000cca264f080a3-part1";
|
||||||
|
"luks-torrenting_pool-wwn-0x5000cca298c33ae5-part1".device = "/dev/disk/by-id/wwn-0x5000cca298c33ae5-part1";
|
||||||
|
# cspell:enable
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
zfs.extraPools = [
|
|
||||||
"media"
|
|
||||||
"scratch"
|
|
||||||
"storage"
|
|
||||||
];
|
|
||||||
|
|
||||||
kernelModules = [ "kvm-amd" ];
|
kernelModules = [ "kvm-amd" ];
|
||||||
extraModulePackages = [ ];
|
extraModulePackages = [ ];
|
||||||
};
|
};
|
||||||
@@ -116,8 +122,8 @@ in
|
|||||||
fsType = "zfs";
|
fsType = "zfs";
|
||||||
};
|
};
|
||||||
|
|
||||||
"/nix" = {
|
"/nix" =
|
||||||
device = "root_pool/nix";
|
{ device = "root_pool/nix";
|
||||||
fsType = "zfs";
|
fsType = "zfs";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -140,7 +146,7 @@ in
|
|||||||
options = [
|
options = [
|
||||||
"fmask=0077"
|
"fmask=0077"
|
||||||
"dmask=0077"
|
"dmask=0077"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
57
systems/jeeves/home_assistant.nix
Normal file
57
systems/jeeves/home_assistant.nix
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
let
|
||||||
|
vars = import ./vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
services.home-assistant = {
|
||||||
|
enable = true;
|
||||||
|
openFirewall = true;
|
||||||
|
configDir = vars.media_home_assistant;
|
||||||
|
config = {
|
||||||
|
http = {
|
||||||
|
server_port = 8123;
|
||||||
|
server_host = [
|
||||||
|
"192.168.95.14"
|
||||||
|
"192.168.90.40"
|
||||||
|
"192.168.98.4"
|
||||||
|
];
|
||||||
|
use_x_forwarded_for = true;
|
||||||
|
trusted_proxies = "172.18.0.0/24";
|
||||||
|
};
|
||||||
|
homeassistant = {
|
||||||
|
time_zone = "America/New_York";
|
||||||
|
unit_system = "imperial";
|
||||||
|
temperature_unit = "F";
|
||||||
|
};
|
||||||
|
assist_pipeline = { };
|
||||||
|
backup = { };
|
||||||
|
bluetooth = { };
|
||||||
|
config = { };
|
||||||
|
dhcp = { };
|
||||||
|
energy = { };
|
||||||
|
history = { };
|
||||||
|
homeassistant_alerts = { };
|
||||||
|
image_upload = { };
|
||||||
|
logbook = { };
|
||||||
|
media_source = { };
|
||||||
|
mobile_app = { };
|
||||||
|
ssdp = { };
|
||||||
|
sun = { };
|
||||||
|
webhook = { };
|
||||||
|
zeroconf = { };
|
||||||
|
automation = "!include automations.yaml";
|
||||||
|
script = "!include scripts.yaml";
|
||||||
|
scene = "!include scenes.yaml";
|
||||||
|
group = "!include groups.yaml";
|
||||||
|
};
|
||||||
|
extraPackages =
|
||||||
|
python3Packages: with python3Packages; [
|
||||||
|
psycopg2
|
||||||
|
gtts
|
||||||
|
aioesphomeapi
|
||||||
|
esphome-dashboard-api
|
||||||
|
bleak-esphome
|
||||||
|
pymetno
|
||||||
|
];
|
||||||
|
extraComponents = [ "isal" ];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -7,12 +7,25 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
systemd.network = {
|
systemd.network = {
|
||||||
|
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
|
netdevs = {
|
||||||
|
"20-ioit-vlan" = {
|
||||||
|
netdevConfig = {
|
||||||
|
Kind = "vlan";
|
||||||
|
Name = "ioit-vlan";
|
||||||
|
};
|
||||||
|
vlanConfig.Id = 20;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
networks = {
|
networks = {
|
||||||
"10-1GB_Primary" = {
|
"10-1GB_Primary" = {
|
||||||
matchConfig.Name = "enp98s0f0";
|
matchConfig.Name = "enp98s0f0";
|
||||||
address = [ "192.168.99.14/24" ];
|
address = [ "192.168.95.14/24" ];
|
||||||
routes = [ { Gateway = "192.168.99.1"; } ];
|
routes = [{ Gateway = "192.168.95.1"; }];
|
||||||
|
vlan = [ "ioit-vlan" ];
|
||||||
linkConfig.RequiredForOnline = "routable";
|
linkConfig.RequiredForOnline = "routable";
|
||||||
};
|
};
|
||||||
"10-1GB_Secondary" = {
|
"10-1GB_Secondary" = {
|
||||||
@@ -28,6 +41,15 @@
|
|||||||
matchConfig.Name = "enp97s0f1np1";
|
matchConfig.Name = "enp97s0f1np1";
|
||||||
DHCP = "yes";
|
DHCP = "yes";
|
||||||
};
|
};
|
||||||
|
"40-ioit-vlan" = {
|
||||||
|
matchConfig.Name = "ioit-vlan";
|
||||||
|
DHCP = "yes";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.zerotierone = {
|
||||||
|
enable = true;
|
||||||
|
joinNetworks = [ "e4da7455b2ae64ca" ];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
29
systems/jeeves/runner.nix
Normal file
29
systems/jeeves/runner.nix
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{ pkgs, ... }:
|
||||||
|
let
|
||||||
|
vars = import ./vars.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
users = {
|
||||||
|
users.github-runners = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = "github-runners";
|
||||||
|
uid = 601;
|
||||||
|
};
|
||||||
|
groups.github-runners = {
|
||||||
|
gid = 601;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.github-runners.nix_builder = {
|
||||||
|
enable = true;
|
||||||
|
replace = true;
|
||||||
|
workDir = "/zfs/media/github-runners/nix_builder/";
|
||||||
|
url = "https://github.com/RichieCahill/dotfiles";
|
||||||
|
extraLabels = [ "nixos" ];
|
||||||
|
tokenFile = "${vars.storage_secrets}/services/github_runners/nix_builder";
|
||||||
|
user = "github-runners";
|
||||||
|
group = "github-runners";
|
||||||
|
extraPackages = [ pkgs.nixos-rebuild ];
|
||||||
|
# extraEnvironment
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
imports = [ ./nix_builder.nix ];
|
|
||||||
|
|
||||||
users = {
|
|
||||||
users.github-runners = {
|
|
||||||
shell = pkgs.bash;
|
|
||||||
isSystemUser = true;
|
|
||||||
group = "github-runners";
|
|
||||||
uid = 601;
|
|
||||||
openssh.authorizedKeys.keys = [
|
|
||||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA/S8i+BNX/12JNKg+5EKGX7Aqimt5KM+ve3wt/SyWuO github-runners" # cspell:disable-line
|
|
||||||
];
|
|
||||||
};
|
|
||||||
groups.github-runners.gid = 601;
|
|
||||||
};
|
|
||||||
|
|
||||||
services.nix_builder.containers = {
|
|
||||||
nix-builder-0.enable = true;
|
|
||||||
nix-builder-1.enable = true;
|
|
||||||
nix-builder-2.enable = true;
|
|
||||||
nix-builder-3.enable = true;
|
|
||||||
nix-builder-4.enable = true;
|
|
||||||
nix-builder-5.enable = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
{
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
outputs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.services.nix_builder.containers = mkOption {
|
|
||||||
type = types.attrsOf (
|
|
||||||
types.submodule (
|
|
||||||
{ name, ... }:
|
|
||||||
{
|
|
||||||
options.enable = mkEnableOption "GitHub runner container";
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
default = { };
|
|
||||||
description = "GitHub runner container configurations";
|
|
||||||
};
|
|
||||||
|
|
||||||
config.containers = mapAttrs (
|
|
||||||
name: cfg:
|
|
||||||
mkIf cfg.enable {
|
|
||||||
autoStart = true;
|
|
||||||
bindMounts = {
|
|
||||||
"/storage" = {
|
|
||||||
mountPoint = "/zfs/media/github-runners/${name}";
|
|
||||||
isReadOnly = false;
|
|
||||||
};
|
|
||||||
"/secrets".mountPoint = "${vars.secrets}/services/github-runners/${name}";
|
|
||||||
"ssh-keys".mountPoint = "${vars.secrets}/services/github-runners/id_ed25519_github-runners";
|
|
||||||
};
|
|
||||||
config =
|
|
||||||
{
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
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"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
system.stateVersion = "24.11";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
) config.services.nix_builder.containers;
|
|
||||||
}
|
|
||||||
@@ -11,24 +11,21 @@ sudo zpool create -o ashift=12 -O acltype=posixacl -O atime=off -O dnodesize=aut
|
|||||||
sudo zpool add storage -o ashift=12 special mirror
|
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
|
# torrenting
|
||||||
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 -o ashift=12 -O acltype=posixacl -O atime=off -O dnodesize=auto -O xattr=sa -O compression=zstd -m /zfs/torrenting torrenting
|
||||||
|
sudo zpool add torrenting -o ashift=12 special
|
||||||
|
|
||||||
# media datasets
|
# media datasets
|
||||||
sudo zfs create -o compression=zstd-9 media/docker
|
sudo zfs create -o compression=zstd-9 media/docker
|
||||||
|
sudo zfs create -o recordsize=1M -o compression=zstd-19 media/library
|
||||||
sudo zfs create -o compression=zstd-9 -o sync=disabled media/github-runners
|
sudo zfs create -o compression=zstd-9 -o sync=disabled media/github-runners
|
||||||
|
sudo zfs create -o exec=off media/minio
|
||||||
sudo zfs create -o copies=3 media/notes
|
sudo zfs create -o copies=3 media/notes
|
||||||
|
sudo zfs create -o recordsize=16k -o primarycache=metadata -o mountpoint=/zfs/media/database/photoprism_mariadb media/photoprism_mariadb
|
||||||
sudo zfs create -o compression=zstd-9 media/plex
|
sudo zfs create -o compression=zstd-9 media/plex
|
||||||
sudo zfs create -o compression=zstd-9 media/services
|
|
||||||
sudo zfs create -o compression=zstd-19 media/home_assistant
|
sudo zfs create -o compression=zstd-19 media/home_assistant
|
||||||
sudo zfs create -o exec=off media/share
|
|
||||||
sudo zfs create -o recordsize=16k -o primarycache=metadata -o mountpoint=/zfs/media/database/postgres media/postgres
|
sudo zfs create -o recordsize=16k -o primarycache=metadata -o mountpoint=/zfs/media/database/postgres media/postgres
|
||||||
|
|
||||||
# scratch datasets
|
|
||||||
sudo zfs create -o recordsize=16k -o sync=disabled scratch/qbitvpn
|
|
||||||
sudo zfs create -o recordsize=16k -o sync=disabled scratch/transmission
|
|
||||||
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 -o recordsize=1M -o compression=zstd-19 storage/archive
|
||||||
sudo zfs create -o compression=zstd-19 storage/main
|
sudo zfs create -o compression=zstd-19 storage/main
|
||||||
@@ -36,7 +33,7 @@ sudo zfs create -o recordsize=16K -o compression=zstd-19 -o copies=2 storage/pho
|
|||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 storage/plex
|
sudo zfs create -o recordsize=1M -o compression=zstd-19 storage/plex
|
||||||
sudo zfs create -o compression=zstd-19 -o copies=3 storage/secrets
|
sudo zfs create -o compression=zstd-19 -o copies=3 storage/secrets
|
||||||
sudo zfs create -o compression=zstd-19 storage/syncthing
|
sudo zfs create -o compression=zstd-19 storage/syncthing
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-9 -o exec=off -o sync=disabled storage/qbitvpn
|
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-9 -o exec=off -o sync=disabled storage/transmission
|
# torrenting datasets
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 storage/library
|
sudo zfs create -o recordsize=16K -o exec=off -o sync=disabled torrenting/qbit
|
||||||
sudo zfs create -o recordsize=1M -o compression=zstd-19 -o sync=disabled storage/ollama
|
sudo zfs create -o recordsize=16K -o exec=off -o sync=disabled torrenting/qbitvpn
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
vars = import ../vars.nix;
|
vars = import ./vars.nix;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
systemd = {
|
systemd = {
|
||||||
@@ -13,7 +13,7 @@ in
|
|||||||
description = "maintains /zfs/storage/plex permissions";
|
description = "maintains /zfs/storage/plex permissions";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "${pkgs.bash}/bin/bash ${../scripts/plex_permission.sh}";
|
ExecStart = "${pkgs.bash}/bin/bash ${./scripts/plex_permission.sh}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
startup_validation = {
|
startup_validation = {
|
||||||
@@ -23,9 +23,9 @@ in
|
|||||||
description = "validates startup";
|
description = "validates startup";
|
||||||
path = [ pkgs.zfs ];
|
path = [ pkgs.zfs ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
EnvironmentFile = "${vars.secrets}/services/server-validation";
|
EnvironmentFile = "${vars.storage_secrets}/services/server-validation";
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "${inputs.system_tools.packages.x86_64-linux.default}/bin/validate_system '${./validate_system.toml}'";
|
ExecStart = "${inputs.system_tools.packages.x86_64-linux.default}/bin/validate_jeeves";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{ lib, ... }:
|
|
||||||
let
|
|
||||||
vars = import ../vars.nix;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
services.audiobookshelf.enable = true;
|
|
||||||
systemd.services.audiobookshelf.serviceConfig.WorkingDirectory =
|
|
||||||
lib.mkForce "${vars.docker_configs}/audiobookshelf";
|
|
||||||
users.users.audiobookshelf.home = lib.mkForce "${vars.docker_configs}/audiobookshelf";
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user