Fix module
This commit is contained in:
12
flake.nix
12
flake.nix
@@ -13,13 +13,17 @@
|
|||||||
flake-utils,
|
flake-utils,
|
||||||
}:
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (system: let
|
flake-utils.lib.eachDefaultSystem (system: let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = import nixpkgs {inherit system;};
|
||||||
in {
|
in {
|
||||||
packages = rec {
|
packages = rec {
|
||||||
tauron-scrapper = pkgs.callPackage ./package.nix {};
|
tauron-scrapper = pkgs.callPackage ./package.nix {};
|
||||||
default = tauron-scrapper;
|
default = tauron-scrapper;
|
||||||
};
|
};
|
||||||
|
})
|
||||||
nixosModules.tauron-scrapper = pkgs.callPackage ./module.nix {inherit self;};
|
// {
|
||||||
});
|
nixosModules = rec {
|
||||||
|
tauron-scrapper = import ./module.nix self;
|
||||||
|
default = tauron-scrapper;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
50
module.nix
50
module.nix
@@ -1,23 +1,42 @@
|
|||||||
{
|
self: {
|
||||||
config,
|
config,
|
||||||
coreutils-full,
|
pkgs,
|
||||||
formats,
|
|
||||||
system,
|
system,
|
||||||
utils,
|
|
||||||
lib,
|
lib,
|
||||||
self,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib; let
|
with lib; let
|
||||||
inherit (utils.systemdUtils.unitOptions) unitOption;
|
inherit (pkgs) coreutils-full formats;
|
||||||
cfg = config.services.tauron-scrapper;
|
cfg = config.services.tauron-scrapper;
|
||||||
yamlConfig = (formats.yaml {}).generate "tauron-scrapper-config.yaml" cfg.config;
|
yamlConfig = (formats.yaml {}).generate "tauron-scrapper-config.yaml" cfg.config;
|
||||||
|
app = pkgs.writeShellApplication {
|
||||||
|
name = "tauron-scrapper";
|
||||||
|
runtimeInputs = [self.packages.${system}.tauron-scrapper];
|
||||||
|
text = ''
|
||||||
|
tauron-scrapper -c "${yamlConfig}" "$@";
|
||||||
|
'';
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.services.tauron-scrapper = {
|
options.services.tauron-scrapper = {
|
||||||
enable = mkEnableOption "tauron-scrapper";
|
enable = mkEnableOption "tauron-scrapper";
|
||||||
|
|
||||||
|
cliArgs = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = "List of CLI arguments. Do not put '-c' argument here as it will be automatically appended basing on the 'config' option.";
|
||||||
|
|
||||||
|
example = [
|
||||||
|
''--date "$(date -d '5 days ago' '+%Y-%m-%d')"''
|
||||||
|
''--to "$(date -d 'yesterday' '+%Y-%m-%d')"''
|
||||||
|
];
|
||||||
|
|
||||||
|
default = [
|
||||||
|
''--date "$(date -d '5 days ago' '+%Y-%m-%d')"''
|
||||||
|
''--to "$(date -d 'yesterday' '+%Y-%m-%d')"''
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
type = types.attr;
|
type = types.attrs;
|
||||||
description = "The configuration of tauron-scrapper command";
|
description = "The configuration of tauron-scrapper command";
|
||||||
example = {
|
example = {
|
||||||
timezone = "Europe/Warsaw";
|
timezone = "Europe/Warsaw";
|
||||||
@@ -26,6 +45,7 @@ in {
|
|||||||
username = "$_file:/run/tauron.username.key";
|
username = "$_file:/run/tauron.username.key";
|
||||||
password = "$_file:/run/tauron.password.key";
|
password = "$_file:/run/tauron.password.key";
|
||||||
point = "123456";
|
point = "123456";
|
||||||
|
cookiesJarPath = "/tmp/tauron-scrapper.cookies.json";
|
||||||
};
|
};
|
||||||
|
|
||||||
consumers = {
|
consumers = {
|
||||||
@@ -54,12 +74,7 @@ in {
|
|||||||
};
|
};
|
||||||
|
|
||||||
timerConfig = mkOption {
|
timerConfig = mkOption {
|
||||||
type = types.nullOr (types.attrsOf unitOption);
|
type = types.attrs;
|
||||||
|
|
||||||
default = {
|
|
||||||
OnCalendar = "*-*-* 03:00";
|
|
||||||
Persistent = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
When to run the scrapping. See {manpage}`systemd.timer(5)` for
|
When to run the scrapping. See {manpage}`systemd.timer(5)` for
|
||||||
@@ -68,13 +83,16 @@ in {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
example = {
|
example = {
|
||||||
OnCalendar = "00:05";
|
OnCalendar = "*-*-* 15:15";
|
||||||
|
RandomizedDelaySec = "2h";
|
||||||
Persistent = true;
|
Persistent = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
environment.systemPackages = [app];
|
||||||
|
|
||||||
systemd.timers.tauron-scrapper = {
|
systemd.timers.tauron-scrapper = {
|
||||||
description = "Tauron Scapper";
|
description = "Tauron Scapper";
|
||||||
wantedBy = ["timers.target"];
|
wantedBy = ["timers.target"];
|
||||||
@@ -90,10 +108,10 @@ in {
|
|||||||
description = "Tauron Scrapper";
|
description = "Tauron Scrapper";
|
||||||
|
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
path = [self.packages.${system}.tauron-scrapper coreutils-full];
|
path = [app coreutils-full];
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
tauron-scrapper -c ${yamlConfig} -d "$(date -d "yesterday" '+%Y-%m-%d')"
|
tauron-scrapper ${lib.concatStringsSep " " cfg.cliArgs};
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user