From 38f4704c842c7441335f18b4e2a640c20262078c Mon Sep 17 00:00:00 2001 From: Wittano Bonarotti Date: Tue, 14 May 2024 07:17:49 +0200 Subject: [PATCH] refactor(nix): moved files to nixos directory --- default.nix | 30 ------------ flake.lock | 6 +-- flake.nix | 6 +-- nixos/default.nix | 92 ++++++++++-------------------------- nixos/module.nix | 73 ++++++++++++++++++++++++++++ shell.nix => nixos/shell.nix | 0 6 files changed, 103 insertions(+), 104 deletions(-) delete mode 100644 default.nix create mode 100644 nixos/module.nix rename shell.nix => nixos/shell.nix (100%) diff --git a/default.nix b/default.nix deleted file mode 100644 index a09f7ad..0000000 --- a/default.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib -, buildGoModule -, gcc -, pkg-config -, libopus -, ffmpeg -, opusfile -}: buildGoModule { - name = "komputer"; - version = "v1.2.0"; - - src = ./.; - - vendorHash = "sha256-CThNuZ16b8SXxJAtCkDMm+mwCqaS5zrr+PbX+5N3GCc="; - - CGO_ENABLED = 1; - proxyVendor = true; - - nativeBuildInputs = [ gcc pkg-config libopus ]; - propagatedBuildInputs = [ ffmpeg opusfile ]; - - 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; - }; -} - diff --git a/flake.lock b/flake.lock index 2090fef..4534a99 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1714314149, - "narHash": "sha256-yNAevSKF4krRWacmLUsLK7D7PlfuY3zF0lYnGYNi9vQ=", + "lastModified": 1715623576, + "narHash": "sha256-ofUOGRGQk6GpQ+HKGXRb0DSzy9BqveubutyJFWQRAJI=", "owner": "nixos", "repo": "nixpkgs", - "rev": "cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae", + "rev": "1daef0114a6074be56586f2cf81898ed142e1e44", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 324b75e..1bf5585 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } diff --git a/nixos/default.nix b/nixos/default.nix index d618575..a09f7ad 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -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. - - 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; }; } diff --git a/nixos/module.nix b/nixos/module.nix new file mode 100644 index 0000000..d751f70 --- /dev/null +++ b/nixos/module.nix @@ -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. + + 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"; + }; + }; +} + diff --git a/shell.nix b/nixos/shell.nix similarity index 100% rename from shell.nix rename to nixos/shell.nix