From dd68285d7949dd87b410fdd48c1332dc081e94ac Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Fri, 11 Dec 2020 17:44:13 +0300 Subject: [PATCH 1/9] nix: fix veloren version string in game, remove obsolete utils --- nix/utils.nix | 29 ----------------------------- nix/veloren.nix | 15 +++++++++------ 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/nix/utils.nix b/nix/utils.nix index 2bd844affb..bea5c91bad 100644 --- a/nix/utils.nix +++ b/nix/utils.nix @@ -1,5 +1,4 @@ { pkgs }: { - isGitLfsSetup = checkFile: let gitLfsCheckOutput = @@ -44,32 +43,4 @@ pad = s: if builtins.stringLength s < 2 then "0" + s else s; in "${toString y'}-${pad (toString m)}-${pad (toString d)}-${pad (toString hours)}:${pad (toString minutes)}"; - - getGitInfo = dotGitPath: - let - makeGitCommand = subcommands: name: - builtins.readFile (pkgs.runCommand name { } '' - cd ${ - # Only copy the `.git` directory to nix store, anything else is a waste. - builtins.path { - path = ../.git; - # Nix store path names don't accept names that start with a dot. - name = "dotgit-dir"; - } - } - (${pkgs.git}/bin/git ${subcommands}) > $out - ''); - - in - { - gitHash = makeGitCommand - "log -n 1 --pretty=format:%h/%cd --date=format:%Y-%m-%d-%H:%M --abbrev=8" - "getGitHash"; - - gitTag = - # If the git command errors out we feed an empty string - makeGitCommand "describe --exact-match --tags HEAD || printf ''" - "getGitTag"; - }; - } diff --git a/nix/veloren.nix b/nix/veloren.nix index 116c370df8..e15852148e 100644 --- a/nix/veloren.nix +++ b/nix/veloren.nix @@ -37,13 +37,19 @@ let prettyRev = with sourceInfo; if sourceInfo ? rev && sourceInfo ? lastModified then builtins.substring 0 8 rev + "/" + utils.dateTimeFormat lastModified - else (utils.getGitInfo ../.git).gitHash; + else throw "Need revision + lastModified to determine version"; + + tag = with sourceInfo; + if sourceInfo ? tag + then sourceInfo.tag + else ""; + # If gitTag has a tag (meaning the commit we are on is a *release*), use # it as version, else: just use the prettified hash we have, if we don't # have it the build fails. # Must be in format f4987672/2020-12-10-12:00 version = - if sourceInfo ? tag then sourceInfo.tag + if tag != "" then tag else if prettyRev != "" then prettyRev else throw "Need a tag or at least revision + lastModified in order to determine version"; # Sanitize version string since it might contain illegal characters for a Nix store path @@ -79,10 +85,7 @@ let DISABLE_GIT_LFS_CHECK = utils.isGitLfsSetup common.gitLfsCheckFile; # Declare env values here so that `common/build.rs` sees them NIX_GIT_HASH = prettyRev; - # if we have a tag (meaning the commit we are on is a *release*), - # use it as version, else use the prettified hash we have; - # if we don't have it the build fails - NIX_GIT_TAG = version; + NIX_GIT_TAG = tag; }; veloren-server-cli = _: { name = "veloren-server-cli_${sanitizedVersion}"; From 4c61914b91986a1774ebd3743d56d12f2071e207 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Fri, 11 Dec 2020 17:50:06 +0300 Subject: [PATCH 2/9] nix: remove version from package names --- nix/veloren.nix | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/nix/veloren.nix b/nix/veloren.nix index e15852148e..7447e639a9 100644 --- a/nix/veloren.nix +++ b/nix/veloren.nix @@ -52,9 +52,6 @@ let if tag != "" then tag else if prettyRev != "" then prettyRev else throw "Need a tag or at least revision + lastModified in order to determine version"; - # Sanitize version string since it might contain illegal characters for a Nix store path - # Used in the derivation(s) name - sanitizedVersion = pkgs.stdenv.lib.strings.sanitizeDerivationName version; veloren-assets = pkgs.runCommand "makeAssetsDir" { } '' mkdir $out @@ -88,7 +85,7 @@ let NIX_GIT_TAG = tag; }; veloren-server-cli = _: { - name = "veloren-server-cli_${sanitizedVersion}"; + name = "veloren-server-cli"; inherit version; VELOREN_USERDATA_STRATEGY = "system"; nativeBuildInputs = [ makeWrapper ]; @@ -103,7 +100,7 @@ let }; }; veloren-voxygen = _: { - name = "veloren-voxygen_${sanitizedVersion}"; + name = "veloren-voxygen"; inherit version; VELOREN_USERDATA_STRATEGY = "system"; inherit (crateDeps.veloren-voxygen) buildInputs; From 9f8ec7e01050ae14d4541943bf9a9f85c056dca7 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Fri, 11 Dec 2020 18:00:16 +0300 Subject: [PATCH 3/9] nix: refactor crateDeps in common to look better --- nix/common.nix | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/nix/common.nix b/nix/common.nix index 755b0e2663..cb4701ef65 100644 --- a/nix/common.nix +++ b/nix/common.nix @@ -20,24 +20,16 @@ in with pkgs; let # deps that crates need (for compiling) - crateDeps = { - libudev-sys = { - buildInputs = [ libudev ]; - nativeBuildInputs = [ pkg-config ]; + crateDeps = + let + makeDeps = b: n: { buildInputs = b; nativeBuildInputs = n; }; + in + { + libudev-sys = makeDeps [ libudev ] [ pkg-config ]; + alsa-sys = makeDeps [ alsaLib ] [ pkg-config ]; + veloren-network = makeDeps [ openssl ] [ pkg-config ]; + veloren-voxygen = makeDeps [ xorg.libxcb ] [ ]; }; - alsa-sys = { - buildInputs = [ alsaLib ]; - nativeBuildInputs = [ pkg-config ]; - }; - veloren-network = { - buildInputs = [ openssl ]; - nativeBuildInputs = [ pkg-config ]; - }; - veloren-voxygen = { - buildInputs = [ xorg.libxcb ]; - nativeBuildInputs = [ ]; - }; - }; # deps that voxygen needs to function # FIXME: Wayland doesn't work (adding libxkbcommon, wayland and wayland-protocols results in a panic) From 9e62a6c32275d63546500543a33d1e9d02217ab3 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Fri, 11 Dec 2020 23:42:08 +0300 Subject: [PATCH 4/9] 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 --- flake.lock | 18 ------ flake.nix | 7 -- nix/Cargo.nix | 96 --------------------------- nix/README.md | 164 +++++++++++++++++++++++++++++------------------ nix/common.nix | 15 +---- nix/devShell.nix | 13 +--- nix/envrc | 3 +- nix/envrc-nvidia | 8 --- nix/rustPkgs.nix | 1 - 9 files changed, 109 insertions(+), 216 deletions(-) delete mode 100644 nix/envrc-nvidia diff --git a/flake.lock b/flake.lock index 5c2ef22ba0..a8212647d1 100644 --- a/flake.lock +++ b/flake.lock @@ -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" } diff --git a/flake.nix b/flake.nix index 979e7d5b52..b3223f95b9 100644 --- a/flake.nix +++ b/flake.nix @@ -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 ; diff --git a/nix/Cargo.nix b/nix/Cargo.nix index f5cf9d09b7..a3dbcec54d 100644 --- a/nix/Cargo.nix +++ b/nix/Cargo.nix @@ -4141,62 +4141,6 @@ rec { }; resolvedDefaultFeatures = [ "default" "std" ]; }; - "failure" = rec { - crateName = "failure"; - version = "0.1.8"; - edition = "2015"; - sha256 = "11jg1wmbkijrs6bk9fqnbrm9zf0850whnqpgnxyswbn0dk8rnbnk"; - authors = [ - "Without Boats " - ]; - 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 " - ]; - 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 " - ]; - 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"; diff --git a/nix/README.md b/nix/README.md index 12069ca79a..646c41554c 100644 --- a/nix/README.md +++ b/nix/README.md @@ -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 ``` diff --git a/nix/common.nix b/nix/common.nix index cb4701ef65..e52ec4e995 100644 --- a/nix/common.nix +++ b/nix/common.nix @@ -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 - ; } diff --git a/nix/devShell.nix b/nix/devShell.nix index 4e12fd817e..70c8c6f382 100644 --- a/nix/devShell.nix +++ b/nix/devShell.nix @@ -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" diff --git a/nix/envrc b/nix/envrc index 94613c39c5..8b2fabb1d0 100644 --- a/nix/envrc +++ b/nix/envrc @@ -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 diff --git a/nix/envrc-nvidia b/nix/envrc-nvidia deleted file mode 100644 index 41a023e85c..0000000000 --- a/nix/envrc-nvidia +++ /dev/null @@ -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 diff --git a/nix/rustPkgs.nix b/nix/rustPkgs.nix index b02027211d..e4f9106c7a 100644 --- a/nix/rustPkgs.nix +++ b/nix/rustPkgs.nix @@ -8,7 +8,6 @@ let rustToolchain = ../rust-toolchain; sha256 = "sha256-kDtMqYvrTbahqYHYFQOWyvT0+F5o4UVcqkMZt0c43kc="; }; - in channel // { rust = channel.rust.override { extensions = [ "rust-src" ]; }; From 64812249ad699f769da2405754269b1bec432399 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sat, 12 Dec 2020 17:03:51 +0300 Subject: [PATCH 5/9] nix: add bundle subcommand usage --- nix/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nix/README.md b/nix/README.md index 646c41554c..26c9f800df 100644 --- a/nix/README.md +++ b/nix/README.md @@ -126,6 +126,20 @@ To enter a shell environment with the necessary tools: nix develop ``` +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 +``` + ### Without flakes To enter the development shell: From b75a5ab32c04f221d6f6f07b095debc87e41cc08 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sat, 12 Dec 2020 17:11:51 +0300 Subject: [PATCH 6/9] nix: regenerate Cargo.nix --- nix/Cargo.nix | 108 +++++++++++--------------------------------------- 1 file changed, 23 insertions(+), 85 deletions(-) diff --git a/nix/Cargo.nix b/nix/Cargo.nix index a3dbcec54d..9dcaf75a95 100644 --- a/nix/Cargo.nix +++ b/nix/Cargo.nix @@ -33,26 +33,6 @@ rec { # You can override the features with # workspaceMembers."${crateName}".build.override { features = [ "default" "feature1" ... ]; }. workspaceMembers = { - "tools" = rec { - packageId = "tools"; - build = internal.buildRustCrateWithFeatures { - packageId = "tools"; - }; - - # Debug support which might change between releases. - # File a bug if you depend on any for non-debug work! - debug = internal.debugCrate { inherit packageId; }; - }; - "veloren-chat-cli" = rec { - packageId = "veloren-chat-cli"; - build = internal.buildRustCrateWithFeatures { - packageId = "veloren-chat-cli"; - }; - - # Debug support which might change between releases. - # File a bug if you depend on any for non-debug work! - debug = internal.debugCrate { inherit packageId; }; - }; "veloren-client" = rec { packageId = "veloren-client"; build = internal.buildRustCrateWithFeatures { @@ -13158,34 +13138,6 @@ rec { }; resolvedDefaultFeatures = [ "default" ]; }; - "tools" = rec { - crateName = "tools"; - version = "0.1.0"; - edition = "2018"; - crateBin = [ - { name = "tools"; path = "src/main.rs"; } - ]; - src = lib.cleanSourceWith { filter = sourceFilter; src = ../tools; }; - authors = [ - "Sam " - ]; - dependencies = [ - { - name = "csv"; - packageId = "csv"; - } - { - name = "structopt"; - packageId = "structopt"; - } - { - name = "veloren-common"; - packageId = "veloren-common"; - rename = "common"; - } - ]; - - }; "tracing" = rec { crateName = "tracing"; version = "0.1.21"; @@ -14202,42 +14154,6 @@ rec { }; resolvedDefaultFeatures = [ "default" "platform_intrinsics" "repr_simd" "rgb" "rgba" "serde" "std" ]; }; - "veloren-chat-cli" = rec { - crateName = "veloren-chat-cli"; - version = "0.8.0"; - edition = "2018"; - crateBin = [ - { name = "veloren-chat-cli"; path = "src/main.rs"; } - ]; - src = lib.cleanSourceWith { filter = sourceFilter; src = ../chat-cli; }; - authors = [ - "Joshua Barretto " - ]; - dependencies = [ - { - name = "tracing"; - packageId = "tracing"; - usesDefaultFeatures = false; - } - { - name = "tracing-subscriber"; - packageId = "tracing-subscriber"; - usesDefaultFeatures = false; - features = [ "fmt" "chrono" "ansi" "smallvec" ]; - } - { - name = "veloren-client"; - packageId = "veloren-client"; - rename = "client"; - } - { - name = "veloren-common"; - packageId = "veloren-common"; - rename = "common"; - } - ]; - - }; "veloren-client" = rec { crateName = "veloren-client"; version = "0.8.0"; @@ -14328,6 +14244,14 @@ rec { features = [ "compression" ]; } ]; + devDependencies = [ + { + name = "tracing-subscriber"; + packageId = "tracing-subscriber"; + usesDefaultFeatures = false; + features = [ "fmt" "chrono" "ansi" "smallvec" ]; + } + ]; features = { "default" = [ "simd" ]; "simd" = [ "vek/platform_intrinsics" ]; @@ -14338,6 +14262,9 @@ rec { crateName = "veloren-common"; version = "0.8.0"; edition = "2018"; + crateBin = [ + { name = "csv_export"; path = "src/bin/csv_export/main.rs"; } + ]; src = lib.cleanSourceWith { filter = sourceFilter; src = ../common; }; authors = [ "Joshua Barretto " @@ -14357,6 +14284,11 @@ rec { name = "crossbeam"; packageId = "crossbeam"; } + { + name = "csv"; + packageId = "csv"; + optional = true; + } { name = "directories-next"; packageId = "directories-next"; @@ -14461,6 +14393,11 @@ rec { name = "spin_sleep"; packageId = "spin_sleep"; } + { + name = "structopt"; + packageId = "structopt"; + optional = true; + } { name = "sum_type"; packageId = "sum_type"; @@ -14488,11 +14425,12 @@ rec { } ]; features = { + "bin_csv_export" = [ "csv" "structopt" ]; "default" = [ "simd" ]; "simd" = [ "vek/platform_intrinsics" ]; "tracy" = [ "tracy-client" ]; }; - resolvedDefaultFeatures = [ "default" "no-assets" "simd" "tracy" "tracy-client" ]; + resolvedDefaultFeatures = [ "bin_csv_export" "csv" "default" "no-assets" "simd" "structopt" "tracy" "tracy-client" ]; }; "veloren-server" = rec { crateName = "veloren-server"; From 23d1abc8a6ec38c4f61f9cb7466d9b2464f8c87f Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sat, 12 Dec 2020 17:26:02 +0300 Subject: [PATCH 7/9] nix: add missing dependency xcb --- nix/common.nix | 1 + nix/veloren.nix | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nix/common.nix b/nix/common.nix index e52ec4e995..5954c2042a 100644 --- a/nix/common.nix +++ b/nix/common.nix @@ -28,6 +28,7 @@ with pkgs; alsa-sys = makeDeps [ alsaLib ] [ pkg-config ]; veloren-network = makeDeps [ openssl ] [ pkg-config ]; veloren-voxygen = makeDeps [ xorg.libxcb ] [ ]; + xcb = makeDeps [ ] [ python3 ]; }; # deps that voxygen needs to function # FIXME: Wayland doesn't work (adding libxkbcommon, wayland and wayland-protocols results in a panic) diff --git a/nix/veloren.nix b/nix/veloren.nix index 7447e639a9..68418634ae 100644 --- a/nix/veloren.nix +++ b/nix/veloren.nix @@ -71,11 +71,8 @@ let veloren-crates = with pkgs; callPackage ./Cargo.nix { - defaultCrateOverrides = with common; + defaultCrateOverrides = with common; with crateDeps; defaultCrateOverrides // { - libudev-sys = _: crateDeps.libudev-sys; - alsa-sys = _: crateDeps.alsa-sys; - veloren-network = _: crateDeps.veloren-network; veloren-common = _: { # Disable `git-lfs` check here since we check it ourselves # We have to include the command output here, otherwise Nix won't run it @@ -103,8 +100,8 @@ let name = "veloren-voxygen"; inherit version; VELOREN_USERDATA_STRATEGY = "system"; - inherit (crateDeps.veloren-voxygen) buildInputs; - nativeBuildInputs = crateDeps.veloren-voxygen.nativeBuildInputs + inherit (veloren-voxygen) buildInputs; + nativeBuildInputs = veloren-voxygen.nativeBuildInputs ++ [ makeWrapper copyDesktopItems ]; desktopItems = [ velorenVoxygenDesktopFile ]; postInstall = '' @@ -121,6 +118,11 @@ let ''; }; }; + } // { + xcb = _: xcb; + libudev-sys = _: libudev-sys; + alsa-sys = _: alsa-sys; + veloren-network = _: veloren-network; }; inherit release pkgs; }; From c5a7db06fb433d4caeb2a6460bc37d794cb21681 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sat, 12 Dec 2020 17:53:48 +0300 Subject: [PATCH 8/9] nix: better instructions for nixGL --- nix/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nix/README.md b/nix/README.md index 26c9f800df..b5f8812859 100644 --- a/nix/README.md +++ b/nix/README.md @@ -108,10 +108,18 @@ nix-env -f nix/default.nix -i 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: +## For Intel and AMD: +# Install it (sadly no flake yet) +nix-env -f https://github.com/guibou/nixGL/archive/master.tar.gz -iA nixGLIntel nixGLIntel veloren-voxygen -# For Nvidia: +## For Nvidia: +# Install it +nix-env -f https://github.com/guibou/nixGL/archive/master.tar.gz -iA nixGLNvidia nixGLNvidia veloren-voxygen +## 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 ``` ## Usage for developers From 9ecaba8552dc64889e51f3ce624369ad64a00381 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sat, 12 Dec 2020 21:14:29 +0300 Subject: [PATCH 9/9] nix: workaround an issue with crate2nix, change some errors to be more clear --- nix/Cargo.nix | 4 ++-- nix/Cargo.nix_patches.md | 6 ++++++ nix/README.md | 1 + nix/veloren.nix | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 nix/Cargo.nix_patches.md diff --git a/nix/Cargo.nix b/nix/Cargo.nix index 9dcaf75a95..1a0719cbb5 100644 --- a/nix/Cargo.nix +++ b/nix/Cargo.nix @@ -14287,7 +14287,7 @@ rec { { name = "csv"; packageId = "csv"; - optional = true; + # optional = true; } { name = "directories-next"; @@ -14396,7 +14396,7 @@ rec { { name = "structopt"; packageId = "structopt"; - optional = true; + # optional = true; } { name = "sum_type"; diff --git a/nix/Cargo.nix_patches.md b/nix/Cargo.nix_patches.md new file mode 100644 index 0000000000..39ef390580 --- /dev/null +++ b/nix/Cargo.nix_patches.md @@ -0,0 +1,6 @@ +Apply these instructions after generating the `Cargo.nix` file. + +- Find `veloren-common` crate in `Cargo.nix`: + - Comment the `optional = true;` line for "structopt" and "csv" dependencies. + - See [this issue](https://github.com/kolloch/crate2nix/issues/129) on `crate2nix` repository for more info. + - Note that the suggested workaround in the issue **does not** work for us. diff --git a/nix/README.md b/nix/README.md index b5f8812859..cd0de67841 100644 --- a/nix/README.md +++ b/nix/README.md @@ -192,6 +192,7 @@ To update `Cargo.nix` (and `crate-hashes.json`) using latest `Cargo.lock`, run: ```shell crate2nix generate -f ../Cargo.toml ``` +Then follow the instructions in the `Cargo.nix_patches.md` file. ### Rust toolchain diff --git a/nix/veloren.nix b/nix/veloren.nix index 68418634ae..e7b2912aff 100644 --- a/nix/veloren.nix +++ b/nix/veloren.nix @@ -37,7 +37,7 @@ let prettyRev = with sourceInfo; if sourceInfo ? rev && sourceInfo ? lastModified then builtins.substring 0 8 rev + "/" + utils.dateTimeFormat lastModified - else throw "Need revision + lastModified to determine version"; + else throw "Need revision + lastModified to determine pretty revision"; tag = with sourceInfo; if sourceInfo ? tag @@ -51,7 +51,7 @@ let version = if tag != "" then tag else if prettyRev != "" then prettyRev - else throw "Need a tag or at least revision + lastModified in order to determine version"; + else throw "Need a tag or pretty revision in order to determine version"; veloren-assets = pkgs.runCommand "makeAssetsDir" { } '' mkdir $out