-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
84 lines (83 loc) · 3.04 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
flake-utils.url = "github:numtide/flake-utils";
nix-npm-buildpackage.url = "github:serokell/nix-npm-buildpackage";
nix-npm-buildpackage.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, nix-npm-buildpackage, ... }:
(flake-utils.lib.eachDefaultSystem (system:
(let
pkgs = import nixpkgs { inherit system; };
buildNpmPackage = args:
(pkgs.callPackage nix-npm-buildpackage {
nodejs = pkgs.nodejs_latest;
}).buildNpmPackage ({
npmBuild = "npm run build";
doCheck = true;
checkPhase = "npm run check";
} // args);
frontend = buildNpmPackage { src = ./frontend; };
backend = buildNpmPackage {
pname = "toadua-backend";
src = ./.;
installPhase = ''
mkdir $out
cp -r dist $out
cp -r node_modules $out
'';
};
toadua = pkgs.runCommand "toadua" { } ''
mkdir -p $out/{bin,libexec/toadua}
cp -r ${backend}/* ${self}/{config,package.json} $out/libexec/toadua
cp -r ${frontend} $out/libexec/toadua/frontend
tee > $out/bin/toadua <<EOF
${pkgs.nodejs_latest}/bin/node --no-warnings=ExperimentalWarning $out/libexec/toadua/dist/core/server.js \$@
EOF
chmod +x $out/bin/toadua
'';
in {
packages = {
inherit frontend backend toadua;
default = toadua;
};
checks = { inherit toadua; };
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs_latest
nodePackages.typescript-language-server
nodePackages.vscode-langservers-extracted # For HTML, CSS, JSON
];
};
}) // {
nixosModules.default = { pkgs, lib, config, inputs, system, ... }:
let inherit (config.services.toadua) enable package port dataDir;
in with lib; {
options.services.toadua = {
enable = mkEnableOption "toadua";
package = mkOption {
default = self.packages.${system}.default;
type = types.package;
};
port = mkOption { type = types.port; };
dataDir = mkOption { type = types.path; };
};
config.systemd.services.toadua = {
inherit enable;
description = "Toaq Dictionary";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
script = strings.concatStringsSep " "
([ "${package}/bin/toadua" "--data-directory" "${dataDir}" ]
++ (lib.optionals (port != null) [
"--port"
(toString port)
]));
serviceConfig = {
Restart = "on-failure";
WorkingDirectory = dataDir;
};
};
};
}));
}