blob: 29c9adedf3ee958f85d8b947d6faf561770ca5a1 (
plain)
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
|
{
description = "Chirp Flake";
inputs.self.submodules = true;
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
packages.default = pkgs.stdenv.mkDerivation {
pname = "chirp";
version = "0.0.0";
src = ./.;
buildPhase = ''
mkdir -p .zig-cache-global/zig
${pkgs.zig}/bin/zig build --verbose --global-cache-dir .zig-cache-global
'';
installPhase = ''
mkdir -p $out/bin $out/db
cp zig-out/bin/chirp $out/bin
'';
};
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/chirp";
};
})
// {
nixosModules.default = { config, lib, pkgs, ... }: {
options.services.chirp = {
enable = lib.mkEnableOption "Enable Chirp";
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = "Port to listen on";
};
};
config = lib.mkIf config.services.chirp.enable {
systemd.services.chirp = {
description = "Chirp SystemD Service";
wantedBy = ["multi-user.target"];
after = ["network.target"];
serviceConfig = {
ExecStart = "${self.packages.${pkgs.system}.default}/bin/chirp";
Restart = "always";
Type = "simple";
DynamicUser = "yes";
};
environment = {
PORT = toString config.services.chirp.port;
};
};
};
};
};
}
|