From 46c4804ffd17dd587b97ba105604623acf775070 Mon Sep 17 00:00:00 2001 From: Lichthagel Date: Mon, 20 May 2024 12:46:53 +0200 Subject: [PATCH] feat(nixos): add support for gitea/forgejo --- modules/lib/default.nix | 12 ++++-- modules/nixos/all-modules.nix | 1 + modules/nixos/gitea.nix | 81 +++++++++++++++++++++++++++++++++++ modules/tests/nixos.nix | 1 + pkgs/gitea/package.nix | 23 ++++++++++ pkgs/sources.json | 2 +- 6 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 modules/nixos/gitea.nix create mode 100644 pkgs/gitea/package.nix diff --git a/modules/lib/default.nix b/modules/lib/default.nix index 84249be3..3ce3fe34 100644 --- a/modules/lib/default.nix +++ b/modules/lib/default.nix @@ -30,15 +30,15 @@ let in lib.makeExtensible (ctp: { - types = { - flavor = types.enum [ + consts = { + flavors = [ "latte" "frappe" "macchiato" "mocha" ]; - accent = types.enum [ + accents = [ "blue" "flamingo" "green" @@ -56,6 +56,12 @@ lib.makeExtensible (ctp: { ]; }; + types = { + flavor = types.enum ctp.consts.flavors; + + accent = types.enum ctp.consts.accents; + }; + /** Capitalize the first letter in a string diff --git a/modules/nixos/all-modules.nix b/modules/nixos/all-modules.nix index 5fd61fce..bd2e1ee9 100644 --- a/modules/nixos/all-modules.nix +++ b/modules/nixos/all-modules.nix @@ -1,5 +1,6 @@ [ ./fcitx5.nix + ./gitea.nix ./grub.nix ./plymouth.nix ./sddm.nix diff --git a/modules/nixos/gitea.nix b/modules/nixos/gitea.nix new file mode 100644 index 00000000..22ebfb38 --- /dev/null +++ b/modules/nixos/gitea.nix @@ -0,0 +1,81 @@ +{ catppuccinLib }: +{ + lib, + config, + ... +}: +let + inherit (config.catppuccin) sources; + + supportedForges = [ + "gitea" + "forgejo" + ]; + + builtinThemes = { + gitea = [ + "auto" + "gitea" + "arc-greeen" + ]; + + forgejo = [ + "forgejo-auto" + "forgejo-light" + "forgejo-dark" + "gitea-auto" + "gitea-light" + "gitea-dark" + "forgejo-auto-deuteranopia-protanopia" + "forgejo-light-deuteranopia-protanopia" + "forgejo-dark-deuteranopia-protanopia" + "forgejo-auto-tritanopia" + "forgejo-light-tritanopia" + "forgejo-dark-tritanopia" + ]; + }; + + generateConfig = + forge: + let + cfg = config.catppuccin.${forge}; + in + lib.mkIf cfg.enable { + systemd.services.${forge}.preStart = + let + inherit (config.services.${forge}) customDir; + + baseDir = + if lib.versionAtLeast config.services.${forge}.package.version "1.21.0" then + "${customDir}/public/assets" + else + "${customDir}/public"; + in + lib.mkAfter '' + rm -rf ${baseDir}/css + mkdir -p ${baseDir} + ln -sf ${sources.gitea} ${baseDir}/css + ''; + + services.${forge}.settings.ui = { + DEFAULT_THEME = "catppuccin-${cfg.flavor}-${cfg.accent}"; + THEMES = builtins.concatStringsSep "," ( + builtinThemes.${forge} + ++ (lib.mapCartesianProduct ({ flavors, accents }: "catppuccin-${flavors}-${accents}") { + inherit (catppuccinLib.consts) flavors accents; + }) + ); + }; + }; +in +{ + options.catppuccin = lib.genAttrs supportedForges ( + name: + catppuccinLib.mkCatppuccinOption { + inherit name; + accentSupport = true; + } + ); + + config = lib.mkMerge (map generateConfig supportedForges); +} diff --git a/modules/tests/nixos.nix b/modules/tests/nixos.nix index 9358d712..d5a9f461 100644 --- a/modules/tests/nixos.nix +++ b/modules/tests/nixos.nix @@ -32,6 +32,7 @@ testers.runNixOSTest { package = pkgs.kdePackages.sddm; # our module/the upstream port requires the qt6 version }; xserver.enable = true; # required for sddm + gitea.enable = true; }; console.enable = true; diff --git a/pkgs/gitea/package.nix b/pkgs/gitea/package.nix new file mode 100644 index 00000000..d74c9952 --- /dev/null +++ b/pkgs/gitea/package.nix @@ -0,0 +1,23 @@ +{ buildCatppuccinPort, fetchzip }: + +buildCatppuccinPort (finalAttrs: { + pname = "gitea"; + version = "0.4.1"; + + src = fetchzip { + url = "https://github.com/catppuccin/gitea/releases/download/v${finalAttrs.version}/catppuccin-gitea.tar.gz"; + sha256 = "sha256-14XqO1ZhhPS7VDBSzqW55kh6n5cFZGZmvRCtMEh8JPI="; + stripRoot = false; + }; + + dontCatppuccinInstall = true; + + installPhase = '' + runHook preInstall + + mkdir -p $out + mv * $out + + runHook postInstall + ''; +}) diff --git a/pkgs/sources.json b/pkgs/sources.json index 8c85881a..cf2ceab2 100644 --- a/pkgs/sources.json +++ b/pkgs/sources.json @@ -187,4 +187,4 @@ "hash": "sha256-l6tztApzYpQ2/CiKuLBf8vI2imM6vPJuFdNDSEi7T/o=", "rev": "7926c3d3e17d26b3779851a2255b95ee650bd928" } -} \ No newline at end of file +}