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.
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 is simple:
- Add flux as an input to your flake
inputs.flux.url = "github:IogaMaster/flux";
- Add the exposed overlay to your global pkgs definition, so the builder functions are available.
nixpkgs.overlays = [ flux.overlays.default ];
- 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 ]; };
- 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 ];
};
});
}
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=";
}
There is still a lot to do.
- Examples
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.
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.