-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
109 lines (94 loc) · 3.18 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
{
description = "Webtarot";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
rust-overlay.url = "github:oxalica/rust-overlay";
# flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, rust-overlay }:
let
systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
# Memoize nixpkgs for different platforms for efficiency.
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
overlays = [ self.overlay ];
}
);
in {
overlay = final: prev: {
webtarot-front = final.stdenv.mkDerivation {
name = "webtarot-front";
src = ./webtarot_client;
installPhase = ''
mkdir -p $out
cp -R ./static/* $out
cp ./dist/*.{css,js,wasm} $out
'';
};
webtarot = with final; ( rustPlatform.buildRustPackage rec {
name = "webtarot";
version = "0.7.8";
src = ./.;
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl ];
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"webgame_protocol-0.6.2" = "sha256-8S+K8EVYK8tiw5cbL3MZJuT+UFi+sJ7ADTXsrN/1DvU=";
};
};
meta = with pkgs.lib; {
description = "A online game of french tarot";
homepage = "https://github.com/mmai/webtarot";
license = licenses.gpl3;
platforms = platforms.unix;
maintainers = with maintainers; [ mmai ];
};
});
webtarot-docker = with final;
let
port = "8080";
data_path = "/var/webtarot";
db_uri = "${data_path}/webtarot_db";
runAsRoot = ''
mkdir -p ${data_path}/archives
'';
entrypoint = writeScript "entrypoint.sh" ''
#!${stdenv.shell}
IP=$(ip route get 1 | awk '{print $NF;exit}')
echo "Starting server. Open your client on http://$IP:${port}"
${webtarot}/bin/webtarot_server -d ${webtarot-front}/ -a $IP -p ${port} -u ${db_uri} --archives-directory ${data_path}/archives
'';
in
dockerTools.buildImage {
name = "mmai/webtarot";
tag = "0.7.1";
contents = [ busybox ];
config = {
Entrypoint = [ entrypoint ];
ExposedPorts = {
"${port}/tcp" = {};
};
};
};
};
packages = forAllSystems (system: {
inherit (nixpkgsFor.${system}) webtarot;
inherit (nixpkgsFor.${system}) webtarot-front;
inherit (nixpkgsFor.${system}) webtarot-docker;
});
defaultPackage = forAllSystems (system: self.packages.${system}.webtarot);
devShell =
let
inherit (nixpkgs) lib;
legacyPackages = lib.attrsets.mapAttrs (system: pkgs: pkgs.extend rust-overlay.overlays.default) nixpkgs.legacyPackages;
in
forAllSystems (system: (import ./shell.nix {
pkgs = legacyPackages.${system};
}));
# webtarot service module
nixosModule = (import ./module.nix);
};
}