Nix-writers: Difference between revisions
imported>MrVanDalo No edit summary |
imported>Skylark m Minor copyedit |
||
(2 intermediate revisions by 2 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. | ||
Line 14: | Line 14: | ||
pkgs.writers.writeBash "hello_world" '' | pkgs.writers.writeBash "hello_world" '' | ||
echo 'hello world!' | echo 'hello world!' | ||
'' | '' | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 97: | Line 81: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
writePython3 "test_python3" { | writePython3 "test_python3" { | ||
libraries = [ pkgs.python3Packages.pyyaml ]; | |||
} '' | } '' | ||
import yaml | import yaml | ||
Line 108: | Line 92: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
To disable errors use 'flakeIgnore' like this: | |||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
writePython3 "test_python3" { | writePython3 "test_python3" { | ||
libraries = [ pkgs.python3Packages.pyyaml ]; | |||
flakeIgnore = [ "E265" "E225" ]; | flakeIgnore = [ "E265" "E225" ]; | ||
} '' | } '' |
Latest revision as of 18:33, 23 October 2023
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. Most of the writers take an attrributeset where one can add libraries.
Languages
bash
This is basically writeScript but with the shebang to bash already included.
pkgs.writers.writeBash "hello_world" ''
echo 'hello world!'
''
dash
pkgs.writers.writeDash "hello_world" ''
echo 'hello world!'
''
Haskell
writeHaskell "missiles" {
libraries = [ pkgs.haskellPackages.acme-missiles ];
} ''
import Acme.Missiles
main = launchMissiles
''
JavaScript
writeJS "example" {
libraries = [ pkgs.nodePackages.uglify-js ];
} ''
var UglifyJS = require("uglify-js");
var code = "function add(first, second) { return first + second; }";
var result = UglifyJS.minify(code);
console.log(result.code);
''
Perl
writePerl "example" {
libraries = [ pkgs.perlPackages.boolean ];
} ''
use boolean;
print "Howdy!\n" if true;
''
Python2
writePython2 "test_python2" {
deps = [ pkgs.python2Packages.enum ];
} ''
from enum import Enum
class Test(Enum):
a = "success"
print Test.a
''
Python3
writePython3 "test_python3" {
libraries = [ pkgs.python3Packages.pyyaml ];
} ''
import yaml
y = yaml.load("""
- test: success
""")
print(y[0]['test'])
''
To disable errors use 'flakeIgnore' like this:
writePython3 "test_python3" {
libraries = [ pkgs.python3Packages.pyyaml ];
flakeIgnore = [ "E265" "E225" ];
} ''
import yaml
y = yaml.load("""
- test: success
""")
print(y[0]['test'])
''