Moved custom services & hardware hacks to nixos root folder

This commit is contained in:
ari committed 2024-08-11 10:34:24 -04:00
1 parent 4e25515b14
commit 8abf744687
12 files changed
+25 -12

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
{ ... }:
{
imports = [
./hardware
];
}
@@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./fan2go.nix
./fancontrol.nix
];
}
+95
View File
@@ -0,0 +1,95 @@
# Source: https://github.com/arnarg/config/blob/3cfad29004a92d310871a56605aa84df1b13741f/hosts/terra/fan2go.nix
{ lib
, config
, pkgs
, ...
}:
let
cfg = config.skyg.hardware.fan2go;
fan2goConfig = pkgs.writeText "fan2go.yaml" ''
dbPath: ${cfg.dbPath}
fans:
- id: out_back
hwmon:
platform: it8613
rpmChannel: 3
pwmChannel: 3
curve: case_max
sensors:
- id: cpu_package
hwmon:
platform: coretemp
index: 1
- id: nvme_ssd
hwmon:
platform: nvme
index: 2
- id: hdd
hwmon:
platform: drivetemp
index: 1
curves:
- id: cpu_curve
linear:
sensor: cpu_package
steps:
- 40: 0
- 50: 50
- 80: 255
- id: nvme_curve
linear:
sensor: nvme_ssd
min: 40
max: 70
- id: hdd_curve
linear:
sensor: hdd
min: 30
max: 50
- id: case_max
function:
type: maximum
curves:
- cpu_curve
- nvme_curve
- hdd_curve
'';
in
{
options.skyg.hardware.fan2go = with lib; {
enable = mkEnableOption "fan2go";
dbPath = mkOption {
type = types.str;
default = "/var/lib/fan2go/fan2go.db";
description = "The path of the database file.";
};
};
config = lib.mkIf cfg.enable {
systemd.services.fan2go = {
description = "A simple daemon providing dynamic fan speed control based on temperature sensors.";
wantedBy = [ "multi-user.target" ];
after = [ "lm_sensors.service" ];
serviceConfig = {
ExecStart = lib.concatStringsSep " " [
"${pkgs.fan2go}/bin/fan2go"
"-c"
"${fan2goConfig}"
"--no-style"
];
LimitNOFILE = 8192;
};
};
};
}
@@ -0,0 +1,33 @@
{ lib
, config
, pkgs
, ...
}:
let
cfg = config.skyg.hardware.fancontrol;
in
{
options.skyg.hardware.fancontrol = with lib; {
enable = mkEnableOption "fancontrol";
configName = mkOption {
type = types.str;
};
};
config = lib.mkIf cfg.enable {
systemd.services.fancontrol = {
enable = true;
description = "Fan control";
wantedBy = [ "multi-user.target" "graphical.target" "rescue.target" ];
unitConfig = {
Type = "simple";
};
serviceConfig = {
ExecStart = "${pkgs.lm_sensors}/bin/fancontrol ${cfg.configName}";
Restart = "always";
};
};
};
}
+7
View File
@@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./common
./server
];
}
+1
View File
@@ -0,0 +1 @@
+104
View File
@@ -0,0 +1,104 @@
{ config, lib, pkgs, ... }:
with lib;
let cfg = config.skyg.homelab.services.audiobookshelf;
in {
options = {
skyg.homelab.services.audiobookshelf = {
enable = mkEnableOption
"Audiobookshelf, self-hosted audiobook and podcast server.";
package = mkPackageOption pkgs "audiobookshelf" { };
configDir = mkOption {
description =
"Path to Audiobookshelf config folder";
type = types.str;
};
dataDir = mkOption {
description = "Path to Audiobookshelf config and metadata inside of /var/lib.";
default = "audiobookshelf";
type = types.str;
};
metadtaDir = mkOption {
description =
"Path to Audiobookshelf config folder";
type = types.str;
};
host = mkOption {
description = "The host Audiobookshelf binds to.";
default = "127.0.0.1";
example = "0.0.0.0";
type = types.str;
};
port = mkOption {
description = "The TCP port Audiobookshelf will listen on.";
default = 8000;
type = types.port;
};
user = mkOption {
description = "User account under which Audiobookshelf runs.";
default = "audiobookshelf";
type = types.str;
};
group = mkOption {
description = "Group under which Audiobookshelf runs.";
default = "audiobookshelf";
type = types.str;
};
openFirewall = mkOption {
description =
"Open ports in the firewall for the Audiobookshelf web interface.";
default = false;
type = types.bool;
};
};
};
config = mkIf cfg.enable {
systemd.services.audiobookshelf = {
description =
"Audiobookshelf is a self-hosted audiobook and podcast server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
StateDirectory = cfg.dataDir;
WorkingDirectory = "/var/lib/${cfg.dataDir}";
ExecStart =
"${cfg.package}/bin/audiobookshelf --host ${cfg.host} --port ${
toString cfg.port
} --config ${cfg.configDir} --metadata ${cfg.metadtaDir}";
Restart = "on-failure";
};
};
users.users = mkIf (cfg.user == "audiobookshelf") {
audiobookshelf = {
isSystemUser = true;
group = cfg.group;
home = "/var/lib/${cfg.dataDir}";
};
};
users.groups =
mkIf (cfg.group == "audiobookshelf") { audiobookshelf = { }; };
networking.firewall =
mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; };
};
meta.maintainers = with maintainers; [ wietsedv ];
}
+22
View File
@@ -0,0 +1,22 @@
{ config, lib, ... }:
with lib;
let cfg = config.skyg.homelab.udevrules.coraltpu;
in {
options = {
skyg.homelab.udevrules.coraltpu = {
enable = mkEnableOption
"Enable Coral TPU Udev rules";
symlinkName = mkOption {
description = "The special symlink to give to the coral tpu";
type = types.str;
default = "coral1";
};
};
};
config = mkIf cfg.enable {
services.udev.extraRules = ''
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a6e", ATTRS{idProduct}=="089a", MODE="0664", TAG+="uaccess", SYMLINK+="${cfg.symlinkName}"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="9302", MODE="0664", TAG+="uaccess", SYMLINK+="${cfg.symlinkName}"
'';
};
}
+7
View File
@@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./audiobookshelf.nix
./coral-tpu-udev.nix
];
}