From b12b7bb6151e89ec79ad02ad7ae569b9ef1be2c3 Mon Sep 17 00:00:00 2001 From: haslersn Date: Wed, 14 Aug 2019 15:12:54 +0200 Subject: [PATCH] default.nix, shell.nix: init This commit inits the `default.nix` and `shell.nix`. They support `nix build` and `nix-shell`, respectively. * `nix-shell` sets up the build environment for Veloren so that you can manually build it using `cargo build`. This is for developping as it speeds up subsequent compilations because intermediate compilation artifacts are reused. * `nix build` builds Veloren, stores the result in the Nix store and creates a `result` symlink to it. Make sure that the LFS files are checked out before using `nix build`. --- default.nix | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 28 ++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 default.nix create mode 100644 shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000000..da3599373f --- /dev/null +++ b/default.nix @@ -0,0 +1,76 @@ +let + fallbackPkgs = import {}; +in + +{ + alsaLib ? fallbackPkgs.alsaLib, + atk ? fallbackPkgs.atk, + cairo ? fallbackPkgs.cairo, + fetchFromGitHub ? fallbackPkgs.fetchFromGitHub, + git ? fallbackPkgs.git, + git-lfs ? fallbackPkgs.git-lfs, + glib ? fallbackPkgs.glib, + gnuplot ? fallbackPkgs.gnuplot, + gtk3 ? fallbackPkgs.gtk3, + makeRustPlatform ? fallbackPkgs.makeRustPlatform, + nix-gitignore ? fallbackPkgs.nix-gitignore, + pango ? fallbackPkgs.pango, + pkg-config ? fallbackPkgs.pkg-config, + pkgs ? fallbackPkgs, + rustup ? fallbackPkgs.rustup, + stdenv ? fallbackPkgs.stdenv, + veloren-src ? null, +}: + +let + mozRepo = fetchFromGitHub { + owner = "mozilla"; + repo = "nixpkgs-mozilla"; + rev = "ac8e9d7bbda8fb5e45cae20c5b7e44c52da3ac0c"; + sha256 = "1irlkqc0jdkxdfznq7r52ycnf0kcvvrz416qc7346xhmilrx2gy6"; + }; + # `mozPkgs` is the package set of `mozRepo`; this differs from their README + # where they use it as an overlay rather than a separate package set + mozPkgs = import "${mozRepo}/package-set.nix" { inherit pkgs; }; + channel = mozPkgs.rustChannelOf { date = "2019-07-03"; channel = "nightly"; }; + nightlyRustPlatform = makeRustPlatform { + rustc = channel.rust; + cargo = channel.cargo; + }; +in + +nightlyRustPlatform.buildRustPackage rec { + name = "veloren"; + version = "unstable"; + # For information on how to automatically fetch the source from GitLab, please + # ask @haslersn + src = if veloren-src == null then (nix-gitignore.gitignoreSource [] ./.) else veloren-src; + nativeBuildInputs = [ + pkg-config + # convenience for nix-shell: + git + git-lfs + gnuplot + rustup # Needed for RLS integration in some IDEs such as vscode + ]; + buildInputs = [ + alsaLib + atk + cairo + glib + gtk3 + pango + ]; + preConfigure = '' + export HOME=`mktemp -d` + ''; + postInstall = '' + cp -R $src/assets $out/bin/assets + ''; + CARGO_INCREMENTAL = 1; + cargoSha256 = "1zhsn69171wazigxxqggwqb5j8qllr5245y2w92dpnrgmdbjqyga"; + + meta = { + platforms = stdenv.lib.platforms.linux; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000000..1c2f87af43 --- /dev/null +++ b/shell.nix @@ -0,0 +1,28 @@ +with import {}; + +import ./default.nix { + # The source is copied to the nix store. We don't want to do this (including assets) for every + # time the `nix-shell` is entered. Therefore we create a source which contains only the files + # necessary to evaluate `buildRustPackage` successfully: + veloren-src = runCommand "veloren-shell" {} (lib.concatMapStrings + (p: "mkdir -p $(dirname $out/${p}); cp ${./. + "/${p}"} $out/${p}\n") + [ + "Cargo.lock" + "Cargo.toml" + "chat-cli/Cargo.toml" + "chat-cli/src/main.rs" + "client/Cargo.toml" + "client/src/lib.rs" + "common/Cargo.toml" + "common/src/lib.rs" + "server-cli/Cargo.toml" + "server-cli/src/main.rs" + "server/Cargo.toml" + "server/src/lib.rs" + "voxygen/Cargo.toml" + "voxygen/src/main.rs" + "world/Cargo.toml" + "world/src/lib.rs" + ] + ); +}