ozai-webui/flake.nix

106 lines
3.9 KiB
Nix

{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { self, nixpkgs}:
let
supportedSystems = [ "x86_64-linux"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
lib = forAllSystems (system: nixpkgs.legacyPackages.${system}).lib;
types = forAllSystems (system: nixpkgs.legacyPackages.${system}).lib.types;
in
{
packages = forAllSystems (system:
let
python = pkgs.${system}.python3.withPackages (ps: [ps.flask ps.flask-socketio]);
ozaiWebui = import ./default.nix { inherit (pkgs.${system}) pkgs; };
in {
default = ozaiWebui;
});
devShells = forAllSystems (system:
let
python = pkgs.${system}.python3.withPackages (ps: [ps.flask ps.flask-socketio]);
in {
default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [
python
];
};
});
nixosModules = forAllSystems (system: let
ozaiWebui = import ./default.nix { inherit (pkgs.${system}) pkgs; };
lib = pkgs.${system}.lib;
types = pkgs.${system}.lib.types;
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 = {
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'";
Restart = "always";
};
};
};
};
});
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;
# }
# ];
# };
# });
};
}