diff --git a/flake.lock b/flake.lock index 3fd52015..6e3c143e 100644 --- a/flake.lock +++ b/flake.lock @@ -32,11 +32,11 @@ ] }, "locked": { - "lastModified": 1680877018, - "narHash": "sha256-jhd0G+LWF79L2m8dME55pBBoDY1FBenZ75WgKRA/Quk=", + "lastModified": 1682226636, + "narHash": "sha256-fmETHfUtQ5zOVr/4MT5wE7eNALCSQCnEUYZYmV3UEwg=", "ref": "main", - "rev": "15db0ea5c19c70bce8504290724661586dc94006", - "revCount": 71, + "rev": "095d14ff2469c8f3de7cbf45d229c0f46a733aae", + "revCount": 77, "type": "git", "url": "ssh://gitea@git.sealight.xyz/aynish/basant" }, @@ -403,11 +403,11 @@ "vimwiki-cli": "vimwiki-cli" }, "locked": { - "lastModified": 1681311621, - "narHash": "sha256-EQo+NdexCl+7I8vTsXpPvLHKJNU7dd4nRE2PqEoGJCA=", + "lastModified": 1682222403, + "narHash": "sha256-mLheDjdJ9TkmrR62FlPQtrYxKc/PJt4lhNBi5s9A97U=", "ref": "main", - "rev": "dfb078dbd8eb679e8f133afb4b6fec0f9e229b6c", - "revCount": 607, + "rev": "01fae2ec19d01256c17b58dcdc8ff43d717ec9da", + "revCount": 640, "type": "git", "url": "ssh://gitea@git.sealight.xyz/aynish/kitaab" }, diff --git a/flake.nix b/flake.nix index 14fd4d0a..3c669ac2 100644 --- a/flake.nix +++ b/flake.nix @@ -83,6 +83,9 @@ unstable = unstable.legacyPackages.${prev.system}; deploy = deploy-rs.packages.${prev.system}.deploy-rs; }; + llamaOverlay = final: prev: { + llama = llamacpp.packages.${prev.system}.default; + }; nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; @@ -222,6 +225,7 @@ self.nixosModules.wireguard self.nixosModules.wallabag self.nixosModules.gonic + self.nixosModules.ulogger-server # grasp.nixosModule home-manager.nixosModules.home-manager { diff --git a/hosts/box/default.nix b/hosts/box/default.nix index ef84fc9f..31c5fd8d 100644 --- a/hosts/box/default.nix +++ b/hosts/box/default.nix @@ -22,6 +22,7 @@ # ../profiles/archivebox ../profiles/woodpecker-agent ../profiles/jellyfin + ../profiles/ulogger-server ]; # Something broke when manually updating grasp... diff --git a/hosts/profiles/dns/default.nix b/hosts/profiles/dns/default.nix index bfa48374..604d7218 100644 --- a/hosts/profiles/dns/default.nix +++ b/hosts/profiles/dns/default.nix @@ -26,6 +26,7 @@ "paper.mossnet.lan" "cal.mossnet.lan" "archive.mossnet.lan" + "tracks.mossnet.lan" ]; "192.168.1.226" = [ "df-web.lan" diff --git a/hosts/profiles/ulogger-server/default.nix b/hosts/profiles/ulogger-server/default.nix index 84ed3fa0..f32b2ab1 100644 --- a/hosts/profiles/ulogger-server/default.nix +++ b/hosts/profiles/ulogger-server/default.nix @@ -2,6 +2,7 @@ { services.postgresql = { + enable = true; ensureDatabases = [ "ulogger" ]; ensureUsers = [{ name = "ulogger"; @@ -14,6 +15,7 @@ services.ulogger = { enable = true; hostName = "tracks.mossnet.lan"; + user = "ulogger"; conf = '' - ''; }; } diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index a7a36bd8..f6aeede9 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -8,4 +8,5 @@ hesienbridge = import ./heisenbridge.nix; wireguard = import ./wireguard.nix; backup = import ./backup.nix; + ulogger-server = import ./ulogger.nix; } diff --git a/modules/nixos/ulogger.nix b/modules/nixos/ulogger.nix index 1f1b0352..f89783ca 100644 --- a/modules/nixos/ulogger.nix +++ b/modules/nixos/ulogger.nix @@ -9,14 +9,7 @@ let configFile = pkgs.writeTextFile { name = "ulogger-config"; text = cfg.conf; - destination = "config.php"; - }; - - appDir = pkgs.buildEnv { - name = "ulogger-app-dir"; - ignoreCollisions = true; - checkCollisionContents = false; - paths = [ configFile "${cfg.package}/app" ]; + destination = "/config.php"; }; in @@ -207,76 +200,78 @@ in services.nginx.virtualHosts."${cfg.hostName}" = { enableACME = false; forceSSL = false; - root = "${cfg.package}"; + root = "${cfg.dataDir}"; extraConfig = '' + index index.php; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; ''; - locations."/" = { - extraConfig = '' - ''; - }; - - locations."~ ^/app\\.php(/|$)" = { + locations."~ .php$" = { extraConfig = '' fastcgi_pass unix:${config.services.phpfpm.pools."${poolName}".socket}; include ${pkgs.nginx}/conf/fastcgi_params; include ${pkgs.nginx}/conf/fastcgi.conf; - fastcgi_index ${conf.pkg}/index.php; - ''; - }; - - systemd.services.ulogger-install = { - description = "ulogger install service"; - wantedBy = [ "multi-user.target" ]; - before = [ "phpfpm-ulogger.service" ]; - after = [ "mysql.service" "postgresql.service" ]; - path = with pkgs; [ coreutils php phpPackages.composer ]; - - serviceConfig = { - User = cfg.user; - Type = "oneshot"; - RemainAfterExit = "yes"; - PermissionsStartOnly = true; - }; - - preStart = '' - mkdir -p "${cfg.dataDir}" - mkdir -p "${cfg.dataDir}/uploads" - chown ${cfg.user}:nginx "${cfg.dataDir}" - ''; - - environment = { - ULOGGER_ADMIN_USER = "admin"; - ULOGGER_ADMIN_PASSWORD = "admin"; - }; - - script = '' - echo "Setting up wallabag files in ${cfg.dataDir} ..." - cd "${cfg.dataDir}" - - rm -rf var/cache/* - rm -f app - ln -sf ${appDir} app - ln -sf ${cfg.package}/composer.{json,lock} . - - if [ ! -f installed ]; then - echo "Install file not found, installing ..." - # TODO, taken from https://github.com/bfabiszewski/ulogger-server/blob/master/.docker/init.sh - su postgres -c "psql -U ulogger < ${appDir}/scripts/ulogger.pgsql" - su postgres -c "psql -d ulogger -c \"INSERT INTO users (login, password, admin) VALUES ('$ULOGGER_ADMIN_USER', '$ULOGGER_ADMIN_PASSWORD', TRUE)\"" - touch installed - fi + fastcgi_param DOCUMENT_ROOT ${cfg.dataDir}; + fastcgi_param SCRIPT_FILENAME ${cfg.dataDir}/$fastcgi_script_name; + fastcgi_index index.php; ''; }; }; - meta = with stdenv.lib; { - maintainers = with maintainers; [ nadrieril ]; + users.users = { + ${cfg.user} = { + group = "nginx"; + description = "ulogger server user"; + isSystemUser = true; + }; }; + systemd.services.ulogger-install = { + description = "ulogger install service"; + wantedBy = [ "multi-user.target" ]; + before = [ "phpfpm-ulogger.service" ]; + after = [ "mysql.service" "postgresql.service" ]; + path = with pkgs; [ coreutils php phpPackages.composer postgresql ]; + + serviceConfig = { + User = cfg.user; + Type = "oneshot"; + RemainAfterExit = "yes"; + PermissionsStartOnly = true; + }; + + preStart = '' + mkdir -p "${cfg.dataDir}" + mkdir -p "${cfg.dataDir}/uploads" + chown -R ${cfg.user}:nginx "${cfg.dataDir}" + ''; + + environment = { + ULOGGER_ADMIN_USER = "admin"; + ULOGGER_ADMIN_PASSWORD = "\$2y\$10\$7OvZrKgonVZM9lkzrTbiou.CVhO3HjPk5y0W9L68fVwPs/osBRIMq"; # hashed "admin" + }; + + script = '' + echo "Setting up ulogger-server files in ${cfg.dataDir} ..." + cd "${cfg.dataDir}" + + cp -R ${cfg.package}/* ./ + cp ${configFile}/config.php ./ + + if [ ! -f installed ]; then + echo "Install file not found, installing ..." + psql -U ulogger < ${cfg.package}/scripts/ulogger.pgsql + psql -d ulogger -c "INSERT INTO users (login, password, admin) VALUES ('$ULOGGER_ADMIN_USER', '$ULOGGER_ADMIN_PASSWORD', TRUE)" + touch installed + fi + ''; + }; + }; + + meta = with stdenv.lib; { + maintainers = with maintainers; [ nadrieril ]; }; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 8f7ffb28..2f1f3488 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -7,4 +7,5 @@ fennel-ls = pkgs.callPackage ./fennel-ls.nix { }; kobopatch = pkgs.callPackage ./kobopatch.nix { }; my-mautrix-discord = pkgs.callPackage ./mautrix-discord.nix { }; # Handled by matrix-appservices input + ulogger-server = pkgs.callPackage ./ulogger.nix { }; } diff --git a/pkgs/ulogger.nix b/pkgs/ulogger.nix index 7ad5dc3f..13a3d8de 100644 --- a/pkgs/ulogger.nix +++ b/pkgs/ulogger.nix @@ -10,7 +10,7 @@ stdenv.mkDerivation { # Release tarball includes vendored files src = fetchurl { url = "https://github.com/bfabiszewski/ulogger-server/archive/refs/tags/v${version}.tar.gz"; - hash = ""; + hash = "sha256-+ZyNA5+lhD6DKXIWNdlLA7ArtV1F61H3UmMyRVRdws0="; }; dontBuild = true; @@ -19,6 +19,7 @@ stdenv.mkDerivation { runHook preInstall rm -R .docker rm -R .tests + rm -R uploads/ mkdir $out cp -R * $out/ runHook postInstall