Skip to content

Commit

Permalink
introduce nix nomad modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Jan 23, 2025
1 parent 3fb5135 commit 9e420b6
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 15 deletions.
112 changes: 110 additions & 2 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
url = "github:numtide/build-go-cache";
inputs.nixpkgs.follows = "nixpkgs";
};

nixnomad = {
url = "github:cottand/nix-nomad";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "utils";
};
};

outputs = inputs@{ self, nixpkgs, cottand, home-manager, utils, attic, filters, go-cache, colmena, ... }:
Expand Down Expand Up @@ -87,6 +93,16 @@
${pkgs.nomad}/bin/nomad fmt
${pkgs.terraform}/bin/terraform fmt
'';

nomadJobs = inputs.nixnomad.lib.evalNomadJobs {
inherit system pkgs;
extraArgs.self = self;

config = {
imports = [ ./jobs ];
};
};

}
)) // {
colmenaHive = colmenaHive // {
Expand Down
59 changes: 59 additions & 0 deletions jobs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{ config, ... }:
let
lib = (import ./lib) { };
in
{
job."bye".group = config.job."whoami".group;
job."whoami" = {
group."whoami" = {
# network = {
# mode = "bridge";
# dynamicPorts = [
# { label = "http"; hostNetwork = "ts"; }
# ];
# };
services = [{
name = "aa";
tags = [
"traefik.enable=true"
"traefik.http.routers.whoami.rule=PathPrefix(`/whoami`)"
"traefik.http.middlewares.whoami-stripprefix.stripprefix.prefixes=/whoami"
"traefik.http.routers.whoami.middlewares=whoami-stripprefix"
"traefik.http.routers.whoami.entrypoints=websecure, web"
];
port = "http";
connect = {
sidecarService = {
proxy = let otlpPort = 9101; in {
upstreams = [
{
destinationName = "web-portfolio";
localBindPort = 8001;
}
{
destinationName = "tempo-otlp-grpc-mesh";
localBindPort = otlpPort;
}
];
config = lib.mkEnvoyProxyConfig {
otlpService = "proxy-whoami";
otlpUpstreamPort = otlpPort;
};
};
};
};
}];
task."whoami" = {
driver = "docker";

config = {
image = "traefik/whoami";
ports = [ "http" ];
args = [
"--port=\${NOMAD_PORT_http}"
];
};
};
};
};
}
10 changes: 10 additions & 0 deletions jobs/lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# utilities to write Jobs in Nix
{ nixpkgs ? (builtins.getFlake "github:nixos/nixpkgs/0ef93bf")
, nixnomad ? (builtins.getFlake "github:tristanpemble/nix-nomad")
, ...
}:
let
Expand All @@ -8,6 +9,15 @@ let
if have != expected then (throw "assertion failed: got ${builtins.toJSON have} but expected ${builtins.toJSON expected}") else "ok";
in
rec {

mkNomadJob = name: job:
let
eval = nixnomad.lib.evalNomadJobs {
config.job.${name} = job;
};
in
eval;

seconds = 1000000000;
minutes = 60 * seconds;
hours = 60 * minutes;
Expand Down
2 changes: 1 addition & 1 deletion jobs/roach.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let
lib = (import ./lib) { };
version = "v23.1.22";
version = "latest-v24.3";
cache = "70MB";
maxSqlMem = "${toString (mem * 0.5)}MB";
cpu = 1200;
Expand Down
25 changes: 13 additions & 12 deletions jobs/whoami.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
let lib = (import ./lib) { }; in
let
lib = (import ./lib) { };
in
{
job = lib.transformJob {
name = "whoami";
id = "whoami";
job = lib.mkNomadJob "whoami" {
group."whoami" = {
network = {
mode = "bridge";
dynamicPorts = [
{ label = "http"; hostNetwork = "ts"; }
];
};
service."whoami" = {
# network = {
# mode = "bridge";
# dynamicPorts = [
# { label = "http"; hostNetwork = "ts"; }
# ];
# };
services = [{
name = "aa";
tags = [
"traefik.enable=true"
"traefik.http.routers.whoami.rule=PathPrefix(`/whoami`)"
Expand Down Expand Up @@ -39,7 +40,7 @@ let lib = (import ./lib) { }; in
};
};
};
};
}];
task."whoami" = {
driver = "docker";

Expand Down

0 comments on commit 9e420b6

Please sign in to comment.