Browse Source

feat: Module

develop 0.3.2
Dale 10 months ago
parent
commit
7121896047
Signed by: Deiru GPG Key ID: AA250C0277B927E1
  1. 2
      default.nix
  2. 35
      module.nix
  3. 7
      src/config.ts

2
default.nix

@ -45,8 +45,6 @@ in mkYarnPackage {
makeWrapper ${nodePkg}/bin/node $out/bin/${executableName} \
--add-flags $out/server.js \
--set NODE_PATH $NODE_PATH:$out:$node_modules \
--set STATIC_PATH $out/static \
--set PORT ${toString port}
'';
distPhase = ''

35
module.nix

@ -0,0 +1,35 @@
{ lib, pkgs, config, ... }:
with lib;
let
statusPkg = (import "${pkgs.fetchgit {
url = "https://code.gensokyo.social/Gensokyo.social/status.git";
rev = "9ff093415e82fb522a9942a5b632b1690ae73d23";
sha256 = "0dgzabsv4lc2i5mi17zch9jfmsrbsmh6h4s7v9j4r779zbgvmidm";
}}/default.nix");
in {
options.services.miracle-tv = {
enable = mkEnableOption "Gensokyo.social status";
port = {
type = types.int;
default = 8080;
description = "Governs port number that server will listen on";
};
settings = {
MASTODON_API_KEY = {
type = types.string;
description = "Mastodon API key";
};
};
};
config = let
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.settings);
in lib.mkIf cfg.enable {
# systemd unit for miracle-tv-server
systemd.services.miracle-tv = {
wantedBy = [ "multi-user.target" "postgresql.service" ];
serviceConfig.ExecStart = "CONFIG_FILE=${configFile} PORT=${cfg.port} ${statusPkg}/bin/gensocStatus";
};
};
}

7
src/config.ts

@ -1,9 +1,8 @@
import * as configFile from "src/config.json";
interface IConfig {
'MASTODON_API_KEY': string;
}
const config: IConfig = configFile
export default config;
const configPath = process.env.CONFIG_PATH || './config.json';
const config: IConfig = require(configPath);
export default config;
Loading…
Cancel
Save