-
Notifications
You must be signed in to change notification settings - Fork 5
/
flake.nix
173 lines (167 loc) · 5.18 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
{
description = "Quickly and securely turn any Linux box into a build and deployment assistant";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nixos-generators,
}:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
buildkit-cni-plugins = pkgs.callPackage ./distros/nix/buildkit-cni.nix { };
buildkitDevPkgs = with pkgs; [
slirp4netns
rootlesskit
runc
cni
buildkit-cni-plugins
buildkit
nerdctl
];
goDevPkgs = with pkgs; [
go
golangci-lint
protobuf
protoc-gen-go
protoc-gen-go-grpc
];
pyAnalysis = with pkgs; [
pipreqs
];
version = builtins.readFile ./go/version.txt;
src = pkgs.callPackage ./distros/nix/src.nix {
inherit version;
dontPatchShebangs = true;
};
vendorHash = "sha256-OmNKmih4OSJSp5Thuotn6SB/TLDvMHNmwFdzJxXyAe4="; #pkgs.lib.fakeHash;
cli = pkgs.callPackage ./distros/nix/cli.nix {
inherit version vendorHash;
};
cli-darwin-arm64 = pkgs.callPackage ./distros/nix/cli-cross.nix {
inherit version vendorHash;
GOOS = "darwin";
GOARCH = "arm64";
};
cli-darwin-amd64 = pkgs.callPackage ./distros/nix/cli-cross.nix {
inherit version vendorHash;
GOOS = "darwin";
GOARCH = "amd64";
};
cli-linux-arm64 = pkgs.callPackage ./distros/nix/cli-cross.nix {
inherit version vendorHash;
GOOS = "linux";
GOARCH = "arm64";
};
cli-linux-amd64 = pkgs.callPackage ./distros/nix/cli-cross.nix {
inherit version vendorHash;
GOOS = "linux";
GOARCH = "amd64";
};
server = pkgs.callPackage ./distros/nix/server.nix {
inherit version cli buildkit-cni-plugins;
};
in
{
devShells.${system}.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs =
buildkitDevPkgs
++ goDevPkgs
++ pyAnalysis
++ [
pkgs.nixfmt-rfc-style
];
shellHook = ''
export PATH=$PATH:$PWD/bin
export AYUP_ASSISTANTS_DIR=$PWD/assistants
'';
};
packages.${system} = {
inherit src;
inherit
cli
cli-darwin-amd64
cli-darwin-arm64
cli-linux-arm64
cli-linux-amd64
;
inherit server;
default = server;
dev = pkgs.stdenv.mkDerivation {
pname = "dev";
inherit version;
src = ./script/.;
nativeBuildInputs = [ pkgs.makeWrapper ];
buildInputs = buildkitDevPkgs;
installPhase = ''
mkdir -p $out/bin
cp start-dev-services.sh $out/bin/dev
wrapProgram $out/bin/dev \
--prefix PATH : ${pkgs.lib.makeBinPath buildkitDevPkgs}
'';
};
ami = nixos-generators.nixosGenerate {
system = "${system}";
format = "amazon";
modules = [
(
{ config, ... }:
{
boot.kernelPackages = pkgs.linuxPackages_6_6;
users.users.ayup = {
isNormalUser = true;
packages = [ server ];
};
amazonImage = {
sizeMB = "auto";
name = "Ayup-${version}-${config.system.nixos.label}-${system}";
};
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
networking.firewall.enable = false;
systemd.services = {
ayup = {
description = "Ayup Deamon";
after = [ "multi-user.target" ];
wantedBy = [ "multi-user.target" ];
requires = [ "network-online.target" ];
serviceConfig = {
ExecStart = "${server}/bin/ay daemon start --aws --host /ip4/0.0.0.0/tcp/50051";
User = "ayup";
RuntimeDirectory = "ayup";
StateDirectory = "ayup";
CacheDirectory = "ayup";
ConfigurationDirectory = "ayup";
RuntimeDirectoryMode = "0700";
StateDirectoryMode = "0700";
CacheDirectoryMode = "0700";
LogsDirectoryMode = "0700";
StandardOutput = "journal";
StandardError = "journal";
Environment = [
# Give access to newuidmap/newgidmap with suid bit set
"PATH=$PATH:/run/wrappers/bin"
];
};
};
};
}
)
(nixpkgs.outPath + "/nixos/modules/profiles/minimal.nix")
];
};
};
};
}