nix: update README, remove nixGL selection from dev shell (which also removes envrc-nvidia), update envrc to be used by both flakes, tidy up some stuff

This commit is contained in:
Yusuf Bera Ertan 2020-12-11 23:42:08 +03:00
parent 9f8ec7e010
commit 9e62a6c322
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
9 changed files with 109 additions and 216 deletions

View File

@ -32,23 +32,6 @@
"type": "github"
}
},
"nixGL": {
"flake": false,
"locked": {
"lastModified": 1604138361,
"narHash": "sha256-I9/myywtqh9xrxC94molYpwN4c92dw1jUmfS2+pHwws=",
"owner": "guibou",
"repo": "nixGL",
"rev": "7d6bc1b21316bab6cf4a6520c2639a11c25a220e",
"type": "github"
},
"original": {
"owner": "guibou",
"repo": "nixGL",
"rev": "7d6bc1b21316bab6cf4a6520c2639a11c25a220e",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1606744648,
@ -85,7 +68,6 @@
"inputs": {
"crate2nix": "crate2nix",
"flake-utils": "flake-utils",
"nixGL": "nixGL",
"nixpkgs": "nixpkgs",
"nixpkgsMoz": "nixpkgsMoz"
}

View File

@ -11,22 +11,15 @@
url = "github:mozilla/nixpkgs-mozilla";
flake = false;
};
nixGL = {
url = "github:guibou/nixGL?rev=7d6bc1b21316bab6cf4a6520c2639a11c25a220e";
flake = false;
};
nixpkgs.url = "github:NixOS/nixpkgs?rev=c00959877fb06b09468562518b408acda886c79e";
};
outputs = inputs: with inputs;
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = inputs.nixpkgs.legacyPackages."${system}";
sources = {
inherit
crate2nix
nixGL
nixpkgs
nixpkgsMoz
;

View File

@ -4141,62 +4141,6 @@ rec {
};
resolvedDefaultFeatures = [ "default" "std" ];
};
"failure" = rec {
crateName = "failure";
version = "0.1.8";
edition = "2015";
sha256 = "11jg1wmbkijrs6bk9fqnbrm9zf0850whnqpgnxyswbn0dk8rnbnk";
authors = [
"Without Boats <boats@mozilla.com>"
];
dependencies = [
{
name = "backtrace";
packageId = "backtrace";
optional = true;
}
{
name = "failure_derive";
packageId = "failure_derive";
optional = true;
}
];
features = {
"default" = [ "std" "derive" ];
"derive" = [ "failure_derive" ];
"std" = [ "backtrace" ];
};
resolvedDefaultFeatures = [ "backtrace" "default" "derive" "failure_derive" "std" ];
};
"failure_derive" = rec {
crateName = "failure_derive";
version = "0.1.8";
edition = "2015";
sha256 = "1936adqqk080439kx2bjf1bds7h89sg6wcif4jw0syndcv3s6kda";
procMacro = true;
authors = [
"Without Boats <woboats@gmail.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 1.0.23";
}
{
name = "quote";
packageId = "quote 1.0.7";
}
{
name = "syn";
packageId = "syn 1.0.42";
}
{
name = "synstructure";
packageId = "synstructure";
}
];
features = { };
};
"fehler" = rec {
crateName = "fehler";
version = "1.0.0";
@ -12502,42 +12446,6 @@ rec {
};
resolvedDefaultFeatures = [ "clone-impls" "default" "derive" "extra-traits" "fold" "full" "parsing" "printing" "proc-macro" "quote" "visit" "visit-mut" ];
};
"synstructure" = rec {
crateName = "synstructure";
version = "0.12.4";
edition = "2018";
sha256 = "00c72ij813xsilssgya6m6f73d0s5zzsld1y26bvhk3kdzbg4d5q";
authors = [
"Nika Layzell <nika@thelayzells.com>"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2 1.0.23";
usesDefaultFeatures = false;
}
{
name = "quote";
packageId = "quote 1.0.7";
usesDefaultFeatures = false;
}
{
name = "syn";
packageId = "syn 1.0.42";
usesDefaultFeatures = false;
features = [ "derive" "parsing" "printing" "clone-impls" "visit" "extra-traits" ];
}
{
name = "unicode-xid";
packageId = "unicode-xid 0.2.1";
}
];
features = {
"default" = [ "proc-macro" ];
"proc-macro" = [ "proc-macro2/proc-macro" "syn/proc-macro" "quote/proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
};
"take_mut" = rec {
crateName = "take_mut";
version = "0.2.2";
@ -14907,10 +14815,6 @@ rec {
name = "euc";
packageId = "euc";
}
{
name = "failure";
packageId = "failure";
}
{
name = "gfx";
packageId = "gfx";

View File

@ -1,71 +1,52 @@
## Important
## Read this first!
If you are going to call the derivations with a custom `nixpkgs` argument, make sure that the `nixpkgs` you pass is on at least the same commit or newer than it.
Unexpected errors may pop up if you use an older version. Same goes for the `sources` argument.
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.
### How to use
See the [NixOS wiki](https://nixos.wiki/wiki/Flakes) for information on how to enable and use flakes.
To enter the development shell (which includes all tools mentioned in this readme + tools you'll need to develop Veloren), run:
It is recommended to first setup the [Cachix](https://cachix.org) cache to save time with builds:
```shell
nix-shell nix/shell.nix
```
It is recommended that you enter the dev shell before starting to build using `nix-build` or `nix-env` (anything which build stuff),
since it will setup a Cachix cache for you. (you can configure this for your user's `nix.conf` by running `cachix use veloren-nix` once in the dev shell,
which will make the cache available when you run commands outside of the dev shell).
If you have [direnv](https://direnv.net) setup on your system, it is also recommended to copy the `envrc`
(or `envrc-nvidia`, if you have an Nvidia GPU) file to the root of the repository as `.envrc`:
```shell
cp nix/envrc .envrc
```
This will make your env have the dev env setup automatically.
To build and install Voxygen and the server CLI into user profile, run:
```shell
nix-env -f nix/default.nix -i
```
You can configure what to install by changing the `cratesToBuild` argument:
```shell
nix-env -f nix/default.nix --arg cratesToBuild '["veloren-voxygen"]'
```
For example, this will install Voxygen only.
You can configure the crates to be built with debug mode (not recommended, equals to `opt-level = 0`):
```shell
nix-env -f nix/default.nix --arg release false
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"
```
If you aren't on NixOS, you can run `veloren-voxygen` using the provided `nixGLIntel` in the dev shell:
As this repository uses `git-lfs`, please make sure `git-lfs` is in your path.
If you have a locally cloned repo, you can make sure it is setup with:
```shell
nixGLIntel veloren-voxygen
git lfs install --local && git lfs fetch && git lfs checkout
```
If you have an Nvidia GPU, you can enter the dev shell like so:
```shell
nix-shell nix/shell.nix --arg nvidia true
```
And you'll be able to use `nixGLNvidia` and `nixGLNvidiaBumblebee`.
This should be automatically done if you use the development shell.
#### Using the flake
## Usage for players
Due to the nature of flakes' reliance on git and the way `git-lfs` is configured for this repo, you must already have `git-lfs` in your environment when running nix commands on a local checkout. Run this to enter a shell environment with `git-lfs` in your path:
```shell
nix shell nixpkgs#git-lfs
```
### With flakes
To enter a shell environment with the necessary tools:
```shell
nix develop
```
If you simply want to run the latest version without necessarily installing it, you can do so with
If you just want to run the game without installing it, you can do so with:
```shell
# Voxygen (the default):
nix run gitlab:veloren/veloren
# Server CLI:
nix run gitlab:veloren/veloren#veloren-server-cli
# or if you have a local repo
nix run .
nix run .#veloren-server-cli
```
To install (for example) the game client on your system, the configuration could look something like this:
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:
nix profile install .
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:
```nix
{ description = "NixOS configuration with flakes";
@ -106,18 +87,64 @@ To install (for example) the game client on your system, the configuration could
}
```
### Managing Cargo.nix
### Without flakes
Enter the development shell.
To update `Cargo.nix` (and `crate-hashes.json`) using latest `Cargo.lock`, run:
You can do this to run the game without installing it (you will need a local clone of the repo though):
```shell
crate2nix generate -f ../Cargo.toml
# build the game
nix-build nix/default.nix
# run it
./result/bin/veloren-voxygen
# or for server cli
./result-2/bin/veloren-server-cli
```
### Managing dependencies
To install Voxygen and server CLI into user profile:
```shell
nix-env -f nix/default.nix -i
```
#### Nix with flakes enabled
### 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
# For Intel and AMD:
nixGLIntel veloren-voxygen
# For Nvidia:
nixGLNvidia veloren-voxygen
```
## 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
```
### Without flakes
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
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.
@ -129,19 +156,34 @@ nix flake update --update-input nixpkgs
nix flake update --recreate-lock-file
```
See the [NixOS wiki](https://nixos.wiki/wiki/Flakes) for more information on how to use flakes.
#### Legacy nix
### Without flakes
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.
### Formatting
### Generating Cargo.nix
Enter the development shell.
To update `Cargo.nix` (and `crate-hashes.json`) using latest `Cargo.lock`, run:
```shell
crate2nix generate -f ../Cargo.toml
```
### Rust toolchain
If the `rust-toolchain` file is updated, you will need to update the `sha256` hash in the `nix/rustPkgs.nix` file.
Trying to build the derivation should give you the correct hash to put in.
## Formatting
Use [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) to format files.
To format every Nix file:
```shell
nixpkgs-fmt flake.nix nix/*.nix
# or
nixpkgs-fmt **/**.nix
```

View File

@ -11,14 +11,13 @@ let
(final: prev: {
rustc = rustChannel.rust;
crate2nix = prev.callPackage sources.crate2nix { pkgs = prev; };
nixGL = prev.callPackage sources.nixGL { pkgs = prev; };
})
];
};
in
with pkgs;
let
{
inherit pkgs;
# deps that crates need (for compiling)
crateDeps =
let
@ -30,19 +29,9 @@ let
veloren-network = makeDeps [ openssl ] [ pkg-config ];
veloren-voxygen = makeDeps [ xorg.libxcb ] [ ];
};
# deps that voxygen needs to function
# FIXME: Wayland doesn't work (adding libxkbcommon, wayland and wayland-protocols results in a panic)
voxygenNeededLibs = (with xorg; [ libX11 libXcursor libXrandr libXi ])
++ [ libGL ];
gitLfsCheckFile = ../assets/voxygen/background/bg_main.png;
in
{
inherit
crateDeps
gitLfsCheckFile
pkgs
voxygenNeededLibs
;
}

View File

@ -1,4 +1,4 @@
{ nixpkgs, sources, system, nvidia ? false }:
{ nixpkgs, sources, system }:
with import ./common.nix
{
inherit
@ -9,22 +9,13 @@ with import ./common.nix
};
with pkgs;
let
nixGLPackages = ((with nixGL; [ nixGLIntel ]) ++ (lib.optional nvidia
(with nixGL; [ nixGLNvidia nixGLNvidiaBumblebee ])));
getAllCratesDeps = name:
(lib.concatLists
(map (attrset: attrset."${name}") (lib.attrValues crateDeps)));
bundleCrate = writeScriptBin "bundleCrate" ''
#!${stdenv.shell}
${nix-bundle}/bin/nix-bundle "(pkgs.callPackage ./nix/veloren.nix { cratesToBuild = [ \"$1\" ]; }).$1" /bin/$1
'';
in
mkShell {
name = "veloren-shell";
nativeBuildInputs = [
bundleCrate
cachix
cargo
clippy
@ -34,7 +25,7 @@ mkShell {
nixpkgs-fmt
rustc
rustfmt
] ++ nixGLPackages ++ (getAllCratesDeps "nativeBuildInputs");
] ++ (getAllCratesDeps "nativeBuildInputs");
buildInputs = getAllCratesDeps "buildInputs";
shellHook = ''
# Setup our cachix "substituter"

View File

@ -5,4 +5,5 @@ watch_file nix/devShell.nix
watch_file nix/rustPkgs.nix
watch_file nix/shell.nix
watch_file nix/utils.nix
use nix nix/shell.nix
use flake

View File

@ -1,8 +0,0 @@
watch_file flake.lock
watch_file flake.nix
watch_file nix/common.nix
watch_file nix/devShell.nix
watch_file nix/rustPkgs.nix
watch_file nix/shell.nix
watch_file nix/utils.nix
use nix nix/shell.nix --arg nvidia true

View File

@ -8,7 +8,6 @@ let
rustToolchain = ../rust-toolchain;
sha256 = "sha256-kDtMqYvrTbahqYHYFQOWyvT0+F5o4UVcqkMZt0c43kc=";
};
in
channel // {
rust = channel.rust.override { extensions = [ "rust-src" ]; };