From 72612b2c3f408bbf5a7fa6246b9981a3e127f673 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 19 Jan 2023 23:03:24 +0100 Subject: [PATCH] cleanup --- nixos/machines/pepe/home-assistant.nix | 294 ------------------ .../pepe/home-assistant/chaospott.nix | 80 ----- .../pepe/home-assistant/iot-control.nix | 30 -- nixos/machines/pepe/home-assistant/kodi.nix | 45 --- .../pepe/home-assistant/light-control.nix | 232 -------------- nixos/machines/pepe/home-assistant/mpd.nix | 13 - nixos/machines/pepe/home-assistant/sonoff.nix | 116 ------- nixos/machines/pepe/home-assistant/stocks.nix | 182 ----------- nixos/machines/pepe/home-assistant/timer.nix | 225 -------------- .../machines/pepe/home-assistant/weather.nix | 18 -- .../machines/pepe/home-assistant/workday.nix | 56 ---- .../home-assistant/zigbee2mqtt/temperatur.nix | 33 -- nixos/machines/robi/configuration.nix | 1 - nixos/machines/robi/gitlab.nix | 140 --------- nixos/machines/robi/mining.nix | 52 ---- 15 files changed, 1517 deletions(-) delete mode 100644 nixos/machines/pepe/home-assistant.nix delete mode 100644 nixos/machines/pepe/home-assistant/chaospott.nix delete mode 100644 nixos/machines/pepe/home-assistant/iot-control.nix delete mode 100644 nixos/machines/pepe/home-assistant/kodi.nix delete mode 100644 nixos/machines/pepe/home-assistant/light-control.nix delete mode 100644 nixos/machines/pepe/home-assistant/mpd.nix delete mode 100644 nixos/machines/pepe/home-assistant/sonoff.nix delete mode 100644 nixos/machines/pepe/home-assistant/stocks.nix delete mode 100644 nixos/machines/pepe/home-assistant/timer.nix delete mode 100644 nixos/machines/pepe/home-assistant/weather.nix delete mode 100644 nixos/machines/pepe/home-assistant/workday.nix delete mode 100644 nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix delete mode 100644 nixos/machines/robi/gitlab.nix delete mode 100644 nixos/machines/robi/mining.nix diff --git a/nixos/machines/pepe/home-assistant.nix b/nixos/machines/pepe/home-assistant.nix deleted file mode 100644 index 36a7e1e..0000000 --- a/nixos/machines/pepe/home-assistant.nix +++ /dev/null @@ -1,294 +0,0 @@ -{ pkgs, config, lib, ... }: { - - imports = [ - ./home-assistant/zigbee2mqtt.nix - ]; - - networking.firewall.allowedTCPPorts = [ 8123 ]; - networking.firewall.allowedUDPPorts = [ 8123 ]; - - services.homeAssistantConfig = { - - # turn on to edit GUI - lovelace = { }; - - homeassistant = { - - name = "Home"; - latitude = 51.444847; - longitude = 6.967006; - elevation = 116; - unit_system = "metric"; - - time_zone = config.time.timeZone; - auth_providers = [{ - type = "trusted_networks"; - trusted_networks = [ - config.module.cluster.services.tinc."private".networkSubnet - "192.168.178.0/24" - "127.0.0.1" - ]; - }]; - - }; - - # needed, don't know why - default_config = { }; - config = { }; - - # to grab metrics via prometheus - prometheus.namespace = "hass"; - - # manual state - # ------------ - # all scenes - input_select.scene = { - icon = "mdi:brightness-auto"; - options = [ "up-bright" "up-dark" "half" "down" "night" "outside" ]; - }; - # scenes controlled by buttons - input_select.scene_button = { - icon = "mdi:brightness-auto"; - options = [ "up-dark" "night" ]; - }; - input_boolean.situation_toggle.icon = "mdi:toggle-switch"; - input_boolean.printer_toggle.icon = "mdi:toggle-switch"; - - input_boolean.windows_up.icon = "mdi:toggle-switch"; - - automation = [ - - { - alias = "Hold Button -> Toggle Printer"; - trigger = { - platform = "state"; - entity_id = "input_boolean.printer_toggle"; - }; - action = { - service = "switch.toggle"; - data.entity_id = "switch.pal02"; - }; - } - - { - alias = "set light-control scene"; - trigger = { - platform = "state"; - entity_id = "input_select.scene"; - }; - action = { - service = "mqtt.publish"; - data_template = { - topic = "control/lights/set"; - payload_template = - ''{"scene":"{{ states('input_select.scene')}}"}''; - }; - }; - } - - # control situation with buttons - { - alias = "Button -> Change Scene"; - trigger = { - platform = "state"; - entity_id = "input_boolean.situation_toggle"; - }; - action = { - service = "input_select.select_next"; - data.entity_id = "input_select.scene_button"; - }; - } - { - alias = "Button Scene -> Scene"; - trigger = { - platform = "state"; - entity_id = "input_select.scene_button"; - }; - action = { - service = "input_select.select_option"; - data_template = { - entity_id = "input_select.scene"; - option = "{{ states('input_select.scene_button') }}"; - }; - }; - } - - # outside and home - { - alias = "when opening door I'm outside"; - trigger = [ - { - platform = "state"; - # todo : groups are not working right now - entity_id = "binary_sensor.door_sensor_4"; - from = "off"; - to = "on"; - } - { - platform = "state"; - # todo : groups are not working right now - entity_id = "binary_sensor.door_sensor_4"; - from = "on"; - to = "off"; - } - ]; - action = [{ - service = "input_select.select_option"; - data = { - entity_id = "input_select.scene"; - option = "outside"; - }; - }]; - } - - { - alias = "reset everything when back home"; - trigger = map - (entity_id: { - platform = "state"; - entity_id = entity_id; - from = "off"; - to = "on"; - }) [ - "binary_sensor.motion_sensor_1" - "binary_sensor.motion_sensor_2" - "binary_sensor.motion_sensor_3" - "binary_sensor.motion_sensor_4" - "binary_sensor.motion_sensor_5" - "binary_sensor.motion_sensor_6" - "binary_sensor.motion_sensor_7" - "binary_sensor.motion_sensor_8" - ]; - condition = { - condition = "template"; - value_template = - ''{{ states.input_select.scene.state == "outside" }}''; - }; - action = [{ - service = "input_select.select_option"; - data = { - entity_id = "input_select.scene"; - option = "up-dark"; - }; - }]; - } - - ]; - - group = - let - create_room = { name, description }: { - "${name}" = { - name = "${description}"; - entities = [ ]; - }; - }; - create_rooms = rooms: - lib.foldr (a: b: a // b) { } (map create_room rooms); - # rooms - # ----- - in - (create_rooms [ - { - name = "floor_room"; - description = "Flur"; - } - { - name = "bed_room"; - description = "Schlafzimmer"; - } - { - name = "living_room"; - description = "Wohnzimmer"; - } - { - name = "kitchen_room"; - description = "Küche"; - } - { - name = "bath_room"; - description = "Klo"; - } - ]) // { - - # overview - # -------- - all_sensors = { name = "Alle Sensoren"; }; - today = { - name = "Today"; - entities = [ "input_select.scene" ]; - }; - # other stuff - # ----------- - tv = { name = "TV"; }; - all_lights = { name = "Alle Lampen"; }; - unknown = { - name = "Not Used"; - entities = [ ]; - }; - - }; - - }; - - services.home-assistant = { - enable = true; - package = pkgs.unstable.home-assistant; - #package = pkgs.unstable.home-assistant.override { - # python3 = pkgs.unstable.python37; - # extraPackages = python: [ - # # todo : check which is still needed - # python.netdisco - # python.xmltodict - # python.mpd2 - # # for mqtt - # python.hbmqtt - # python.paho-mqtt - # # needed for platform workday - # #(python.buildPythonPackage rec { - # # pname = "holidays"; - # # version = "0.9.10"; - # # src = python.fetchPypi { - # # inherit pname version; - # # sha256 = - # # "9f06d143eb708e8732230260636938f2f57114e94defd8fa2082408e0d422d6f"; - # # }; - # # doCheck = false; - # # buildInputs = [ pkgs.dateutils ]; - # # propagatedBuildInputs = [ python."python-dateutil" python."six" ]; - # # meta = with pkgs.stdenv.lib; { - # # homepage = "https://github.com/dr-prodigy/python-holidays"; - # # license = licenses.mit; - # # description = "Generate and work with holidays in Python"; - # # maintainers = with maintainers; [ mrVanDalo ]; - # # }; - # #}) - # ]; - #}; - - }; - - # host nginx setup - services.nginx = { - enable = true; - recommendedProxySettings = true; - virtualHosts = { - "iot.pepe.private" = { - serverAliases = [ "hass.pepe.private" "home.pepe.private" ]; - extraConfig = '' - proxy_buffering off; - ''; - locations."/" = { - proxyPass = "http://127.0.0.1:8123"; - proxyWebsockets = true; - extraConfig = '' - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - ''; - }; - }; - }; - }; - -} diff --git a/nixos/machines/pepe/home-assistant/chaospott.nix b/nixos/machines/pepe/home-assistant/chaospott.nix deleted file mode 100644 index fc10fb4..0000000 --- a/nixos/machines/pepe/home-assistant/chaospott.nix +++ /dev/null @@ -1,80 +0,0 @@ -{ config, pkgs, ... }: -let - - name = "chaospott"; - folderPath = config.services.home-assistant.configDir; - filePath = "${folderPath}/${name}.json"; - -in -{ - services.homeAssistantConfig = { - - sensor = [ - { - platform = "file"; - name = "${name}_aerie"; - file_path = filePath; - value_template = "{{ value_json.aerie }}"; - } - { - platform = "file"; - name = "${name}_cellar"; - file_path = filePath; - value_template = "{{ value_json.cellar }}"; - } - ]; - - homeassistant = { - whitelist_external_dirs = [ folderPath ]; - customize = { - "sensor.${name}_aerie" = { - icon = "mdi:store"; - entity_picture = "https://chaospott.de/images/logo.png"; - friendly_name = "ChaosPott Oben"; - }; - "sensor.${name}_cellar" = { - icon = "mdi:store"; - entity_picture = "https://chaospott.de/images/logo.png"; - friendly_name = "ChaosPott Unten"; - }; - }; - }; - - group = { - "${name}" = { - name = "ChaosPott (Essen)"; - entities = [ "sensor.${name}_aerie" "sensor.${name}_cellar" ]; - }; - }; - - }; - - systemd.services."${name}" = { - enable = true; - before = [ "home-assistant.service" ]; - wantedBy = [ "home-assistant.service" ]; - serviceConfig = { - User = "hass"; - Type = "oneshot"; - }; - description = "set ${name} for homeassistant"; - script = '' - ${pkgs.curl}/bin/curl --location --silent https://status.chaospott.de/api \ - | ${pkgs.jq}/bin/jq --compact-output \ - '.sensors.door_locked | - [.[] | { "\(.location)" : (if .value then "closed" else "open" end) }] | - reduce .[] as $item ({}; . + $item) ' \ - >> ${filePath} - ''; - }; - - systemd.timers."${name}" = { - enable = true; - wantedBy = [ "multi-user.target" ]; - timerConfig = { - OnCalendar = "hourly"; - Persistent = "true"; - }; - }; - -} diff --git a/nixos/machines/pepe/home-assistant/iot-control.nix b/nixos/machines/pepe/home-assistant/iot-control.nix deleted file mode 100644 index 5033693..0000000 --- a/nixos/machines/pepe/home-assistant/iot-control.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib, pkgs, config, ... }: { - - users.users.heater-control = { }; - - #systemd.services.heater-control = { - # enable = true; - # wantedBy = [ "multi-user.target" ]; - # serviceConfig = { User = "heater-control"; }; - # script = - # let myPython = pkgs.python3.withPackages (ps: with ps; [ paho-mqtt ]); - # in '' - # cd ${} - # ${myPython}/bin/python heater.py - # ''; - #}; - - users.users.fyrtur-control = { }; - - systemd.services.fyrtur-control = { - enable = true; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { User = "fyrtur-control"; }; - script = - let myPython = pkgs.python3.withPackages (ps: with ps; [ paho-mqtt ]); - in '' - cd ${} - ${myPython}/bin/python fyrtur.py - ''; - }; -} diff --git a/nixos/machines/pepe/home-assistant/kodi.nix b/nixos/machines/pepe/home-assistant/kodi.nix deleted file mode 100644 index d6c7a6a..0000000 --- a/nixos/machines/pepe/home-assistant/kodi.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ pkgs, config, lib, ... }: { - - services.homeAssistantConfig = { - - media_player = [{ - platform = "kodi"; - host = "127.0.0.1"; - }]; - - shell_command = { - start_kodi = "sudo ${pkgs.systemd}/bin/systemctl start display-manager"; - stop_kodi = "sudo ${pkgs.systemd}/bin/systemctl stop display-manager"; - }; - - automation = [ - { - alias = "turn kodi on once the tv is turned on"; - trigger = { - platform = "state"; - entity_id = "group.tv"; - from = "off"; - to = "on"; - for.seconds = 60; - }; - action = [{ service = "shell_command.start_kodi"; }]; - } - { - alias = "turn off kodi on once the tv is turned off"; - trigger = { - platform = "state"; - entity_id = "group.tv"; - from = "on"; - to = "off"; - }; - action = [{ service = "shell_command.stop_kodi"; }]; - } - ]; - - }; - - security.sudo.extraConfig = '' - hass ALL= (root) NOPASSWD: ${pkgs.systemd}/bin/systemctl start display-manager - hass ALL= (root) NOPASSWD: ${pkgs.systemd}/bin/systemctl stop display-manager - ''; -} diff --git a/nixos/machines/pepe/home-assistant/light-control.nix b/nixos/machines/pepe/home-assistant/light-control.nix deleted file mode 100644 index 018b50e..0000000 --- a/nixos/machines/pepe/home-assistant/light-control.nix +++ /dev/null @@ -1,232 +0,0 @@ -{ pkgs, lib, config, ... }: { - - services.mqtt.light-control.enable = true; - services.mqtt.light-control.loglevel = "debug"; - services.mqtt.light-control.config = { - credentials = { - host = "tcp://localhost:1883"; - user = "homeassistant"; - password = "hallo"; - }; - scenes = [ - { - name = "up-dark"; - ignored_sensors = [ - "zigbee2mqtt/door_sensor_1" - "zigbee2mqtt/door_sensor_4" - "zigbee2mqtt/door_sensor_5" - ]; - } - { - name = "half"; - ignored_sensors = [ - "zigbee2mqtt/door_sensor_1" - "zigbee2mqtt/door_sensor_4" - "zigbee2mqtt/door_sensor_5" - ]; - disabled_switches = [ - "zigbee2mqtt/led_1" - "zigbee2mqtt/led_2" - "zigbee2mqtt/light_2" - "zigbee2mqtt/light_4" - "zigbee2mqtt/light_5" - "zigbee2mqtt/light_7" - ]; - } - { - name = "down"; - ignored_sensors = [ - "zigbee2mqtt/door_sensor_1" - "zigbee2mqtt/door_sensor_4" - "zigbee2mqtt/door_sensor_5" - ]; - } - { - name = "up-bright"; - disabled_switches = [ - "zigbee2mqtt/led_1" - "zigbee2mqtt/led_2" - "zigbee2mqtt/light_2" - "zigbee2mqtt/light_4" - "zigbee2mqtt/light_5" - "zigbee2mqtt/light_7" - ]; - ignored_sensors = [ "zigbee2mqtt/door_sensor_4" ]; - } - { - name = "outside"; - room_tracking_enabled = false; - ignored_sensors = [ "zigbee2mqtt/door_sensor_4" ]; - } - { - name = "night"; - room_tracking_enabled = false; - brightness = 25; - ignored_sensors = - [ "zigbee2mqtt/motion_sensor_7" "zigbee2mqtt/door_sensor_4" ]; - } - ]; - sensors = - let - door = { topic, room }: { - topic = topic; - key = "contact"; - room = room; - invert_state = true; - delay = 90; - }; - motion = { topic, room }: { - topic = topic; - key = "occupancy"; - room = room; - delay = 60; - }; - in - [ - - (motion { - topic = "zigbee2mqtt/motion_sensor_1"; - room = "office_room"; - }) - (motion { - topic = "zigbee2mqtt/motion_sensor_2"; - room = "office_room"; - }) - (motion { - topic = "zigbee2mqtt/motion_sensor_6"; - room = "office_room"; - }) - (motion { - topic = "zigbee2mqtt/motion_sensor_8"; - room = "office_room"; - }) - (motion { - topic = "zigbee2mqtt/motion_sensor_7"; - room = "sleeping_room"; - }) - (motion { - topic = "zigbee2mqtt/motion_sensor_5"; - room = "kitchen"; - }) - (motion { - topic = "zigbee2mqtt/motion_sensor_4"; - room = "storage_room"; - }) - - (door { - topic = "zigbee2mqtt/door_sensor_1"; - room = "storage_room"; - }) - (door { - topic = "zigbee2mqtt/door_sensor_5"; - room = "sleeping_room"; - }) - (door { - # house door - topic = "zigbee2mqtt/door_sensor_4"; - room = "floor"; - }) - - ]; - switches = - let - sonoff = { id, rooms, delay ? 0 }: { - topic = "stat/${id}/RESULT"; - key = "POWER"; - rooms = rooms; - delay = delay; - command = { - command = "{{state}}"; - init_command = "(null)"; - topic = "cmnd/${id}/POWER"; - on = "ON"; - off = "OFF"; - }; - }; - light = { topic, rooms, delay ? 0 }: { - topic = topic; - key = "state"; - rooms = rooms; - delay = delay; - command = { - command = ''{"state":"{{state}}","brightness":{{brightness}}}''; - topic = "${topic}/set"; - on = "ON"; - off = "OFF"; - }; - }; - led = { topic, rooms, delay ? 0 }: { - topic = topic; - key = "state"; - rooms = rooms; - delay = delay; - command = { - # Configure it once to the color you like - # {"state":"{{state}}","brightness":{{brightness}},"color":{"hex":"#FFFFFF},"color_temp":255","transition":0} - command = '' - {"state":"{{state}}","brightness":{{brightness}},"transition":0}''; - topic = "${topic}/set"; - on = "ON"; - off = "OFF"; - }; - }; - in - [ - - (light { - topic = "zigbee2mqtt/light_2"; - rooms = [ "office_room" ]; - }) - (light { - topic = "zigbee2mqtt/light_4"; - rooms = [ "office_room" ]; - }) - (light { - topic = "zigbee2mqtt/light_5"; - rooms = [ "storage_room" ]; - }) - (light { - topic = "zigbee2mqtt/light_7"; - rooms = [ "sleeping_room" ]; - }) - (led { - topic = "zigbee2mqtt/led_1"; - rooms = [ "office_room" ]; - }) - (led { - topic = "zigbee2mqtt/led_2"; - rooms = [ "kitchen" ]; - }) - - #(sonoff { - # id = "PAL01"; - # rooms = [ "bed_room" ]; - #}) - #(sonoff { - # id = "PAL03"; - # rooms = [ "living_room" ]; - #}) - #(sonoff { - # id = "PAL04"; - # rooms = [ "bed_room" ]; - #}) - #(sonoff { - # id = "PAL06"; - # rooms = [ "kitchen" ]; - #}) - ## monitor and speakers - #(sonoff { - # id = "PAL07"; - # rooms = [ "bed_room" ]; - # delay = 180; - #}) - #(sonoff { - # id = "PAL08"; - # rooms = [ "bed_room" ]; - # delay = 180; - #}) - - ]; - }; - -} diff --git a/nixos/machines/pepe/home-assistant/mpd.nix b/nixos/machines/pepe/home-assistant/mpd.nix deleted file mode 100644 index 80b4cc6..0000000 --- a/nixos/machines/pepe/home-assistant/mpd.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ lib, ... }: - -{ - services.homeAssistantConfig = { - - media_player = [{ - platform = "mpd"; - host = "localhost"; - }]; - - }; - -} diff --git a/nixos/machines/pepe/home-assistant/sonoff.nix b/nixos/machines/pepe/home-assistant/sonoff.nix deleted file mode 100644 index b290ee7..0000000 --- a/nixos/machines/pepe/home-assistant/sonoff.nix +++ /dev/null @@ -1,116 +0,0 @@ -{ pkgs, config, lib, ... }: -let - - sonoffSwitches = { - #"pal01" = { - # label = "Schlafzimmer Lampe Links"; - # icon = "mdi:lightbulb"; - # groups = [ "bed_room" ]; - #}; - "pal02" = { - label = "Drucker / Scanner"; - icon = "mdi:printer"; - groups = [ "bed_room" "today" ]; - }; - #"pal03" = { - # label = "Wohnzimmer Lampe"; - # icon = "mdi:lightbulb"; - # groups = [ "living_room" ]; - #}; - #"pal04" = { - # label = "Schlafzimmer Lampe Rechts"; - # icon = "mdi:lightbulb"; - # groups = [ "bed_room" ]; - #}; - "pal05" = { - label = "TV"; - icon = "mdi:television"; - groups = [ "tv" ]; - device = "tv"; - }; - #"pal06" = { - # label = "Küchen Lampe"; - # icon = "mdi:lightbulb"; - # groups = ["kitchen_room"]; - #}; - "pal07" = { label = "Nummer 7"; }; - "pal08" = { label = "Nummer 8"; }; - }; - - toSwitch = name: "switch.${name}"; - -in -{ - - imports = [ ./mqtt.nix ]; - - services.homeAssistantConfig = { - - # nicer names - # ----------- - homeassistant.customize = lib.mapAttrs' - (entity: - { label, icon ? "mdi:power-plug-off", ... }: { - name = toSwitch entity; - value = { - friendly_name = label; - icon = icon; - }; - }) - sonoffSwitches; - - # define switches - # --------------- - switch = lib.mapAttrsToList - (name: - { ... }: { - name = name; - platform = "mqtt"; - command_topic = "cmnd/${lib.toUpper name}/POWER"; - state_topic = "stat/${lib.toUpper name}/POWER"; - payload_on = "ON"; - payload_off = "OFF"; - state_on = "ON"; - state_off = "OFF"; - }) - sonoffSwitches; - - # discover state on init - # ---------------------- - automation = [{ - alias = "Sonoff initial Power state"; - trigger = { - platform = "homeassistant"; - event = "start"; - }; - action = lib.mapAttrsToList - (name: - { ... }: { - service = "mqtt.publish"; - data = { - topic = "cmnd/${lib.toUpper name}/power"; - payload = ""; - }; - }) - sonoffSwitches; - }]; - - # append to groups - # ---------------- - group = - let - # sort lights into given groups. - sortedInGroups = - let - groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList - (name: - { groups ? [ ], ... }: - map (groupName: { "${groupName}" = "switch.${name}"; }) groups) - sonoffSwitches)); - in - lib.mapAttrs (name: entities: { inherit entities; }) groupEntries; - in - sortedInGroups; - }; - -} diff --git a/nixos/machines/pepe/home-assistant/stocks.nix b/nixos/machines/pepe/home-assistant/stocks.nix deleted file mode 100644 index 33ccc50..0000000 --- a/nixos/machines/pepe/home-assistant/stocks.nix +++ /dev/null @@ -1,182 +0,0 @@ -{ lib, config, pkgs, ... }: -let - - folderPath = config.services.home-assistant.configDir; - - # find symbols with - # https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=&apikey= - # as described here : https://www.alphavantage.co/documentation/#symbolsearch - # - # example: - # -------- - # stocks = [ - # { - # symbol = "GOOGL"; - # name = "google"; - # friendly_name = "Google"; - # currency = "$"; - # # I own 50 and bought at a price of 1000 - # own = { - # pieces = 50; - # price = 1000; - # }; - # } - # ]; - stocks = import ; - filePath = name: "${folderPath}/stock_${name}.json"; - - cleanup_list = list: lib.filter (entry: entry != { }) (lib.flatten list); - -in -{ - services.homeAssistantConfig = { - - sensor = cleanup_list (map - ({ name, currency, own ? { }, ... }: [ - { - platform = "file"; - name = "stock_${name}"; - file_path = filePath name; - value_template = "{{ value_json.price}} ${currency}"; - - } - { - platform = "file"; - name = "stock_${name}_change"; - file_path = filePath name; - value_template = "{{ value_json.change}} ${currency}"; - - } - { - platform = "file"; - name = "stock_${name}_change_percent"; - file_path = filePath name; - value_template = "{{ value_json.change_percent}} %"; - } - (lib.optionalAttrs (own != { }) { - platform = "file"; - name = "stock_${name}_profit"; - file_path = filePath name; - value_template = '' - {{ "{:,.2f}".format( value_json.price * ${toString own.pieces} - ${ - toString (own.pieces * own.price) - } ) }} ${currency}''; - }) - ]) - stocks); - - homeassistant = { - whitelist_external_dirs = [ folderPath ]; - customize = builtins.listToAttrs (cleanup_list (map - ({ name, own ? { }, ... }: [ - { - name = "sensor.stock_${name}"; - value = { - icon = "mdi:cash-usd-outline"; - friendly_name = "Price"; - }; - } - { - name = "sensor.stock_${name}_change"; - value = { - icon = "mdi:radar"; - friendly_name = "Difference"; - }; - } - { - name = "sensor.stock_${name}_change_percent"; - value = { - icon = "mdi:radar"; - friendly_name = "Percent"; - }; - } - (lib.optionalAttrs (own != { }) { - name = "sensor.stock_${name}_profit"; - value = { - icon = "mdi:radar"; - friendly_name = "Profit"; - }; - }) - ]) - stocks)); - }; - - group = (builtins.listToAttrs (map - ({ name, friendly_name, own ? { }, ... }: { - name = "stock_${name}"; - value = { - name = "${friendly_name} Aktie"; - entities = [ - "sensor.stock_${name}" - "sensor.stock_${name}_change" - "sensor.stock_${name}_change_percent" - ] ++ (lib.optional (own != { }) "sensor.stock_${name}_profit"); - }; - }) - stocks)); - - }; - - systemd.services = - let - pullService = { name, symbol, currency, ... }: { - name = "pull_stock_${name}"; - value = { - enable = true; - before = [ "home-assistant.service" ]; - wantedBy = [ "home-assistant.service" ]; - serviceConfig = { - User = "hass"; - Type = "oneshot"; - }; - description = "pull stock_${name} for homeassistant"; - script = '' - SYMBOL="${symbol}" - CURRENCY="${currency}" - APIKEY=${ - lib.fileContents - } - - ${pkgs.curl}/bin/curl --location --silent \ - "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$SYMBOL&apikey=$APIKEY" \ - | ${pkgs.jq}/bin/jq --compact-output \ - '.["Global Quote"] | - { - price: .["05. price"] | tonumber, - currency: "'$CURRENCY'", - change_percent: .["10. change percent"] | .[0:-1] | tonumber, - change: .["09. change"] | tonumber, - last_date: .["07. latest trading day"], - }' \ - >> ${filePath name} - - # old and stupid - #${pkgs.curl}/bin/curl --location --silent \ - #"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=$SYMBOL&interval=5min&apikey=$APIKEY" \ - #| ${pkgs.jq}/bin/jq --compact-output \ - # '.["Time Series (5min)"] | to_entries | [ .[] - # | { date : .key , value : .value["4. close"], currency: "'$CURRENCY'" } ] - # | sort_by(.date) | reverse | .[0]' \ - ''; - }; - }; - in - builtins.listToAttrs (map pullService stocks); - - systemd.timers = - let - pullTimer = { name, ... }: { - name = "pull_stock_${name}"; - value = { - enable = true; - wantedBy = [ "multi-user.target" ]; - timerConfig = { - OnCalendar = "hourly"; - Persistent = "true"; - }; - }; - }; - in - builtins.listToAttrs (map pullTimer stocks); - -} diff --git a/nixos/machines/pepe/home-assistant/timer.nix b/nixos/machines/pepe/home-assistant/timer.nix deleted file mode 100644 index 3109d04..0000000 --- a/nixos/machines/pepe/home-assistant/timer.nix +++ /dev/null @@ -1,225 +0,0 @@ -{ config, ... }: { - - imports = [ ./mpd.nix ]; - - services.homeAssistantConfig = { - - sensor = [{ - platform = "time_date"; - display_options = [ "time" "date" ]; - }]; - - input_datetime = { - wakeup = { - name = "Arbeitswecker"; - has_time = true; - has_date = false; - icon = "mdi:alarm"; - }; - leave = { - name = "Turn off Time"; - has_time = true; - has_date = false; - icon = "mdi:alarm"; - }; - return = { - name = "Return home"; - has_time = true; - has_date = false; - icon = "mdi:alarm"; - }; - sleep = { - name = "Turn off Time"; - has_time = true; - has_date = false; - icon = "mdi:alarm"; - }; - }; - - input_boolean = { - wakeup = { - name = "enable"; - icon = "mdi:toggle-switch"; - }; - leave = { - name = "enable"; - icon = "mdi:toggle-switch"; - }; - return = { - name = "enable"; - icon = "mdi:toggle-switch"; - }; - sleep = { - name = "enable"; - icon = "mdi:toggle-switch"; - }; - }; - - input_select = { - wakeup = { - name = "Playlist"; - icon = "mdi:library-music"; - options = [ "wakeup" "wakeup1" "wakeup2" ]; - }; - }; - - binary_sensor = [ - { - platform = "tod"; - name = "night"; - after = "sunset"; - before = "sunrise"; - } - { - platform = "tod"; - name = "daytime"; - after = "sunrise"; - before = "sunset"; - } - ]; - - group = { - - timer_wakeup = { - name = "Arbeits Aufwachen"; - entities = [ - "input_boolean.wakeup" - "input_datetime.wakeup" - "input_select.wakeup" - ]; - }; - - timer_leave = { - name = "Leave Time"; - entities = [ "input_boolean.leave" "input_datetime.leave" ]; - }; - - timer_return = { - name = "Nach Hause kommen"; - entities = [ "input_boolean.sleep" "input_datetime.sleep" ]; - }; - - timers.entities = [ - "group.timer_wakeup" - "group.timer_leave" - "group.timer_return" - "group.timer_sleep" - "binary_sensor.night" - "binary_sensor.daytime" - ]; - - today.entities = [ "sensor.date" "sensor.time" ]; - - }; - - automation = [ - { - alias = "Wecker Arbeiten"; - trigger = { - platform = "template"; - value_template = - "{{ states('sensor.time') == (states.input_datetime.wakeup.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"; - }; - condition = { - condition = "and"; - conditions = [ - { - condition = "state"; - entity_id = "input_boolean.wakeup"; - state = "on"; - } - { - condition = "state"; - entity_id = "binary_sensor.workday"; - state = "on"; - } - ]; - }; - action = [ - { - alias = "Play wakeup list"; - service = "media_player.play_media"; - data_template = { - entity_id = "media_player.mpd"; - media_content_type = "playlist"; - media_content_id = "{{ states('input_select.wakeup') }}"; - }; - } - { - alias = "turn all on"; - service = "script.turn_on"; - entity_id = "script.turn_all_on"; - } - ]; - } - - { - alias = "Leave Turn all off Timer"; - trigger = { - platform = "template"; - value_template = - "{{ states('sensor.time') == (states.input_datetime.leave.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"; - }; - condition = { - condition = "and"; - conditions = [{ - condition = "state"; - entity_id = "input_boolean.leave"; - state = "on"; - }]; - }; - action = [{ - alias = "turn all off"; - service = "script.turn_on"; - entity_id = "script.turn_all_off"; - }]; - } - - { - alias = "Return to Home"; - trigger = { - platform = "template"; - value_template = - "{{ states('sensor.time') == (states.input_datetime.return.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"; - }; - condition = { - condition = "and"; - conditions = [{ - condition = "state"; - entity_id = "input_boolean.return"; - state = "on"; - }]; - }; - action = [{ - alias = "turn all on"; - service = "script.turn_on"; - entity_id = "script.turn_all_on"; - }]; - } - - { - alias = "Sleep Turn all off Timer"; - trigger = { - platform = "template"; - value_template = - "{{ states('sensor.time') == (states.input_datetime.sleep.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"; - }; - condition = { - condition = "and"; - conditions = [{ - condition = "state"; - entity_id = "input_boolean.sleep"; - state = "on"; - }]; - }; - action = [{ - alias = "turn all off"; - service = "script.turn_on"; - entity_id = "script.turn_all_off"; - }]; - } - - ]; - }; - -} diff --git a/nixos/machines/pepe/home-assistant/weather.nix b/nixos/machines/pepe/home-assistant/weather.nix deleted file mode 100644 index 48c857b..0000000 --- a/nixos/machines/pepe/home-assistant/weather.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ config, ... }: { - services.homeAssistantConfig = { - - sensor = [ - # Weather prediction - { - platform = "zamg"; - name = "weather"; - } - ]; - - sun = { }; - - group.today.entities = [ "sensor.weather_temperature" "sun.sun" ]; - - }; - -} diff --git a/nixos/machines/pepe/home-assistant/workday.nix b/nixos/machines/pepe/home-assistant/workday.nix deleted file mode 100644 index 00fdeec..0000000 --- a/nixos/machines/pepe/home-assistant/workday.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ config, lib, ... }: -let - holiday-range = month: dayA: dayB: - map (day: "${month}-${toString day}") - (map (lib.fixedWidthNumber 2) (lib.range dayA dayB)); - privateHolidays = import ; - # for example : - # holidays = lib.flatten [ - # (holiday-range "2020-06" 7 24) - # (holiday-range "2020-10" 10 16) - #]; - holidays = lib.flatten (privateHolidays holiday-range); - -in -{ - services.homeAssistantConfig = { - - binary_sensor = [ - { - name = "before_workday"; - platform = "workday"; - country = "DE"; - province = "NW"; - workdays = [ "mon" "tue" "wed" "thu" "fri" ]; - days_offset = 1; - add_holidays = holidays; - } - { - name = "workday"; - platform = "workday"; - country = "DE"; - province = "NW"; - workdays = [ "mon" "tue" "wed" "thu" "fri" ]; - add_holidays = holidays; - } - ]; - - homeassistant.customize = { - "binary_sensor.workday" = { - icon = "mdi:calendar"; - friendly_name = "Workday?"; - }; - "binary_sensor.before_workday" = { - icon = "mdi:calendar"; - friendly_name = "Workday Tomorrow?"; - }; - }; - - group = { - today.entities = - [ "binary_sensor.before_workday" "binary_sensor.workday" ]; - }; - - }; - -} diff --git a/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix b/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix deleted file mode 100644 index d80ee5f..0000000 --- a/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ pkgs, lib, ... }: -let - - # https://www.zigbee2mqtt.io/devices/WSDCGQ11LM.html - allDevices = { - "temperature_sensor_1" = { - id = "0x00158d0002d79220"; - groups = [ "living_room" ]; - }; - "temperature_sensor_2" = { - id = "0x00158d0002d7913d"; - groups = [ "living_room" ]; - }; - }; - -in -{ - - services.zigbee2mqtt.settings = lib.mapAttrs' - (name: - { id, ... }: { - name = id; - value = { - retain = false; - friendly_name = name; - }; - }) - allDevices; - - -}; - -} diff --git a/nixos/machines/robi/configuration.nix b/nixos/machines/robi/configuration.nix index 90f7639..d861327 100644 --- a/nixos/machines/robi/configuration.nix +++ b/nixos/machines/robi/configuration.nix @@ -33,7 +33,6 @@ #../../system/server #./hardware-configuration.nix - #./mail-fetcher.nix #./finance.nix #./grafana.nix #./graylog.nix diff --git a/nixos/machines/robi/gitlab.nix b/nixos/machines/robi/gitlab.nix deleted file mode 100644 index 93a6903..0000000 --- a/nixos/machines/robi/gitlab.nix +++ /dev/null @@ -1,140 +0,0 @@ -{ config, lib, pkgs, ... }: -let - host = "gitlab.ingolf-wagner.de"; -in - -#let - # - # errorPages = pkgs.fetchgit { - # url = "https://git.ingolf-wagner.de/palo/http-errors.git"; - # rev = "74b8e4c1d9bbba3db6ad858b888e1867318af1f0"; - # sha256 = "0czdzafx4k76q773lyf3vsjm74g1995iz542dhw15kpy5xbivsrg"; - # }; - # - # error = { - # extraConfig = '' - # error_page 400 /errors/400.html; - # error_page 401 /errors/401.html; - # error_page 402 /errors/402.html; - # error_page 403 /errors/403.html; - # error_page 404 /errors/404.html; - # error_page 405 /errors/405.html; - # error_page 406 /errors/406.html; - # error_page 500 /errors/500.html; - # error_page 501 /errors/501.html; - # error_page 502 /errors/502.html; - # error_page 503 /errors/503.html; - # error_page 504 /errors/504.html; - # ''; - # locations."^~ /errors/" = { - # extraConfig = "internal;"; - # root = "${errorPages}/"; - # }; - # }; - # - #in -{ - - #services.nginx = { - # enable = true; - # statusPage = true; - # virtualHosts = { - # "git.${config.networking.hostName}.private" = { - # extraConfig = error.extraConfig; - # locations."/" = { - # proxyPass = "http://${config.networking.hostName}.private:${ - # toString config.services.gogs.httpPort - # }"; - # }; - # }; - # }; - #}; - - #services.gogs = { - # enable = true; - # appName = "Kruck GoGs"; - # domain = "git.ingolf-wagner.de"; - # httpPort = 3000; - # repositoryRoot = "/home/gogs/repositories"; - # stateDir = "/home/gogs"; - # rootUrl = "https://git.ingolf-wagner.de/"; - # extraConfig = '' - # [service] - # DISABLE_REGISTRATION = true - # SHOW_REGISTRATION_BUTTON = false - # [server] - # SSH_DOMAIN = "git.ingolf-wagner.de" - # SSH_PORT = 2222 - # START_SSH_SERVER = true - # SSH_LISTEN_PORT = 2222 - - # [log.file] - # LEVEL = Warn - - # [log.console] - # LEVEL = Warn - - # [log.sublogger.macaron] - # LEVEL = Warn - # ''; - #}; - #backup.dirs = [ config.services.gogs.repositoryRoot ]; - - services.nginx = { - enable = true; - recommendedGzipSettings = true; - recommendedOptimisation = true; - recommendedProxySettings = true; - recommendedTlsSettings = true; - virtualHosts.${host} = { - enableACME = true; - forceSSL = true; - locations."/".proxyPass = "http://unix:/run/gitlab/gitlab-workhorse.socket"; - }; - }; - - sops.secrets.gitlab_database_password.owner = config.services.gitlab.user; - sops.secrets.gitlab_initial_root_password.owner = config.services.gitlab.user; - sops.secrets.gitlab_secrets_db.owner = config.services.gitlab.user; - sops.secrets.gitlab_secrets_jws.owner = config.services.gitlab.user; - sops.secrets.gitlab_secrets_otp.owner = config.services.gitlab.user; - sops.secrets.gitlab_secrets_secret.owner = config.services.gitlab.user; - - services.postgresql = { - enable = true; - package = pkgs.postgresql_12; - }; - - services.gitlab = { - enable = true; - host = host; - port = 443; - https = true; - smtp.enable = false; - - databasePasswordFile = config.sops.secrets.gitlab_database_password.path; - initialRootPasswordFile = config.sops.secrets.gitlab_initial_root_password.path; - - secrets = { - # Make sure the secret is at least 30 characters and all random, - # no regular words or you'll be exposed to dictionary attacks - dbFile = config.sops.secrets.gitlab_secrets_db.path; - - # openssl genrsa 2048 - jwsFile = config.sops.secrets.gitlab_secrets_jws.path; - - # Make sure the secret is at least 30 characters and all random, - # no regular words or you'll be exposed to dictionary attacks - otpFile = config.sops.secrets.gitlab_secrets_otp.path; - - # Make sure the secret is at least 30 characters and all random, - # no regular words or you'll be exposed to dictionary attacks - secretFile = config.sops.secrets.gitlab_secrets_secret.path; - }; - - # smtp? - - # gitlab-runner? - }; - -} diff --git a/nixos/machines/robi/mining.nix b/nixos/machines/robi/mining.nix deleted file mode 100644 index 6f95ec0..0000000 --- a/nixos/machines/robi/mining.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ pkgs, config, ... }: -let - maxPower = 90; - pool = "eu1.ethermine.org"; - toolkit = "opencl"; - wallet = ""; - rig = config.networking.hostName; - recheckInterval = 2000; - package = pkgs.ethminer; -in -{ - - systemd.services.ethminer = { - description = "ethminer ethereum mining service"; - wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; - - serviceConfig = { - DynamicUser = true; - ExecStartPre = "${package}/bin/.ethminer-wrapped --list-devices"; - Restart = "always"; - }; - - script = '' - ${package}/bin/.ethminer-wrapped \ - --farm-recheck ${toString recheckInterval} \ - --report-hashrate \ - --${toolkit} \ - --pool stratum1+tcp://${wallet}.${rig}@${pool}:4444 - ''; - - }; - - # https://wiki.archlinux.org/title/GPGPU#Intel - hardware.opengl = { - enable = true; - extraPackages = with pkgs; [ intel-ocl intel-compute-runtime beignet ]; - driSupport = true; - driSupport32Bit = true; - }; - - environment.systemPackages = with pkgs; [ - package - # go-ethereum - go-ethereum - # to check opencl config - clinfo - # check temperature - i7z - ]; - -}