From a382d78d6353b19dad69922472d758051e0c29e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 19 Jan 2024 14:26:28 +0200 Subject: [PATCH] module does not build: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $ nix build .#nixosConfigurations.vm.config.system.build.vm error: … while calling the 'derivationStrict' builtin at /builtin/derivation.nix:9:12: (source not available) … while evaluating derivation 'nixos-vm' whose name attribute is located at /nix/store/ikx99aci297hpgys7114fjwyf38iv9qi-source/pkgs/stdenv/generic/make-derivation.nix:348:7 … while evaluating attribute 'buildCommand' of derivation 'nixos-vm' at /nix/store/ikx99aci297hpgys7114fjwyf38iv9qi-source/pkgs/build-support/trivial-builders/default.nix:87:14: 86| enableParallelBuilding = true; 87| inherit buildCommand name; | ^ 88| passAsFile = [ "buildCommand" ] (stack trace truncated; use '--show-trace' to show the full trace) error: attribute 'system' missing at /nix/store/ikx99aci297hpgys7114fjwyf38iv9qi-source/lib/modules.nix:506:28: 505| builtins.addErrorContext (context name) 506| (args.${name} or config._module.args.${name}) | ^ 507| ) (lib.functionArgs f); --- flake.nix | 59 +++++++------------------------------ modules/e11sync/default.nix | 28 +++++++----------- pkgs.nix | 25 ++++++++++++++++ 3 files changed, 46 insertions(+), 66 deletions(-) create mode 100644 pkgs.nix 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 {}; + }) + ]; + }