Configuration
Override

Override

Override allows users to modify certain fields in configuration files, commonly used to modify the content of managed or subscribed configurations. Stash allows multiple override files to be enabled simultaneously, and they will override the original configuration from top to bottom.

A best practice is to divide override files based on individual feature points for easier control and sharing.

Syntax Reference

  • Override files use the YAML format with the file extension .stoverride.
  • Typically, the name and desc fields are used as the name and description of the override file, and these two fields are only used for display purposes.
  • The override file modifies the configuration file according to the following rules:
    • For simple types with the same key, such as string, number, boolean, they will be directly overridden.
    • For dictionary types with the same key, they will be merged recursively according to the key.
    • For array types with the same key, the array in the override file will be inserted at the beginning of the configuration file array.
    • If a line comment #!replace is added after a dictionary or array key, it will be merged using the override method.
⚠️

Modifying elements in an array is not currently supported, and other syntax will be provided for modification in the future.

Common override examples:

name: Redirect BiliBili MCDN / PCDN to Regular CDN
desc: Cheers to a smoother BiliBili loading experience! 🍻
 
http:
  force-http-engine:
    - 'upos-*.bilivideo.com:80'
    - '*:4480'
    - '*:9102'
  url-rewrite:
    - https?:\/\/(.*):4480\/upgcxcode http://upos-sz-mirrorcos.bilivideo.com/upgcxcode 302
    - https?:\/\/(.*):9102\/upgcxcode http://upos-sz-mirrorcos.bilivideo.com/upgcxcode 302
    - https?:\/\/upos-.*-.*oss\d*\.bilivideo\.com\/upgcxcode http://upos-sz-mirrorcos.bilivideo.com/upgcxcode 302
    - https?:\/\/upos-sz-mirror(?!cos\.).*bilivideo\.com\/upgcxcode http://upos-sz-mirrorcos.bilivideo.com/upgcxcode 302
    # alternative:
    # upos-sz-mirrorhw.bilivideo.com
    # upos-sz-mirrorcos.bilivideo.com
    # upos-sz-mirrorcoso1.bilivideo.com
    # upos-sz-mirrorcoso2.bilivideo.com
    # upos-sz-mirrorbs.bilivideo.com
    # upos-sz-mirrorali.bilivideo.com
script:
  shortcuts:
    bilibili-quic: network == 'udp' and geoip(dst_ip) == 'CN' and dst_port == 3478
rules:
  - SCRIPT,bilibili-quic,REJECT

Override example using #!replace syntax:

name: Use Only CloudFlare DNS
dns:
  # This will completely replace the original default-nameserver
  default-nameserver: #!replace
    - system
    - 223.5.5.5
    - 1.0.0.1
  # This will completely replace the original nameserver
  nameserver: #!replace
    - https://1.0.0.1/dns-query # CF IPv4
    - https://[2606:4700:4700::1111]/dns-query # CF IPv6

Here is a simple merging example:

# config.yaml
dict:
  k1: true
  k2: 1
  k3:
    - 1
    - 2
    - 3
  k4:
    - 1
    - 2
    - 3
# override file
key: value
dict:
  k3:
    - 0
  k4: #!replace
    - 1
  k5: null
# after override
key: value
dict:
  k1: true
  k2: 1
  k3:
    - 0
    - 1
    - 2
    - 3
  k4:
    - 1
  k5: null