Nix-writers: Difference between revisions
imported>Lassulus No edit summary |
m Add category nix language |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
Nix-writers are a way to write other programming languages inline in nix-code. | Nix-writers are a way to write other programming languages inline in nix-code. | ||
They are like writeScript/writeScriptBin but for other languages. | |||
Every writer has a ...Bin variant which can be used inside environment.systemPackages. | Every writer has a ...Bin variant which can be used inside environment.systemPackages. | ||
Most of the writers take an attrributeset where one can add libraries. | Most of the writers take an attrributeset where one can add libraries. | ||
These are declared in [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/writers/scripts.nix <code>/pkgs/build-support/writers/scripts.nix</code>]. | |||
== Languages == | == Languages == | ||
Line 14: | Line 16: | ||
pkgs.writers.writeBash "hello_world" '' | pkgs.writers.writeBash "hello_world" '' | ||
echo 'hello world!' | echo 'hello world!' | ||
'' | '' | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 82: | Line 68: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
writePython2 "test_python2" { | writePython2 "test_python2" { | ||
deps = [ pkgs.python2Packages.enum ]; | |||
} '' | } '' | ||
from enum import Enum | from enum import Enum | ||
Line 107: | Line 93: | ||
'' | '' | ||
</syntaxHighlight> | </syntaxHighlight> | ||
To disable errors use 'flakeIgnore' like this: | |||
<syntaxHighlight lang=nix> | |||
writePython3 "test_python3" { | |||
libraries = [ pkgs.python3Packages.pyyaml ]; | |||
flakeIgnore = [ "E265" "E225" ]; | |||
} '' | |||
import yaml | |||
y = yaml.load(""" | |||
- test: success | |||
""") | |||
print(y[0]['test']) | |||
'' | |||
</syntaxHighlight> | |||
[[Category:Nix Language]] |