9 format = pkgs.formats.yaml { };
10 cfg = config.services.private-gpt;
14 services.private-gpt = {
15 enable = lib.mkEnableOption "private-gpt for local large language models";
16 package = lib.mkPackageOption pkgs "private-gpt" { };
18 stateDir = lib.mkOption {
20 default = "/var/lib/private-gpt";
21 description = "State directory of private-gpt.";
24 settings = lib.mkOption {
36 embedding_model = "nomic-embed-text";
37 api_base = "http://localhost:11434";
38 embedding_api_base = "http://localhost:11434";
45 request_timeout = 120;
51 path = "/var/lib/private-gpt/vectorstore/qdrant";
54 local_data_folder = "/var/lib/private-gpt";
60 settings-local.yaml for private-gpt
66 config = lib.mkIf cfg.enable {
67 systemd.services.private-gpt = {
68 description = "Interact with your documents using the power of GPT, 100% privately, no data leaks";
69 wantedBy = [ "multi-user.target" ];
70 after = [ "network.target" ];
74 config = format.generate "settings-local.yaml" (cfg.settings // { server.env_name = "local"; });
77 mkdir -p ${cfg.stateDir}/{settings,huggingface,matplotlib,tiktoken_cache}
78 cp ${cfg.package.cl100k_base.tiktoken} ${cfg.stateDir}/tiktoken_cache/9b5ad71b2ce5302211f9c61530b329a4922fc6a4
79 cp ${pkgs.python3Packages.private-gpt}/${pkgs.python3.sitePackages}/private_gpt/settings.yaml ${cfg.stateDir}/settings/settings.yaml
80 cp "${config}" "${cfg.stateDir}/settings/settings-local.yaml"
81 chmod 600 "${cfg.stateDir}/settings/settings-local.yaml"
85 PGPT_PROFILES = "local";
86 PGPT_SETTINGS_FOLDER = "${cfg.stateDir}/settings";
87 HF_HOME = "${cfg.stateDir}/huggingface";
88 TRANSFORMERS_OFFLINE = "1";
89 HF_DATASETS_OFFLINE = "1";
90 MPLCONFIGDIR = "${cfg.stateDir}/matplotlib";
94 ExecStart = lib.getExe cfg.package;
95 WorkingDirectory = cfg.stateDir;
96 StateDirectory = "private-gpt";
97 RuntimeDirectory = "private-gpt";
98 RuntimeDirectoryMode = "0755";
101 DevicePolicy = "closed";
102 LockPersonality = true;
103 MemoryDenyWriteExecute = true;
106 ProtectHostname = true;
107 ProtectKernelLogs = true;
108 ProtectKernelModules = true;
109 ProtectKernelTunables = true;
110 ProtectControlGroups = true;
112 RestrictNamespaces = true;
113 RestrictRealtime = true;
114 SystemCallArchitectures = "native";
120 meta.maintainers = [ ];