reCoreD-UI/flake.nix

103 lines
2.8 KiB
Nix
Raw Normal View History

2024-04-02 13:23:28 +00:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
2024-04-19 01:44:37 +00:00
outputs = { self, nixpkgs, utils }:
2024-04-02 13:23:28 +00:00
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
2024-04-23 07:23:35 +00:00
name = "reCoreD-UI";
2024-04-20 03:02:48 +00:00
version = "v1.0.0";
2024-04-02 13:23:28 +00:00
in
{
2024-04-20 03:02:48 +00:00
defaultPackage = with pkgs; let
web = buildNpmPackage {
inherit version;
pname = name;
src = "${self}/web";
npmDepsHash = "sha256-e4AYJa0PXhuBRytH4860v6t3DEcQ5awR24HeXRD5pew=";
};
app = buildGoModule {
pname = name;
inherit version;
2024-04-19 07:10:08 +00:00
src = self;
2024-04-20 03:02:48 +00:00
ldflags = [
"-s"
"-w"
2024-04-23 07:23:35 +00:00
"-X main.Version=${version}"
2024-04-19 07:10:08 +00:00
];
2024-04-20 03:02:48 +00:00
configurePhase = ''
cp -r ${web}/lib/node_modules/web/dist server
export HOME=/tmp/build
2024-04-19 07:10:08 +00:00
'';
2024-04-20 03:02:48 +00:00
2024-04-19 07:10:08 +00:00
installPhase = ''
mkdir -p $out/bin
2024-04-23 07:23:35 +00:00
ls -l
cp $HOME/go/bin/reCoreD-UI $out/bin
2024-04-19 07:10:08 +00:00
'';
2024-04-20 03:02:48 +00:00
doCheck = false;
deleteVendor = true;
proxyVendor = true;
2024-04-19 07:10:08 +00:00
};
2024-04-20 03:02:48 +00:00
in
stdenv.mkDerivation {
name = "${name}-${version}";
src = self;
installPhase = ''
mkdir -p $out/bin
2024-04-23 07:23:35 +00:00
cp ${app}/bin/reCoreD-UI $out/bin
2024-04-20 03:02:48 +00:00
'';
2024-04-19 07:10:08 +00:00
};
2024-04-02 13:23:28 +00:00
devShell = with pkgs; mkShell {
buildInputs = [
go
2024-04-02 13:26:57 +00:00
nodejs
2024-04-19 01:44:37 +00:00
dig
2024-04-10 03:00:38 +00:00
tokei
2024-04-02 13:23:28 +00:00
];
2024-04-03 09:05:12 +00:00
GOPATH = "/home/coder/.cache/go";
2024-04-11 02:51:33 +00:00
RECORED_MYSQL_DSN = "recoredui:A123456a-@tcp(mysql.dev:3306)/recoredui?charset=utf8mb4";
2024-04-02 13:23:28 +00:00
};
nixosModule = { config, pkgs, lib, ... }: with lib;
let
cfg = config.services.recored-ui;
in
{
options.services.hangitbot = {
enable = mkEnableOption "reCoreD-UI service";
2024-04-19 07:10:08 +00:00
mysql-dsn = mkOption {
2024-04-02 13:23:28 +00:00
type = types.str;
2024-04-19 07:10:08 +00:00
example = "recoredui:A123456a-@tcp(mysql.dev:3306)/recoredui?charset=utf8mb4";
description = lib.mdDoc "mysql connection DSN";
2024-04-02 13:23:28 +00:00
};
extraOptions = mkOption {
type = types.str;
2024-04-19 07:10:08 +00:00
description = lib.mdDoc "Extra options";
2024-04-02 13:23:28 +00:00
default = "";
};
};
2024-04-19 07:10:08 +00:00
config = mkIf cfg.enable {
2024-04-23 07:23:35 +00:00
systemd.services.reCoreD-UI = {
2024-04-19 07:10:08 +00:00
wantedBy = [ "multi-uesr.target" ];
environment = {
RECORED_MYSQL_DSN = cfg.mysql-dsn;
2024-04-02 13:23:28 +00:00
};
2024-04-23 07:23:35 +00:00
serviceconfig.ExecStart = "${defaultPackage}/bin/reCoreD-UI server";
2024-04-02 13:23:28 +00:00
};
2024-04-19 07:10:08 +00:00
};
2024-04-02 13:23:28 +00:00
};
});
}