-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
101 lines (96 loc) · 2.82 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
description = "Nomad Housekeeper";
inputs = {
nixpkgs.url = "github:nixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:inclyc/flake-compat";
flake = false;
};
};
outputs = {
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
name = "nomad-housekeeper";
goPlatform = {
"aarch64-darwin" = {
GOOS = "darwin";
GOARCH = "arm64";
};
"aarch64-linux" = {
GOOS = "linux";
GOARCH = "arm64";
};
"x86-64-darwin" = {
GOOS = "darwin";
GOARCH = "amd64";
};
"x86-64-linux" = {
GOOS = "linux";
GOARCH = "amd64";
};
};
housekeeperRecipe = {
GOOS,
GOARCH,
...
} @ args:
(pkgs.buildGoModule {
inherit name GOOS GOARCH;
pname = name;
src = ./.;
vendorHash = "sha256-pFNlP3zPQhAX/emjTdiMdLIk7FQIIUQjFzQiBNTtQK4=";
CGO_ENABLED = 0;
# Typically wouldn't do this, but otherwise buildGoModule insists on
# messing with the output path when cross-compiling
buildPhase = ''
mkdir -p $out/bin
go build -o $out/bin/nomad-housekeeper
'';
})
.overrideAttrs (old: old // args);
linuxSystem = (pkgs.lib.removeSuffix "darwin" system) + "linux";
in {
formatter = pkgs.alejandra;
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.go
pkgs.nomad
];
};
packages = {
nomad-housekeeper = housekeeperRecipe goPlatform.${system};
testing = housekeeperRecipe goPlatform.${linuxSystem};
default = self.packages.${system}.nomad-housekeeper;
dockerContainer =
pkgs.dockerTools.buildImage
{
# TODO: figure out how to get container tar to change name
name = "nomad-housekeeper";
tag = "latest"; # TODO: add versioning
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [(housekeeperRecipe goPlatform.${linuxSystem})];
pathsToLink = ["/bin"];
};
config = {
Cmd = ["/bin/nomad-housekeeper"];
ExposedPorts = {"8080/tcp" = {};};
};
};
};
# TODO: sample nomad job files
# TODO: github actions build releases - also build nightly
# TODO: add a vmtest
}
);
}