-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
71 lines (66 loc) · 2.32 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
fup.url = "github:gytis-ivaskevicius/flake-utils-plus";
};
outputs = { self, nixpkgs, fup }@inputs:
fup.lib.mkFlake {
inherit self inputs;
supportedSystems = [ "x86_64-linux" ];
outputsBuilder = channels: {
packages.default = channels.nixpkgs.runCommand "freopen_chat_bot" {
src = ./.;
__noChroot = true;
nativeBuildInputs = with channels.nixpkgs; [
pkg-config
protobuf
cargo
rustc
gcc
];
buildInputs = with channels.nixpkgs; [ openssl ];
} ''
export CARGO_HTTP_CAINFO="${channels.nixpkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
export SSL_CERT_FILE=${channels.nixpkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cp -R $src/* .
cargo build --release
mkdir -p $out/bin
cp target/release/chat_bot $out/bin
cp -R assets $out/assets
'';
};
nixosModules.freopen_chat_bot = { config, pkgs, lib, ... }: {
options.services.freopen_chat_bot = {
enable = lib.mkEnableOption "freopen_chat_bot";
envFile = lib.mkOption { type = lib.types.str; };
};
config = let
opts = config.services.freopen_chat_bot;
pkg = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
in lib.mkIf opts.enable {
users.groups.freopen_chat_bot = { };
users.users.freopen_chat_bot = {
isSystemUser = true;
group = "freopen_chat_bot";
};
systemd.services.freopen_chat_bot = {
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
startLimitIntervalSec = 0;
serviceConfig = {
User = "freopen_chat_bot";
ExecStart = "${pkg}/bin/chat_bot";
EnvironmentFile = opts.envFile;
WorkingDirectory = "/var/lib/freopen_chat_bot";
StateDirectory = "freopen_chat_bot";
StateDirectoryMode = "0700";
Restart = "always";
RestartSec = 60;
};
};
};
};
};
}