From 711a83b8e0050baf905d974f357f62328f3ee138 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 10 Jan 2025 03:11:04 -0500 Subject: [PATCH 01/10] feat: new custom Tokyo Night forgejo theme --- aether/config.nix | 3 ++- flake.nix | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/aether/config.nix b/aether/config.nix index 95b8319..9fd4a76 100644 --- a/aether/config.nix +++ b/aether/config.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, aether, ... }: +{ config, lib, pkgs, aether, forgejo-tokyo-night, ... }: { networking.hostName = "toki-aether"; time.timeZone = "America/New_York"; @@ -30,6 +30,7 @@ aether.domain = "tokinanpa.dev"; aether.acmeEmail = "kiana.a.sheibani@gmail.com"; + aether.forgejo.theme = "${forgejo-tokyo-night}/public/assets"; aether.forgejo.templates = ./forgejo-templates; services.forgejo.settings = { DEFAULT.APP_NAME = "Code by toki!"; diff --git a/flake.nix b/flake.nix index 7d6c4cc..4bb3099 100644 --- a/flake.nix +++ b/flake.nix @@ -10,6 +10,9 @@ inputs = { agenix.url = "github:ryantm/agenix"; agenix.inputs.nixpkgs.follows = "nixpkgs"; agenix.inputs.darwin.follows = ""; + + forgejo-tokyo-night.url = "https://git.tokinanpa.dev/toki/forgejo-tokyo-night/archive/main.tar.gz"; + forgejo-tokyo-night.flake = false; }; outputs = inputs@{ self, nixpkgs, agenix, rpi5-kernel, ... }: @@ -37,7 +40,10 @@ outputs = inputs@{ self, nixpkgs, agenix, rpi5-kernel, ... }: nixosConfigurations."toki-aether" = nixpkgs.lib.nixosSystem { - specialArgs.aether = self.nixosModules; + specialArgs = { + inherit forgejo-tokyo-night; + aether = self.nixosModules; + }; modules = [ agenix.nixosModules.default ./aether/hardware-configuration.nix From 159980a6f8020faa595ae036a5fac5a45fce1add Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 10 Jan 2025 17:25:38 -0500 Subject: [PATCH 02/10] fix: invalid special args --- flake.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 4bb3099..2c62bc9 100644 --- a/flake.nix +++ b/flake.nix @@ -40,8 +40,7 @@ outputs = inputs@{ self, nixpkgs, agenix, rpi5-kernel, ... }: nixosConfigurations."toki-aether" = nixpkgs.lib.nixosSystem { - specialArgs = { - inherit forgejo-tokyo-night; + specialArgs = inputs // { aether = self.nixosModules; }; modules = [ From 11398c5a84fa870b3f7234c6bd0864438defac46 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 10 Jan 2025 17:31:41 -0500 Subject: [PATCH 03/10] chore: bump inputs --- flake.lock | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index e8849c6..0e34e11 100644 --- a/flake.lock +++ b/flake.lock @@ -37,6 +37,20 @@ "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" } }, + "forgejo-tokyo-night": { + "flake": false, + "locked": { + "lastModified": 1736496165, + "narHash": "sha256-WVVAK1pnyu7s7Wsh/FO7DQrU6FDbmgMfXeqAOBwGC50=", + "rev": "dcb107d2015eed36c74c9efddc97f0327b6c2bea", + "type": "tarball", + "url": "https://git.tokinanpa.dev/api/v1/repos/toki/forgejo-tokyo-night/archive/dcb107d2015eed36c74c9efddc97f0327b6c2bea.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://git.tokinanpa.dev/toki/forgejo-tokyo-night/archive/main.tar.gz" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -60,11 +74,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1729413321, - "narHash": "sha256-I4tuhRpZFa6Fu6dcH9Dlo5LlH17peT79vx1y1SpeKt0=", + "lastModified": 1736344531, + "narHash": "sha256-8YVQ9ZbSfuUk2bUf2KRj60NRraLPKPS0Q4QFTbc+c2c=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26", + "rev": "bffc22eb12172e6db3c5dde9e3e5628f8e3e7912", "type": "github" }, "original": { @@ -77,6 +91,7 @@ "root": { "inputs": { "agenix": "agenix", + "forgejo-tokyo-night": "forgejo-tokyo-night", "nixpkgs": "nixpkgs", "rpi5-kernel": "rpi5-kernel" } From 79c0dfa16275c413c4522d3fc67ab17b7cc2c8e5 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 10 Jan 2025 21:12:59 -0500 Subject: [PATCH 04/10] feat: enable new theme --- aether/config.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aether/config.nix b/aether/config.nix index 9fd4a76..bc9b490 100644 --- a/aether/config.nix +++ b/aether/config.nix @@ -51,7 +51,8 @@ }; ui = { - DEFAULT_THEME = "forgejo-dark"; + DEFAULT_THEME = "forgejo-tokyo-night"; + THEMES = "forgejo-tokyo-night"; GRAPH_MAX_COMMIT_NUM = 250; }; "ui.meta" = { From 80834ea71cae4fd2a9d11919627c95d48e0c9b55 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 10 Jan 2025 22:02:53 -0500 Subject: [PATCH 05/10] fix: refactor improper use of `mkIf` Apparently you should NOT do this, because not only will it not work, it will also break the entire module! --- modules/forgejo/default.nix | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/forgejo/default.nix b/modules/forgejo/default.nix index 89e3709..b1cd06e 100644 --- a/modules/forgejo/default.nix +++ b/modules/forgejo/default.nix @@ -45,13 +45,16 @@ in { "L+ ${forgejo.stateDir}/custom/public/assets - - - - ${cfg.theme}" ++ lib.optional (!(builtins.isNull cfg.templates)) "L+ ${forgejo.stateDir}/custom/templates - - - - ${cfg.templates}"; -} -// lib.mkIf cfg.createUser { - users.users.${forgejo.user} = { - home = forgejo.stateDir; - useDefaultShell = true; - group = forgejo.group; - isSystemUser = true; + + users.users = lib.mkIf cfg.createUser { + ${forgejo.user} = { + home = forgejo.stateDir; + useDefaultShell = true; + group = forgejo.group; + isSystemUser = true; + }; + }; + users.groups = lib.mkIf cfg.createUser { + ${forgejo.group} = {}; }; - users.groups.${forgejo.group} = {}; } From f7e030244b5b8f1e05ad0164181e024e528884da Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 10 Jan 2025 22:33:10 -0500 Subject: [PATCH 06/10] fix: correct config option names --- modules/forgejo/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/forgejo/default.nix b/modules/forgejo/default.nix index b1cd06e..7200449 100644 --- a/modules/forgejo/default.nix +++ b/modules/forgejo/default.nix @@ -21,7 +21,7 @@ in { }; security.acme.acceptTerms = config.aether.https; - security.acme.defaults.email = cfg.acmeEmail; + security.acme.defaults.email = config.aether.acmeEmail; networking.firewall.allowedTCPPorts = [ 80 443 ]; @@ -41,7 +41,7 @@ in { }; systemd.tmpfiles.rules = - lib.optional (!(builtins.isNull cfg.themes)) + lib.optional (!(builtins.isNull cfg.theme)) "L+ ${forgejo.stateDir}/custom/public/assets - - - - ${cfg.theme}" ++ lib.optional (!(builtins.isNull cfg.templates)) "L+ ${forgejo.stateDir}/custom/templates - - - - ${cfg.templates}"; From 5b602799f65d77f1f2d58ef8194f03760d8ff725 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 29 Mar 2025 07:25:16 -0400 Subject: [PATCH 07/10] fix(forgejo): fix possible duplicate user creation --- modules/forgejo/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/forgejo/default.nix b/modules/forgejo/default.nix index 7200449..615958e 100644 --- a/modules/forgejo/default.nix +++ b/modules/forgejo/default.nix @@ -46,7 +46,7 @@ in { ++ lib.optional (!(builtins.isNull cfg.templates)) "L+ ${forgejo.stateDir}/custom/templates - - - - ${cfg.templates}"; - users.users = lib.mkIf cfg.createUser { + users.users = lib.mkIf (cfg.createUser && forgejo.user != "forgejo") { ${forgejo.user} = { home = forgejo.stateDir; useDefaultShell = true; @@ -54,7 +54,7 @@ in { isSystemUser = true; }; }; - users.groups = lib.mkIf cfg.createUser { + users.groups = lib.mkIf (cfg.createUser && forgejo.group != "forgejo") { ${forgejo.group} = {}; }; } From c559bf629feada368f1c6499826a65c55ff48fc0 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 29 Mar 2025 07:25:41 -0400 Subject: [PATCH 08/10] tweak(forgejo)!: switch to postgres database --- modules/forgejo/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/forgejo/default.nix b/modules/forgejo/default.nix index 615958e..6808e62 100644 --- a/modules/forgejo/default.nix +++ b/modules/forgejo/default.nix @@ -31,7 +31,9 @@ in { enable = true; user = cfg.user; group = forgejo.user; + database.name = forgejo.user; database.user = forgejo.user; + database.type = "postgres"; settings.server = { DOMAIN = lib.optionalString useSubdomain "${cfg.subdomain}." From 5965922b5709253520851bee3ec4b7df66aeede1 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 1 Apr 2025 22:19:54 -0400 Subject: [PATCH 09/10] refactor: generalize flake input injection --- deploy/rpi5/default.nix | 8 +++++--- flake.nix | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/deploy/rpi5/default.nix b/deploy/rpi5/default.nix index 96b78fe..8a3cfbf 100644 --- a/deploy/rpi5/default.nix +++ b/deploy/rpi5/default.nix @@ -1,9 +1,11 @@ { config, lib, ... }: { options.aether.deploy.rpi5 = { - kernelPackages = lib.mkOption { + _internal.kernelPackages = lib.mkOption { type = lib.types.raw; - description = "Kernel package to use for Raspberry Pi 5 support"; + description = '' + Kernel package to use for Raspberry Pi 5 support. + ''; }; }; @@ -11,7 +13,7 @@ let cfg = config.aether.deploy.rpi5; in { nixpkgs.system = "aarch64-linux"; - boot.kernelPackages = cfg.kernelPackages; + boot.kernelPackages = cfg._internal.kernelPackages; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = false; }; diff --git a/flake.nix b/flake.nix index 2c62bc9..bd59b40 100644 --- a/flake.nix +++ b/flake.nix @@ -19,23 +19,43 @@ outputs = inputs@{ self, nixpkgs, agenix, rpi5-kernel, ... }: let inherit (nixpkgs) lib; + # Extra config applied to each module + # (Mostly used for injecting flake inputs) + extraConfig = { + deploy-rpi5 = { + aether.deploy.rpi5._internal.kernelPackages = lib.mkDefault + rpi5-kernel.legacyPackages.aarch64-linux.linuxPackages_rpi5; + }; + }; + moduleNames = let sub = builtins.readDir ./modules; in builtins.filter (d: sub.${d} == "directory") (builtins.attrNames sub); - modules = lib.genAttrs moduleNames (name: ./modules/${name}); + deployNames = + let sub = builtins.readDir ./deploy; + in builtins.map (d: "deploy-${d}") + (builtins.filter + (d: sub.${d} == "directory") + (builtins.attrNames sub)); + + modules = lib.genAttrs moduleNames + (name: ./modules/${name}); + deployments = lib.genAttrs deployNames + (name: ./deploy/${lib.removePrefix "deploy-" name}); + + modulesWithCfg = builtins.mapAttrs (k: v: { + imports = [ v ]; + } // extraConfig.${k} or {}) modules; + deploymentsWithCfg = builtins.mapAttrs (k: v: { + imports = [ v ]; + } // extraConfig.${k} or {}) deployments; in { nixosModules = - modules - // { - all.imports = lib.attrValues modules; - deploy-rpi5 = { lib, ... }: { - imports = [ ./deploy/rpi5 ]; - aether.deploy.rpi5.kernelPackages = lib.mkDefault - rpi5-kernel.legacyPackages.aarch64-linux.linuxPackages_rpi5; - }; + modulesWithCfg // deploymentsWithCfg // { + all.imports = lib.attrValues modulesWithCfg; }; nixosConfigurations."toki-aether" = From dedd95c442e41789c370532b6ed2d7fa52fceab2 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 1 Apr 2025 22:20:26 -0400 Subject: [PATCH 10/10] fix: resolve conflicting module options Apparently you aren't allowed to define the same option in multiple modules, even if the definitions are identical. --- modules/forgejo/options.nix | 9 ++------- modules/options.nix | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/modules/forgejo/options.nix b/modules/forgejo/options.nix index ca36137..102255d 100644 --- a/modules/forgejo/options.nix +++ b/modules/forgejo/options.nix @@ -1,13 +1,8 @@ args@{ config, lib, ... }: { - options.aether = { - # Referenced general options - inherit (import ../options.nix args) - domain - https - acmeEmail; + imports = [ ../options.nix ]; - # Module-specific options + options.aether = { forgejo = { subdomain = lib.mkOption { type = lib.types.nullOr lib.types.str; diff --git a/modules/options.nix b/modules/options.nix index 5d606d0..a482a52 100644 --- a/modules/options.nix +++ b/modules/options.nix @@ -1,19 +1,21 @@ { lib, ... }: { - domain = lib.mkOption { - type = lib.types.str; - description = "The domain name the server is hosted on."; - }; + options.aether = { + domain = lib.mkOption { + type = lib.types.str; + description = "The domain name the server is hosted on."; + }; - https = lib.mkOption { - type = lib.types.boolByOr; - default = true; - description = "Whether to force HTTPS connections for websites."; - }; + https = lib.mkOption { + type = lib.types.boolByOr; + default = true; + description = "Whether to force HTTPS connections for websites."; + }; - acmeEmail = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = null; - description = "Email address for ACME."; + acmeEmail = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = "Email address for ACME."; + }; }; }