aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2026-09-22 17:20:10 -0500
committerTim Keller <tjk@tjkeller.xyz>2026-09-22 17:20:10 -0500
commite8f8e18e05210cd0ced19522b3fb06463e4645d0 (patch)
tree98c51903d2e501fa64d117cc2d4f0c1589fe2b1b
parent55c7c104c0d548837c510ca831e0f1f29c210323 (diff)
downloadembedtube-e8f8e18e05210cd0ced19522b3fb06463e4645d0.tar.xz
embedtube-e8f8e18e05210cd0ced19522b3fb06463e4645d0.zip
add flake.nix with option option module + package build + dev shell
-rw-r--r--.gitignore1
-rw-r--r--flake.lock27
-rw-r--r--flake.nix78
3 files changed, 106 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 4c49bd7..82af664 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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";
+ };
+ };
+ };
+ };
+ };
+}