2020-12-11 20:42:08 +00:00
## Read this first!
2020-11-30 21:15:18 +00:00
2021-03-23 13:02:47 +00:00
#### You'll need at least Nix `2.4pre20210317_8a5203d`!
2020-12-11 20:42:08 +00:00
Since this repo uses a new Nix feature called "Flakes", it is recommended to enable it.
It massively improves the `nix` CLI UX, and adds many useful features.
We include instructions for Nix without flakes enabled, but using flakes is the recommended way.
2020-11-30 21:15:18 +00:00
2024-08-01 17:50:43 +00:00
See the [NixOS wiki ](https://wiki.nixos.org/wiki/Flakes ) for information on how to enable and use flakes.
2020-06-17 11:06:40 +00:00
2022-07-15 16:59:37 +00:00
It is recommended to first set up the [Cachix ](https://cachix.org ) cache to save time with builds:
2020-11-28 23:02:46 +00:00
```shell
2020-12-11 20:42:08 +00:00
nix shell nixpkgs#cachix -c cachix use veloren-nix
# or if you don't have flakes:
nix-shell -p cachix --run "cachix use veloren-nix"
2020-11-24 01:08:57 +00:00
```
2020-12-11 20:42:08 +00:00
As this repository uses `git-lfs` , please make sure `git-lfs` is in your path.
2022-07-15 16:59:37 +00:00
If you have a locally cloned repo, you can make sure it is set up with:
2020-11-24 01:08:57 +00:00
```shell
2020-12-11 20:42:08 +00:00
git lfs install --local & & git lfs fetch & & git lfs checkout
2020-11-24 01:08:57 +00:00
```
2020-12-11 20:42:08 +00:00
This should be automatically done if you use the development shell.
2020-06-17 11:06:40 +00:00
2021-08-02 21:45:01 +00:00
If you get an issue such as `WARN gfx_backend_vulkan: Unable to create Vulkan instance: VkError(ERROR_INCOMPATIBLE_DRIVER)` ,
it might be that your system nixpkgs version and veloren repo nixpkgs version might be too far apart. In that case, you can try
changing your system nixpkgs to the unstable channel, or change the `nixpkgs` input in the `flake.nix` to match your system
nixpkgs.
2020-12-11 20:42:08 +00:00
## Usage for players
2020-11-30 00:48:00 +00:00
2020-12-11 20:42:08 +00:00
### With flakes
2020-12-11 12:00:04 +00:00
2020-12-11 20:42:08 +00:00
If you just want to run the game without installing it, you can do so with:
2020-12-11 12:00:04 +00:00
```shell
# Voxygen (the default):
nix run gitlab:veloren/veloren
# Server CLI:
nix run gitlab:veloren/veloren#veloren-server-cli
2020-12-11 20:42:08 +00:00
# or if you have a local repo
2021-03-27 09:41:35 +00:00
nix run
2020-12-11 20:42:08 +00:00
nix run .#veloren-server-cli
2020-12-11 12:00:04 +00:00
```
2020-12-11 20:42:08 +00:00
To install the game into your user profile:
```shell
# Voxygen:
nix profile install gitlab:veloren/veloren
# Server CLI:
nix profile install giltab:veloren/veloren#veloren-server-cli
# or if you have a local repo:
2021-03-27 09:41:35 +00:00
nix profile install
2020-12-11 20:42:08 +00:00
nix profile install .#veloren-server-cli
```
To install (for example) Voxygen on your system, the NixOS configuration (if you use a flake based setup) could look something like this:
2020-12-11 12:00:04 +00:00
```nix
{ description = "NixOS configuration with flakes";
inputs.veloren.url = gitlab:veloren/veloren;
outputs = { self, nixpkgs, veloren }: {
nixosConfigurations.< your-hostname > = nixpkgs.lib.nixosSystem rec {
system = < your-system-arch > ;
# ...
modules = [
# add to your overlay so that the packages appear in pkgs
# for subsequent modules
({...}: {
nixpkgs.overlays = [
# ...
(final: prev: {
inherit (veloren.packages."${system}") veloren-voxygen;
})
];
# You can also add the flake to your registry
nix.registry.veloren.flake = veloren;
# with this, you can run latest master
# regardless of version installed like this:
# nix run veloren/master
})
# some module
({ pkgs, ... }: {
environment.systemPackages = [
pkgs.veloren-voxygen
];
})
# ...
];
};
};
}
```
2020-12-11 20:42:08 +00:00
### Without flakes
2020-06-17 11:06:40 +00:00
2020-12-11 20:42:08 +00:00
You can do this to run the game without installing it (you will need a local clone of the repo though):
```shell
# build the game
nix-build nix/default.nix
# run it
./result/bin/veloren-voxygen
# or for server cli
./result-2/bin/veloren-server-cli
```
2020-06-17 11:06:40 +00:00
2020-12-11 20:42:08 +00:00
To install Voxygen and server CLI into user profile:
2020-11-24 01:08:57 +00:00
```shell
2020-12-11 20:42:08 +00:00
nix-env -f nix/default.nix -i
```
### Notes for non-NixOS setups
You'll need to use [nixGL ](https://github.com/guibou/nixGL ) to be able to run the game (after installing it):
```shell
2020-12-12 14:53:48 +00:00
## For Intel and AMD:
# Install it (sadly no flake yet)
nix-env -f https://github.com/guibou/nixGL/archive/master.tar.gz -iA nixGLIntel
2020-12-11 20:42:08 +00:00
nixGLIntel veloren-voxygen
2020-12-12 14:53:48 +00:00
## For Nvidia:
# Install it
nix-env -f https://github.com/guibou/nixGL/archive/master.tar.gz -iA nixGLNvidia
2020-12-11 20:42:08 +00:00
nixGLNvidia veloren-voxygen
2020-12-12 14:53:48 +00:00
## For Nvidia driver on hybrid hardware:
# Install it
nix-env -f https://github.com/guibou/nixGL/archive/master.tar.gz -iA nixGLNvidiaBumblebee
nixGLNvidiaBumblebee veloren-voxygen
2020-12-11 20:42:08 +00:00
```
## Usage for developers
The development shell automatically setups the Cachix cache for you, so it is recommended to be in the dev shell always.
If you have the Cachix cache setup in `~/.config/nix/nix.conf` (as described in the beginning of this document), then this isn't a necessity.
### With flakes
To enter a shell environment with the necessary tools:
```shell
nix develop
2020-11-24 01:08:57 +00:00
```
2020-06-17 11:06:40 +00:00
2020-12-12 14:03:51 +00:00
You can use the `bundle` subcommand to bundle the game into a single distro-agnostic executable file:
```shell
## bundling latest commit to master
# Voxygen:
nix bundle gitlab:veloren/veloren
# Server CLI:
nix bundle gitlab:veloren/veloren#veloren-server-cli
## for local repo:
# Voxygen:
nix bundle .#veloren-voxygen
# Server CLI:
nix bundle .#veloren-server-cli
```
2020-12-11 20:42:08 +00:00
### Without flakes
2020-06-17 11:06:40 +00:00
2020-12-11 20:42:08 +00:00
To enter the development shell:
```shell
nix-shell nix/shell.nix
```
### Direnv
This only works if you have flakes. There is an issue with the git-lfs hook in `shellHook` erroring out with `use nix` , so you'll have to enable flakes if you want to use the `envrc` file included.
If you have [direnv ](https://direnv.net ) and [nix-direnv ](https://github.com/nix-community/nix-direnv ) on your system, you can copy the `envrc` file to the root of the repository as `.envrc` :
```shell
cp nix/envrc .envrc
```
## Managing dependencies
### With flakes
2020-12-11 12:00:04 +00:00
If a specific revision is specified in `flake.nix` , you will have to update that first, either by specifying a new desired revision or by removing it.
2020-06-17 11:06:40 +00:00
2021-03-27 09:41:35 +00:00
You can update dependencies with:
2020-11-24 01:08:57 +00:00
```shell
2021-03-27 09:41:35 +00:00
nix flake update
2020-11-24 01:08:57 +00:00
```
2020-06-20 11:11:24 +00:00
2020-12-11 20:42:08 +00:00
### Without flakes
2020-12-11 12:00:04 +00:00
It is inadvised to update revisions without the use of `nix flake update` as it's both tedious and error-prone to attempt setting all fields to their correct values in both `flake.nix` and `flake.lock` , but if you need to do it for testing, `flake.lock` is where legacy nix commands get the input revisions from (through `flake-compat` ), regardless of what is specified in `flake.nix` (see https://github.com/edolstra/flake-compat/issues/10).
Modify the relevant `rev` field in `flake.lock` to what you need - you can use `nix-prefetch-git` to find an up-to-date revision. Leave the `narHash` entry as is and attempt a rebuild to find out what its value should be.
2020-12-11 20:42:08 +00:00
## Formatting
2020-06-20 11:11:24 +00:00
2022-09-08 09:28:56 +00:00
Use [alejandra ](https://github.com/kamadorueda/alejandra ) to format files.
2020-06-20 11:11:24 +00:00
2020-11-30 00:48:00 +00:00
To format every Nix file:
2020-11-24 01:08:57 +00:00
```shell
2022-09-08 09:28:56 +00:00
# From repository root
alejandra .
2020-11-24 01:08:57 +00:00
```