https://github.com/IogaMaster/flux
Create and deploy game servers with nix
https://github.com/IogaMaster/flux
game-server gameserver gaming minecraft nix nix-flake steam
Last synced: 5 months ago
JSON representation
Create and deploy game servers with nix
- Host: GitHub
- URL: https://github.com/IogaMaster/flux
- Owner: IogaMaster
- License: mit
- Created: 2024-04-02T17:18:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T01:36:33.000Z (about 1 year ago)
- Last Synced: 2025-04-01T22:17:03.744Z (10 months ago)
- Topics: game-server, gameserver, gaming, minecraft, nix, nix-flake, steam
- Language: Nix
- Homepage:
- Size: 72.3 KB
- Stars: 59
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- best-of-nix - GitHub - 75% open ยท โฑ๏ธ 20.10.2024) (DevOps)
README
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.
- [mcman](https://github.com/ParadigmMC/mcman)
- [playit](https://playit.gg/)
#### 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](https://github.com/ParadigmMC/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
```nix
inputs.flux.url = "github:IogaMaster/flux";
```
2. Add the exposed overlay to your global pkgs definition, so the builder functions are available.
```nix
nixpkgs.overlays = [ flux.overlays.default ];
```
3. Import the NixOS module `flux.nixosModules.default` in your host config.
```nix
nixosConfigurations.host1 = lib.nixosSystem {
system = "x86_64-linux";
modules = [
./host1/configuration.nix
flux.nixosModules.default
];
};
```
4. Define a server using the module.
```nix
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
```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:
```nix
{lib, pkgs, ... }:
pkgs.mkMinecraftServer {
name = "myminecraftserver";
src = ./mcmanconfig; # Path to a mcman config
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
```
Example generic server:
```nix
{
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:
```nix
{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](CONTRIBUTING.md).
## ๐ License
Licensed under the MIT license ([LICENSE](LICENSE) or ).
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.