Nix Embedded Languages

Features
Syntax highlighting for embedded languages inside Nix multi-line strings ('' ... '').
Usage
Place # lang on its own line inside the string:
script = ''
# shell
echo "Hello, world!"
ls -la
'';
For clarity, use # syntax: lang:
script = ''
# syntax: python
def greet(name):
print(f"Hello, {name}!")
greet("World")
'';
For languages where // is a comment:
code = ''
// syntax: javascript
const greeting = "Hello!";
console.log(greeting);
'';
For languages without comments (like JSON), place the marker BEFORE the string as a Nix comment:
# syntax: json
configData = ''
{
"name": "example",
"version": "1.0.0"
}
'';
Built-In Languages
| Language |
Identifiers |
| Shell |
shell, bash, sh |
| Python |
python, py |
| JavaScript |
javascript, js |
| TypeScript |
typescript, ts |
| JSON |
json |
| YAML |
yaml, yml |
| SQL |
sql |
| Lua |
lua |
| Ruby |
ruby, rb |
| Rust |
rust, rs |
| Go |
go, golang |
| HTML |
html |
| CSS |
css |
| Nix |
nix |
Extension Settings
| Name |
Description |
nix-embedded-languages.include |
Add custom languages. Key is the identifier (supports regex), value is either the TextMate scope name or an object with name and scopeName (required) properties. |
Example Configuration
{
"nix-embedded-languages.include": {
"hcl|terraform": {
"name": "HCL/Terraform",
"scopeName": "source.hcl"
}
}
}
Requirements
- The Nix IDE extension (or another extension providing
source.nix grammar)
Contributing
- Install devenv
- Load development environment:
$ devenv shell