diff --git a/flake.nix b/flake.nix index c86905a..15dd2ea 100644 --- a/flake.nix +++ b/flake.nix @@ -36,53 +36,19 @@ ... }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ - (_: super: { - python3 = super.python3.override { - packageOverrides = _: python-super: { - django = python-super.django_5; - }; - }; - geoip-mmdb = pkgs.callPackage ./pkgs/geoip-mmdb.nix { - inherit geoip2-tarball; - }; - e11sync-static = pkgs.callPackage ./pkgs/e11sync-static.nix {}; - e11sync-frontend = pkgs.callPackage ./pkgs/e11sync-frontend.nix {}; - e11sync-backend = pkgs.callPackage ./pkgs/e11sync-backend.nix {}; - }) - ]; - }; - - geoip-mmdb = pkgs.callPackage ./pkgs/geoip-mmdb.nix { - inherit geoip2-tarball; - }; - - e11sync-static = pkgs.callPackage ./pkgs/e11sync-static.nix {}; - - e11sync-frontend = pkgs.callPackage ./pkgs/e11sync-frontend.nix { - inherit e11sync-static; - }; - - e11sync-backend = pkgs.callPackage ./pkgs/e11sync-backend.nix { - inherit geoip-mmdb; - e11sync-static-manifest = e11sync-static.passthru.manifest; - }; - - e11sync-module = import ./modules/e11sync { - inherit e11sync-backend e11sync-frontend; + pkgs = import ./pkgs.nix { + inherit nixpkgs system geoip2-tarball; }; in { packages = { - inherit geoip-mmdb; - inherit e11sync-static; - inherit e11sync-frontend; - inherit e11sync-backend; + inherit (pkgs) geoip-mmdb; + inherit (pkgs) e11sync-static; + inherit (pkgs) e11sync-frontend; + inherit (pkgs) e11sync-backend; }; checks = { - e11sync-unit = e11sync-backend.passthru.tests.unit; + e11sync-unit = pkgs.e11sync-backend.passthru.tests.unit; pre-commit-check = pre-commit-hooks.lib.${system}.run { src = ./.; hooks = { @@ -98,9 +64,6 @@ ''; }; - nixosModules.e11sync = e11sync-module; - nixosModules.default = e11sync-module; - apps = { e11sync-frontend = { type = "app"; @@ -115,7 +78,7 @@ debug } :8001 - ${builtins.readFile "${e11sync-frontend}"} + ${builtins.readFile "${pkgs.e11sync-frontend}"} ''; }} --adapter caddyfile''); }; @@ -124,7 +87,7 @@ name = "e11sync-backend"; program = toString (pkgs.writeShellScript "wrapper" '' export E11SYNC_DATABASE_PATH=$PWD/db.sqlite3 - exec ${e11sync-backend}/bin/e11sync-backend + exec ${pkgs.e11sync-backend}/bin/e11sync-backend ''); }; }; @@ -145,7 +108,7 @@ libmaxminddb dart-sass ]; - GEOIP_PATH = "${geoip-mmdb}"; + GEOIP_PATH = "${pkgs.geoip-mmdb}"; E11SYNC_DEBUG = "1"; LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; inherit (self.checks.${system}.pre-commit-check) shellHook; @@ -162,6 +125,6 @@ self.nixosModules.e11sync ]; }; - nixosModules.e11sync = import ./modules/e11sync geoip2-tarball; + nixosModules.e11sync = import ./modules/e11sync nixpkgs; }; } diff --git a/modules/e11sync/default.nix b/modules/e11sync/default.nix index dfb16c1..79d954f 100644 --- a/modules/e11sync/default.nix +++ b/modules/e11sync/default.nix @@ -1,9 +1,12 @@ -geoip2-tarball: { +nixpkgs: { config, lib, - pkgs, + system, + geoip2-tarball, ... -}: { +}: let + pkgs = import ../../pkgs.nix {inherit nixpkgs system geoip2-tarball;}; +in { options.e11sync = with lib.types; { enable = lib.mkEnableOption "Enable e11sync"; secretKeyPath = lib.mkOption {type = oneOf [path (enum ["unsafe"])];}; @@ -28,21 +31,10 @@ geoip2-tarball: { config = let cfg = config.e11sync; - geoip-mmdb = pkgs.callPackage ../../pkgs/geoip-mmdb.nix { - inherit geoip2-tarball; - }; - e11sync-static = pkgs.callPackage ../../pkgs/e11sync-static.nix {}; - e11sync-frontend = pkgs.callPackage ../../pkgs/e11sync-frontend.nix { - inherit e11sync-static; - }; - e11sync-backend = pkgs.callPackage ../../pkgs/e11sync-backend.nix { - inherit e11sync-static geoip-mmdb; - inherit (cfg) backendPort databasePath; - }; in lib.mkIf cfg.enable { environment.systemPackages = [ - e11sync-backend + pkgs.e11sync-backend ]; systemd.services = { @@ -67,7 +59,7 @@ geoip2-tarball: { StateDirectory = "e11sync-backend"; WorkingDirectory = "/var/lib/e11sync-backend"; KillSignal = "SIGQUIT"; - ExecStart = "${e11sync-backend}/bin/e11sync-backend"; + ExecStart = "${pkgs.e11sync-backend}/bin/e11sync-backend"; MemoryHigh = "1535M"; MemoryMax = "4096M"; @@ -79,7 +71,7 @@ geoip2-tarball: { ProtectControlGroups = true; } (lib.mkIf cfg.migrateOnStart { - ExecStartPre = "${e11sync-backend}/bin/e11sync migrate"; + ExecStartPre = "${pkgs.e11sync-backend}/bin/e11sync migrate"; }) (lib.mkIf (cfg.secretKeyPath != "unsafe") { LoadCredential = "secret_key:${cfg.secretKeyPath}"; @@ -89,6 +81,6 @@ geoip2-tarball: { }; services.caddy.virtualHosts."${cfg.vhost}".extraConfig = - builtins.readFile "${e11sync-frontend}"; + builtins.readFile "${pkgs.e11sync-frontend}"; }; } diff --git a/pkgs.nix b/pkgs.nix new file mode 100644 index 0000000..77e4dea --- /dev/null +++ b/pkgs.nix @@ -0,0 +1,25 @@ +{ + nixpkgs, + system, + geoip2-tarball, +}: let + inherit (import nixpkgs {inherit system;}) callPackage; +in + import nixpkgs { + inherit system; + overlays = [ + (_: super: { + python3 = super.python3.override { + packageOverrides = _: python-super: { + django = python-super.django_5; + }; + }; + geoip-mmdb = callPackage ./pkgs/geoip-mmdb.nix { + inherit geoip2-tarball; + }; + e11sync-static = callPackage ./pkgs/e11sync-static.nix {}; + e11sync-frontend = callPackage ./pkgs/e11sync-frontend.nix {}; + e11sync-backend = callPackage ./pkgs/e11sync-backend.nix {}; + }) + ]; + }