aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authortoufic ar <contact@toufy.me>2026-05-13 23:16:11 +0300
committertoufic ar <contact@toufy.me>2026-05-13 23:16:11 +0300
commitb8d6c62f731c3c7886f2ecc661265eedeb65e41c (patch)
tree88e9b424e51197af993572a722f1e5c1d1bda758 /flake.nix
parentaca0b3964d79e58aa1b319cbdbd7b1513ba9cfd8 (diff)
downloadmakeshiftci-b8d6c62f731c3c7886f2ecc661265eedeb65e41c.tar.gz
makeshiftci-b8d6c62f731c3c7886f2ecc661265eedeb65e41c.zip
test flake webui
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix110
1 files changed, 84 insertions, 26 deletions
diff --git a/flake.nix b/flake.nix
index f4789d2..bdea298 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,18 +3,28 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+ pyproject-nix = {
+ url = "github:nix-community/pyproject.nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
};
outputs = {
self,
nixpkgs,
+ pyproject-nix,
}: let
system = "x86_64-linux";
pkgs = import nixpkgs {inherit system;};
+ python = pkgs.python3;
msci = (pkgs.writeScriptBin
"msci" (builtins.readFile ./msci)).overrideAttrs (old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
});
+ msci-web = pyproject-nix.lib.project.loadPyproject {
+ projectRoot = ./.;
+ };
+ msci-web-attrs = msci-web.renderers.buildPythonPackage {inherit python;};
in {
packages."${system}".msci = pkgs.symlinkJoin {
name = "msci";
@@ -22,6 +32,8 @@
buildInputs = [pkgs.makeWrapper];
postBuild = "wrapProgram $out/bin/msci --prefix PATH : $out/bin";
};
+ packages."${system}".msci-web =
+ python.pkgs.buildPythonPackage msci-web-attrs;
nixosModules.default = {
lib,
config,
@@ -40,40 +52,86 @@
description = "data directory of makeshiftci";
};
createUser = mkEnableOption "create a non-root user";
+ webUI = mkOption {
+ type = types.submodule {
+ options = {
+ enable = mkEnableOption "enable makeshiftci web UI";
+ port = mkOption {
+ type = types.int;
+ default = 5000;
+ description = "port to run the web UI on";
+ };
+ timeout = mkOption {
+ type = types.int;
+ default = 3600;
+ description = "gunicorn timeout";
+ };
+ workers = mkOption {
+ type = types.int;
+ default = 4;
+ description = "number of gunicorn workers";
+ };
+ };
+ };
+ default = {};
+ };
};
};
default = {};
};
};
- config = lib.mkIf cfg.enable {
- environment = {
- variables.MSCI_HOME = cfg.dataDir;
- systemPackages = [self.packages."${system}".msci];
- };
- systemd.tmpfiles.settings."makeshiftci" = {
- "${cfg.dataDir}" = {
- d = {
- user =
- if cfg.createUser
- then "makeshiftci"
- else "root";
- group =
- if cfg.createUser
- then "makeshiftci"
- else "root";
- mode = "0750";
+ config = lib.mkIf cfg.enable ({
+ environment = {
+ variables.MSCI_HOME = cfg.dataDir;
+ systemPackages = [self.packages."${system}".msci];
+ };
+ systemd.tmpfiles.settings."makeshiftci" = {
+ "${cfg.dataDir}" = {
+ d = {
+ user =
+ if cfg.createUser
+ then "makeshiftci"
+ else "root";
+ group =
+ if cfg.createUser
+ then "makeshiftci"
+ else "root";
+ mode = "0750";
+ };
};
};
- };
- services.cron.enable = true;
- users = lib.mkIf cfg.createUser {
- users."makeshiftci" = {
- group = "makeshiftci";
- home = cfg.dataDir;
- useDefaultShell = true;
+ services.cron.enable = true;
+ users = lib.mkIf cfg.createUser {
+ users."makeshiftci" = {
+ group = "makeshiftci";
+ home = cfg.dataDir;
+ useDefaultShell = true;
+ };
};
- };
- };
+ }
+ // lib.mkIf cfg.webUI.enable {
+ systemd.services.makeshiftci-web = {
+ wantedBy = ["multi-user.target"];
+ unitConfig.ConditionUser =
+ if cfg.createUser
+ then "makeshiftci"
+ else "root";
+ serviceConfig = let
+ webui = pkgs.python3.withPackages (p:
+ with p; [
+ gunicorn
+ (callPackage self.packages."${system}".msci-web {})
+ ]);
+ in {
+ ExecStart =
+ "${webui}/bin/gunicorn "
+ + "-w ${cfg.webUI.workers} "
+ + "--timeout ${cfg.webUI.timeout} "
+ + "-b 127.0.0.1:${cfg.webUI.port} "
+ + "'web:create_app()'";
+ };
+ };
+ });
};
};
}