-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
nixos/sillytavern: add it #418452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
nixos/sillytavern: add it #418452
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
|
|
||
| let | ||
| cfg = config.services.sillytavern; | ||
| defaultUser = "sillytavern"; | ||
| defaultGroup = "sillytavern"; | ||
| in | ||
| { | ||
| meta.maintainers = [ | ||
| lib.maintainers.wrvsrx | ||
| lib.maintainers.A1ca7raz | ||
| ]; | ||
|
|
||
| options = { | ||
| services.sillytavern = { | ||
| enable = lib.mkEnableOption "sillytavern"; | ||
|
|
||
| user = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = defaultUser; | ||
| description = '' | ||
| User account under which the web-application run. | ||
| ''; | ||
| }; | ||
| group = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = defaultGroup; | ||
| description = '' | ||
| Group account under which the web-application run. | ||
| ''; | ||
| }; | ||
|
|
||
| package = lib.mkPackageOption pkgs "sillytavern" { }; | ||
|
|
||
| configFile = lib.mkOption { | ||
| type = lib.types.path; | ||
| default = "${pkgs.sillytavern}/lib/node_modules/sillytavern/config.yaml"; | ||
| defaultText = lib.literalExpression "\${pkgs.sillytavern}/lib/node_modules/sillytavern/config.yaml"; | ||
| description = '' | ||
| Path to the SillyTavern configuration file. | ||
| ''; | ||
| }; | ||
|
|
||
| port = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.port; | ||
| default = null; | ||
| example = 8045; | ||
| description = '' | ||
| Port on which SillyTavern will listen. | ||
| ''; | ||
| }; | ||
|
|
||
| listenAddressIPv4 = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.str; | ||
| default = null; | ||
| example = "127.0.0.1"; | ||
| description = '' | ||
| Specific IPv4 address to listen to. | ||
| ''; | ||
| }; | ||
|
|
||
| listenAddressIPv6 = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.str; | ||
| default = null; | ||
| example = "::1"; | ||
| description = '' | ||
| Specific IPv6 address to listen to. | ||
| ''; | ||
| }; | ||
|
|
||
| listen = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.bool; | ||
| default = null; | ||
| example = true; | ||
| description = '' | ||
| Whether to listen on all network interfaces. | ||
| ''; | ||
| }; | ||
|
|
||
| whitelist = lib.mkOption { | ||
| type = lib.types.nullOr lib.types.bool; | ||
| default = null; | ||
| example = true; | ||
| description = '' | ||
| Enables whitelist mode. | ||
| ''; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
| systemd.services.sillytavern = { | ||
| description = "Silly Tavern"; | ||
| after = [ "network.target" ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
wrvsrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # required by sillytavern's extension manager | ||
| path = [ pkgs.git ]; | ||
wrvsrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| environment.XDG_DATA_HOME = "%S"; | ||
| serviceConfig = { | ||
| Type = "simple"; | ||
| ExecStart = | ||
| let | ||
| f = x: name: lib.optional (x != null) "--${name}=${builtins.toString x}"; | ||
| in | ||
| lib.concatStringsSep " " ( | ||
| [ | ||
| "${lib.getExe pkgs.sillytavern}" | ||
| ] | ||
| ++ f cfg.port "port" | ||
| ++ f cfg.listen "listen" | ||
| ++ f cfg.listenAddressIPv4 "listenAddressIPv4" | ||
| ++ f cfg.listenAddressIPv6 "listenAddressIPv6" | ||
| ++ f cfg.whitelist "whitelist" | ||
| ); | ||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| Restart = "always"; | ||
| StateDirectory = "SillyTavern"; | ||
| BindPaths = [ | ||
| "%S/SillyTavern/extensions:${pkgs.sillytavern}/lib/node_modules/sillytavern/public/scripts/extensions/third-party" | ||
| ]; | ||
wrvsrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Security hardening | ||
| CapabilityBoundingSet = [ "" ]; | ||
| LockPersonality = true; | ||
| NoNewPrivileges = true; | ||
| PrivateDevices = true; | ||
| PrivateTmp = true; | ||
| ProtectClock = true; | ||
| ProtectControlGroups = true; | ||
| ProtectHome = true; | ||
| ProtectHostname = true; | ||
| ProtectKernelLogs = true; | ||
| ProtectKernelModules = true; | ||
| ProtectKernelTunables = true; | ||
| ProtectProc = "invisible"; | ||
| ProtectSystem = "strict"; | ||
| }; | ||
| }; | ||
|
|
||
| users.users.${cfg.user} = lib.mkIf (cfg.user == defaultUser) { | ||
| description = "sillytavern service user"; | ||
| isSystemUser = true; | ||
| inherit (cfg) group; | ||
| }; | ||
|
|
||
| users.groups.${cfg.group} = lib.mkIf (cfg.group == defaultGroup) { }; | ||
wrvsrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| systemd.tmpfiles.settings.sillytavern = { | ||
| "/var/lib/SillyTavern/data".d = { | ||
| mode = "0700"; | ||
| inherit (cfg) user group; | ||
| }; | ||
| "/var/lib/SillyTavern/extensions".d = { | ||
| mode = "0700"; | ||
| inherit (cfg) user group; | ||
| }; | ||
| "/var/lib/SillyTavern/config.yaml"."L+" = { | ||
| mode = "0600"; | ||
| argument = cfg.configFile; | ||
| inherit (cfg) user group; | ||
| }; | ||
| }; | ||
wrvsrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.