Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
refactor(nix): moved files to nixos directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed May 14, 2024
1 parent 10fc24b commit 38f4704
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 104 deletions.
30 changes: 0 additions & 30 deletions default.nix

This file was deleted.

6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
pkgs = import nixpkgs { inherit system; };
in
{
packages.default = pkgs.callPackage ./default.nix { };
devShells.default = pkgs.callPackage ./shell.nix { };
packages.default = pkgs.callPackage ./nixos/default.nix { };
devShells.default = pkgs.callPackage ./nixos/shell.nix { };
}
) // { nixosModules.default = ./nixos/default.nix; };
) // { nixosModules.default = ./nixos/module.nix; };
}

92 changes: 24 additions & 68 deletions nixos/default.nix
Original file line number Diff line number Diff line change
@@ -1,74 +1,30 @@
{ pkgs, lib, config, ... }:
with lib;
with builtins;
let
cfg = config.komputer;
{ lib
, buildGoModule
, gcc
, pkg-config
, libopus
, ffmpeg
, opusfile
}: buildGoModule {
name = "komputer";
version = "v1.2.0";

komputer = pkgs.callPackage ./../default.nix { };
in
{
options = {
komputer = {
enable = mkEnableOption "Enable komputer discord bot";
package = mkOption {
type = types.package;
default = komputer;
description = "komputer package";
};
guildID = mkOption {
type = types.str;
description = "Discord server id, that you deploy bot";
};
applicationID = mkOption {
type = types.str;
description = "Application ID for you local version of komputer bot";
};
token = mkOption {
type = types.str;
description = ''
Discord token for bot.
<REMEMBER!>
Your token never shouldn't be publish on any public git repository e.g. Github or Gitlab
'';
};
mongodbURI = mkOption {
type = types.str;
description = "Connection URI to your instance of mongodb";
};
};
};
src = ./.;

vendorHash = "sha256-CThNuZ16b8SXxJAtCkDMm+mwCqaS5zrr+PbX+5N3GCc=";

CGO_ENABLED = 1;
proxyVendor = true;

config = mkIf (cfg.enable) {
assertions = [
{
assertion = cfg.token != "";
message = "Option komputer.token is empty";
}
{
assertion = cfg.guildID != "";
message = "Option komputer.guildID is empty";
}
{
assertion = cfg.applicationID != "";
message = "Option komputer.applicationID is empty";
}
{
assertion = cfg.mongodb != "";
message = "Option komputer.mongodbURI is empty";
}
];
nativeBuildInputs = [ gcc pkg-config libopus ];
propagatedBuildInputs = [ ffmpeg opusfile ];

systemd.services.komputer = {
description = "Komputer - Discord bot behave as like 'komputer'. One of character in Star Track parody series created by Dem3000";
wantedBy = [ "multi-user.target" ];
environment = {
DISCORD_BOT_TOKEN = cfg.token;
APPLICATION_ID = cfg.applicationID;
SERVER_GUID = cfg.guildID;
MONGODB_URI = cfg.mongodbURI;
};
script = "${cfg.package}/bin/komputer";
};
meta = with lib; {
homepage = "https://github.com/Wittano/komputer";
description = "Discord bot behave as like 'komputer'. One of character in Star Track parody series created by Dem3000";
license = licenses.gpl3;
maintainers = with maintainers; [ Wittano ];
platforms = platforms.linux;
};
}

73 changes: 73 additions & 0 deletions nixos/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.komputer;

komputer = pkgs.callPackage ./../default.nix { };
in
{
options = {
komputer = {
enable = mkEnableOption "Enable komputer discord bot";
package = mkOption {
type = types.package;
default = komputer;
description = "komputer package";
};
guildID = mkOption {
type = types.str;
description = "Discord server id, that you deploy bot";
};
applicationID = mkOption {
type = types.str;
description = "Application ID for you local version of komputer bot";
};
token = mkOption {
type = types.str;
description = ''
Discord token for bot.
<REMEMBER!>
Your token never shouldn't be publish on any public git repository e.g. Github or Gitlab
'';
};
mongodbURI = mkOption {
type = types.str;
description = "Connection URI to your instance of mongodb";
};
};
};

config = mkIf (cfg.enable) {
assertions = [
{
assertion = cfg.token != "";
message = "Option komputer.token is empty";
}
{
assertion = cfg.guildID != "";
message = "Option komputer.guildID is empty";
}
{
assertion = cfg.applicationID != "";
message = "Option komputer.applicationID is empty";
}
{
assertion = cfg.mongodb != "";
message = "Option komputer.mongodbURI is empty";
}
];

systemd.services.komputer = {
description = "Komputer - Discord bot behave as like 'komputer'. One of character in Star Track parody series created by Dem3000";
wantedBy = [ "multi-user.target" ];
environment = {
DISCORD_BOT_TOKEN = cfg.token;
APPLICATION_ID = cfg.applicationID;
SERVER_GUID = cfg.guildID;
MONGODB_URI = cfg.mongodbURI;
};
script = "${cfg.package}/bin/komputer";
};
};
}

File renamed without changes.

0 comments on commit 38f4704

Please sign in to comment.