Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ automatically setup these arbitrary injections.
- `programs.firefox.profiles.*.userChrome`
* Wezterm (lua language)
- `programs.wezterm.extraConfig`
* Nginx (nginx language)
- `services.nginx.config`
- `services.nginx.eventsConfig`
- `services.nginx.streamConfig`
- `services.nginx.prependConfig`
- `services.nginx.appendConfig`
- `services.nginx.httpConfig`
- `services.nginx.commonHttpConfig`
- `services.nginx.appendHttpConfig`
- `services.nginx.upstreams.*.extraConfig`
- `services.nginx.virtualHosts.*.extraConfig`
- `services.nginx.virtualHosts.*.locations.*.extraConfig`
- `services.*.nginx.extraConfig`
- `services.*.nginx.locations.*.extraConfig`
</details>

> [!Warning]
Expand Down
50 changes: 50 additions & 0 deletions queries/nix/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,53 @@
(#set! injection.language "css")
(#set! injection.combined)
)

; Nginx
; https://search.nixos.org/options?query=services.nginx.%20config
(binding
attrpath: (_) @_path (#hmts-path? @_path "services" "nginx" "((events|stream|(prep|app)end)C|c)onfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)
(binding
attrpath: (_) @_path (#hmts-path? @_path "services" "nginx" "((append|common)H|h)ttpConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)
Comment on lines +127 to +138

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two binding blocks are very similar and can be combined into one for better conciseness and maintainability. You can merge the two regular expressions for the attribute path using an | operator.

(binding
  attrpath: (_) @_path (#hmts-path? @_path "services" "nginx" "(((events|stream|(prep|app)end)C|c)onfig|((append|common)H|h)ttpConfig)")
  expression: (_ (string_fragment) @injection.content)
  (#set! injection.language "nginx")
  (#set! injection.combined)
)

@n0099 n0099 Jan 28, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're unrelated as *config lays under the top-level main context like many directives in the core module, and *HttpConfig is under the http context: https://nginx.org/en/docs/beginners_guide.html#Configuration%20File%E2%80%99s%20Structure:~:text=Configuration%20File%E2%80%99s%20Structure,-nginx


(binding
attrpath: (_) @_path (#hmts-path? @_path "services" "nginx" "upstreams" ".*" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)

(binding
attrpath: (_) @_path (#hmts-path? @_path "services" "nginx" "virtualHosts" ".*" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)
(binding
attrpath: (_) @_path (#hmts-path? @_path "services" "nginx" "virtualHosts" ".*" "locations" ".*" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)
Comment on lines +140 to +158

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These three binding blocks for extraConfig under services.nginx are identical except for the hmts-path? predicate. They can be consolidated into a single binding by using a list of predicates [...] to represent alternatives. This improves readability and reduces code duplication.

(binding
  attrpath: ((_) @_path
    [
      (#hmts-path? @_path "services" "nginx" "upstreams" ".*" "extraConfig")
      (#hmts-path? @_path "services" "nginx" "virtualHosts" ".*" "extraConfig")
      (#hmts-path? @_path "services" "nginx" "virtualHosts" ".*" "locations" ".*" "extraConfig")
    ]
  )
  expression: (_ (string_fragment) @injection.content)
  (#set! injection.language "nginx")
  (#set! injection.combined)
)

@n0099 n0099 Jan 28, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't work, bro.


; https://search.nixos.org/options?query=services.%20nginx.%20config
; https://github.com/search?q=repo%3ANixOS%2Fnixpkgs%20nginx%2Fvhost-options.nix&type=code
(binding
attrpath: (_) @_path (#hmts-path? @_path "services" ".*" "nginx" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)
(binding
attrpath: (_) @_path (#hmts-path? @_path "services" ".*" "nginx" "locations" ".*" "extraConfig")
expression: (_ (string_fragment) @injection.content)
(#set! injection.language "nginx")
(#set! injection.combined)
)
Comment on lines +162 to +173

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the previous comments, these two binding blocks can be merged into one. Using a list of predicates [...] for the attrpath will make the query more compact and easier to maintain.

(binding
  attrpath: ((_) @_path
    [
      (#hmts-path? @_path "services" ".*" "nginx" "extraConfig")
      (#hmts-path? @_path "services" ".*" "nginx" "locations" ".*" "extraConfig")
    ]
  )
  expression: (_ (string_fragment) @injection.content)
  (#set! injection.language "nginx")
  (#set! injection.combined)
)