files.nim

Nim code to create an command

It includes some helpers and libraries for laziness, so it better fit prototyping and simples commands/script.

Vars:

  • PRJ_ROOT : devshell PRJ_ROOT env information
  • ARGS : Arguments command arguments
  • NO_ARGS : empty arguments
  • PWD : DirPath "."
  • All devshell like: let PRJ_DATA_DIR = env "PRJ_DATA_DIR"

Procs:

  • arg : get arg n, default="", ie. 1.arg
  • env : get env name, default="", ie. "PRJ_DATA_DIR".env
  • cd : set current dir
  • exec : execute {cmd}, args=NO_ARGS, dir=".".dirPath
  • jPath: creates a path to access json ie: "foo/0/^1/0..1/0..^1/bar".jPath
    • / : concat paths, ie: myPath / "blerg" / 0 / ^1 / 0 .. 1 / 0 .. ^1/baz
    • get : get JsonNode in path of object, myPath.get myObj
    • [] : get JsonNode in pat of object, myObj[myPath]
    • set : set JsonNode in path of object, myPath.set myObj, myVal
    • []= : set JsonNode in path of object, myObj[myPath] = myVal

Using:

  • sep : string
  • dir : string
  • path: JsonPath
  • obj : JsonNode

Imports:

  • Import almost all std libraries

Flags:

  • -w:off -d:ssl --threads:on --mm:orc --hints:off --parallelBuild:4 --tlsEmulation:on

Todo:

  • Add an option to configure flags
  • Add an option for static linking

Examples:

# examples/nim.nix
{pkgs, ...}:{
  # compile nim files and them to shell
  files.nim.helloNim    = ''echo ARGS'';
  # keep an /tmp file with last result for n seconds
  files.nim.memoise     = builtins.readFile ./nim/memoise.nim;
  # clustersSTS is a good candidate to be used with services
  files.nim.clustersSTS = builtins.readFile ./nim/clustersSTS.nim;
  # our poor man jq alternative
  files.nim.jsonildo    = builtins.readFile ./nim/jsonildo.nim;
  files.nim.helloNimAgain.deps = [ pkgs.termbox pkgs.nimPackages.nimbox ];
  files.nim.helloNimAgain.src  = ''
    import nimbox
    proc main() =
      var nb = newNimbox()
      defer: nb.shutdown()
    
      nb.print(0, 0, "Hello, world!")
      nb.present()
      sleep(1000)
    
    when isMainModule:
      main()
  '';
}

```</para>

#### type

attribute set of ((submodule) or Concatenated string)

#### example

```nix
{
  files.nim = {
    dokr = ''
      // create an docker compose alias
      // cd $PRJ_ROOT/subdir; docker "compose" $@
      exec "docker", "compose" + ARGS, PRJ_ROOT / "subdir"
    '';
    hello = ''
      #compile-at-mkshell
      
      # by default nim commands were compiled at first run to reduce
      # shell activation time, add comment #compile-at-mkshell to 
      # compile at shell activation
      echo "hello"
    '';
    manage = ''
      // create an pipenv alias
      // pipenv run python ./manage.py
      exec "pipenv", args("run python ./manage.py") + ARGS
    '';
  };
}

default

{
  files.nim = { };
}