Nix-writers: Difference between revisions

imported>MrVanDalo
No edit summary
Pigs (talk | contribs)
m Add category nix language
 
(5 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.
Basically it's like writeScript/writeScriptBin but for other Languages.
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>
===C===
<syntaxHighlight lang=nix>
pkgs.writers.writeC "hello-world-ncurses" {
  libraries = [ pkgs.ncurses ];
} ''
  #include <ncurses.h>
  int main() {
    initscr();
    printw("Hello World !!!");
    refresh(); endwin();
    return 0;
  }
''
''
</syntaxHighlight>
</syntaxHighlight>
Line 97: Line 83:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
writePython3 "test_python3" {
writePython3 "test_python3" {
   deps = [ pkgs.python3Packages.pyyaml ];
   libraries = [ pkgs.python3Packages.pyyaml ];
} ''
} ''
   import yaml
   import yaml
Line 108: Line 94:
</syntaxHighlight>
</syntaxHighlight>


For disable errors use `flakeIgnore`
To disable errors use 'flakeIgnore' like this:
 
<syntaxHighlight lang=nix>
writePython3 "test_python3" {
writePython3 "test_python3" {
   deps = [ pkgs.python3Packages.pyyaml ];
   libraries = [ pkgs.python3Packages.pyyaml ];
   flakeIgnore = [ "E265" "E225" ];
   flakeIgnore = [ "E265" "E225" ];
} ''
} ''
Line 121: Line 109:
''
''
</syntaxHighlight>
</syntaxHighlight>
[[Category:Nix Language]]