-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathflake.nix
135 lines (111 loc) · 3.55 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
{
description = "Nocturne UI";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
let
overlay = final: prev: {
nocturne-ui = self.packages.${prev.system}.default;
};
in
{
nixosModules.default = { config, lib, pkgs, ... }:
let
cfg = config.services.nocturne-ui;
in
{
options.services.nocturne-ui = {
enable = lib.mkEnableOption "Nocturne UI service";
host = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = "Host to listen on";
};
port = lib.mkOption {
type = lib.types.port;
default = 3500;
description = "Port to listen on";
};
};
config = lib.mkIf cfg.enable {
nixpkgs.overlays = [ overlay ];
security.pki.certificateFiles = [ "${pkgs.nocturne-ui}/share/nocturne/rootCA.pem" ];
systemd.services.nocturne-ui = {
description = "Nocturne UI service";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.nocturne-ui}/bin/nocturne";
Environment = [
"HOST=${toString cfg.host}"
"PORT=${toString cfg.port}"
];
User = "superbird";
Group = "users";
Restart = "always";
};
};
};
};
} //
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
nodeDeps = with pkgs; [
nodejs_20
bun
];
in
{
packages.default = pkgs.stdenv.mkDerivation {
pname = "nocturne-ui";
version = "3.0.0-beta.1";
src = ./.;
nativeBuildInputs = nodeDeps ++ [ pkgs.cacert pkgs.mkcert ];
buildPhase = ''
runHook preBuild
bun install
bun run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/share/nocturne/.next
cp -r .next/standalone/. $out/share/nocturne/
cp -r .next/static $out/share/nocturne/.next
cp -r public $out/share/nocturne
cp prodserver.js $out/share/nocturne/
export CAROOT="$out/share/nocturne"
mkcert localhost 127.0.0.1 ::1
mv localhost+2.pem $out/share/nocturne/cert.crt
mv localhost+2-key.pem $out/share/nocturne/cert.key
mkdir -p $out/bin
cat > $out/bin/nocturne << EOF
#!/bin/sh
exec ${pkgs.nodejs_20}/bin/node $out/share/nocturne/prodserver.js
EOF
chmod +x $out/bin/nocturne
runHook postInstall
'';
};
devShells.default = pkgs.mkShell {
buildInputs = nodeDeps ++ (with pkgs; [
mkcert
openssl
]);
shellHook = ''
echo "Node $(node --version)"
echo "bun $(bun --version)"
if [ ! -f "cert.crt" ]; then
echo "Setting up local SSL certificates..."
mkcert -install
mkcert localhost 127.0.0.1 ::1
mv localhost+2.pem cert.crt
mv localhost+2-key.pem cert.key
fi
'';
};
}
);
}