From d860ddc9006a9fc4e407e896c72b72ac3b067135 Mon Sep 17 00:00:00 2001 From: dusk Date: Tue, 22 Jul 2025 21:49:36 +0300 Subject: [PATCH] flake.nix,nix/modules: add package option for all the nixos modules --- flake.nix | 30 +++++++++++++++-- nix/modules/appview.nix | 75 ++++++++++++++++++++++------------------- nix/modules/knot.nix | 17 ++++++---- nix/modules/spindle.nix | 9 +++-- 4 files changed, 84 insertions(+), 47 deletions(-) diff --git a/flake.nix b/flake.nix index 39225f9..d01c9f7 100644 --- a/flake.nix +++ b/flake.nix @@ -190,9 +190,33 @@ }; }); - nixosModules.appview = import ./nix/modules/appview.nix {inherit self;}; - nixosModules.knot = import ./nix/modules/knot.nix {inherit self;}; - nixosModules.spindle = import ./nix/modules/spindle.nix {inherit self;}; + nixosModules.appview = { + lib, + pkgs, + ... + }: { + imports = [./nix/modules/appview.nix]; + + services.tangled-appview.package = lib.mkDefault self.packages.${pkgs.system}.appview; + }; + nixosModules.knot = { + lib, + pkgs, + ... + }: { + imports = [./nix/modules/knot.nix]; + + services.tangled-knot.package = lib.mkDefault self.packages.${pkgs.system}.knot; + }; + nixosModules.spindle = { + lib, + pkgs, + ... + }: { + imports = [./nix/modules/spindle.nix]; + + services.tangled-spindle.package = lib.mkDefault self.packages.${pkgs.system}.spindle; + }; nixosConfigurations.vm = import ./nix/vm.nix {inherit self nixpkgs;}; }; } diff --git a/nix/modules/appview.nix b/nix/modules/appview.nix index 0b7fe90..1c4c53d 100644 --- a/nix/modules/appview.nix +++ b/nix/modules/appview.nix @@ -1,45 +1,50 @@ -{self}: { +{ config, - pkgs, lib, ... -}: -with lib; { - options = { - services.tangled-appview = { - enable = mkOption { - type = types.bool; - default = false; - description = "Enable tangled appview"; - }; - port = mkOption { - type = types.int; - default = 3000; - description = "Port to run the appview on"; - }; - cookie_secret = mkOption { - type = types.str; - default = "00000000000000000000000000000000"; - description = "Cookie secret"; +}: let + cfg = config.services.tangled-appview; +in + with lib; { + options = { + services.tangled-appview = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable tangled appview"; + }; + package = mkOption { + type = types.package; + description = "Package to use for the appview"; + }; + port = mkOption { + type = types.int; + default = 3000; + description = "Port to run the appview on"; + }; + cookie_secret = mkOption { + type = types.str; + default = "00000000000000000000000000000000"; + description = "Cookie secret"; + }; }; }; - }; - config = mkIf config.services.tangled-appview.enable { - systemd.services.tangled-appview = { - description = "tangled appview service"; - wantedBy = ["multi-user.target"]; + config = mkIf cfg.enable { + systemd.services.tangled-appview = { + description = "tangled appview service"; + wantedBy = ["multi-user.target"]; - serviceConfig = { - ListenStream = "0.0.0.0:${toString config.services.tangled-appview.port}"; - ExecStart = "${self.packages.${pkgs.system}.appview}/bin/appview"; - Restart = "always"; - }; + serviceConfig = { + ListenStream = "0.0.0.0:${toString cfg.port}"; + ExecStart = "${cfg.package}/bin/appview"; + Restart = "always"; + }; - environment = { - TANGLED_DB_PATH = "appview.db"; - TANGLED_COOKIE_SECRET = config.services.tangled-appview.cookie_secret; + environment = { + TANGLED_DB_PATH = "appview.db"; + TANGLED_COOKIE_SECRET = cfg.cookie_secret; + }; }; }; - }; -} + } diff --git a/nix/modules/knot.nix b/nix/modules/knot.nix index 62adf56..8b4bb37 100644 --- a/nix/modules/knot.nix +++ b/nix/modules/knot.nix @@ -1,4 +1,4 @@ -{self}: { +{ config, pkgs, lib, @@ -15,6 +15,11 @@ in description = "Enable a tangled knot"; }; + package = mkOption { + type = types.package; + description = "Package to use for the knot"; + }; + appviewEndpoint = mkOption { type = types.str; default = "https://tangled.sh"; @@ -94,9 +99,9 @@ in }; config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ - git - self.packages."${pkgs.system}".knot + environment.systemPackages = [ + pkgs.git + cfg.package ]; system.activationScripts.gitConfig = '' @@ -135,7 +140,7 @@ in mode = "0555"; text = '' #!${pkgs.stdenv.shell} - ${self.packages.${pkgs.system}.knot}/bin/knot keys \ + ${cfg.package}/bin/knot keys \ -output authorized-keys \ -internal-api "http://${cfg.server.internalListenAddr}" \ -git-dir "${cfg.repo.scanPath}" \ @@ -160,7 +165,7 @@ in "KNOT_SERVER_HOSTNAME=${cfg.server.hostname}" ]; EnvironmentFile = cfg.server.secretFile; - ExecStart = "${self.packages.${pkgs.system}.knot}/bin/knot server"; + ExecStart = "${cfg.package}/bin/knot server"; Restart = "always"; }; }; diff --git a/nix/modules/spindle.nix b/nix/modules/spindle.nix index 5d45e89..60081bd 100644 --- a/nix/modules/spindle.nix +++ b/nix/modules/spindle.nix @@ -1,6 +1,5 @@ -{self}: { +{ config, - pkgs, lib, ... }: let @@ -14,6 +13,10 @@ in default = false; description = "Enable a tangled spindle"; }; + package = mkOption { + type = types.package; + description = "Package to use for the spindle"; + }; server = { listenAddr = mkOption { @@ -89,7 +92,7 @@ in "SPINDLE_PIPELINES_NIXERY=${cfg.pipelines.nixery}" "SPINDLE_PIPELINES_WORKFLOW_TIMEOUT=${cfg.pipelines.workflowTimeout}" ]; - ExecStart = "${self.packages.${pkgs.system}.spindle}/bin/spindle"; + ExecStart = "${cfg.package}/bin/spindle"; Restart = "always"; }; }; -- 2.43.0