flak
This commit is contained in:
		
							parent
							
								
									c664e0caeb
								
							
						
					
					
						commit
						1013b7153f
					
				
					 2 changed files with 171 additions and 0 deletions
				
			
		
							
								
								
									
										24
									
								
								flake.lock
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								flake.lock
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
{
 | 
			
		||||
  "nodes": {
 | 
			
		||||
    "nixpkgs": {
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1696983906,
 | 
			
		||||
        "narHash": "sha256-L7GyeErguS7Pg4h8nK0wGlcUTbfUMDu+HMf1UcyP72k=",
 | 
			
		||||
        "path": "/nix/store/mbz4hixfgxq5b6vc0k3pp2iglcd4c353-source",
 | 
			
		||||
        "rev": "bd1cde45c77891214131cbbea5b1203e485a9d51",
 | 
			
		||||
        "type": "path"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "id": "nixpkgs",
 | 
			
		||||
        "type": "indirect"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "root": {
 | 
			
		||||
      "inputs": {
 | 
			
		||||
        "nixpkgs": "nixpkgs"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "root": "root",
 | 
			
		||||
  "version": 7
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										147
									
								
								flake.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								flake.nix
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,147 @@
 | 
			
		|||
{
 | 
			
		||||
  inputs.nixpkgs.url = "nixpkgs";
 | 
			
		||||
 | 
			
		||||
  outputs = {
 | 
			
		||||
    self,
 | 
			
		||||
    nixpkgs,
 | 
			
		||||
    ...
 | 
			
		||||
  }: let
 | 
			
		||||
    version = builtins.substring 0 7 self.lastModifiedDate;
 | 
			
		||||
 | 
			
		||||
    systems = [
 | 
			
		||||
      "x86_64-linux"
 | 
			
		||||
      "aarch64-linux"
 | 
			
		||||
      "x86_64-darwin"
 | 
			
		||||
      "aarch64-darwin"
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    forAllSystems = nixpkgs.lib.genAttrs systems;
 | 
			
		||||
    nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
 | 
			
		||||
 | 
			
		||||
    packageFn = pkgs:
 | 
			
		||||
      pkgs.rustPlatform.buildRustPackage {
 | 
			
		||||
        pname = "discord-cc-bridge";
 | 
			
		||||
        inherit version;
 | 
			
		||||
 | 
			
		||||
        src = builtins.path {
 | 
			
		||||
          name = "source";
 | 
			
		||||
          path = ./.;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        cargoSha256 = "sha256-W0GbOUDQtSeMTq1wl15phRPc+cqONjCizumcoi3qoq4=";
 | 
			
		||||
      };
 | 
			
		||||
  in rec {
 | 
			
		||||
    packages = forAllSystems (s: let
 | 
			
		||||
      pkgs = nixpkgsFor.${s};
 | 
			
		||||
    in rec {
 | 
			
		||||
      discord-cc-bridge = packageFn pkgs;
 | 
			
		||||
      default = discord-cc-bridge;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    devShells = forAllSystems (s: let
 | 
			
		||||
      pkgs = nixpkgsFor.${s};
 | 
			
		||||
      inherit (pkgs) mkShell;
 | 
			
		||||
    in {
 | 
			
		||||
      default = mkShell {
 | 
			
		||||
        packages = with pkgs; [rustc cargo rustfmt];
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    nixosModules = rec {
 | 
			
		||||
      discord-cc-bridge = { config, lib, pkgs, ... }:
 | 
			
		||||
      with lib;
 | 
			
		||||
      let
 | 
			
		||||
        cfg = config.services.discord-cc-bridge;
 | 
			
		||||
      in {
 | 
			
		||||
        options = {
 | 
			
		||||
          services.discord-cc-bridge = {
 | 
			
		||||
            enable =
 | 
			
		||||
              mkEnableOption "Enable discord-cc-bridge relay server";
 | 
			
		||||
 | 
			
		||||
            package = mkOption {
 | 
			
		||||
              default = packages.${pkgs.system}.discord-cc-bridge;
 | 
			
		||||
              type = types.package;
 | 
			
		||||
              defaultText = literalExpression "packages.${pkgs.system}.discord-cc-bridge";
 | 
			
		||||
              description = lib.mdDoc "discord-cc-bridge derivation to use";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            user = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              default = "discord-cc-bridge";
 | 
			
		||||
              description = lib.mdDoc "User account under which discord-cc-bridge runs.";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            group = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              default = "discord-cc-bridge";
 | 
			
		||||
              description = lib.mdDoc "Group under which discord-cc-bridge runs.";
 | 
			
		||||
            };
 | 
			
		||||
            
 | 
			
		||||
            addr = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              default = "0.0.0.0:54321";
 | 
			
		||||
              description = lib.mdDoc "The socket address to listen to Minecraft connections.";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            discordToken = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              description = lib.mdDoc "The discord bot token.";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            authToken = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              description = lib.mdDoc "The auth token used by CC.";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            webhookUrl = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              description = lib.mdDoc "The webhook URL.";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            channelId = mkOption {
 | 
			
		||||
              type = types.str;
 | 
			
		||||
              description = lib.mdDoc "The channel id for the bridge.";
 | 
			
		||||
            };
 | 
			
		||||
          };
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        config = mkIf cfg.enable {
 | 
			
		||||
          systemd.services.discord-cc-bridge = {
 | 
			
		||||
            wantedBy = [ "multi-user.target" ];
 | 
			
		||||
            after = [ "network-online.target" ];
 | 
			
		||||
            description = "discord-cc-bridge relay server";
 | 
			
		||||
            serviceConfig = {
 | 
			
		||||
              Type = "simple";
 | 
			
		||||
              User = cfg.user;
 | 
			
		||||
              Group = cfg.group;
 | 
			
		||||
              ExecStart =
 | 
			
		||||
                "${cfg.package}/bin/discord-cc-bridge";
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            environment = {
 | 
			
		||||
              DISCORD_TOKEN = cfg.discordToken;
 | 
			
		||||
              BIND_ADDR = cfg.addr;
 | 
			
		||||
              AUTH_TOKEN = cfg.authToken;
 | 
			
		||||
              WEBHOOK_URL = cfg.webhookUrl;
 | 
			
		||||
              CHANNEL_ID = cfg.channelId;
 | 
			
		||||
            };
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          users.users = mkIf (cfg.user == "discord-cc-bridge") {
 | 
			
		||||
            discord-cc-bridge = {
 | 
			
		||||
              description = "discord-cc-bridge relay server";
 | 
			
		||||
              useDefaultShell = true;
 | 
			
		||||
              group = cfg.group;
 | 
			
		||||
              isSystemUser = true;
 | 
			
		||||
            };
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          users.groups = mkIf (cfg.group == "discord-cc-bridge") {
 | 
			
		||||
            discord-cc-bridge = {};
 | 
			
		||||
          };
 | 
			
		||||
        };
 | 
			
		||||
      };
 | 
			
		||||
      default = discord-cc-bridge;
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in a new issue