mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
writers: add writeNim and writeNimBin
This adds convenience writers for self-contained Nim programs. Those are compiled into very small binaries. Test with: `nix build .#pkgs.tests.writers.{bin,simple,wrapping}.nim`
This commit is contained in:
parent
1b42ea0abc
commit
ca23669cf8
@ -651,6 +651,53 @@ rec {
|
||||
*/
|
||||
writeHaskellBin = name: writeHaskell "/bin/${name}";
|
||||
|
||||
/**
|
||||
writeNim takes a name, an attrset with an optional Nim compiler, and some
|
||||
Nim source code, returning an executable.
|
||||
|
||||
# Examples
|
||||
:::{.example}
|
||||
## `pkgs.writers.writeNim` usage example
|
||||
|
||||
```nix
|
||||
writeNim "hello-nim" { nim = pkgs.nim2; } ''
|
||||
echo "hello nim"
|
||||
'';
|
||||
```
|
||||
:::
|
||||
*/
|
||||
writeNim =
|
||||
name:
|
||||
{
|
||||
makeWrapperArgs ? [ ],
|
||||
nim ? pkgs.nim2,
|
||||
nimCompileOptions ? { },
|
||||
strip ? true,
|
||||
}:
|
||||
let
|
||||
nimCompileCmdArgs = lib.cli.toGNUCommandLineShell { optionValueSeparator = ":"; } (
|
||||
{
|
||||
d = "release";
|
||||
nimcache = ".";
|
||||
}
|
||||
// nimCompileOptions
|
||||
);
|
||||
in
|
||||
makeBinWriter {
|
||||
compileScript = ''
|
||||
cp $contentPath tmp.nim
|
||||
${lib.getExe nim} compile ${nimCompileCmdArgs} tmp.nim
|
||||
mv tmp $out
|
||||
'';
|
||||
inherit makeWrapperArgs strip;
|
||||
} name;
|
||||
|
||||
/**
|
||||
writeNimBin takes the same arguments as writeNim but outputs a directory
|
||||
(like writeScriptBin)
|
||||
*/
|
||||
writeNimBin = name: writeNim "/bin/${name}";
|
||||
|
||||
/**
|
||||
Like writeScript but the first line is a shebang to nu
|
||||
|
||||
|
@ -31,6 +31,8 @@ let
|
||||
writeJSBin
|
||||
writeJSON
|
||||
writeLua
|
||||
writeNim
|
||||
writeNimBin
|
||||
writeNu
|
||||
writePerl
|
||||
writePerlBin
|
||||
@ -109,6 +111,10 @@ recurseIntoAttrs {
|
||||
_ -> print "fail"
|
||||
'');
|
||||
|
||||
nim = expectSuccessBin (writeNimBin "test-writers-nim-bin" { } ''
|
||||
echo "success"
|
||||
'');
|
||||
|
||||
js = expectSuccessBin (writeJSBin "test-writers-js-bin" { libraries = [ nodePackages.semver ]; } ''
|
||||
var semver = require('semver');
|
||||
|
||||
@ -191,6 +197,10 @@ recurseIntoAttrs {
|
||||
end
|
||||
'');
|
||||
|
||||
nim = expectSuccess (writeNim "test-writers-nim" { } ''
|
||||
echo "success"
|
||||
'');
|
||||
|
||||
nu = expectSuccess (writeNu "test-writers-nushell" ''
|
||||
echo "success"
|
||||
'');
|
||||
@ -411,6 +421,23 @@ recurseIntoAttrs {
|
||||
''
|
||||
);
|
||||
|
||||
nim = expectSuccess (
|
||||
writeNim "test-writers-wrapping-nim"
|
||||
{
|
||||
makeWrapperArgs = [
|
||||
"--set"
|
||||
"ThaigerSprint"
|
||||
"Thailand"
|
||||
];
|
||||
}
|
||||
''
|
||||
import os
|
||||
|
||||
if getEnv("ThaigerSprint") == "Thailand":
|
||||
echo "success"
|
||||
''
|
||||
);
|
||||
|
||||
python = expectSuccess (
|
||||
writePython3 "test-writers-wrapping-python"
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user