{"id":23008109,"url":"https://github.com/tristanpemble/nix-nomad","last_synced_at":"2026-04-04T23:43:47.389Z","repository":{"id":40683666,"uuid":"466898045","full_name":"tristanpemble/nix-nomad","owner":"tristanpemble","description":"HashiCorp Nomad job definitions in Nix","archived":false,"fork":false,"pushed_at":"2025-01-30T03:42:21.000Z","size":182,"stargazers_count":72,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-13T21:06:18.507Z","etag":null,"topics":["nix","nomad"],"latest_commit_sha":null,"homepage":"https://tristanpemble.github.io/nix-nomad/","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tristanpemble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-07T01:01:08.000Z","updated_at":"2025-09-07T21:45:27.000Z","dependencies_parsed_at":"2025-08-14T04:32:20.106Z","dependency_job_id":"bdd93d25-3b9a-48c6-ae20-a09e2b221e43","html_url":"https://github.com/tristanpemble/nix-nomad","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tristanpemble/nix-nomad","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristanpemble%2Fnix-nomad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristanpemble%2Fnix-nomad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristanpemble%2Fnix-nomad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristanpemble%2Fnix-nomad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tristanpemble","download_url":"https://codeload.github.com/tristanpemble/nix-nomad/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristanpemble%2Fnix-nomad/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31419543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nix","nomad"],"created_at":"2024-12-15T09:00:43.714Z","updated_at":"2026-04-04T23:43:47.370Z","avatar_url":"https://github.com/tristanpemble.png","language":"Nix","funding_links":[],"categories":["Infrastructure setup"],"sub_categories":["Automation and Infrastructure Management"],"readme":"# Disclaimer\n\nThis project is still in an early proof of concept stage. While I will soon be rolling this out in production at work,\ndeploying dozens of services across multiple environments, hundreds of times daily, the API may change without\ndocumentation or warning.\n\n# nix-nomad\n\nGenerate [HashiCorp Nomad](https://nomadproject.io) JSON job files with [Nix](https://nixos.org) using\n[NixOS modules](https://github.com/NixOS/nixpkgs/blob/master/lib/modules.nix).\n\n## Why?\n\nOn its own, if used for a single job definition, this is overkill. However, NixOS modules becomes most  powerful when\nworking with many job definitions across multiple environments. You can compose jobs as modules, and create an API for\nconfiguring each environment by defining your own NixOS module options.\n\nThe goal of this project is, if used with a tool like [terranix](https://terranix.org), to help adopt a fully Nix-ified HashiCorp stack.\n\n## Usage\n\n### Overview\n\nThe `mkNomadJobs` function takes in a module, path to a module, a list of modules, or a list of paths to modules. The\noutput is an attrset where each attr is a derivation that builds a JSON job file for the Nomad job of the same name.\n\nModule options are enumerated in [the documentation](https://tristanpemble.github.io/nix-nomad/).\n\n```nix\nmkNomadJobs {\n  pkgs = import \u003cnixpkgs\u003e {};\n  config = {\n    job.hello = {\n      type = \"batch\";\n      datacenters = [\"dc1\"];\n\n      group.webs = {\n        count = 1;\n\n        task.frontend = {\n          driver = \"raw_exec\";\n\n          config = {\n            command = \"echo\";\n            args = [\"hello\"];\n          };\n        };\n      };\n\n      update = with time; {\n        healthyDeadline = 15 * minute;\n        progressDeadline = 1 * hour;\n      };\n    };\n  };\n}\n```\n\nThe above example evaluates to a derivation, that when built, outputs a folder containing a file named \"hello.json\".\nThe contents of the file, when prettified for readability, look like:\n\n```json\n{\n  \"Datacenters\": [\n    \"dc1\"\n  ],\n  \"ID\": \"hello\",\n  \"Name\": \"hello\",\n  \"TaskGroups\": [\n    {\n      \"Count\": 1,\n      \"Name\": \"webs\",\n      \"Tasks\": [\n        {\n          \"Config\": {\n            \"args\": [\n              \"hello\"\n            ],\n            \"command\": \"echo\"\n          },\n          \"Driver\": \"raw_exec\",\n          \"Name\": \"frontend\"\n        }\n      ]\n    }\n  ],\n  \"Type\": \"batch\",\n  \"Update\": {\n    \"HealthyDeadline\": 900000000000,\n    \"ProgressDeadline\": 3600000000000\n  }\n}\n```\n\nYou can run this job with the Nomad CLI on Nomad v1.3 and later:\n\n```bash\nnomad run -json ./result/hello.json\n```\n\nOlder versions of Nomad will require using Nomad's JSON API to run the job.\n\n### Migrating from HCL\n\nYou can import an HCL job file using the method `importNomadModule`. It takes a path to an HCL job file, and an attrset\nof variables to pass to the job.\n\n```nix\n{ lib, ... }:\n\n{\n  imports = [\n    (lib.importNomadModule ./my-job.hcl { foo = \"bar\"; })\n  ];\n  \n  job.my-job.region = lib.mkForce \"global\";  \n}\n```\n\nThis is using [import from derivation](https://nixos.wiki/wiki/Import_From_Derivation) with the `nomad job run -output [file]`\ncommand; so it will be pretty slow. This is best used as an intermediate step for migrating your jobs to Nix.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftristanpemble%2Fnix-nomad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftristanpemble%2Fnix-nomad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftristanpemble%2Fnix-nomad/lists"}