Create Nix module
This commit is contained in:
34
flake.lock
generated
34
flake.lock
generated
@@ -1,5 +1,23 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1731319897,
|
"lastModified": 1731319897,
|
||||||
@@ -18,8 +36,24 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
17
flake.nix
17
flake.nix
@@ -3,14 +3,23 @@
|
|||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
flake-utils.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
}: {
|
flake-utils,
|
||||||
packages.x86_64-linux.tauron-scrapper = nixpkgs.legacyPackages.x86_64-linux.callPackage ./package.nix {};
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system: let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in {
|
||||||
|
packages = rec {
|
||||||
|
tauron-scrapper = pkgs.callPackage ./package.nix {};
|
||||||
|
default = tauron-scrapper;
|
||||||
|
};
|
||||||
|
|
||||||
packages.x86_64-linux.default = self.packages.x86_64-linux.tauron-scrapper;
|
nixosModules.tauron-scrapper = pkgs.callPackage ./module.nix {inherit self;};
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
100
module.nix
Normal file
100
module.nix
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
coreutils-full,
|
||||||
|
formats,
|
||||||
|
system,
|
||||||
|
utils,
|
||||||
|
lib,
|
||||||
|
self,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
|
inherit (utils.systemdUtils.unitOptions) unitOption;
|
||||||
|
cfg = config.services.tauron-scrapper;
|
||||||
|
yamlConfig = (formats.yaml {}).generate "tauron-scrapper-config.yaml" cfg.config;
|
||||||
|
in {
|
||||||
|
options.services.tauron-scrapper = {
|
||||||
|
enable = mkEnableOption "tauron-scrapper";
|
||||||
|
|
||||||
|
config = mkOption {
|
||||||
|
type = types.attr;
|
||||||
|
description = "The configuration of tauron-scrapper command";
|
||||||
|
example = {
|
||||||
|
timezone = "Europe/Warsaw";
|
||||||
|
|
||||||
|
tauron = {
|
||||||
|
usernamePath = "/run/tauron.username.key";
|
||||||
|
passwordPath = "/run/tauron.password.key";
|
||||||
|
point = "123456";
|
||||||
|
};
|
||||||
|
|
||||||
|
consumers = {
|
||||||
|
influxdb = {
|
||||||
|
enable = true;
|
||||||
|
databaseURL = "https://influxdb.lan";
|
||||||
|
apiToken = "/run/mqtt/influxdb.token.key";
|
||||||
|
organization = "home";
|
||||||
|
bucket = "tauron";
|
||||||
|
};
|
||||||
|
|
||||||
|
mqtt = {
|
||||||
|
enable = true;
|
||||||
|
brokerURL = "https://mqtt.lan";
|
||||||
|
usernamePath = "/run/mqtt.username.key";
|
||||||
|
passwordPath = "/run/mqtt.password.key";
|
||||||
|
clientId = "tauron-scrapper";
|
||||||
|
prefix = "tauron";
|
||||||
|
publishOptions = {
|
||||||
|
qos = 2;
|
||||||
|
retain = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
timerConfig = mkOption {
|
||||||
|
type = types.nullOr (types.attrsOf unitOption);
|
||||||
|
|
||||||
|
default = {
|
||||||
|
OnCalendar = "*-*-* 03:00";
|
||||||
|
Persistent = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
When to run the scrapping. See {manpage}`systemd.timer(5)` for
|
||||||
|
details. If null no timer is created and the data will only
|
||||||
|
be fetched when explicitly triggered.
|
||||||
|
'';
|
||||||
|
|
||||||
|
example = {
|
||||||
|
OnCalendar = "00:05";
|
||||||
|
Persistent = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
systemd.timers.tauron-scrapper = {
|
||||||
|
description = "Tauron Scapper";
|
||||||
|
wantedBy = ["timers.target"];
|
||||||
|
|
||||||
|
timerConfig =
|
||||||
|
cfg.timerConfig
|
||||||
|
// {
|
||||||
|
Unit = "tauron-scrapper.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.tauron-scrapper = {
|
||||||
|
description = "Tauron Scrapper";
|
||||||
|
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
path = [self.packages.${system}.tauron-scrapper coreutils-full];
|
||||||
|
|
||||||
|
script = ''
|
||||||
|
tauron-scrapper -c ${yamlConfig} -d "$(date -d "yesterday" '+%Y-%m-%d')"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user