mirror of
https://codeberg.org/icewind/log-archiver.git
synced 2026-06-03 09:34:09 +02:00
flake rework, sqlx 0.7
This commit is contained in:
parent
00dcd7354c
commit
0842c3e136
10 changed files with 1021 additions and 409 deletions
15
.sqlx/query-bcd0843c15afc0443df1ab40d7d0c5632ab9d025cdcf3646f4e9d5872b7c8c89.json
generated
Normal file
15
.sqlx/query-bcd0843c15afc0443df1ab40d7d0c5632ab9d025cdcf3646f4e9d5872b7c8c89.json
generated
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO logs_raw(id, json) VALUES($1, $2)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int4",
|
||||
"Jsonb"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "bcd0843c15afc0443df1ab40d7d0c5632ab9d025cdcf3646f4e9d5872b7c8c89"
|
||||
}
|
||||
20
.sqlx/query-e4dfb1fbca2c91ac837d11aff64e035ccce38867e3503653ec2ef28eeeb8907d.json
generated
Normal file
20
.sqlx/query-e4dfb1fbca2c91ac837d11aff64e035ccce38867e3503653ec2ef28eeeb8907d.json
generated
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT MAX(id) AS last_archived FROM logs_raw",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "last_archived",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": []
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "e4dfb1fbca2c91ac837d11aff64e035ccce38867e3503653ec2ef28eeeb8907d"
|
||||
}
|
||||
1062
Cargo.lock
generated
1062
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,10 +5,10 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
sqlx = { version = "0.6.0", default_features = false, features = ["macros", "postgres", "json", "runtime-actix-rustls", "offline"] }
|
||||
sqlx = { version = "0.7.3", default_features = false, features = ["macros", "postgres", "json", "runtime-tokio-rustls"] }
|
||||
dotenv = "0.15.0"
|
||||
main_error = "0.1.2"
|
||||
tokio = { version = "1.20.0", features = ["macros", "time"] }
|
||||
tokio = { version = "1.20.0", features = ["macros", "time", "rt-multi-thread"] }
|
||||
reqwest = { version = "0.11.11", default-features = false, features = ["rustls-tls"] }
|
||||
serde = { version = "1.0.140", features = ["derive"] }
|
||||
serde_json = "1.0.82"
|
||||
|
|
|
|||
72
flake.lock
generated
72
flake.lock
generated
|
|
@ -1,67 +1,57 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1656928814,
|
||||
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1655042882,
|
||||
"narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=",
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f",
|
||||
"lastModified": 1705309234,
|
||||
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 0,
|
||||
"narHash": "sha256-WbZKCf6g4+dljZ6Z866SGZzNA+WWjXt4Lc7td4zsRkw=",
|
||||
"path": "/nix/store/vavqvhqw8x42kqb1m3wkcys65jvvnl5i-source",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 0,
|
||||
"narHash": "sha256-WbZKCf6g4+dljZ6Z866SGZzNA+WWjXt4Lc7td4zsRkw=",
|
||||
"path": "/nix/store/vavqvhqw8x42kqb1m3wkcys65jvvnl5i-source",
|
||||
"type": "path"
|
||||
"lastModified": 1707650010,
|
||||
"narHash": "sha256-dOhphIA4MGrH4ElNCy/OlwmN24MsnEqFjRR6+RY7jZw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "809cca784b9f72a5ad4b991e0e7bcf8890f9c3a6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "release-23.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
"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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
116
flake.nix
116
flake.nix
|
|
@ -1,111 +1,55 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/release-23.11";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
naersk.url = "github:nix-community/naersk";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
naersk,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
naersk-lib = naersk.lib."${system}";
|
||||
overlays = [
|
||||
(import ./overlay.nix)
|
||||
];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
in rec {
|
||||
# `nix build`
|
||||
packages.log-archiver = naersk-lib.buildPackage {
|
||||
pname = "log-archiver";
|
||||
root = ./.;
|
||||
packages = rec {
|
||||
inherit (pkgs) log-archiver;
|
||||
default = log-archiver;
|
||||
};
|
||||
defaultPackage = packages.log-archiver;
|
||||
defaultApp = packages.log-archiver;
|
||||
|
||||
# `nix develop`
|
||||
devShell = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated];
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
rustc
|
||||
cargo
|
||||
bacon
|
||||
clippy
|
||||
cargo-edit
|
||||
cargo-outdated
|
||||
cargo-insta
|
||||
sqlx-cli
|
||||
];
|
||||
};
|
||||
}
|
||||
)
|
||||
// {
|
||||
nixosModule = {
|
||||
overlays.default = import ./overlay.nix;
|
||||
nixosModules.default = {
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.log-archiver;
|
||||
in {
|
||||
options.services.log-archiver = {
|
||||
enable = mkEnableOption "Log archiver";
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
description = "user to save logs as";
|
||||
};
|
||||
|
||||
databaseUrlFile = mkOption {
|
||||
type = types.str;
|
||||
description = "file containg DATABASE_URL variable";
|
||||
};
|
||||
|
||||
baseUrl = mkOption {
|
||||
type = types.str;
|
||||
default = "https://logs.tf";
|
||||
description = "logs.tf base url";
|
||||
};
|
||||
|
||||
target = mkOption {
|
||||
type = types.str;
|
||||
description = "path to store logs to";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services."log-archiver" = let
|
||||
pkg = self.defaultPackage.${pkgs.system};
|
||||
in {
|
||||
wantedBy = ["multi-user.target"];
|
||||
script = "${pkg}/bin/log-archiver";
|
||||
environment = {
|
||||
API_BASE = cfg.baseUrl;
|
||||
LOG_TARGET = cfg.target;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
EnvironmentFile = cfg.databaseUrlFile;
|
||||
Restart = "on-failure";
|
||||
User = cfg.user;
|
||||
PrivateTmp = true;
|
||||
ProtectSystem = "strict";
|
||||
ReadWritePaths = cfg.target;
|
||||
ProtectHome = true;
|
||||
NoNewPrivileges = true;
|
||||
PrivateDevices = true;
|
||||
ProtectClock = true;
|
||||
CapabilityBoundingSet = true;
|
||||
ProtectKernelLogs = true;
|
||||
ProtectControlGroups = true;
|
||||
SystemCallArchitectures = "native";
|
||||
ProtectKernelModules = true;
|
||||
RestrictNamespaces = true;
|
||||
MemoryDenyWriteExecute = true;
|
||||
ProtectHostname = true;
|
||||
LockPersonality = true;
|
||||
ProtectKernelTunables = true;
|
||||
RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX";
|
||||
RestrictRealtime = true;
|
||||
ProtectProc = "noaccess";
|
||||
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
||||
IPAddressDeny = "multicast";
|
||||
PrivateUsers = true;
|
||||
ProcSubset = "pid";
|
||||
};
|
||||
};
|
||||
};
|
||||
}: {
|
||||
imports = [./module.nix];
|
||||
config = lib.mkIf config.services.log-archiver.enable {
|
||||
nixpkgs.overlays = [self.overlays.default];
|
||||
services.log-archiver.package = lib.mkDefault pkgs.log-archiver;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
80
module.nix
Normal file
80
module.nix
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.log-archiver;
|
||||
in {
|
||||
options.services.log-archiver = {
|
||||
enable = mkEnableOption "Log archiver";
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
description = "user to save logs as";
|
||||
};
|
||||
|
||||
databaseUrlFile = mkOption {
|
||||
type = types.str;
|
||||
description = "file containg DATABASE_URL variable";
|
||||
};
|
||||
|
||||
baseUrl = mkOption {
|
||||
type = types.str;
|
||||
default = "https://logs.tf";
|
||||
description = "logs.tf base url";
|
||||
};
|
||||
|
||||
target = mkOption {
|
||||
type = types.str;
|
||||
description = "path to store logs to";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
description = "package to use";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services."log-archiver" = {
|
||||
wantedBy = ["multi-user.target"];
|
||||
environment = {
|
||||
API_BASE = cfg.baseUrl;
|
||||
LOG_TARGET = cfg.target;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
EnvironmentFile = cfg.databaseUrlFile;
|
||||
ExecStart = "${cfg.package}/bin/log-archiver";
|
||||
Restart = "on-failure";
|
||||
User = cfg.user;
|
||||
PrivateTmp = true;
|
||||
ProtectSystem = "strict";
|
||||
ReadWritePaths = cfg.target;
|
||||
ProtectHome = true;
|
||||
NoNewPrivileges = true;
|
||||
PrivateDevices = true;
|
||||
ProtectClock = true;
|
||||
CapabilityBoundingSet = true;
|
||||
ProtectKernelLogs = true;
|
||||
ProtectControlGroups = true;
|
||||
SystemCallArchitectures = "native";
|
||||
ProtectKernelModules = true;
|
||||
RestrictNamespaces = true;
|
||||
MemoryDenyWriteExecute = true;
|
||||
ProtectHostname = true;
|
||||
LockPersonality = true;
|
||||
ProtectKernelTunables = true;
|
||||
RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX";
|
||||
RestrictRealtime = true;
|
||||
ProtectProc = "noaccess";
|
||||
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
||||
IPAddressDeny = "multicast";
|
||||
PrivateUsers = true;
|
||||
ProcSubset = "pid";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
3
overlay.nix
Normal file
3
overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
final: prev: {
|
||||
log-archiver = final.callPackage ./package.nix {};
|
||||
}
|
||||
20
package.nix
Normal file
20
package.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
stdenv,
|
||||
rustPlatform,
|
||||
lib,
|
||||
}: let
|
||||
inherit (lib.sources) sourceByRegex;
|
||||
src = sourceByRegex ./. ["Cargo.*" "(src|tests|.sqlx)(/.*)?"];
|
||||
in
|
||||
rustPlatform.buildRustPackage rec {
|
||||
pname = "log-archiver";
|
||||
version = "0.1.0";
|
||||
|
||||
SQLX_OFFLINE = 1;
|
||||
|
||||
inherit src;
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"db": "PostgreSQL",
|
||||
"bcd0843c15afc0443df1ab40d7d0c5632ab9d025cdcf3646f4e9d5872b7c8c89": {
|
||||
"query": "INSERT INTO logs_raw(id, json) VALUES($1, $2)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int4",
|
||||
"Jsonb"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"e4dfb1fbca2c91ac837d11aff64e035ccce38867e3503653ec2ef28eeeb8907d": {
|
||||
"query": "SELECT MAX(id) AS last_archived FROM logs_raw",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "last_archived",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": []
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue