-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
129 lines (121 loc) · 4.38 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{
description = "API for aviators";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
nixos-generators,
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
jdk = pkgs.openjdk17_headless;
# Build Dependencies.
buildInputs = with pkgs; [
jdk
maven
];
# Development environment. Includes additional tools not needed at build time.
devInputs = with pkgs; buildInputs ++ [
ktlint
];
# CI Environment.
ciInputs = with pkgs; [
docker
doctl
kubectl
kubernetes-helm
];
# Environment variables passed into shell at creation.
testEnvironment = ''
export SPRING_MAIN_ALLOWBEANDEFINITIONOVERRIDING=true
export APPLICATION_AIRPORT_DAYSUNTILSTALE=0
export APPLICATION_AIRPORT_API_APIKEY="k"
export APPLICATION_AIRPORT_API_BASEURL="https://airports-by-api-ninjas.p.rapidapi.com/v1/airports"
export APPLICATION_RESTAURANT_DAYSUNTILSTALE=0
export APPLICATION_RESTAURANT_API_APIKEY="k"
export APPLICATION_RESTAURANT_API_BASEURL="https://maps.googleapis.com/maps/api/place"
export APPLICATION_REDIS_HOSTNAME="http:https://0.0.0.0"
export APPLICATION_REDIS_PORT=6379
export APPLICATION_REDIS_USERNAME="redis-user"
export APPLICATION_REDIS_PASSWORD="redis-password"
export APPLICATION_SECURITY_SECURITYHEADERKEY="key"
export APPLICATION_SECURITY_SECURITYHEADERVALUE="value"
'';
in rec {
packages = {
# Using `nixos-generators`, nix can be used to build a wide variety of images.
# This example generates a Digitalocean image although this application doesn't make use of it.
# Instead, `skylunch` uses `nixos-infect` to build the infractructure after creation.
k3s-host = nixos-generators.nixosGenerate {
inherit system;
modules = [ ./ci/server/k3s-host.nix ];
format = "do";
};
# Nix derivation of `skylunch` application.
skylunch =
let
# Maven repository
repository = pkgs.stdenv.mkDerivation {
name = "skylunch";
src = ./.;
inherit buildInputs;
buildPhase = "mvn clean install -Dmaven.repo.local=$out -DskipTests=true";
installPhase = ''
find $out -type f \
-name \*.lastUpdated -or \
-name resolver-status.properties -or \
-name _remote.repositories \
-delete
'';
dontFixup = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "sha256-8v8ME+0nB71Zz5XDRjb5C2nT8tY3n+X+NpCs6XIZTn4=";
};
in
pkgs.stdenv.mkDerivation rec {
name = "skylunch";
version = "0.1.6";
src = ./.;
nativeBuildInputs = [ pkgs.makeWrapper ] ++ buildInputs;
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/jar
cp ${repository}/com/skylunch/skylunch/${version}/${name}-${version}.jar $out/jar
makeWrapper ${jdk}/bin/java $out/bin/${name} \
--add-flags "-jar $out/jar/${name}-${version}.jar"
'';
};
default = packages.skylunch;
};
apps = {
skylunch = flake-utils.lib.mkApp { drv = packages.skylunch; };
default = apps.skylunch;
};
devShells = with pkgs; rec {
build = mkShell {
name = "build-environment";
inherit buildInputs;
shellHook = testEnvironment;
};
ci = mkShell {
name = "ci-tools";
buildInputs = ciInputs;
};
dev = mkShell {
name = "dev-environment";
buildInputs = devInputs;
};
default = dev;
};
});
}