{"id":24311678,"url":"https://github.com/aanderse/teraflops","last_synced_at":"2025-09-26T17:31:22.053Z","repository":{"id":222404660,"uuid":"757193188","full_name":"aanderse/teraflops","owner":"aanderse","description":"a terraform ops tool which is sure to be a flop","archived":false,"fork":false,"pushed_at":"2024-12-16T20:15:45.000Z","size":106,"stargazers_count":44,"open_issues_count":7,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-12-16T20:22:51.002Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/aanderse.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}},"created_at":"2024-02-14T01:21:42.000Z","updated_at":"2024-12-16T20:15:49.000Z","dependencies_parsed_at":"2024-03-22T21:28:36.394Z","dependency_job_id":"78ce20b6-281e-406c-b143-106855298994","html_url":"https://github.com/aanderse/teraflops","commit_stats":null,"previous_names":["aanderse/teraflops"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aanderse%2Fteraflops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aanderse%2Fteraflops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aanderse%2Fteraflops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aanderse%2Fteraflops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aanderse","download_url":"https://codeload.github.com/aanderse/teraflops/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234325223,"owners_count":18814395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-01-17T07:13:39.446Z","updated_at":"2025-09-26T17:31:21.764Z","avatar_url":"https://github.com/aanderse.png","language":"Nix","readme":"# teraflops\n\n\u003e `teraflops` - a terraform ops tool which is sure to be a flop\n\n`teraflops` aims to provide an integrated experience for deployment workflows which involve both [terraform](https://github.com/hashicorp/terraform) and [NixOS](https://github.com/NixOS/nixos) - similar to that of [NixOps](https://github.com/NixOS/nixops). `teraflops` uses the excellent [colmena](https://github.com/zhaofengli/colmena) deployment tool to do most of the heavy lifting, so the following example should look somewhat familiar if you have ever used `colmena`.\n\n```nix\n{\n  inputs = {\n    nixpkgs.url = \"github:NixOS/nixpkgs/nixos-unstable\";\n    teraflops.url = \"github:aanderse/teraflops\";\n  };\n\n  outputs = { nixpkgs, teraflops, ... }: {\n    teraflops = {\n      imports = [ teraflops.modules.hcloud ];\n\n      meta = {\n        nixpkgs = import nixpkgs {\n          system = \"x86_64-linux\";\n        };\n      };\n\n      machine = { pkgs, ... }: {\n        deployment.targetEnv = \"hcloud\";\n        deployment.hcloud = {\n          server_type = \"cx11\";\n          location = \"nbg1\";\n        };\n\n        environment.systemPackages = [ pkgs.htop ];\n      };\n\n      # if desired you can write terraform code directly inside your teraflops modules\n      terraform = {\n        backend.s3 = {\n          bucket = \"mybucket\";\n          key = \"path/to/my/key\";\n          region = \"us-east-1\";\n        };\n      };\n    };\n  }\n}\n```\n\n## Usage\n\nThe `teraflops` tool has a number of high level commands that often resemble the `NixOps` CLI.\n\n```sh\n# prepare your terraform state in the current working directory\nteraflops init\n\n# applies all terraform state and deploys your NixOS configuration\nteraflops deploy --reboot --confirm\n\n# perform some operational commands\nteraflops ssh-for-each -- df -h\nteraflops scp machine:/root/.ssh/id_ed25519.pub .\n\n# NixOS introspection\nteraflops repl\nteraflops eval '{ nodes, ... }: builtins.attrNames nodes'\n```\n\nAdditionally there are two low level subcommands which get out of your way and let you use the tools you're used to: `terraform` and `colmena`.\n\n```sh\n# 'teraflops tf' is a direct passthrough to terraform\nteraflops tf init\nteraflops tf apply\n\n# 'teraflops nix' is a direct passthrough to colmena\nteraflops nix repl\nteraflops nix apply --reboot\n```\n\n## Deployment arguments\n\n`terapflops` implements the `set-args` command from [NixOps](https://github.com/NixOS/nixops/blob/master/doc/overview.rst#network-arguments). Referencing the example from `NixOps`:\n\n```nix\n{\n  inputs = {\n    nixpkgs.url = \"github:NixOS/nixpkgs/nixos-unstable\";\n    teraflops.url = \"github:aanderse/teraflops\";\n  };\n\n  outputs = { nixpkgs, teraflops, ... }: {\n    teraflops =\n      { maintenance ? false }:\n      {\n        machine =\n          { config, pkgs, ... }:\n          { services.httpd.enable = maintenance;\n            ...\n          };\n      };\n  };\n}\n```\n\nYou can pass deployment arguments using the `set-args` command. For example, if we want to set the `maintenance` argument to `true` in the previous example, you can run:\n\n```sh\nteraflops set-args --arg maintenance true\n```\n\n## Special arguments\n\nIn addition to the regular `nix` module inputs and those defined by calls to the `set-args` command the following arguments are available to `teraflops` modules:\n\n- `outputs`: The fully evaluated [terraform output values](https://developer.hashicorp.com/terraform/language/values/outputs). Generally these aren't as useful in `teraflops` as they are in `terraform` because the `teraflops eval` command has full access to a `resources` argument which accounts for _most_ use cases in `terraform`.\n- `resources`: The fully evaluated `terraform` resource set, which includes `resource`, `data`, `module`, etc... objects representing the full state of your deployment.\n- `tf`: A minor helper which is most useful for the `tf.ref` function it contains which is used to create `terraform` references, just like in [terranix](https://terranix.org/news/2023-05-24_release-2.6.0.html).\n\n_NOTE:_ Both `outputs` and `resources` will be `null` when a `teraflops` module is evaluated for the purpose of generating `terraform` code in order to avoid recursion.\n\n## `opentofu` support\n\n`teraflops` provides support for `opentofu` via `nixpkgs`. See [examples/opentofu](examples/opentofu/flake.nix) for a working example.\n\n## Comparison\n\n### colmena\n\n- `colmena` is entirely stateless\n- `teraflops` can make full use of `terraform` state\n\n### terranix\n\n- `terranix` builds a high level `nix` api on top of `terraform` which includes full build time validation\n- `teraflops` exposes `terraform` directly to you through `nix`, sacraficing build time validation in favor of run time validation in order to make the development of various `teraflops` backends (like `digitalocean`, `hetznercloud`, `linode`, `lxd`, etc...) extremely quick and easy in the spirit of [RFC42](https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md#part-2-balancing-module-option-count)\n\n- `terranix` focuses on `terraform` code generation and leaves NixOS integration to the user\n- `teraflops` provides full and direct integration with NixOS\n\n### NixOps\n\n- `NixOps` builds a high level `nix` api on top of various cloud providers which includes full build time validation, though requires extensive `python` development for every backend desired, many of which do not yet exist\n- `teraflops` leverages `terraform` for all of this work so as long as a `terraform` backend exists it is near trivial to create a `teraflops` module for it\n\n- `NixOps` development is has lagged for a number of years, though apparently there are [plans](https://github.com/NixOS/nixops/issues/1574#issuecomment-1866651601) to bring it back!\n- `teraflops` is a young project and relies on established software like `colmena`, `terraform`, and `nixos-infect` to provide all major functionality making `teraflops` already quite a capable tool\n\n## Implementation\n\nA very quick `python` script I hacked together which isn't great. Don't look at the code yet... really 😅\n\n## See also\n\n- [colmena](https://github.com/zhaofengli/colmena) - used by `teraflops` to manage deployments\n- [NixOps](https://github.com/NixOS/nixops) - inspiration for `teraflops`\n- [nixos-infect](https://github.com/elitak/nixos-infect) - used by `teraflops` for integration with various cloud providers\n- [terranix](https://github.com/terranix/terranix) - inspiration for `teraflops`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faanderse%2Fteraflops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faanderse%2Fteraflops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faanderse%2Fteraflops/lists"}