2024-04-24 17:09:10 +02:00
|
|
|
{
|
|
|
|
|
description = "Coder Templates";
|
|
|
|
|
|
|
|
|
|
outputs = {
|
|
|
|
|
self,
|
|
|
|
|
nixpkgs,
|
|
|
|
|
flake-parts,
|
|
|
|
|
systems,
|
|
|
|
|
...
|
|
|
|
|
} @ inputs:
|
|
|
|
|
flake-parts.lib.mkFlake {inherit inputs;} {
|
|
|
|
|
imports = [
|
|
|
|
|
inputs.devenv.flakeModule
|
|
|
|
|
inputs.nix-gitlab-ci.flakeModule
|
|
|
|
|
];
|
|
|
|
|
systems = import systems;
|
|
|
|
|
flake = {
|
|
|
|
|
};
|
|
|
|
|
perSystem = {
|
|
|
|
|
config,
|
|
|
|
|
self',
|
|
|
|
|
inputs',
|
|
|
|
|
pkgs,
|
|
|
|
|
system,
|
|
|
|
|
...
|
|
|
|
|
}: {
|
|
|
|
|
_module.args.pkgs = import nixpkgs {
|
|
|
|
|
inherit system;
|
|
|
|
|
config.allowUnfree = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formatter = pkgs.alejandra;
|
|
|
|
|
devenv.shells.default = {
|
|
|
|
|
imports = [
|
|
|
|
|
inputs.nix-devtools.devenvModule
|
|
|
|
|
];
|
|
|
|
|
packages = [
|
|
|
|
|
pkgs.opentofu
|
|
|
|
|
pkgs.coder
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
pre-commit.hooks = {
|
|
|
|
|
alejandra.enable = true;
|
|
|
|
|
};
|
|
|
|
|
task = {
|
|
|
|
|
enable = true;
|
|
|
|
|
alias = ",";
|
2024-04-24 19:01:04 +02:00
|
|
|
tasks = {
|
|
|
|
|
"build" = {
|
|
|
|
|
requires.vars = ["TEMPLATE"];
|
|
|
|
|
cmds = [
|
|
|
|
|
"nix build .#{{ .TEMPLATE }}"
|
|
|
|
|
"install result {{ .TEMPLATE }}/template.tf.json"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
"validate" = {
|
|
|
|
|
desc = "Validate the resulting terraform files";
|
|
|
|
|
deps = ["build"];
|
|
|
|
|
requires.vars = ["TEMPLATE"];
|
|
|
|
|
dir = "{{ .TEMPLATE }}";
|
|
|
|
|
cmds = [
|
|
|
|
|
"${pkgs.opentofu}/bin/tofu init"
|
|
|
|
|
"${pkgs.opentofu}/bin/tofu validate"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
"upload-to-coder" = {
|
|
|
|
|
desc = "Uploads the specified template to coder";
|
|
|
|
|
deps = ["build" "validate"];
|
|
|
|
|
requires.vars = ["TEMPLATE"];
|
|
|
|
|
dir = "{{ .TEMPLATE }}";
|
|
|
|
|
interactive = true;
|
|
|
|
|
cmd = ''${pkgs.coder}/bin/coder templates push "{{ .TEMPLATE }}"'';
|
|
|
|
|
};
|
|
|
|
|
};
|
2024-04-24 17:09:10 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
packages = {
|
|
|
|
|
nix-coder-image = pkgs.callPackage ./image.nix {};
|
2024-04-24 19:01:04 +02:00
|
|
|
nix-kubernetes = inputs.terranix.lib.terranixConfiguration {
|
|
|
|
|
inherit system;
|
|
|
|
|
modules = [./nix-kubernetes];
|
|
|
|
|
};
|
2024-04-24 17:09:10 +02:00
|
|
|
};
|
2024-04-24 19:06:12 +02:00
|
|
|
|
|
|
|
|
ci = {
|
|
|
|
|
stages = ["build" "upload"];
|
|
|
|
|
jobs = {
|
|
|
|
|
"build" = {
|
2024-04-24 21:41:43 +02:00
|
|
|
stage = "build";
|
|
|
|
|
parallel.matrix = [
|
|
|
|
|
{TEMPLATE = ["nix-kubernetes"];}
|
|
|
|
|
];
|
|
|
|
|
deps = [pkgs.gnutar];
|
|
|
|
|
script = [
|
|
|
|
|
"nix build .#\${TEMPLATE}"
|
2024-04-24 21:46:10 +02:00
|
|
|
"install -D result templates/\${TEMPLATE}.tf.json"
|
2024-04-24 21:41:43 +02:00
|
|
|
"tar -cf templates/\${TEMPLATE}.tar -C templates \${TEMPLATE}.tf.json"
|
|
|
|
|
];
|
|
|
|
|
artifacts.paths = ["templates/"];
|
|
|
|
|
};
|
|
|
|
|
"build:image" = {
|
2024-04-24 19:06:12 +02:00
|
|
|
stage = "build";
|
|
|
|
|
script = [
|
|
|
|
|
"nix build .#nix-coder-image"
|
|
|
|
|
];
|
|
|
|
|
after_script = [
|
|
|
|
|
"install -D result dist/nix-coder-image.tar.gz"
|
|
|
|
|
];
|
|
|
|
|
artifacts.paths = ["dist/"];
|
|
|
|
|
};
|
|
|
|
|
"upload" = {
|
|
|
|
|
stage = "upload";
|
|
|
|
|
deps = [pkgs.skopeo];
|
2024-04-24 21:41:43 +02:00
|
|
|
needs = ["build:image"];
|
2024-04-24 19:06:12 +02:00
|
|
|
script = [
|
|
|
|
|
''
|
|
|
|
|
skopeo --insecure-policy copy --dest-creds "''${CI_REGISTRY_USER}:''${CI_REGISTRY_PASSWORD}" --tmpdir /tmp \
|
|
|
|
|
"docker-archive:dist/nix-coder-image.tar.gz" \
|
|
|
|
|
"docker://''${CI_REGISTRY_IMAGE}/nix-coder-image:''${CI_COMMIT_SHORT_SHA}"
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2024-04-24 17:09:10 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
|
|
|
|
|
|
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
|
|
|
systems.url = "github:nix-systems/default";
|
|
|
|
|
devenv.url = "github:cachix/devenv";
|
|
|
|
|
nix-gitlab-ci = {
|
|
|
|
|
url = "gitlab:TECHNOFAB/nix-gitlab-ci";
|
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
inputs.devenv.follows = "devenv";
|
|
|
|
|
inputs.systems.follows = "systems";
|
|
|
|
|
};
|
|
|
|
|
nix-devtools = {
|
|
|
|
|
url = "gitlab:TECHNOFAB/nix-devtools";
|
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
inputs.devenv.follows = "devenv";
|
|
|
|
|
inputs.systems.follows = "systems";
|
|
|
|
|
};
|
2024-04-24 19:01:04 +02:00
|
|
|
|
|
|
|
|
terranix.url = "github:terranix/terranix";
|
2024-04-24 17:09:10 +02:00
|
|
|
};
|
|
|
|
|
}
|