diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | flake.lock | 27 | ||||
| -rw-r--r-- | flake.nix | 78 |
3 files changed, 106 insertions, 0 deletions
@@ -1 +1,2 @@ .env +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..631dde9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1790046670, + "narHash": "sha256-MYiI+CzL0tuWgRPjGsKCDHqYs2T3OzMlMQWOYWG0qso=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6774f7bc253789b113a4f39285dc0fa100abeacc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6092965 --- /dev/null +++ b/flake.nix @@ -0,0 +1,78 @@ +{ + description = "EmbedTube - A YouTube micro-client for embeded videos"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: let + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); + in { + packages = forAllSystems (pkgs: { + default = pkgs.buildGoModule { + pname = "embedtube"; + version = "1.0.0"; + src = ./.; + vendorHash = "sha256-bVuk+0Ukt8AOueQHRMK1sphjfk9eG5SG9gRLxe3eHJg="; + meta.mainProgram = "embedtube"; + }; + }); + + devShells = forAllSystems (pkgs: { + default = pkgs.mkShell { + packages = with pkgs; [ go gopls gotools ]; + }; + }); + + nixosModules.default = { config, lib, pkgs, ... }: let + cfg = config.services.embedtube; + haveAPIKey = cfg.apiKeyFile != null; + in { + options.services.embedtube = { + enable = lib.mkEnableOption "enable embedtube service"; + package = lib.mkOption { + type = lib.types.package; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.default; + defaultText = lib.literalExpression "embedtube.packages.\${system}.default"; + description = "The embedtube package to use"; + }; + port = lib.mkOption { + type = lib.types.port; + default = 8080; + description = "port to listen on"; + }; + listenAddress = lib.mkOption { + type = lib.types.str; + default = "127.0.0.1"; + description = "address to bind to"; + }; + openFirewall = lib.mkEnableOption "open the listen port in the firewall"; + apiKeyFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = "file containing api key, not to be included in nix store"; + }; + }; + + config = lib.mkIf cfg.enable { + networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ]; + systemd.services.embedtube = { + description = "embedtube"; + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + serviceConfig = { + ExecStart = lib.getExe cfg.package; + LoadCredential = lib.mkIf haveAPIKey [ "api_key:${cfg.apiKeyFile}" ]; + Restart = "on-failure"; + DynamicUser = true; + }; + environment = { + PORT = toString cfg.port; + HOST = cfg.listenAddress; + API_KEY_FILE = lib.mkIf haveAPIKey "%d/api_key"; + }; + }; + }; + }; + }; +} |
