build(nix): switch to crate2nix

This commit is contained in:
Yusuf Bera Ertan 2021-04-27 05:18:12 +03:00
parent b99404749a
commit 685f4971ac
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
5 changed files with 108 additions and 58 deletions

View File

@ -100,10 +100,11 @@ vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" }
[workspace.metadata.nix] [workspace.metadata.nix]
systems = ["x86_64-linux"] 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] [workspace.metadata.nix.cachix]
name = "veloren-nix" name = "veloren-nix"
key = "veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc=" key = "veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc="
[workspace.metadata.nix.crateOverride.veloren-network]
buildInputs = ["openssl"]
nativeBuildInputs = ["pkg-config"]

View File

@ -1,12 +1,29 @@
{ {
"nodes": { "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": { "devshell": {
"locked": { "locked": {
"lastModified": 1618213758, "lastModified": 1618523768,
"narHash": "sha256-qkuen2xlT7gVfX+99OeM4lsKXGjT5EDjytWAeAWX0Fw=", "narHash": "sha256-Gev9da35pHUey3kGz/zrJFc/9ICs++vPCho7qB1mqd8=",
"owner": "numtide", "owner": "numtide",
"repo": "devshell", "repo": "devshell",
"rev": "eac56f015b0975be3b725721503626e926b285e8", "rev": "709fe4d04a9101c9d224ad83f73416dce71baf21",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -32,11 +49,11 @@
}, },
"flakeUtils": { "flakeUtils": {
"locked": { "locked": {
"lastModified": 1618217525, "lastModified": 1619345332,
"narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -52,38 +69,37 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1618579991, "lastModified": 1619312121,
"narHash": "sha256-aIWvSjn/rjfOBUdL5uM4iDVVLM7ioRz9zs3e94lT9Ac=", "narHash": "sha256-Zx1rTlonsp54lVlnIg38HV3bYx6GdIoKS1SgDnV+YBY=",
"owner": "yusdacra", "owner": "yusdacra",
"repo": "naersk", "repo": "naersk",
"rev": "dc8868af09c8a0f0d47df0927161cb14675c5534", "rev": "07d0b56bdbd353a705f26b799e3a125c7be0f8c3",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "yusdacra", "owner": "yusdacra",
"ref": "veloren", "ref": "feat/cargolock-git-deps",
"repo": "naersk", "repo": "naersk",
"type": "github" "type": "github"
} }
}, },
"nixCargoIntegration": { "nixCargoIntegration": {
"inputs": { "inputs": {
"crate2nix": "crate2nix",
"devshell": "devshell", "devshell": "devshell",
"flakeUtils": "flakeUtils", "flakeUtils": "flakeUtils",
"naersk": [ "naersk": "naersk",
"naersk"
],
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
"rustOverlay": "rustOverlay" "rustOverlay": "rustOverlay"
}, },
"locked": { "locked": {
"lastModified": 1618597947, "lastModified": 1619489852,
"narHash": "sha256-wiwHpQPzgkuOEZXFpet7bmv6Z8dusxyp6DQbpYCXJDk=", "narHash": "sha256-ZiWHvTrMHcTAyPyT0HiqvTXjh3cFO4tHWSV/2v2g5YI=",
"owner": "yusdacra", "owner": "yusdacra",
"repo": "nix-cargo-integration", "repo": "nix-cargo-integration",
"rev": "fc26a4e1d807e8b9722d67097be4dfb8be5ea862", "rev": "ab95ec5f81cce07b3c76609f4681772fe20bcfa1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -94,11 +110,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1618530127, "lastModified": 1619446560,
"narHash": "sha256-jQPk7XpabppYa+GIO5LVTtUFhHq/VqHhPggwIKhTCnQ=", "narHash": "sha256-R9iG5d1ORvho5UlyEUsX8Nu1cnCV+YtWEHlWlqftaQo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "294d1925af6462e55c76b49624b983036f0093b9", "rev": "32f7980afb5e33f1e078a51e715b9f102f396a69",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -110,7 +126,6 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"naersk": "naersk",
"nixCargoIntegration": "nixCargoIntegration", "nixCargoIntegration": "nixCargoIntegration",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
@ -123,11 +138,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1618366946, "lastModified": 1619404147,
"narHash": "sha256-5zevIklODemySoUY8xtIemD/WO7ftaXeltz9rraEVAc=", "narHash": "sha256-qJafGirQc8LfELiU6cJU7e/CS8PuZpyxjNkXd8KXR08=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "82b13c9048b345cf6345dd326478ad5ec059e6c6", "rev": "c9c3bd19e542dc3532d58297fbbc1762fdc8497a",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -2,15 +2,10 @@
description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust."; description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust.";
inputs = { inputs = {
naersk = {
url = "github:yusdacra/naersk/veloren";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixCargoIntegration = { nixCargoIntegration = {
url = "github:yusdacra/nix-cargo-integration"; url = "github:yusdacra/nix-cargo-integration";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.naersk.follows = "naersk";
}; };
}; };
@ -18,14 +13,19 @@
let let
output = inputs.nixCargoIntegration.lib.makeOutputs { output = inputs.nixCargoIntegration.lib.makeOutputs {
root = ./.; root = ./.;
buildPlatform = "crate2nix";
overrides = { overrides = {
common = prev: { build = common: prev: {
gitLfsCheckFile = ./assets/voxygen/background/bg_main.png; runTests = !prev.release && prev.runTests;
utils = import ./nix/utils.nix { pkgs = prev.pkgs; };
}; };
build = common: prevb: common = prev:
let 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 = sourceInfo =
if inputs.self.sourceInfo ? rev if inputs.self.sourceInfo ? rev
then inputs.self.sourceInfo // { then inputs.self.sourceInfo // {
@ -35,7 +35,7 @@
} }
else (throw "Can't get revision because the git tree is dirty"); 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; tag = with sourceInfo;
if sourceInfo ? tag if sourceInfo ? tag
@ -56,47 +56,61 @@
ln -sf ${./assets} $out/assets ln -sf ${./assets} $out/assets
''; '';
velorenOverride = oldAttr: velorenOverride = common: oldAttr:
if common.cargoPkg.name == "veloren-voxygen" if common.cargoPkg.name == "veloren-voxygen"
then then
{ {
nativeBuildInputs = oldAttr.nativeBuildInputs ++ [ pkgs.makeWrapper ]; VELOREN_USERDATA_STRATEGY = "system";
postInstall = '' postInstall = ''
wrapProgram $out/bin/veloren-voxygen\ if [ -f $out/bin/veloren-voxygen ]; then
--set VELOREN_ASSETS ${veloren-assets}\ wrapProgram $out/bin/veloren-voxygen \
--set LD_LIBRARY_PATH ${ --set VELOREN_ASSETS ${veloren-assets} \
pkgs.lib.makeLibraryPath common.runtimeLibs --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" else if common.cargoPkg.name == "veloren-server-cli"
then then
{ {
nativeBuildInputs = oldAttr.nativeBuildInputs ++ [ pkgs.makeWrapper ]; VELOREN_USERDATA_STRATEGY = "system";
postInstall = '' 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 { }; else { };
in in
{ {
allRefs = true; crateOverrides = prev.crateOverrides // {
override = old: (prevb.override old) // { veloren-world = oldAttrs: {
# Disable `git-lfs` check here since we check it ourselves crateBin = lib.filter (bin: bin.name != "chunk_compression_benchmarks") oldAttrs.crateBin;
# We have to include the command output here, otherwise Nix won't run it };
DISABLE_GIT_LFS_CHECK = common.utils.isGitLfsSetup common.gitLfsCheckFile; veloren-client = oldAttrs: {
# Declare env values here so that `common/build.rs` sees them crateBin = lib.filter (bin: bin.name != "bot") oldAttrs.crateBin;
NIX_GIT_HASH = prettyRev; };
NIX_GIT_TAG = tag; veloren-common = oldAttrs: {
VELOREN_USERDATA_STRATEGY = "system"; # 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 in
output // { output // {
defaultApp = builtins.mapAttrs (_: apps: apps.veloren-voxygen-debug) output.apps; defaultApp = builtins.mapAttrs (_: apps: apps.veloren-voxygen) output.apps;
defaultPackage = builtins.mapAttrs (_: packages: packages.veloren-voxygen-debug) output.packages; defaultPackage = builtins.mapAttrs (_: packages: packages.veloren-voxygen) output.packages;
}; };
} }

18
nix/nullOggPatch.nix Normal file
View File

@ -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(),
))
}
}
''

View File

@ -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. This package includes the official client, Voxygen.
""" """
runtimeLibs = ["libGL", "xorg.libX11", "xorg.libXcursor", "xorg.libXrandr", "xorg.libXi"]
buildInputs = ["xorg.libxcb"]
[features] [features]
gl = ["gfx_device_gl", "gfx_gl"] gl = ["gfx_device_gl", "gfx_gl"]