Merge remote-tracking branch 'gum/master'

This commit is contained in:
lassulus 2020-12-30 09:13:07 +01:00
commit e0bb61d3d3
24 changed files with 625 additions and 513 deletions

View File

@ -1,12 +1,16 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = [ imports = [
./net.nix
<stockholm/krebs> <stockholm/krebs>
<stockholm/krebs/2configs> <stockholm/krebs/2configs>
<stockholm/krebs/2configs/secret-passwords.nix> <stockholm/krebs/2configs/secret-passwords.nix>
<stockholm/krebs/2configs/hw/x220.nix> <stockholm/krebs/2configs/hw/x220.nix>
# see documentation in included getty-for-esp.nix:
# brain hosts/puyak/root
<stockholm/krebs/2configs/hw/getty-for-esp.nix>
## initrd unlocking ## initrd unlocking
# (brain hosts/puyak/luks-ssd;echo) | ssh root@$(brain krebs-secrets/puyak/initrd/hostname) 'cat > /crypt-ramfs/passphrase' # (brain hosts/puyak/luks-ssd;echo) | ssh root@$(brain krebs-secrets/puyak/initrd/hostname) 'cat > /crypt-ramfs/passphrase'
@ -118,7 +122,6 @@
krebs.build.host = config.krebs.hosts.puyak; krebs.build.host = config.krebs.hosts.puyak;
sound.enable = false; sound.enable = false;
boot = { boot = {
loader.systemd-boot.enable = true; loader.systemd-boot.enable = true;
loader.efi.canTouchEfiVariables = true; loader.efi.canTouchEfiVariables = true;
@ -163,10 +166,6 @@
services.logind.lidSwitchExternalPower = "ignore"; services.logind.lidSwitchExternalPower = "ignore";
services.udev.extraRules = ''
SUBSYSTEM=="net", ATTR{address}=="8c:70:5a:b2:84:58", NAME="wl0"
SUBSYSTEM=="net", ATTR{address}=="3c:97:0e:07:b9:14", NAME="et0"
'';
environment.systemPackages = [ pkgs.zsh ]; environment.systemPackages = [ pkgs.zsh ];
@ -179,5 +178,4 @@
isNormalUser = true; isNormalUser = true;
shell = "/run/current-system/sw/bin/zsh"; shell = "/run/current-system/sw/bin/zsh";
}; };
networking.firewall.allowedTCPPorts = [ 5901 ];
} }

View File

@ -0,0 +1,23 @@
let
ext-if = "enp0s25";
shack-ip = "10.42.22.184";
shack-gw = "10.42.20.1";
in {
services.udev.extraRules = ''
SUBSYSTEM=="net", ATTR{address}=="8c:70:5a:b2:84:58", NAME="wl0"
SUBSYSTEM=="net", ATTR{address}=="3c:97:0e:07:b9:14", NAME="et0"
'';
networking = {
firewall.enable = false;
firewall.allowedTCPPorts = [ 8088 8086 8083 5901 ];
interfaces."${ext-if}".ipv4.addresses = [
{
address = shack-ip;
prefixLength = 20;
}
];
defaultGateway = shack-gw;
nameservers = [ "10.42.0.100" "10.42.0.200" ];
};
}

View File

@ -0,0 +1,17 @@
{
# 1. Program an esp8266 devboard (esp8266+usb-ttl) with # https://github.com/jeelabs/esp-link
# tested vesion: esp-link v3.2.47-g9c6530d
# Pin Preset: esp-bridge
# tx-enable: false
# uart-pins: normal
# 2. connect directly with usb-cable to device, check that vendorID and ProductID match
# 3. nc <esp-link-ip> 23
# Info: for puyak the root pw is `brain hosts/puyak/root`
services.udev.extraRules = ''
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ilo", MODE="0660"
'';
systemd.services."serial-getty@ilo".enable = true;
systemd.services."serial-getty@ilo".wantedBy = [ "multi-user.target" ];
systemd.services."serial-getty@ilo".serviceConfig.Restart = "always";
}

View File

@ -1,5 +1,6 @@
{ pkgs,lib, ... }: { pkgs,lib, ... }:
{ {
boot.kernel.sysctl."net.ipv4.ip_forward" = true;
services.gitlab-runner = { services.gitlab-runner = {
enable = true; enable = true;
services= { services= {
@ -17,6 +18,7 @@
"/nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket:ro" "/nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket:ro"
]; ];
dockerDisableCache = true; dockerDisableCache = true;
# TODO: use the channel from <stockholm/krebs/nixpkgs.json>
preBuildScript = pkgs.writeScript "setup-container" '' preBuildScript = pkgs.writeScript "setup-container" ''
mkdir -p -m 0755 /nix/var/log/nix/drvs mkdir -p -m 0755 /nix/var/log/nix/drvs
mkdir -p -m 0755 /nix/var/nix/gcroots mkdir -p -m 0755 /nix/var/nix/gcroots
@ -28,9 +30,9 @@
mkdir -p -m 0755 /nix/var/nix/profiles/per-user/root mkdir -p -m 0755 /nix/var/nix/profiles/per-user/root
mkdir -p -m 0700 "$HOME/.nix-defexpr" mkdir -p -m 0700 "$HOME/.nix-defexpr"
. ${pkgs.nix}/etc/profile.d/nix.sh . ${pkgs.nix}/etc/profile.d/nix.sh
${pkgs.nix}/bin/nix-env -i ${concatStringsSep " " (with pkgs; [ nix cacert git openssh ])} ${pkgs.nix}/bin/nix-channel --add https://nixos.org/channels/nixos-20.09 nixpkgs
${pkgs.nix}/bin/nix-channel --add https://nixos.org/channels/nixpkgs-unstable
${pkgs.nix}/bin/nix-channel --update nixpkgs ${pkgs.nix}/bin/nix-channel --update nixpkgs
${pkgs.nix}/bin/nix-env -i ${concatStringsSep " " (with pkgs; [ nix cacert git openssh ])}
''; '';
environmentVariables = { environmentVariables = {
ENV = "/etc/profile"; ENV = "/etc/profile";

View File

@ -1,5 +1,7 @@
# needs: # needs:
# light.fablab_led # light.fablab_led
{
services.home-assistant.config.automation =
[ [
{ alias = "State on HA start-up"; { alias = "State on HA start-up";
trigger = { trigger = {
@ -17,5 +19,6 @@
} }
]; ];
} }
] ];
}

View File

@ -6,6 +6,8 @@ let
disko_schalter = "switch.lounge_diskoschalter_relay"; disko_schalter = "switch.lounge_diskoschalter_relay";
player = "media_player.lounge"; player = "media_player.lounge";
in in
{
services.home-assistant.config.automation =
[ [
{ alias = "Party um 21 Uhr"; { alias = "Party um 21 Uhr";
trigger = { trigger = {
@ -26,4 +28,5 @@ in
} # TODO: also start playlist if nothing is running? } # TODO: also start playlist if nothing is running?
]; ];
} }
] ];
}

View File

@ -13,6 +13,8 @@
let let
glados = import ../lib; glados = import ../lib;
in in
{
services.home-assistant.config.automation =
[ [
{ {
alias = "Bedanken bei Übernahme von Key"; alias = "Bedanken bei Übernahme von Key";
@ -94,4 +96,5 @@ in
} }
]; ];
} }
] ];
}

View File

@ -1,9 +1,5 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
shackopen = import ./multi/shackopen.nix;
wasser = import ./multi/wasser.nix;
badair = import ./multi/schlechte_luft.nix;
rollos = import ./multi/rollos.nix;
in { in {
services.nginx.virtualHosts."hass.shack" = { services.nginx.virtualHosts."hass.shack" = {
serverAliases = [ "glados.shack" ]; serverAliases = [ "glados.shack" ];
@ -21,14 +17,28 @@ in {
''; '';
}; };
}; };
imports = [
./multi/shackopen.nix
./multi/wasser.nix
./multi/schlechte_luft.nix
./multi/rollos.nix
./switch/power.nix
./sensors/power.nix
./sensors/mate.nix
./sensors/darksky.nix
./sensors/spaceapi.nix
./sensors/sensemap.nix
./automation/shack-startup.nix
./automation/party-time.nix
./automation/hass-restart.nix
];
services.home-assistant = services.home-assistant =
{ {
enable = true; enable = true;
package = pkgs.home-assistant.override {
extraPackages = ps: with ps; [
python-forecastio jsonrpc-async jsonrpc-websocket mpd2 pkgs.picotts
];
};
autoExtraComponents = true; autoExtraComponents = true;
config = { config = {
homeassistant = { homeassistant = {
@ -85,9 +95,6 @@ in {
retain = true; retain = true;
}; };
}; };
switch =
(import ./switch/power.nix)
;
light = []; light = [];
media_player = [ media_player = [
{ platform = "mpd"; { platform = "mpd";
@ -100,34 +107,23 @@ in {
} }
]; ];
sensor =
(import ./sensors/power.nix)
++ (import ./sensors/mate.nix)
++ (import ./sensors/darksky.nix { inherit lib;})
++ shackopen.sensor
++ wasser.sensor
;
air_quality = (import ./sensors/sensemap.nix );
binary_sensor =
shackopen.binary_sensor
++ (import ./sensors/spaceapi.nix)
;
camera = []; camera = [];
frontend = { }; frontend = { };
config = { }; config = { };
sun = {};
http = { http = {
base_url = "http://hass.shack"; base_url = "http://hass.shack";
use_x_forwarded_for = true; use_x_forwarded_for = true;
trusted_proxies = "127.0.0.1"; trusted_proxies = "127.0.0.1";
}; };
#conversation = {}; #conversation = {};
# history = {};
#logbook = {}; history = {};
logger.default = "info"; logbook = {};
#recorder = {}; #recorder = {};
logger.default = "info";
tts = [ tts = [
{ platform = "google_translate"; { platform = "google_translate";
service_name = "say"; service_name = "say";
@ -136,15 +132,6 @@ in {
time_memory = 57600; time_memory = 57600;
} }
]; ];
sun = {};
automation = wasser.automation
++ badair.automation
++ rollos.automation
++ (import ./automation/shack-startup.nix)
++ (import ./automation/party-time.nix)
++ (import ./automation/hass-restart.nix);
device_tracker = []; device_tracker = [];
}; };
}; };

View File

@ -10,6 +10,8 @@ let
"cover.retroraum_rollo" "cover.retroraum_rollo"
]; ];
in in
{
services.home-assistant.config =
{ {
automation = automation =
[ [
@ -53,4 +55,5 @@ in
]; ];
} }
]; ];
};
} }

View File

@ -3,6 +3,8 @@ let
feinstaub_sensor = "sensor.fablab_particulate_matter_2_5um_concentration"; feinstaub_sensor = "sensor.fablab_particulate_matter_2_5um_concentration";
ledring = "light.fablab_led_ring"; ledring = "light.fablab_led_ring";
in in
{
services.home-assistant.config =
{ {
automation = automation =
[ [
@ -103,4 +105,5 @@ in
]; ];
} }
]; ];
};
} }

View File

@ -1,3 +1,5 @@
{
services.home-assistant.config =
{ {
binary_sensor = [ binary_sensor = [
{ platform = "mqtt"; { platform = "mqtt";
@ -20,4 +22,5 @@
payload_not_available = "offline"; payload_not_available = "offline";
} }
]; ];
};
} }

View File

@ -10,6 +10,8 @@ let
sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture"; sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture";
}; };
in in
{
services.home-assistant.config =
{ {
sensor = map ( entity_id: { sensor = map ( entity_id: {
platform = "statistics"; platform = "statistics";
@ -107,4 +109,5 @@ in
]; ];
} }
]; ];
};
} }

View File

@ -1,4 +1,6 @@
{lib,...}: {lib,...}:
{
services.home-assistant.config.sensor =
[ [
{ platform = "darksky"; { platform = "darksky";
api_key = lib.removeSuffix "\n" api_key = lib.removeSuffix "\n"
@ -18,4 +20,5 @@
units = "si" ; units = "si" ;
scan_interval = "00:15:00"; scan_interval = "00:15:00";
} }
] ];
}

View File

@ -6,11 +6,15 @@ let
name = "Füllstand ${name}"; name = "Füllstand ${name}";
value_template = "{{ value_json.fuellstand }}"; value_template = "{{ value_json.fuellstand }}";
}; };
in [ in
{
services.home-assistant.config.sensor =
[
(fuellstand "Wasser" 1) (fuellstand "Wasser" 1)
(fuellstand "Mate Cola" 2) (fuellstand "Mate Cola" 2)
(fuellstand "Apfelschorle" 3) (fuellstand "Apfelschorle" 3)
(fuellstand "Zitronensprudel" 4) (fuellstand "Zitronensprudel" 4)
(fuellstand "Mate 1" 26) (fuellstand "Mate 1" 26)
(fuellstand "Mate 2" 27) (fuellstand "Mate 2" 27)
] ];
}

View File

@ -20,7 +20,10 @@ let
power_watt = (power_x "Power") ; power_watt = (power_x "Power") ;
power_curr = power_x "Current"; power_curr = power_x "Current";
in in
{
services.home-assistant.config.sensor =
(map power_volt [ "L1" "L2" "L3" ]) (map power_volt [ "L1" "L2" "L3" ])
++ (map (x: ((power_watt x) // { device_class = "power"; })) [ "L1" "L2" "L3" ]) ++ (map (x: ((power_watt x) // { device_class = "power"; })) [ "L1" "L2" "L3" ])
++ (map power_curr [ "L1" "L2" "L3" ]) ++ (map power_curr [ "L1" "L2" "L3" ])
++ [ power_consumed ] ++ [ power_consumed ];
}

View File

@ -1,6 +1,9 @@
{
services.home-assistant.config.air_quality =
[ [
{ {
platform = "opensensemap"; platform = "opensensemap";
station_id = "56a0de932cb6e1e41040a68b"; station_id = "56a0de932cb6e1e41040a68b";
} }
] ];
}

View File

@ -1,3 +1,5 @@
{
services.home-assistant.config.binary_sensor =
[ [
{ {
platform = "rest"; platform = "rest";
@ -49,4 +51,5 @@
value_template = "false"; value_template = "false";
scan_interval = 2592000; scan_interval = 2592000;
} }
] ];
}

View File

@ -15,12 +15,23 @@ let
power = nodelight "power"; power = nodelight "power";
light = ident: name: { icon = "mdi:lightbulb";} // nodelight "light" ident name; light = ident: name: { icon = "mdi:lightbulb";} // nodelight "light" ident name;
in in
{
services.home-assistant.config.switch =
[ [
(power 1 "Hauptschalter") # These commands we see with a shutdown:
(power 2 "Dusche") # power/143/state on
(power 3 "Warmwasser") # power/142/state on
(power 4 "Optionsräume") # power/141/state on
(power 5 "Küche") # power/142/state off
# power/141/state off
# power/10/state off
# power/main/state off
(power "10" "Hauptschalter")
(power 1 "Dusche") # ???
(power 2 "Warmwasser") # ???
(power 3 "Optionsräume") # ???
(power 4 "Küche") # ???
(light 1 "Decke Lounge 1") (light 1 "Decke Lounge 1")
(light 2 "Decke Lounge 2") (light 2 "Decke Lounge 2")
(light 3 "Decke Lounge 3") (light 3 "Decke Lounge 3")
@ -29,4 +40,5 @@ in
(light 6 "Decke Lounge 6") (light 6 "Decke Lounge 6")
(light 7 "Decke Lounge 7") (light 7 "Decke Lounge 7")
(light 8 "Decke Lounge 8") (light 8 "Decke Lounge 8")
] ];
}

View File

@ -67,7 +67,7 @@ in {
}; };
sensor = "total"; sensor = "total";
types = [ "Voltage" "Current" "Power" ]; types = [ "Voltage" "Current" "Power" ];
phases = [ 1 2 3 ]; phases = [ "1" "2" "3" ];
in in
[ (genTopic "Power consumed" "/power/${sensor}/consumed" { inherit sensor; }) ] ++ [ (genTopic "Power consumed" "/power/${sensor}/consumed" { inherit sensor; }) ] ++
(lib.flatten (map (type: (map (phase: (genTopic "Power" "/power/${sensor}/L${toString phase}/${type}" { inherit sensor phase type; }) ) phases)) types)); (lib.flatten (map (type: (map (phase: (genTopic "Power" "/power/${sensor}/L${toString phase}/${type}" { inherit sensor phase type; }) ) phases)) types));

View File

@ -3,11 +3,11 @@
with import <stockholm/lib>; with import <stockholm/lib>;
let let
pkg = pkgs.stdenv.mkDerivation { pkg = pkgs.stdenv.mkDerivation {
name = "worlddomination-2018-04-21"; name = "worlddomination-2020-12-01";
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "https://github.com/shackspace/worlddomination/"; url = "https://git.shackspace.de/rz/worlddomination.git";
rev = "1b32403b9"; rev = "c7aedcde7cd1fcb870b5356a6125e1a384b0776c";
sha256 = "10x7aiil13k3x9wqy95mi1ys999d6fxg5sys3jwv7a1p930gkl1i"; sha256 = "0y6haz5apwa33lz64l7b2x78wrrckbw39j4wzyd1hfk46478xi2y";
}; };
buildInputs = [ buildInputs = [
(pkgs.python3.withPackages (pythonPackages: with pythonPackages; [ (pkgs.python3.withPackages (pythonPackages: with pythonPackages; [
@ -17,6 +17,7 @@ let
grequests grequests
paramiko paramiko
python python
setuptools
])) ]))
]; ];
installPhase = '' installPhase = ''

View File

@ -0,0 +1,33 @@
let
toggle = light: btn:
{
alias = "Toggle Light ${light} via ${btn}";
trigger = {
platform = "state";
entity_id = "sensor.${btn}_click";
to = "single";
};
action = {
service = "light.toggle";
entity = light;
};
};
turn_off_all = btn:
{
alias = "Turn of all lights via ${btn} double click";
trigger = {
platform = "state";
entity_id = "sensor.${btn}_click";
to = "double";
};
action = {
service = "light.turn_off";
entity = "light.alle_lichter";
};
};
in {
services.home-assistant.config.automation = [
(toggle "light.wohnzimmer_lichter" "btn3")
(turn_off_all "btn3")
];
}

View File

@ -26,6 +26,7 @@ in {
./calendar/nextcloud.nix ./calendar/nextcloud.nix
./automation/firetv_restart.nix ./automation/firetv_restart.nix
./automation/light_buttons.nix
./light/groups.nix ./light/groups.nix
]; ];

View File

@ -13,7 +13,7 @@ let
"light.wohnzimmer_stehlampe_osram_light" "light.wohnzimmer_stehlampe_osram_light"
]; ];
schlafzimmer_licht = [ schlafzimmer_licht = [
"schlafzimmer_komode_osram_light" "light.schlafzimmer_komode_osram_light"
]; ];
in { in {
services.home-assistant.config.light = [ services.home-assistant.config.light = [

View File

@ -52,6 +52,7 @@
xo = "mimeopen"; xo = "mimeopen";
nmap = "nmap -oN $HOME/loot/scan-`date +\%s`.nmap -oX $HOME/loot/scan-`date +%s`.xml"; nmap = "nmap -oN $HOME/loot/scan-`date +\%s`.nmap -oX $HOME/loot/scan-`date +%s`.xml";
}; };
# navi package does not come with the navi.plugin.zsh anymore so we use .src
initExtra = '' initExtra = ''
bindkey -e bindkey -e
# shift-tab # shift-tab
@ -69,7 +70,7 @@
zstyle ':completion::complete:secrets::' prefix "$HOME/.secrets-pass/" zstyle ':completion::complete:secrets::' prefix "$HOME/.secrets-pass/"
# navi # navi
source ${pkgs.navi}/share/navi/shell/navi.plugin.zsh . ${pkgs.navi.src}/shell/navi.plugin.zsh
# ctrl-x ctrl-e # ctrl-x ctrl-e
autoload -U compinit && compinit autoload -U compinit && compinit
autoload -U edit-command-line autoload -U edit-command-line