ozai-webui/flake.nix

106 lines
3.9 KiB
Nix
Raw Normal View History

2024-03-23 17:49:50 +01:00
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
2024-03-24 00:48:43 +01:00
outputs = { self, nixpkgs}:
2024-03-23 17:49:50 +01:00
let
2024-03-24 00:48:43 +01:00
supportedSystems = [ "x86_64-linux"];
2024-03-23 17:49:50 +01:00
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
2024-03-24 00:48:43 +01:00
lib = forAllSystems (system: nixpkgs.legacyPackages.${system}).lib;
2024-03-24 03:38:24 +01:00
types = forAllSystems (system: nixpkgs.legacyPackages.${system}).lib.types;
2024-03-23 17:49:50 +01:00
in
{
2024-03-24 03:38:24 +01:00
packages = forAllSystems (system:
let
2024-03-24 00:48:43 +01:00
python = pkgs.${system}.python3.withPackages (ps: [ps.flask ps.flask-socketio]);
ozaiWebui = import ./default.nix { inherit (pkgs.${system}) pkgs; };
2024-03-23 17:49:50 +01:00
in {
2024-03-24 00:48:43 +01:00
default = ozaiWebui;
2024-03-23 17:49:50 +01:00
});
2024-03-24 03:38:24 +01:00
devShells = forAllSystems (system:
let
2024-03-24 00:48:43 +01:00
python = pkgs.${system}.python3.withPackages (ps: [ps.flask ps.flask-socketio]);
2024-03-23 17:49:50 +01:00
in {
default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [
2024-03-24 00:48:43 +01:00
python
2024-03-23 17:49:50 +01:00
];
};
});
2024-03-24 00:48:43 +01:00
nixosModules = forAllSystems (system: let
ozaiWebui = import ./default.nix { inherit (pkgs.${system}) pkgs; };
2024-03-24 03:38:24 +01:00
lib = pkgs.${system}.lib;
types = pkgs.${system}.lib.types;
2024-03-24 00:48:43 +01:00
in {
ozai-webui = { config, pkgs, ... }: {
options.services.ozai-webui = {
enable = lib.mkEnableOption "Ozai WebUI";
host = lib.mkOption {
type = types.str;
default = "127.0.0.1";
description = "The host to run the server on";
};
port = lib.mkOption {
type = types.int;
default = 8080;
description = "The port to run the server on";
};
ozaiUrl = lib.mkOption {
type = types.str;
default = "http://localhost:8000/api/";
description = "The URL of the Ozai server";
};
secretKey = lib.mkOption {
type = types.str;
default = "secret_key";
description = "The secret key for the Flask app";
};
};
config = lib.mkIf config.services.ozai-webui.enable {
systemd.services.ozai-webui = {
description = "Ozai WebUI";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
2024-03-24 03:38:24 +01:00
ExecStart = "${ozaiWebui}/bin/ozai-webui --port ${toString config.services.ozai-webui.port} --host '${config.services.ozai-webui.host}' --ozai_url '${config.services.ozai-webui.ozaiUrl}' --secret_key '${config.services.ozai-webui.secretKey}' --static_folder '/share/ozai-webui/static' --template_folder '/share/ozai-webui/templates'";
2024-03-24 00:48:43 +01:00
Restart = "always";
};
};
};
};
});
2024-03-24 03:38:24 +01:00
nixosConfigurations = {
ozai-webui = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
self.nixosModules.x86_64-linux.ozai-webui
{
system.stateVersion = "23.11";
boot.isContainer = true;
services.ozai-webui.enable = true;
}
];
};
};
# nixosConfigurations = forAllSystems (system: {
# ozai-webui = { config, pkgs, ... }: {
# modules = [
# self.systems.${system}.nixosModules.ozai-webui
# {
# system.stateVersion = "23.11";
# boot.isContainer = true;
# services.ozai-webui.enable = true;
# }
# ];
# };
# });
2024-03-24 00:48:43 +01:00
};
}