-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
158 lines (150 loc) · 5 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
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = {
self,
nixpkgs,
...
} @ inputs:
let
flake = inputs: system: nixpkgs.lib.mapAttrs (name: flake: {
# TODO filter non-flake inputs
nixos = flake.nixosModules
or null;
pkgs = flake.packages.${system}
or flake.legacyPackages.${system}
or null;
lib = flake.lib.${system}
or flake.lib
or null;
}) inputs;
forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f rec {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.legacyPackages.${system}.lib;
flakes = flake inputs system;
});
forAllSystems = forSystems [
"x86_64-linux"
"aarch64-linux"
#"riscv64-linux"
];
in {
inherit inputs;
packages = forAllSystems ({ pkgs, flakes, ...}: {
remi = with pkgs.python3.pkgs; buildPythonPackage rec {
pname = "remi";
version = "1.0";
src = fetchPypi {
inherit pname version;
hash = "sha256-65qc+td/mk/RSUcRWbPGVbS9S0F1o1S9zIkJb0Ek2eQ=";
extension = "zip";
};
# https://github.com/rawpython/remi/issues/216
postPatch = ''
substituteInPlace remi/server.py \
--replace \
"WebSocket('ws://%s:%s/');" \
"WebSocket('wss://%s/websocket'); // %s"
'';
};
grzegorz-clients = with pkgs.python3.pkgs; buildPythonPackage {
pname = "grzegorz-clients";
version = (builtins.fromTOML (builtins.readFile ./pyproject.toml)).tool.poetry.version;
format = "pyproject";
src = ./.;
nativeBuildInputs = [ poetry-core ];
propagatedBuildInputs = [ setuptools flakes.self.pkgs.remi requests typer rich urllib3 ];
};
grzegorzctl = pkgs.runCommandNoCCLocal "grzegorzctl" (
{
nativeBuildInputs = [ pkgs.installShellFiles ];
} //
{ inherit (flakes.self.pkgs.grzegorz-clients) meta; } //
{ meta.mainProgram = "grzegorzctl"; }
)''
mkdir -p $out/bin
ln -s "${flakes.self.pkgs.grzegorz-clients}/bin/grzegorzctl" $out/bin/grzegorzctl
installShellCompletion --cmd grzegorzctl \
--bash <($out/bin/grzegorzctl --show-completion bash) \
--zsh <($out/bin/grzegorzctl --show-completion zsh) \
--fish <($out/bin/grzegorzctl --show-completion fish)
'';
default = flakes.self.pkgs.grzegorzctl;
});
apps = forAllSystems ({ system, ...}: rec {
grzegorz-webui.type = "app";
grzegorz-webui.program = "${self.packages.${system}.grzegorz-clients}/bin/grzegorz-webui";
grzegorzctl.type = "app";
grzegorzctl.program = "${self.packages.${system}.grzegorzctl}/bin/grzegorzctl";
default = grzegorzctl;
});
nixosModules.grzegorz-webui = { config, pkgs, ... }: let
inherit (pkgs) lib;
cfg = config.services.grzegorz-webui;
in {
options.services.grzegorz-webui = {
enable = lib.mkEnableOption (lib.mdDoc "grzegorz");
package = lib.mkPackageOption self.packages.${config.nixpkgs.system} "grzegorz-clients" { };
listenAddr = lib.mkOption {
type = lib.types.str;
default = "::";
};
listenPort = lib.mkOption {
type = lib.types.port;
default = 8080;
};
listenWebsocketPort = lib.mkOption {
type = lib.types.port;
default = 0;
};
multipleInstance = lib.mkOption {
type = lib.types.bool;
default = false;
};
hostName = lib.mkOption {
type = lib.types.str;
default = "brzeczyszczykiewicz.pvv.ntnu.no";
};
apiBase = lib.mkOption {
type = lib.types.str;
default = "https://brzeczyszczykiewicz.pvv.ntnu.no/api";
};
};
config = {
systemd.services.grzegorz-webui = lib.mkIf cfg.enable {
description = "grzegorz-webui";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "grzegorz-webui";
Group = "grzegorz-webui";
DynamicUser = true;
#StateDirectory = "grzegorz-webui";
#CacheDirectory = "grzegorz-webui";
ExecStart = lib.escapeShellArgs [
"${cfg.package}/bin/grzegorz-webui"
"--address" cfg.listenAddr
"--port" cfg.listenPort
"--host-name" cfg.hostName
"--api-base" cfg.apiBase
"--websocket-port" cfg.listenWebsocketPort
(if cfg.multipleInstance
then "--multiple-instance"
else "--no-multiple-instance")
];
Restart = "on-failure";
};
};
};
};
devShells = forAllSystems ({ pkgs, ... }: rec {
default = pkgs.mkShellNoCC {
packages = [
pkgs.poetry
pkgs.python3
pkgs.entr
];
};
});
};
}