From 7940d8472969628d6747dcc837703bb4bd29defe Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 9 Apr 2024 01:19:01 +0200 Subject: [PATCH] Make module more general --- flake.nix | 8 ++--- module.nix | 29 +++++++++++-------- default.nix => themes/monokai/default.nix | 0 .../monokai/theme-monokai.less | 0 4 files changed, 21 insertions(+), 16 deletions(-) rename default.nix => themes/monokai/default.nix (100%) rename theme-monokai.less => themes/monokai/theme-monokai.less (100%) diff --git a/flake.nix b/flake.nix index 608d4f4..7a1cb6c 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ in { packages = forAllSystems (system: pkgs: { default = self.packages.${system}.gitea-theme-monokai; - gitea-theme-monokai = pkgs.callPackage ./default.nix { }; + gitea-theme-monokai = pkgs.callPackage ./themes/monokai { }; test-machine = let system = "x86_64-linux"; @@ -35,10 +35,10 @@ system.stateVersion = "23.11"; boot.isContainer = true; } - { + ({pkgs, ... }: { services.gitea.enable = true; - services.gitea-themes.monokai.enable = true; - } + services.gitea-themes."monokai" = pkgs.gitea-theme-monokai; + }) ]; }).config.system.build.toplevel; }); diff --git a/module.nix b/module.nix index 9757ec8..3f5a7be 100644 --- a/module.nix +++ b/module.nix @@ -1,22 +1,27 @@ { config, pkgs, lib, ... }: let - cfg = config.services.gitea-themes.monokai; + cfg = config.services.gitea-themes; giteaCfg = config.services.gitea; in { - options.services.gitea-themes.monokai = { - enable = lib.mkEnableOption "monokai theme for gitea"; - package = lib.mkPackageOption pkgs "gitea-theme-monokai" { }; + options.services.gitea-themes = lib.mkOption { + description = '' + Derivations containing gitea themes to install. + + The theme should be named `theme-.css`, and reside in `$out/share/gitea/public/assets/css/`. + ''; + default = { }; + type = with lib.types; attrsOf path; }; - config = lib.mkIf (cfg.enable && giteaCfg.enable) { - services.gitea.settings.ui.THEMES = lib.strings.concatStringsSep "," [ + config = lib.mkIf (cfg != { }) { + services.gitea.settings.ui.THEMES = lib.strings.concatStringsSep "," ([ "gitea" "arc-green" - "monokai" - ]; + ] ++ lib.attrNames cfg); systemd.services.install-gitea-theme-monokai = { + description = "Install gitea themes in gitea's CUSTOM_DIR"; wantedBy = [ "gitea.service" ]; requiredBy = [ "gitea.service" ]; @@ -25,13 +30,13 @@ in User = giteaCfg.user; Group = giteaCfg.group; }; - script = '' + script = lib.concatMapStringsSep "\n" (theme-package: '' mkdir -p "${giteaCfg.customDir}/public/assets/css" if ! [ -f "${giteaCfg.customDir}/public/assets/css/theme-monokai.css" ]; then - ln -s "${cfg.package}/share/gitea/public/assets/css/theme-monokai.css" "${giteaCfg.customDir}/public/assets/css/theme-monokai.css" - ln -s "${cfg.package}/share/gitea/public/css/theme-monokai.css" "${giteaCfg.customDir}/public/css/theme-monokai.css" + ln -s "${theme-package}/share/gitea/public/assets/css/*.css" "${giteaCfg.customDir}/public/assets/css/" + ln -s "${theme-package}/share/gitea/public/css/*.css" "${giteaCfg.customDir}/public/css/" fi - ''; + '') (lib.attrValues cfg); }; }; } diff --git a/default.nix b/themes/monokai/default.nix similarity index 100% rename from default.nix rename to themes/monokai/default.nix diff --git a/theme-monokai.less b/themes/monokai/theme-monokai.less similarity index 100% rename from theme-monokai.less rename to themes/monokai/theme-monokai.less