File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed
pkgs/build-support/writers Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -651,6 +651,53 @@ rec {
651651 */
652652 writeHaskellBin = name : writeHaskell "/bin/${ name } " ;
653653
654+ /**
655+ writeNim takes a name, an attrset with an optional Nim compiler, and some
656+ Nim source code, returning an executable.
657+
658+ # Examples
659+ :::{.example}
660+ ## `pkgs.writers.writeNim` usage example
661+
662+ ```nix
663+ writeNim "hello-nim" { nim = pkgs.nim2; } ''
664+ echo "hello nim"
665+ '';
666+ ```
667+ :::
668+ */
669+ writeNim =
670+ name :
671+ {
672+ makeWrapperArgs ? [ ] ,
673+ nim ? pkgs . nim2 ,
674+ nimCompileOptions ? { } ,
675+ strip ? true ,
676+ } :
677+ let
678+ nimCompileCmdArgs = lib . cli . toGNUCommandLineShell { optionValueSeparator = ":" ; } (
679+ {
680+ d = "release" ;
681+ nimcache = "." ;
682+ }
683+ // nimCompileOptions
684+ ) ;
685+ in
686+ makeBinWriter {
687+ compileScript = ''
688+ cp $contentPath tmp.nim
689+ ${ lib . getExe nim } compile ${ nimCompileCmdArgs } tmp.nim
690+ mv tmp $out
691+ '' ;
692+ inherit makeWrapperArgs strip ;
693+ } name ;
694+
695+ /**
696+ writeNimBin takes the same arguments as writeNim but outputs a directory
697+ (like writeScriptBin)
698+ */
699+ writeNimBin = name : writeNim "/bin/${ name } " ;
700+
654701 /**
655702 Like writeScript but the first line is a shebang to nu
656703
Original file line number Diff line number Diff line change 3131 writeJSBin
3232 writeJSON
3333 writeLua
34+ writeNim
35+ writeNimBin
3436 writeNu
3537 writePerl
3638 writePerlBin
@@ -109,6 +111,10 @@ recurseIntoAttrs {
109111 _ -> print "fail"
110112 '' ) ;
111113
114+ nim = expectSuccessBin ( writeNimBin "test-writers-nim-bin" { } ''
115+ echo "success"
116+ '' ) ;
117+
112118 js = expectSuccessBin ( writeJSBin "test-writers-js-bin" { libraries = [ nodePackages . semver ] ; } ''
113119 var semver = require('semver');
114120
@@ -191,6 +197,10 @@ recurseIntoAttrs {
191197 end
192198 '' ) ;
193199
200+ nim = expectSuccess ( writeNim "test-writers-nim" { } ''
201+ echo "success"
202+ '' ) ;
203+
194204 nu = expectSuccess ( writeNu "test-writers-nushell" ''
195205 echo "success"
196206 '' ) ;
@@ -411,6 +421,23 @@ recurseIntoAttrs {
411421 ''
412422 ) ;
413423
424+ nim = expectSuccess (
425+ writeNim "test-writers-wrapping-nim"
426+ {
427+ makeWrapperArgs = [
428+ "--set"
429+ "ThaigerSprint"
430+ "Thailand"
431+ ] ;
432+ }
433+ ''
434+ import os
435+
436+ if getEnv("ThaigerSprint") == "Thailand":
437+ echo "success"
438+ ''
439+ ) ;
440+
414441 python = expectSuccess (
415442 writePython3 "test-writers-wrapping-python"
416443 {
You can’t perform that action at this time.
0 commit comments