-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
143 lines (136 loc) · 5.82 KB
/
Copy pathflake.nix
File metadata and controls
143 lines (136 loc) · 5.82 KB
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
utils.url = "github:numtide/flake-utils";
sbt.url = "github:zaninime/sbt-derivation";
sbt.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, utils, sbt }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
# ---------------------------------------------------------------------------
# nix develop
devShells.default = pkgs.mkShell {
buildInputs = [pkgs.sbt pkgs.metals pkgs.jdk24 pkgs.hello];
};
# ---------------------------------------------------------------------------
# nix build
packages.default = sbt.mkSbtDerivation.${system} {
pname = "nix-zwords";
version = builtins.elemAt (builtins.match ''[^"]+"(.*)".*'' (builtins.readFile ./version.sbt)) 0;
depsSha256 = "sha256-pXwtO5bh/rB0MZggsg59x9W0ExGO0D7yxtcZqZLTX0U=";
src = ./.;
buildInputs = [pkgs.sbt pkgs.jdk24_headless pkgs.makeWrapper];
buildPhase = "sbt Universal/packageZipTarball";
installPhase = ''
mkdir -p $out
cp -r static-user-interfaces $out/user-interface
tar xf webapi/target/universal/zwords-webapi.tgz --directory $out
makeWrapper $out/bin/zwords-webapi $out/bin/nix-zwords \
--set PATH ${pkgs.lib.makeBinPath [
pkgs.gnused
pkgs.gawk
pkgs.coreutils
pkgs.bash
pkgs.jdk24_headless
]}
'';
};
# ---------------------------------------------------------------------------
# simple nixos services integration
nixosModules.default = { config, pkgs, lib, ... }: {
options = {
services.zwords = {
enable = lib.mkEnableOption "zwords";
user = lib.mkOption {
type = lib.types.str;
description = "User name that will run the zwords service";
};
ip = lib.mkOption {
type = lib.types.str;
description = "Listening network interface - 0.0.0.0 for all interfaces";
default = "127.0.0.1";
};
port = lib.mkOption {
type = lib.types.int;
description = "Service zwords listing port";
default = 8080;
};
datastore = lib.mkOption {
type = lib.types.str;
description = "where zwords stores its data";
default = "/data/zwords";
};
clientResourcesPath = lib.mkOption {
type = lib.types.str;
default = "user-interface";
};
frAffFilename = lib.mkOption {
type = lib.types.str;
default = "dicos/fr-classique.aff";
};
frDicFilename = lib.mkOption {
type = lib.types.str;
default = "dicos/fr-classique.dic";
};
enAffFilename = lib.mkOption {
type = lib.types.str;
default = "dicos/en-classique.aff";
};
enDicFilename = lib.mkOption {
type = lib.types.str;
default = "dicos/en-classique.dic";
};
frSubsetFilename = lib.mkOption {
type = lib.types.str;
default = "dicos/subset-french-10000.txt";
};
enSubsetFilename = lib.mkOption {
type = lib.types.str;
default = "dicos/subset-english-10000.txt";
};
lmdbPath = lib.mkOption {
type = lib.types.str;
default = "lmdb-data/";
};
lmdbName = lib.mkOption {
type = lib.types.str;
default = "zwords";
};
};
};
config = lib.mkIf config.services.zwords.enable {
systemd.tmpfiles.rules = [
"d ${config.services.zwords.datastore} 0750 ${config.services.zwords.user} ${config.services.zwords.user} -"
];
systemd.services.zwords = {
description = "ZWords wordle like game";
environment = {
ZWORDS_LISTEN_IP = config.services.zwords.ip;
ZWORDS_LISTEN_PORT = (toString config.services.zwords.port);
ZWORDS_CLIENT_RESOURCES_PATH = config.services.zwords.clientResourcesPath;
ZWORDS_STORE_PATH = config.services.zwords.datastore;
ZWORDS_FR_AFF_FILENAME = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.frAffFilename]);
ZWORDS_FR_DIC_FILENAME = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.frDicFilename]);
ZWORDS_EN_AFF_FILENAME = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.enAffFilename]);
ZWORDS_EN_DIC_FILENAME = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.enDicFilename]);
ZWORDS_FR_SUBSET_FILENAME = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.frSubsetFilename]);
ZWORDS_EN_SUBSET_FILENAME = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.enSubsetFilename]);
ZWORDS_LMDB_PATH = (lib.strings.concatStrings [config.services.zwords.datastore "/" config.services.zwords.lmdbPath]);
ZWORDS_LMDB_NAME = config.services.zwords.lmdbName;
};
serviceConfig = {
ExecStart = "${self.packages.${pkgs.system}.default}/bin/nix-zwords";
User = config.services.zwords.user;
Restart = "on-failure";
WorkingDirectory = "${self.packages.${pkgs.system}.default}";
};
wantedBy = [ "multi-user.target" ];
};
};
};
# ---------------------------------------------------------------------------
});
}