tristanpemble / nix-nomad

HashiCorp Nomad job definitions in Nix
https://tristanpemble.github.io/nix-nomad/
MIT License
66 stars 6 forks source link

how to use it with terranix #5

Closed cliarena closed 1 year ago

cliarena commented 1 year ago

hi.

is there an example of how to use it with terranix. how to pass hello.nix to resource.nomad_job

thank you so much

cliarena commented 1 year ago

it looks like i needed to use it like that:

  jobs = nix-nomad.lib.mkNomadJobs {
    system = "x86_64-linux";
    # system = "aarch64-linux";
    config = [ ./nginx.nix ];
  };

resource.nomad_job.nginx = {
    jobspec = ''''${file("${jobs}/nginx.json")}'';
    json = true;
  };
tristanpemble commented 1 year ago

yep, that's one way to do it. there's a few other ways you could do it. my preference is to actually include the nix-nomad module in my terranix config and reference nomad.build.apiJobFile. I'm on vacation in Europe atm and can't check the exact config, but I think something along the lines of this works:

{ config, ... }:

let
  inherit (config.nomad.build) apiJobFile;
in

{
  imports = [
    "${nix-nomad}/modules"
  ];

  job.foo.group.foo.task.foo = {
    driver = "raw_exec";
    config.command = "echo";
  };

  resource.nomad_job.nginx = {
    jobspec = apiJobFile.foo;
    json = true;
  };
}

this gives you a lot of control/modularity for your infra

KiaraGrouwstra commented 9 months ago

i think the jobspec line should be:

    jobspec = lib.strings.toJSON apiJob.foo;

(importing apiJob over apiJobFile earlier)