mirror of
https://codeberg.org/icewind/log-normalizer.git
synced 2026-06-03 13:54:11 +02:00
flake rework
This commit is contained in:
parent
ff82fc9eb8
commit
de4705c72a
5 changed files with 131 additions and 119 deletions
33
flake.lock
generated
33
flake.lock
generated
|
|
@ -15,37 +15,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1655042882,
|
||||
"narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=",
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"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": 1707514827,
|
||||
"narHash": "sha256-Y+wqFkvikpE1epCx57PsGw+M1hX5aY5q/xgk+ebDwxI=",
|
||||
|
|
@ -63,8 +33,7 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
115
flake.nix
115
flake.nix
|
|
@ -2,112 +2,53 @@
|
|||
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-normalizer = naersk-lib.buildPackage {
|
||||
pname = "log-normalizer";
|
||||
root = ./.;
|
||||
|
||||
SQLX_OFFLINE = 1;
|
||||
packages = rec {
|
||||
inherit (pkgs) log-normalizer;
|
||||
default = log-normalizer;
|
||||
};
|
||||
defaultPackage = packages.log-normalizer;
|
||||
defaultApp = packages.log-normalizer;
|
||||
|
||||
# `nix develop`
|
||||
devShell = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated cargo-insta];
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
rustc
|
||||
cargo
|
||||
bacon
|
||||
clippy
|
||||
cargo-edit
|
||||
cargo-outdated
|
||||
cargo-insta
|
||||
];
|
||||
};
|
||||
}
|
||||
)
|
||||
// {
|
||||
nixosModule = {
|
||||
overlays.default = import ./overlay.nix;
|
||||
nixosModules.default = {
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.log-normalizer;
|
||||
in {
|
||||
options.services.log-normalizer = {
|
||||
enable = mkEnableOption "Log normalizer";
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
description = "user to run as";
|
||||
};
|
||||
|
||||
databaseUrlFile = mkOption {
|
||||
type = types.str;
|
||||
description = "file containg DATABASE_URL variable";
|
||||
};
|
||||
|
||||
rawDatabaseUrlFile = mkOption {
|
||||
type = types.str;
|
||||
description = "file containg RAW_DATABASE_URL variable";
|
||||
};
|
||||
|
||||
logLevel = mkOption {
|
||||
type = types.str;
|
||||
default = "info,sqlx=warn";
|
||||
description = "log level";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services."log-normalizer" = let
|
||||
pkg = self.defaultPackage.${pkgs.system};
|
||||
in {
|
||||
wantedBy = ["multi-user.target"];
|
||||
script = "${pkg}/bin/log-normalizer";
|
||||
environment = {
|
||||
RUST_LOG = cfg.logLevel;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
EnvironmentFile = [cfg.databaseUrlFile cfg.rawDatabaseUrlFile];
|
||||
Restart = "on-failure";
|
||||
User = cfg.user;
|
||||
PrivateTmp = true;
|
||||
ProtectSystem = "strict";
|
||||
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 = "any";
|
||||
IPAddressAllow = "localhost";
|
||||
PrivateUsers = true;
|
||||
ProcSubset = "pid";
|
||||
};
|
||||
};
|
||||
};
|
||||
}: {
|
||||
imports = [./module.nix];
|
||||
config = lib.mkIf config.services.log-normalizer.enable {
|
||||
nixpkgs.overlays = [self.overlays.default];
|
||||
services.log-normalizer.package = lib.mkDefault pkgs.log-normalizer;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
79
module.nix
Normal file
79
module.nix
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.log-normalizer;
|
||||
in {
|
||||
options.services.log-normalizer = {
|
||||
enable = mkEnableOption "Log normalizer";
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
description = "user to run as";
|
||||
};
|
||||
|
||||
databaseUrlFile = mkOption {
|
||||
type = types.str;
|
||||
description = "file containg DATABASE_URL variable";
|
||||
};
|
||||
|
||||
rawDatabaseUrlFile = mkOption {
|
||||
type = types.str;
|
||||
description = "file containg RAW_DATABASE_URL variable";
|
||||
};
|
||||
|
||||
logLevel = mkOption {
|
||||
type = types.str;
|
||||
default = "info,sqlx=warn";
|
||||
description = "log level";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
description = "package to use";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services.log-normalizer = {
|
||||
wantedBy = ["multi-user.target"];
|
||||
environment = {
|
||||
RUST_LOG = cfg.logLevel;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
EnvironmentFile = [cfg.databaseUrlFile cfg.rawDatabaseUrlFile];
|
||||
ExecStart = "${cfg.package}/bin/log-normalizer";
|
||||
Restart = "on-failure";
|
||||
User = cfg.user;
|
||||
PrivateTmp = true;
|
||||
ProtectSystem = "strict";
|
||||
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 = "any";
|
||||
IPAddressAllow = "localhost";
|
||||
PrivateUsers = true;
|
||||
ProcSubset = "pid";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
3
overlay.nix
Normal file
3
overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
final: prev: {
|
||||
log-normalizer = 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-data.json)(/.*)?"];
|
||||
in
|
||||
rustPlatform.buildRustPackage rec {
|
||||
pname = "log-normalizer";
|
||||
version = "0.1.0";
|
||||
|
||||
SQLX_OFFLINE = 1;
|
||||
|
||||
inherit src;
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue