nixos/shlink: init
Some checks failed
Build packages / Build derivations (push) Failing after 2m41s

This commit is contained in:
uku 2025-01-29 11:34:29 +01:00
parent c3319b9712
commit edcd0a4ddf
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o
2 changed files with 88 additions and 0 deletions

View file

@ -39,6 +39,7 @@
nixosModules = {
reposilite = import ./modules/reposilite.nix;
asus-numpad = import ./modules/asus-numpad.nix self;
shlink = import ./modules/shlink.nix self;
};
formatter = forEachSystem (system: (pkgsFor system).nixfmt-rfc-style);

87
modules/shlink.nix Normal file
View file

@ -0,0 +1,87 @@
self:
{
lib,
config,
pkgs,
...
}:
let
cfg = config.services.shlink;
inherit (pkgs.stdenv.hostPlatform) system;
basePath = "${cfg.package}/share/php/shlink";
vars = builtins.map (a: "--set ${a.name} ${a.value}") (lib.attrsToList cfg.environment);
varsStr = lib.concatStringsSep " " vars;
wrappedPkg = pkgs.symlinkJoin {
name = "shlink-wrapped";
paths = [ cfg.package ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/shlink ${varsStr}
'';
};
in
{
options.services.shlink = {
enable = lib.mkEnableOption "shlink";
package = lib.mkPackageOption self.packages.${system} "shlink" { };
roadrunnerPackage = lib.mkPackageOption pkgs "roadrunner" { };
environment = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = { };
description = "Environment variables passed to the RoadRunner process";
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = (cfg.environment.DB_DRIVER ? "sqlite") != "sqlite";
message = "sqlite is not supported. please set DB_DRIVER to one of the other supported values";
}
];
environment.systemPackages = [ wrappedPkg ];
users = {
groups.shlink = { };
users.shlink = {
isSystemUser = true;
group = "shlink";
};
};
systemd.services."shlink" = {
wantedBy = [ "default.target" ];
path = [ cfg.package.php ];
environment = cfg.environment // {
SHLINK_RUNTIME = "nixos"; # writes logs to stderr instead of a file inside the nix store
};
preStart = ''
export SHELL_VERBOSITY=3
cd ${basePath}
php vendor/bin/shlink-installer init --no-interaction --clear-db-cache --skip-download-geolite
'';
serviceConfig = {
Type = "notify";
ExecStart = "${lib.getExe cfg.roadrunnerPackage} serve -c ${basePath}/config/roadrunner/.rr.yml";
User = "shlink";
Group = "shlink";
StateDirectory = "shlink";
KillMode = "mixed";
TimeoutStopSec = 30;
Restart = "always";
RestartSec = 30;
};
};
};
}