Git Product home page Git Product logo

flux's Introduction

Flux


With flux you can build servers as packages with a simple interface and deploy them with the included module.

  • ๐Ÿ—๏ธ Builders that make packaging and running servers simple:
    • mkGenericServer (builder for any server)
    • mkMinecraftServer (builder for mcman based servers)
    • mkSteamServer (wrapper for steamcmd and steam-run)
  • โš™๏ธ A module for running servers with additional tools:
    • ๐Ÿญ Runs the server
    • ๐ŸŒ Sets up proxy (playit.gg, ngrok, cloudflare tunnels)
    • ๐Ÿซ™ Works great on host, nixos-containers, and microvms
  • ๐Ÿ“ฆ Packages not present in nixpkgs (yet) that are useful for servers.

Why?

I set up servers for my friends all of the time, and I became frustrated at the amount of work it took change a vanilla minecraft server to a modded one. So I integrated mcman to make this easy, then I decided to make servers for steam and other random projects.

๐Ÿ“ฆ Installation and Usage

Installation is simple:

  1. Add flux as an input to your flake
    inputs.flux.url = "github:IogaMaster/flux";
  2. Add the exposed overlay to your global pkgs definition, so the builder functions are available.
     nixpkgs.overlays = [ flux.overlays.default ];
  3. Import the NixOS module flux.nixosModules.default in your host config.
    nixosConfigurations.host1 = lib.nixosSystem {
       system = "x86_64-linux";
       modules = [
         ./host1/configuration.nix
         flux.nixosModules.default
       ];
    };
  4. Define a server using the module.
    flux = {
        enable = true;
        servers = {
            vanilla-minecraft = {
                package = pkgs.mkMinecraftServer {
                   name = "myminecraftserver";
                   src = ./mcmanconfig; # Path to a mcman config
                   hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
                };
                proxy.enable = true;
            };
         };
    };
Example flake.nix
{
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flux.url = "github:oddlama/nix-flux";
    flux.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, flake-utils, nixpkgs, flux, ... }: {
    # Example. Use your own hosts and add the module to them
    nixosConfigurations.host1 = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        {
            flux = {
                enable = true;
                servers = {
                    vanilla-minecraft = {
                        package = pkgs.mkMinecraftServer {
                           name = "myminecraftserver";
                           src = ./mcmanconfig; # Path to a mcman config
                           hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
                        };
                        proxy.enable = true;
                    };
                 };
            };
        }
        flux.nixosModules.default
      ];
    };
  }
  // flake-utils.lib.eachDefaultSystem (system: rec {
    pkgs = import nixpkgs {
      inherit system;
      overlays = [ flux.overlays.default ];
    };
  });
}

๐ŸŒฑ Using the builder functions:

You can create packages that run the server instead of using them in the module:

Example minecraft server:

{lib, pkgs, ... }: 
pkgs.mkMinecraftServer {
   name = "myminecraftserver";
   src = ./mcmanconfig; # Path to a mcman config
   hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}

Example generic server:

{
  lib,
  mkGenericServer,
  fetchzip,
  ...
}: 
mkGenericServer {
  name = "myserver";

  src = fetchzip {
    url = "http://www.example.org/server.tar.gz";
    hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
  };

  nativeBuildInputs = [];

  buildInputs = [];

  buildPhase = ''
    HOME=$TMPDIR

    cd $src
    cp -r . $out
  '';

  startCmd = "./start.sh";
}

Example steam server:

{lib, pkgs, ... }: 
pkgs.mkSteamServer rec {
   name = "mygameserver";
   src = pkgs.fetchSteam {
       inherit name;
       appId = ""; # Dedicated server app id, can be found with https://steamdb.info/
       hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
   };
   
   startCmd = "./FactoryServer.sh";

   hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}

๐Ÿ”จ TODO

There is still a lot to do.

  • Examples

โค๏ธ Contributing

Contributions are whole-heartedly welcome! Please feel free to suggest new features, implement additional builders, helpers, or generally assist if you'd like. We'd be happy to have you. There's more information in CONTRIBUTING.md.

๐Ÿ“œ License

Licensed under the MIT license (LICENSE or https://opensource.org/licenses/MIT). Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, shall be licensed as above, without any additional terms or conditions.

flux's People

Contributors

iogamaster avatar bananad3v avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.