updated nix modules

This commit is contained in:
Kristian Krsnik 2023-08-04 23:10:47 +02:00
parent e4f94e04a6
commit fcd9326cf9
3 changed files with 86 additions and 30 deletions

View File

@ -6,7 +6,7 @@ from datetime import datetime
def loadSettings(path: str = f"{os.path.expanduser('~')}/.config/dyn-gandi/config.json") -> dict:
# TODO: check integrity
# TODO: check integrity of the config file
try:
with open(path, 'r') as file:
# Read if the API keys are path to files
@ -26,11 +26,6 @@ def loadSettings(path: str = f"{os.path.expanduser('~')}/.config/dyn-gandi/confi
# TODO log error and remove code below (do not create an unwanted config)
def anewfunction():
for i, key in range(12):
print(i)
def log(logline: str, path: str = './log.txt') -> None:
# Appends logline at the end of the file file with a timestamp
with open(path, 'a') as file:

View File

@ -5,23 +5,24 @@ self: {
...
}: let
cfg = config.services.dyn-gandi;
package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
inherit (lib) mkIf mkEnableOption mkOption types;
in {
options.services.dyn-gandi = {
enable = mkEnableOption "dyn-gandi";
timer = lib.mkOption {
type = lib.types.int;
default = 0;
type = types.nullOr types.int;
default = null;
description = lib.mdDoc ''
The time intervall in seconds the script should be repeated.
0 disables automatic starts.
'';
};
settings = mkOption {
type = with types; let
valueType = nullOr (oneOf [
# TODO: restrict type to actual config file structure
bool
int
float
@ -32,33 +33,37 @@ in {
]);
in
valueType;
default = {};
description = '''';
default = throw "Please specify services.dyn-gandi.settings";
};
};
config = mkIf cfg.enable {
home.packages = [self.packages.x86_64-linux.default];
home.packages = [package]; # TODO: make this architecture independent
xdg.configFile."dyn-gandi/config.json" = {
text = builtins.toJSON cfg.settings;
};
systemd.user.services.dyn-gandi =
mkIf cfg.timer
!= 0 {
systemd.user.services.dyn-gandi = mkIf (cfg.timer
!= null) {
Unit = {
Description = "DNS Updater tool for Gandi.net";
After = ["graphical-session-pre.target"];
PartOf = ["graphical-session.target"];
After = ["network.target"];
};
Install = {WantedBy = ["default.target"];};
Service = {
Type = "oneshot";
ExecStart = "${package}/bin/dyn_gandi"; # TODO: add config file via command line options
};
};
systemd.user.timers.dyn-gandi = {
wantedBy = ["timers.target"];
timerConfig = {
systemd.user.timers.dyn-gandi = mkIf (cfg.timer
!= null) {
Install = {WantedBy = ["timers.target"];};
Timer = {
OnBootSec = "0s";
OnUnitActiveSec = "${cfg.timer}s";
OnUnitActiveSec = "${toString cfg.timer}s";
Unit = "dyn-gandi.service";
};
};

View File

@ -1,18 +1,74 @@
inputs: {
self: {
config,
lib,
pkgs,
system,
...
}: let
cfg = config.services.dyn-gandi;
inherit (lib) mkIf mkEnableOption;
#package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
inherit (lib) mkIf mkEnableOption mkOption types;
in {
options.services.dyn-gandi = {
enable = mkEnableOption null;
enable = mkEnableOption "dyn-gandi";
timer = lib.mkOption {
type = types.nullOr types.int;
default = null;
description = lib.mdDoc ''
The time intervall in seconds the script should be repeated.
'';
};
settings = mkOption {
type = with types; let
valueType = nullOr (oneOf [
# TODO: restrict type to actual config file structure
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
]);
in
valueType;
default = throw "Please specify services.dyn-gandi.settings";
};
};
config = mkIf cfg.enable {
environment.systemPackages = [cfg.package];
environment = {
systemPackages = [package];
}; # TODO: make this architecture independent
xdg.configFile."dyn-gandi/config.json" = {
text = builtins.toJSON cfg.settings;
};
systemd.services.dyn-gandi = mkIf (cfg.timer
!= null) {
Unit = {
After = ["network.target"];
};
Install = {WantedBy = ["default.target"];};
Service = {
Type = "oneshot";
ExecStart = "${package}/bin/dyn_gandi"; # TODO: add config file via command line options
};
};
systemd.timers.dyn-gandi = mkIf (cfg.timer
!= null) {
Install = {WantedBy = ["timers.target"];};
Timer = {
OnBootSec = "0s";
OnUnitActiveSec = "${toString cfg.timer}s";
Unit = "dyn-gandi.service";
};
};
};
}