Unverified Commit 12614d7b authored by Pol Dellaiera's avatar Pol Dellaiera Committed by GitHub
Browse files

nixos/bookstack: Updated to accommodate passwordless login for mysql & Module...

nixos/bookstack: Updated to accommodate passwordless login for mysql & Module now creates themes directory; nixosTests.bookstack: Updated to also test passwordless login for mysql; bookstack: Changed to allow themes directory to be writable (#422309)
parents 5422d9b1 bc5a563b
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -16,17 +16,17 @@ let

  artisan = "${cfg.package}/artisan";

  env-file-values = lib.attrsets.mapAttrs' (
    n: v: lib.attrsets.nameValuePair (lib.strings.removeSuffix "_FILE" n) v
  ) (lib.attrsets.filterAttrs (n: v: lib.strings.hasSuffix "_FILE" n) cfg.settings);
  env-nonfile-values = lib.attrsets.filterAttrs (n: v: !lib.strings.hasSuffix "_FILE" n) cfg.settings;
  env-file-values = lib.mapAttrs' (n: v: {
    name = lib.removeSuffix "_FILE" n;
    value = v;
  }) (lib.filterAttrs (n: v: v != null && lib.match ".+_FILE" n != null) cfg.settings);

  env-nonfile-values = lib.filterAttrs (n: v: lib.match ".+_FILE" n == null) cfg.settings;

  bookstack-maintenance = pkgs.writeShellScript "bookstack-maintenance.sh" ''
    set -a
    ${lib.strings.toShellVars env-nonfile-values}
    ${lib.strings.concatLines (
      lib.attrsets.mapAttrsToList (n: v: "${n}=\"$(< ${v})\"") env-file-values
    )}
    ${lib.toShellVars env-nonfile-values}
    ${lib.concatLines (lib.mapAttrsToList (n: v: "${n}=\"$(< ${v})\"") env-file-values)}
    set +a
    ${artisan} optimize:clear
    rm ${cfg.dataDir}/cache/*.php
@@ -137,7 +137,7 @@ in
      "bookstack"
      "database"
      "createLocally"
    ] "This option is deprecated. Please create your database manually.")
    ] "Use services.mysql.ensureDatabases and services.mysql.ensureUsers instead.")
    (lib.mkRemovedOptionModule [
      "services"
      "bookstack"
@@ -281,11 +281,12 @@ in
            '';
          };
          DB_PASSWORD_FILE = lib.mkOption {
            type = lib.types.path;
            type = lib.types.nullOr lib.types.path;
            description = ''
              The file containing your mysql/mariadb database password.
            '';
            example = "/var/secrets/bookstack-mysql-pass.txt";
            default = null;
          };
          APP_KEY_FILE = lib.mkOption {
            type = lib.types.path;
@@ -464,6 +465,7 @@ in
        "${cfg.dataDir}/storage/logs".d = defaultConfig;
        "${cfg.dataDir}/storage/uploads".d = defaultConfig;
        "${cfg.dataDir}/cache".d = defaultConfig;
        "${cfg.dataDir}/themes".d = defaultConfig;
      };

    users = {
+15 −8
Original line number Diff line number Diff line
{ pkgs, ... }:

let
  db-pass = "Test2Test2";
  app-key = "TestTestTestTestTestTestTestTest";
in
{
  name = "bookstack";
  meta.maintainers = [ pkgs.lib.maintainers.savyajha ];
  meta = {
    maintainers = [ pkgs.lib.maintainers.savyajha ];
    platforms = pkgs.lib.platforms.linux;
  };

  nodes.bookstackMysql = {
    services.bookstack = {
@@ -19,7 +21,6 @@ in
        SITE_OWNER = "mail@example.com";
        DB_DATABASE = "bookstack";
        DB_USERNAME = "bookstack";
        DB_PASSWORD_FILE = pkgs.writeText "mysql-pass" db-pass;
        DB_SOCKET = "/run/mysqld/mysqld.sock";
      };
    };
@@ -27,12 +28,18 @@ in
    services.mysql = {
      enable = true;
      package = pkgs.mariadb;
      initialScript = pkgs.writeText "bookstack-init.sql" ''
        create database bookstack DEFAULT CHARACTER SET utf8mb4;
        create user 'bookstack'@'localhost' identified by '${db-pass}';
        grant all on bookstack.* to 'bookstack'@'localhost';
      '';
      settings.mysqld.character-set-server = "utf8mb4";
      ensureDatabases = [
        "bookstack"
      ];
      ensureUsers = [
        {
          name = "bookstack";
          ensurePermissions = {
            "bookstack.*" = "ALL PRIVILEGES";
          };
        }
      ];
    };
  };

+2 −1
Original line number Diff line number Diff line
@@ -27,10 +27,11 @@ php83.buildComposerProject2 (finalAttrs: {
  postInstall = ''
    chmod -R u+w $out/share
    mv $out/share/php/bookstack/* $out
    rm -R $out/share $out/storage $out/bootstrap/cache $out/public/uploads
    rm -R $out/share $out/storage $out/bootstrap/cache $out/public/uploads $out/themes
    ln -s ${dataDir}/storage $out/storage
    ln -s ${dataDir}/cache $out/bootstrap/cache
    ln -s ${dataDir}/public/uploads $out/public/uploads
    ln -s ${dataDir}/themes $out/themes
  '';

  meta = {