From 78b1773c05bdf39e0ef29bde4024a5e78a582828 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Tue, 27 Apr 2021 05:18:12 +0300 Subject: [PATCH] build(nix): switch to crate2nix --- Cargo.toml | 7 ++-- flake.lock | 61 +++++++++++++++++++++------------- flake.nix | 78 ++++++++++++++++++++++++++------------------ nix/nullOggPatch.nix | 18 ++++++++++ voxygen/Cargo.toml | 2 ++ 5 files changed, 108 insertions(+), 58 deletions(-) create mode 100644 nix/nullOggPatch.nix diff --git a/Cargo.toml b/Cargo.toml index d1cfa92648..5e1c09240b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,10 +100,11 @@ vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" } [workspace.metadata.nix] systems = ["x86_64-linux"] -buildInputs = ["libudev", "alsaLib", "openssl", "xorg.libxcb", "libxkbcommon"] -nativeBuildInputs = ["pkg-config", "python3", "binutils"] -runtimeLibs = ["libGL", "xorg.libX11", "xorg.libXcursor", "xorg.libXrandr", "xorg.libXi"] [workspace.metadata.nix.cachix] name = "veloren-nix" key = "veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc=" + +[workspace.metadata.nix.crateOverride.veloren-network] +buildInputs = ["openssl"] +nativeBuildInputs = ["pkg-config"] diff --git a/flake.lock b/flake.lock index 640c2acb74..4dd00e15c9 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,29 @@ { "nodes": { + "crate2nix": { + "flake": false, + "locked": { + "lastModified": 1619462726, + "narHash": "sha256-bQuUBOGzPnL3S+aweK/P9WRfNGk/tuoLDPfzIiX7XXY=", + "owner": "yusdacra", + "repo": "crate2nix", + "rev": "e10f71834d1464cd4b07d1bf7965c65abbff3fab", + "type": "github" + }, + "original": { + "owner": "yusdacra", + "ref": "feat/builtinfetchgit", + "repo": "crate2nix", + "type": "github" + } + }, "devshell": { "locked": { - "lastModified": 1618213758, - "narHash": "sha256-qkuen2xlT7gVfX+99OeM4lsKXGjT5EDjytWAeAWX0Fw=", + "lastModified": 1618523768, + "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=", "owner": "numtide", "repo": "devshell", - "rev": "eac56f015b0975be3b725721503626e926b285e8", + "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21", "type": "github" }, "original": { @@ -32,11 +49,11 @@ }, "flakeUtils": { "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", + "lastModified": 1619345332, + "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", "owner": "numtide", "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", + "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", "type": "github" }, "original": { @@ -52,38 +69,37 @@ ] }, "locked": { - "lastModified": 1618579991, - "narHash": "sha256-aIWvSjn/rjfOBUdL5uM4iDVVLM7ioRz9zs3e94lT9Ac=", + "lastModified": 1619312121, + "narHash": "sha256-Zx1rTlonsp54lVlnIg38HV3bYx6GdIoKS1SgDnV+YBY=", "owner": "yusdacra", "repo": "naersk", - "rev": "dc8868af09c8a0f0d47df0927161cb14675c5534", + "rev": "07d0b56bdbd353a705f26b799e3a125c7be0f8c3", "type": "github" }, "original": { "owner": "yusdacra", - "ref": "veloren", + "ref": "feat/cargolock-git-deps", "repo": "naersk", "type": "github" } }, "nixCargoIntegration": { "inputs": { + "crate2nix": "crate2nix", "devshell": "devshell", "flakeUtils": "flakeUtils", - "naersk": [ - "naersk" - ], + "naersk": "naersk", "nixpkgs": [ "nixpkgs" ], "rustOverlay": "rustOverlay" }, "locked": { - "lastModified": 1618597947, - "narHash": "sha256-wiwHpQPzgkuOEZXFpet7bmv6Z8dusxyp6DQbpYCXJDk=", + "lastModified": 1619489852, + "narHash": "sha256-ZiWHvTrMHcTAyPyT0HiqvTXjh3cFO4tHWSV/2v2g5YI=", "owner": "yusdacra", "repo": "nix-cargo-integration", - "rev": "fc26a4e1d807e8b9722d67097be4dfb8be5ea862", + "rev": "ab95ec5f81cce07b3c76609f4681772fe20bcfa1", "type": "github" }, "original": { @@ -94,11 +110,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1618530127, - "narHash": "sha256-jQPk7XpabppYa+GIO5LVTtUFhHq/VqHhPggwIKhTCnQ=", + "lastModified": 1619446560, + "narHash": "sha256-R9iG5d1ORvho5UlyEUsX8Nu1cnCV+YtWEHlWlqftaQo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "294d1925af6462e55c76b49624b983036f0093b9", + "rev": "32f7980afb5e33f1e078a51e715b9f102f396a69", "type": "github" }, "original": { @@ -110,7 +126,6 @@ }, "root": { "inputs": { - "naersk": "naersk", "nixCargoIntegration": "nixCargoIntegration", "nixpkgs": "nixpkgs" } @@ -123,11 +138,11 @@ ] }, "locked": { - "lastModified": 1618366946, - "narHash": "sha256-5zevIklODemySoUY8xtIemD/WO7ftaXeltz9rraEVAc=", + "lastModified": 1619404147, + "narHash": "sha256-qJafGirQc8LfELiU6cJU7e/CS8PuZpyxjNkXd8KXR08=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "82b13c9048b345cf6345dd326478ad5ec059e6c6", + "rev": "c9c3bd19e542dc3532d58297fbbc1762fdc8497a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 37eb2641f3..d5d0820086 100644 --- a/flake.nix +++ b/flake.nix @@ -2,15 +2,10 @@ description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust."; inputs = { - naersk = { - url = "github:yusdacra/naersk/veloren"; - inputs.nixpkgs.follows = "nixpkgs"; - }; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixCargoIntegration = { url = "github:yusdacra/nix-cargo-integration"; inputs.nixpkgs.follows = "nixpkgs"; - inputs.naersk.follows = "naersk"; }; }; @@ -18,14 +13,19 @@ let output = inputs.nixCargoIntegration.lib.makeOutputs { root = ./.; + buildPlatform = "crate2nix"; overrides = { - common = prev: { - gitLfsCheckFile = ./assets/voxygen/background/bg_main.png; - utils = import ./nix/utils.nix { pkgs = prev.pkgs; }; + build = common: prev: { + runTests = !prev.release && prev.runTests; }; - build = common: prevb: + common = prev: let - pkgs = common.pkgs; + pkgs = prev.pkgs; + lib = pkgs.lib; + + gitLfsCheckFile = ./assets/voxygen/background/bg_main.png; + utils = import ./nix/utils.nix { inherit pkgs; }; + sourceInfo = if inputs.self.sourceInfo ? rev then inputs.self.sourceInfo // { @@ -35,7 +35,7 @@ } else (throw "Can't get revision because the git tree is dirty"); - prettyRev = with sourceInfo; builtins.substring 0 8 rev + "/" + common.utils.dateTimeFormat lastModified; + prettyRev = with sourceInfo; builtins.substring 0 8 rev + "/" + utils.dateTimeFormat lastModified; tag = with sourceInfo; if sourceInfo ? tag @@ -56,47 +56,61 @@ ln -sf ${./assets} $out/assets ''; - velorenOverride = oldAttr: + velorenOverride = common: oldAttr: if common.cargoPkg.name == "veloren-voxygen" then { - nativeBuildInputs = oldAttr.nativeBuildInputs ++ [ pkgs.makeWrapper ]; + VELOREN_USERDATA_STRATEGY = "system"; postInstall = '' - wrapProgram $out/bin/veloren-voxygen\ - --set VELOREN_ASSETS ${veloren-assets}\ - --set LD_LIBRARY_PATH ${ - pkgs.lib.makeLibraryPath common.runtimeLibs - } + if [ -f $out/bin/veloren-voxygen ]; then + wrapProgram $out/bin/veloren-voxygen \ + --set VELOREN_ASSETS ${veloren-assets} \ + --set LD_LIBRARY_PATH ${lib.makeLibraryPath common.runtimeLibs} + fi ''; + patches = [ + (import ./nix/nullOggPatch.nix { nullOgg = ./assets/voxygen/audio/null.ogg; inherit pkgs; }) + ]; } else if common.cargoPkg.name == "veloren-server-cli" then { - nativeBuildInputs = oldAttr.nativeBuildInputs ++ [ pkgs.makeWrapper ]; + VELOREN_USERDATA_STRATEGY = "system"; postInstall = '' - wrapProgram $out/bin/veloren-server-cli --set VELOREN_ASSETS ${veloren-assets} + if [ -f $out/bin/veloren-server-cli ]; then + wrapProgram $out/bin/veloren-server-cli --set VELOREN_ASSETS ${veloren-assets} + fi ''; } else { }; in { - allRefs = true; - override = old: (prevb.override old) // { - # Disable `git-lfs` check here since we check it ourselves - # We have to include the command output here, otherwise Nix won't run it - DISABLE_GIT_LFS_CHECK = common.utils.isGitLfsSetup common.gitLfsCheckFile; - # Declare env values here so that `common/build.rs` sees them - NIX_GIT_HASH = prettyRev; - NIX_GIT_TAG = tag; - VELOREN_USERDATA_STRATEGY = "system"; + crateOverrides = prev.crateOverrides // { + veloren-world = oldAttrs: { + crateBin = lib.filter (bin: bin.name != "chunk_compression_benchmarks") oldAttrs.crateBin; + }; + veloren-client = oldAttrs: { + crateBin = lib.filter (bin: bin.name != "bot") oldAttrs.crateBin; + }; + veloren-common = oldAttrs: { + # Disable `git-lfs` check here since we check it ourselves + # We have to include the command output here, otherwise Nix won't run it + DISABLE_GIT_LFS_CHECK = utils.isGitLfsSetup gitLfsCheckFile; + # Declare env values here so that `common/build.rs` sees them + NIX_GIT_HASH = prettyRev; + NIX_GIT_TAG = tag; + crateBin = lib.filter (bin: bin.name != "csv_export" && bin.name != "csv_import") oldAttrs.crateBin; + }; + }; + overrides = prev.overrides // { + mainBuild = velorenOverride; }; - overrideMain = old: (prevb.overrideMain old) // (velorenOverride old); }; }; }; in output // { - defaultApp = builtins.mapAttrs (_: apps: apps.veloren-voxygen-debug) output.apps; - defaultPackage = builtins.mapAttrs (_: packages: packages.veloren-voxygen-debug) output.packages; + defaultApp = builtins.mapAttrs (_: apps: apps.veloren-voxygen) output.apps; + defaultPackage = builtins.mapAttrs (_: packages: packages.veloren-voxygen) output.packages; }; } diff --git a/nix/nullOggPatch.nix b/nix/nullOggPatch.nix new file mode 100644 index 0000000000..27f22303a4 --- /dev/null +++ b/nix/nullOggPatch.nix @@ -0,0 +1,18 @@ +{ nullOgg, pkgs }: +pkgs.writeText + "nullOgg.patch" + '' + diff --git a/src/audio/soundcache.rs b/src/audio/soundcache.rs + index 8cf703577..678295cac 100644 + --- a/src/audio/soundcache.rs + +++ b/src/audio/soundcache.rs + @@ -44,7 +44,7 @@ impl OggSound { + + pub fn empty() -> OggSound { + OggSound(Arc::new( + - include_bytes!("../../../assets/voxygen/audio/null.ogg").to_vec(), + + include_bytes!("${nullOgg}").to_vec(), + )) + } + } + '' diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 5a83a1dc4f..374431b9eb 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -18,6 +18,8 @@ It is inspired by games such as Cube World, Legend of Zelda: Breath of the Wild, This package includes the official client, Voxygen. """ +runtimeLibs = ["libGL", "xorg.libX11", "xorg.libXcursor", "xorg.libXrandr", "xorg.libXi"] +buildInputs = ["xorg.libxcb"] [features] gl = ["gfx_device_gl", "gfx_gl"]