fix vmware, fix hass script

This commit is contained in:
mjallen18
2025-06-27 21:10:47 -05:00
parent 6639792b54
commit 1ad3669908
13 changed files with 138 additions and 205 deletions

50
flake.lock generated
View File

@@ -87,11 +87,11 @@
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
"lastModified": 1750642025, "lastModified": 1751025233,
"narHash": "sha256-ZixZpSMtrf2MFw7Ztg6JUbMRkoxxvDDipQCPqnlCDgE=", "narHash": "sha256-tDIv1qnNv22QoDIkReSB2qH6yH7LoVk/sGjjOr9k700=",
"owner": "chaotic-cx", "owner": "chaotic-cx",
"repo": "nyx", "repo": "nyx",
"rev": "2b666bb8aca306397ef6abb68dec67e78680882b", "rev": "3755956975a439001b40954a9eede46ba7adf0d1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -131,11 +131,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1750654717, "lastModified": 1750973805,
"narHash": "sha256-YXlhTUGaLAY1rSosaRXO5RSGriEyF9BGdLkpKV+9jyI=", "narHash": "sha256-BZXgag7I0rnL/HMHAsBz3tQrfKAibpY2vovexl2lS+Y=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "4c9e99e8e8e36bcdfa9cdb102e45e4dc95aa5c5b", "rev": "080e8b48b0318b38143d5865de9334f46d51fce3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -187,11 +187,11 @@
}, },
"desktop-nixos-hardware": { "desktop-nixos-hardware": {
"locked": { "locked": {
"lastModified": 1750431636, "lastModified": 1750837715,
"narHash": "sha256-vnzzBDbCGvInmfn2ijC4HsIY/3W1CWbwS/YQoFgdgPg=", "narHash": "sha256-2m1ceZjbmgrJCZ2PuQZaK4in3gcg3o6rZ7WK6dr5vAA=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixos-hardware", "repo": "nixos-hardware",
"rev": "1552a9f4513f3f0ceedcf90320e48d3d47165712", "rev": "98236410ea0fe204d0447149537a924fb71a6d4f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -203,11 +203,11 @@
}, },
"desktop-nixpkgs": { "desktop-nixpkgs": {
"locked": { "locked": {
"lastModified": 1750506804, "lastModified": 1750776420,
"narHash": "sha256-VLFNc4egNjovYVxDGyBYTrvVCgDYgENp5bVi9fPTDYc=", "narHash": "sha256-/CG+w0o0oJ5itVklOoLbdn2dGB0wbZVOoDm4np6w09A=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "4206c4cb56751df534751b058295ea61357bbbaa", "rev": "30a61f056ac492e3b7cdcb69c1e6abdcf00e39cf",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -648,11 +648,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1750614446, "lastModified": 1750798083,
"narHash": "sha256-6WH0aRFay79r775RuTqUcnoZNm6A4uHxU1sbcNIk63s=", "narHash": "sha256-DTCCcp6WCFaYXWKFRA6fiI2zlvOLCf5Vwx8+/0R8Wc4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "7c35504839f915abec86a96435b881ead7eb6a2b", "rev": "ff31a4677c1a8ae506aa7e003a3dba08cb203f82",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -1128,11 +1128,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1750506804, "lastModified": 1750776420,
"narHash": "sha256-VLFNc4egNjovYVxDGyBYTrvVCgDYgENp5bVi9fPTDYc=", "narHash": "sha256-/CG+w0o0oJ5itVklOoLbdn2dGB0wbZVOoDm4np6w09A=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "4206c4cb56751df534751b058295ea61357bbbaa", "rev": "30a61f056ac492e3b7cdcb69c1e6abdcf00e39cf",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -1223,16 +1223,16 @@
}, },
"nixpkgs-stable_5": { "nixpkgs-stable_5": {
"locked": { "locked": {
"lastModified": 1750330365, "lastModified": 1750838302,
"narHash": "sha256-hJ7XMNVsTnnbV2NPmStCC07gvv5l2x7+Skb7hyUzazg=", "narHash": "sha256-aVkL3/yu50oQzi2YuKo0ceiCypVZpZXYd2P2p1FMJM4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d883b6213afa179b58ba8bace834f1419707d0ad", "rev": "7284e2decc982b81a296ab35aa46e804baaa1cfe",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-24.11", "ref": "nixos-25.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@@ -1795,11 +1795,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1750560265, "lastModified": 1750905536,
"narHash": "sha256-jQCojKl1/TzqE6ANOu6rP2qqxOcGK2xs6hpxZ77wrR8=", "narHash": "sha256-Mo7yXM5IvMGNvJPiNkFsVT2UERmnvjsKgnY6UyDdySQ=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "076fdb0d45a9de3f379a626f51a62c78afe7efb1", "rev": "2fa7c0aabd15fa0ccc1dc7e675a4fcf0272ad9a1",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -290,7 +290,7 @@
}; };
nixpkgs-stable = { nixpkgs-stable = {
url = "github:NixOS/nixpkgs/nixos-24.11"; url = "github:NixOS/nixpkgs/nixos-25.05";
}; };
}; };

View File

@@ -1,4 +1,4 @@
{ lib, pkgs, ... }: { pkgs, ... }:
let let
shellAliases = { shellAliases = {
update-boot = "sudo nixos-rebuild boot --max-jobs 10 --build-host admin@10.0.1.18"; update-boot = "sudo nixos-rebuild boot --max-jobs 10 --build-host admin@10.0.1.18";
@@ -44,6 +44,7 @@ in
unstable.compose2nix unstable.compose2nix
discord discord
heroic heroic
stable.vmware-horizon-client
jq jq
lutris lutris
lzip lzip
@@ -59,7 +60,6 @@ in
unigine-heaven unigine-heaven
via via
virt-manager virt-manager
vmware-horizon-client
vorta vorta
waydroid-helper waydroid-helper
]; ];

View File

@@ -2,5 +2,6 @@
{ {
specialisation.cosmic.configuration = { specialisation.cosmic.configuration = {
imports = [ ./default.nix ]; imports = [ ./default.nix ];
environment.etc."specialisation".text = "cosmic";
}; };
} }

View File

@@ -64,7 +64,9 @@ in
# black # black
color0 = theme.nord.polarNight.nord0; color0 = theme.nord.polarNight.nord0;
color8 = theme.nord.polarNight.nord1;
# Autosuggestion
color8 = theme.nord.frost.nord10;
# red # red
color1 = theme.nord.aurora.nord11; color1 = theme.nord.aurora.nord11;

View File

@@ -23,6 +23,7 @@ let
in in
{ {
imports = [ imports = [
./scripts/hass.nix
./scripts/weather.nix ./scripts/weather.nix
]; ];
# https://github.com/Alexays/Waybar/wiki/Module:-Hyprland # https://github.com/Alexays/Waybar/wiki/Module:-Hyprland
@@ -48,7 +49,6 @@ in
modules-right = [ modules-right = [
"tray" "tray"
# "custom/updates"
"custom/lights" "custom/lights"
"temperature" "temperature"
"temperature#gpu" "temperature#gpu"
@@ -84,18 +84,10 @@ in
spacing = 10; spacing = 10;
}; };
# "custom/updates" = {
# tooltip = true;
# format = { };
# interval = 30;
# exec = "waybar-updates";
# return-type = "json";
# };
"custom/lights" = { "custom/lights" = {
tooltip = false; tooltip = false;
format = "󱉓"; format = "󱉓";
on-click = "nix-shell /home/matt/.config/waybar/scripts/hass.nix --run \"python /home/matt/.config/waybar/scripts/hass.py --toggle_light light.bedroom_lights\""; on-click = "waybar-hass --toggle_light light.living_room_lights";
}; };
temperature = { temperature = {
@@ -372,13 +364,6 @@ in
border-radius: 0; border-radius: 0;
} }
#custom-updates {
color: ${theme.nord.frost.nord8};
background-color: ${theme.nord.polarNight.nord0};
${defaultOpacity}
${borderLeft}
}
#custom-lights { #custom-lights {
color: ${theme.nord.frost.nord8}; color: ${theme.nord.frost.nord8};
background-color: ${theme.nord.polarNight.nord0}; background-color: ${theme.nord.polarNight.nord0};

View File

@@ -1,18 +1,89 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs, ... }:
let
homeassistant-api = pkgs.python3.pkgs.buildPythonPackage rec {
pname = "homeassistant_api";
version = "5.0.0";
format = "pyproject";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "sha256-UNKTtgInrVJtjHb1WVlUbcbhjBOtTX00eHmm54ww0rY=";
};
pkgs.mkShell { # do not run tests
# The Nix packages provided in the environment doCheck = false;
packages = [ nativeBuildInputs = with pkgs.python3.pkgs; [ poetry-core requests-cache ];
pkgs.python312 dependencies = with pkgs.python3.pkgs; [
pkgs.python3Packages.pip requests-cache
# Whatever other packages are required pydantic
]; websockets
shellHook = '' ];
export TMPDIR=/tmp propagatedBuildInputs = with pkgs.python3.pkgs; [
export VENV_DIR=/tmp/lights aiohttp
mkdir $VENV_DIR aiohttp-client-cache
python -m venv $VENV_DIR/.venv requests
source $VENV_DIR/.venv/bin/activate simplejson
pip install homeassistant-api
''; requests-cache
pydantic
websockets
];
pythonRelaxDeps = [
"requests-cache"
"pydantic"
"websockets"
];
pythonImportsCheck = [
"homeassistant_api"
];
};
pythonEnv = pkgs.python3.withPackages (ps: [
homeassistant-api
]);
waybar-hass = pkgs.writeScriptBin "waybar-hass" ''
#!${pythonEnv}/bin/python
import os
import argparse
import time
from homeassistant_api import Client
hass_url = 'http://homeassistant.local:8123/api'
parser = argparse.ArgumentParser(prog='hass python wrapper')
parser.add_argument('--toggle_light')
args = parser.parse_args()
def loadKey():
token_path = "/run/secrets/desktop/hass_token"
with open(token_path, "r") as key_file:
key = key_file.readline()
return key
def toggle_light(client, light):
lights = client.get_domain("light")
lights.toggle(entity_id=light)
time.sleep(0.5)
light_entity = client.get_entity(entity_id=light)
state = light_entity.get_state()
if state.state == 'on':
return "󰛨"
else:
return "󰹏"
def main():
token = loadKey()
with Client(hass_url, token) as client:
if args.toggle_light is not None:
status = toggle_light(client=client, light=args.toggle_light)
print("{ text: \"" + status + "\" }")
main()
'';
in
{
home.packages = [ waybar-hass ];
} }

View File

@@ -1,42 +0,0 @@
import os
import argparse
import time
from homeassistant_api import Client
hass_url = 'https://hass.mjallen.dev/api'
parser = argparse.ArgumentParser(prog='hass python wrapper')
parser.add_argument('--toggle_light')
args = parser.parse_args()
def loadKey():
token_path = ""
for folder in range(1,100):
if os.path.exists("/run/secrets.d/" + str(folder) + "/desktop/hass_token"):
token_path = "/run/secrets.d/" + str(folder) + "/desktop/hass_token"
break
with open(token_path, "r") as key_file:
key = key_file.readline()
return key
def toggle_light(client, light):
lights = client.get_domain("light")
lights.toggle(entity_id=light)
time.sleep(0.5)
light_entity = client.get_entity(entity_id=light)
state = light_entity.get_state()
if state.state == 'on':
return "󰛨"
else:
return "󰹏"
def main():
token = loadKey()
with Client(hass_url, token) as client:
if args.toggle_light is not None:
status = toggle_light(client=client, light=args.toggle_light)
print("{ text: \"" + status + "\" }")
main()

View File

@@ -1,90 +0,0 @@
#!/usr/bin/env nix-shell
#! nix-shell -i python3 --pure
#! nix-shell -p python3
import os
import json
import subprocess
import re
from datetime import datetime
import time
tmp_path = '/tmp/waybar-scripts/updates'
json_cache = tmp_path + "/data.json"
git_repo = 'git@github.com:mjallen18/nix-config.git'
def cache_json(data):
with open(json_cache, mode="w") as cache:
json.dump(data, cache)
def create_folders():
if not os.path.exists(tmp_path):
os.makedirs(tmp_path)
os.chdir(tmp_path)
def clone_repo():
reset_repo()
if os.path.exists(tmp_path) and len(os.listdir(tmp_path)) == 0:
subprocess.run(["git", "clone", git_repo, tmp_path])
def check_for_flake_updates():
return subprocess.run(["sudo", "nix", "flake", "update", "-I", tmp_path, tmp_path], capture_output=True, text=True)
def reset_repo():
if os.path.exists(tmp_path) and not len(os.listdir(tmp_path)) == 0:
subprocess.run(["git", "reset", "--hard"])
subprocess.run(["git", "pull"])
def parse_output(output):
updates_dict = {}
updates = re.findall(r"(• Updated input '(.+)':((\n|\r|\n)(.+\((\d\d\d\d-\d\d-\d\d\)))){2})", output)
for update in updates:
input = re.findall(r"'(.+)':", update[0])[0].strip()
dates = re.findall(r"(\d{4}-\d{2}-\d{2})", update[0])
updates_dict[input] = dates
return updates_dict
def check():
data = {}
# print("create folders")
create_folders()
# print("clone repo")
clone_repo()
# print("checking for updates")
updates = check_for_flake_updates()
updates_dict = parse_output(updates.stderr)
if len(updates_dict.keys()) > 0:
data["text"] = ("󰏕")
else:
data["text"] = (u"\u00A0")
if len(updates_dict.keys()) <= 0:
data["tooltip"] = ("flake inputs up to date")
else:
data["tooltip"] = ("flake input updates:\n\n")
for input in updates_dict.keys():
data["tooltip"] += "<b>{}</b>\n".format(input)
data["tooltip"] += "Old Ref: {0}{1}\n\n".format(updates_dict[input][0].strip(), updates_dict[input][1].strip())
cache_json(data)
print(json.dumps(data))
def read_cache():
with open(json_cache, mode="r") as cache:
print(json.dumps(json.load(cache)))
def main():
now = int(datetime.now().strftime("%H"))
if os.path.exists(json_cache):
mtime = int(time.localtime(os.stat(json_cache).st_ctime).tm_hour)
else:
mtime = now + 1
if (now % 2 == 0 and mtime < now) or not os.path.exists(json_cache):
check()
else:
read_cache()
main()

View File

@@ -67,9 +67,14 @@ in
services = { services = {
preload-bing-wallpaper = { preload-bing-wallpaper = {
enable = true; enable = true;
wants = [ "network.target" ]; wants = [ "network-online.target" ];
after = [ "network.target" ]; after = [ "network-online.target" ];
wantedBy = [ "graphical-session.target" ]; before = [ "display-manager.service" ];
requiredBy = [
"plymouth-quit-wait.service"
"display-manager.service"
];
wantedBy = [ "display-manager.service" ];
path = [ path = [
pkgs.bash pkgs.bash
pkgs.jq pkgs.jq

View File

@@ -2,5 +2,6 @@
{ {
specialisation.hyprland.configuration = { specialisation.hyprland.configuration = {
imports = [ ./default.nix ]; imports = [ ./default.nix ];
environment.etc."specialisation".text = "hyprland";
}; };
} }

View File

@@ -1,6 +1,6 @@
desktop: desktop:
matt_password: ENC[AES256_GCM,data:wmcn47H15fVRhzLwuw5rATFIjKblT0TNY+K2abT6WAF89M4sATGqpRCB7p21CCXjAGM9HSY/E5EfPoKFFh6qYe6D9ykvvWTB0g==,iv:IIG0IotGRXrEYNq0PjOt0gI0TJIWBieI16RCYCyKS6w=,tag:6+QvPuK7wo5o1x1p0dz8/A==,type:str] matt_password: ENC[AES256_GCM,data:wmcn47H15fVRhzLwuw5rATFIjKblT0TNY+K2abT6WAF89M4sATGqpRCB7p21CCXjAGM9HSY/E5EfPoKFFh6qYe6D9ykvvWTB0g==,iv:IIG0IotGRXrEYNq0PjOt0gI0TJIWBieI16RCYCyKS6w=,tag:6+QvPuK7wo5o1x1p0dz8/A==,type:str]
hass_token: ENC[AES256_GCM,data:Mmk0gTD616umqKACxH7w+r6uHAP4U5lZyQu/gNXlnUn0369wPlph358qy6sZy9ooM0bJEXr321IS5h+VrHpHpV9IFAAjszwgTg7tbniWwl76tkkykh4o/9L3oal8ZcpzMY64ayQ/gmzv6KAXXjGUhKmsQ80P4elJqulICOPITCJw6qZU0Yvlj3WxAgHb7rZK95OypgbRBcrCO7CF9QH9R/OyNzQanXHlPXEJOdb7NvAG/7XBpmwY,iv:did3dfo0YvRyIr+sEiUOnOROlbFmTsqwjbpVY6TSfe0=,tag:3pBmoZgfz6TOQqT+NFdHng==,type:str] hass_token: ENC[AES256_GCM,data:xex09ibizTRtqY4hdeXDnuBfpUUKn+cBeaPJkHeBNzO3nbMGXdaW5WXOc07ea/ANPj1Qz2U/npjzG41AUHVUSVeOK4e/FkrPsMPzTH0TiPURPJr/XPaOTCzoA+ryL1NPFc3sTIbX+wSVRtNQr7Jm59IIyfLv/wdd4De7RnhD+kyNLBDXnT9kPFJKfp4WcxcgmiJZGFPby6+U/c4gT3Z5hG0NzwmtLcur4VI79q+4RIoQYVb0A1oH,iv:2P766cm+rJ+8cWzYRV2tgmzoVWbX0gJe71aNQVoGNp4=,tag:8DusTheWmAIiDcKepS4Anw==,type:str]
restic: restic:
user: ENC[AES256_GCM,data:IoDWBPg=,iv:Am5YWSr6qhQZumY/BUUgtL131q/gsk3OpSLFjPpYu8c=,tag:3fhkAZdukXbppH9BLUVSfA==,type:str] user: ENC[AES256_GCM,data:IoDWBPg=,iv:Am5YWSr6qhQZumY/BUUgtL131q/gsk3OpSLFjPpYu8c=,tag:3fhkAZdukXbppH9BLUVSfA==,type:str]
password: ENC[AES256_GCM,data:D0u9Wq67jDetyzI=,iv:yjL3Ywfa5VlKbMhQFduujReElGWTJFT2ppUEtYxsLwk=,tag:YlnW17CTmADN8p9rzwGhlQ==,type:str] password: ENC[AES256_GCM,data:D0u9Wq67jDetyzI=,iv:yjL3Ywfa5VlKbMhQFduujReElGWTJFT2ppUEtYxsLwk=,tag:YlnW17CTmADN8p9rzwGhlQ==,type:str]
@@ -101,7 +101,7 @@ sops:
b2x6YXBNbnRweU9jYlJtWmhCNmdXTE0K1LXP8uPq7nRH4HljuCzYxKIMfoJxGahu b2x6YXBNbnRweU9jYlJtWmhCNmdXTE0K1LXP8uPq7nRH4HljuCzYxKIMfoJxGahu
zhfoN34WKe8dUHyy18/5H48EZ0eIUaKZir3KlpewViTRrFXt/kkj8w== zhfoN34WKe8dUHyy18/5H48EZ0eIUaKZir3KlpewViTRrFXt/kkj8w==
-----END AGE ENCRYPTED FILE----- -----END AGE ENCRYPTED FILE-----
lastmodified: "2025-05-29T02:18:21Z" lastmodified: "2025-06-28T00:47:28Z"
mac: ENC[AES256_GCM,data:6R3wUJm3Tc29zxqGZP+Jh9PcQ0rBOG9mBiBVKjAGzSiQfzOZNwghT4YrBA4s6byL8EK4hDKzQwtI2+nyzBXBKK328GGGbA8O3xxm30lIx2a4iDA7Au0ssYkIhHx8n/o34TN0tMvxyGhyJpf667ELfrEJlspTf2iAnEu1o7mIxNE=,iv:cA7B840UmQft5FdZ8ACxyQ1xapVOKGqFk7r8Ff7w74M=,tag:BCTfG/mpiUREqKbt+qn0lg==,type:str] mac: ENC[AES256_GCM,data:C1yDwlZXQLkyF/ri2Au5+K6pVX2aavu6+ViWzDMzqD+l55dYuU/70YNEGEzQIygUmZdr3FCubY2uTXWEABaaez4JHsykTlNgnxRqk6660nZNbhahV0+BddoTQ4s1GG8N5tI/3WlfwofPCvrpb2Bcn733leBnQvxNvLbIRcRCxvI=,iv:qFWTOprHfV83aEA6M8vSQXGg/SbVFJnmyGFBmT+PZAo=,tag:IZF3fxtY7T78REUwaEucJg==,type:str]
unencrypted_suffix: _unencrypted unencrypted_suffix: _unencrypted
version: 3.10.2 version: 3.10.2

View File

@@ -20,10 +20,10 @@ in
theme = "fishy"; theme = "fishy";
}; };
initContent = '' # initContent = ''
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then # if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
tmux attach-session -t default || tmux new-session -s default # tmux attach-session -t default || tmux new-session -s default
fi # fi
''; # '';
}; };
} }