Unverified Commit 64046f01 authored by lassulus's avatar lassulus Committed by GitHub
Browse files

writers: add writeNim and writeNimBin (#338857)

parents 5f821de2 ca23669c
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -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

+27 −0
Original line number Diff line number Diff line
@@ -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"
        {