Revert "Merge branch 'revert-441acd3e' into 'master'"

This reverts commit f170da4da6, reversing
changes made to aa7569061b.
This commit is contained in:
Yusuf Bera Ertan 2022-09-08 12:28:56 +03:00
parent f170da4da6
commit 58e74a26cd
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
10 changed files with 319 additions and 183 deletions

View File

@ -115,10 +115,6 @@ systems = ["x86_64-linux"]
name = "veloren-nix"
key = "veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc="
[workspace.metadata.nix.crateOverride.veloren-network]
buildInputs = ["openssl"]
nativeBuildInputs = ["pkg-config"]
[patch.crates-io]
vek = { git = "https://github.com/yoanlcq/vek.git", rev = "84d5cb65841d46599a986c5477341bea4456be26" }
# patch wgpu so we can use wgpu-profiler crate

View File

@ -8,11 +8,21 @@ pub mod projection;
/// entities
mod spatial_grid;
pub const GIT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/githash"));
pub const GIT_TAG: &str = include_str!(concat!(env!("OUT_DIR"), "/gittag"));
pub const GIT_VERSION_BUILD: &str = include_str!(concat!(env!("OUT_DIR"), "/githash"));
pub const GIT_TAG_BUILD: &str = include_str!(concat!(env!("OUT_DIR"), "/gittag"));
pub const VELOREN_VERSION_STAGE: &str = "Pre-Alpha";
lazy_static::lazy_static! {
pub static ref GIT_VERSION: String = if GIT_VERSION_BUILD.is_empty() {
std::env::var("VELOREN_GIT_VERSION").expect("failed to get git version")
} else {
GIT_VERSION_BUILD.to_string()
};
pub static ref GIT_TAG: String = if GIT_TAG_BUILD.is_empty() {
std::env::var("VELOREN_GIT_TAG").expect("failed to get git tag")
} else {
GIT_TAG_BUILD.to_string()
};
pub static ref GIT_HASH: &'static str = GIT_VERSION.split('/').next().expect("failed to retrieve git_hash!");
static ref GIT_DATETIME: &'static str = GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_datetime!");
pub static ref GIT_DATE: String = GIT_DATETIME.split('-').take(3).collect::<Vec<&str>>().join("-");
@ -20,12 +30,12 @@ lazy_static::lazy_static! {
pub static ref DISPLAY_VERSION: String = if GIT_TAG.is_empty() {
format!("{}-{}", VELOREN_VERSION_STAGE, *GIT_DATE)
} else {
format!("{}-{}", VELOREN_VERSION_STAGE, GIT_TAG)
format!("{}-{}", VELOREN_VERSION_STAGE, GIT_TAG.as_str())
};
pub static ref DISPLAY_VERSION_LONG: String = if GIT_TAG.is_empty() {
format!("{} ({})", DISPLAY_VERSION.as_str(), *GIT_HASH)
} else {
format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_VERSION)
format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_VERSION.as_str())
};
}

View File

@ -1,12 +1,29 @@
{
"nodes": {
"devshell": {
"crane": {
"flake": false,
"locked": {
"lastModified": 1625086391,
"narHash": "sha256-IpNPv1v8s4L3CoxhwcgZIitGpcrnNgnj09X7TA0QV3k=",
"lastModified": 1661875961,
"narHash": "sha256-f1h/2c6Teeu1ofAHWzrS8TwBPcnN+EEu+z1sRVmMQTk=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d9f394e4e20e97c2a60c3ad82c2b6ef99be19e24",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"devshell": {
"flake": false,
"locked": {
"lastModified": 1660811669,
"narHash": "sha256-V6lmsaLNFz41myppL0yxglta92ijkSvpZ+XVygAh+bU=",
"owner": "numtide",
"repo": "devshell",
"rev": "4b5ac7cf7d9a1cc60b965bb51b59922f2210cbc7",
"rev": "c2feacb46ee69949124c835419861143c4016fb5",
"type": "github"
},
"original": {
@ -15,20 +32,69 @@
"type": "github"
}
},
"nixCargoIntegration": {
"dream2nix": {
"inputs": {
"devshell": "devshell",
"nixpkgs": [
"alejandra": [
"nci",
"nixpkgs"
],
"rustOverlay": "rustOverlay"
"crane": "crane",
"devshell": [
"nci",
"devshell"
],
"flake-utils-pre-commit": [
"nci",
"nixpkgs"
],
"gomod2nix": [
"nci",
"nixpkgs"
],
"mach-nix": [
"nci",
"nixpkgs"
],
"nixpkgs": [
"nci",
"nixpkgs"
],
"poetry2nix": [
"nci",
"nixpkgs"
],
"pre-commit-hooks": [
"nci",
"nixpkgs"
]
},
"locked": {
"lastModified": 1627940369,
"narHash": "sha256-KtY837WKsX9B/pIKFDKzN0wl1t3et1JZjMjGa7SAZxI=",
"lastModified": 1662507674,
"narHash": "sha256-vnXfje4pfTqDEqI837GCT+hNKqzfVwPen++gnLVO9F0=",
"owner": "nix-community",
"repo": "dream2nix",
"rev": "5ba9061857e3e265538c9785bb56bda2bb8f9bca",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "dream2nix",
"type": "github"
}
},
"nci": {
"inputs": {
"devshell": "devshell",
"dream2nix": "dream2nix",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1662507702,
"narHash": "sha256-Q8zfpLNCJublP7t4oHizr5tgsCS4BHFk7Fc7wzWbrzE=",
"owner": "yusdacra",
"repo": "nix-cargo-integration",
"rev": "fac8518469e226db4805ff80788979c847b0c322",
"rev": "97aa58c683ccf628175118052b3306f40ac21ca0",
"type": "github"
},
"original": {
@ -39,34 +105,33 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1627814220,
"narHash": "sha256-P+MDgdZw2CBk9X1ZZaUgHgN+32pTfLFf3XVIBOXirI4=",
"lastModified": 1662019588,
"narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ab5b6828af26215bf2646c31961da5d3749591ef",
"rev": "2da64a81275b68fdad38af669afeda43d401e94b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixCargoIntegration": "nixCargoIntegration",
"nixpkgs": "nixpkgs"
"nci": "nci"
}
},
"rustOverlay": {
"rust-overlay": {
"flake": false,
"locked": {
"lastModified": 1627870491,
"narHash": "sha256-0Myg04QOIcTN1RhgfRNx0i/iCRyVyf/Z6rJxZUmot5k=",
"lastModified": 1662433378,
"narHash": "sha256-DqMtTtIownl+UIPG1O917IH10UF0Hwql636p22vOJfw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "71d825269cfaa30605d058bd92381be9af87b0be",
"rev": "12aa8ea4381b28b7a3118f96682dc3ffb13fb6b6",
"type": "github"
},
"original": {

289
flake.nix
View File

@ -1,112 +1,205 @@
{
description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixCargoIntegration = {
url = "github:yusdacra/nix-cargo-integration";
inputs.nixpkgs.follows = "nixpkgs";
};
};
inputs.nci.url = "github:yusdacra/nix-cargo-integration";
outputs = inputs:
inputs.nixCargoIntegration.lib.makeOutputs {
outputs = inputs: let
lib = inputs.nci.inputs.nixpkgs.lib;
ncl = inputs.nci.lib.nci-lib;
git = let
sourceInfo = inputs.self.sourceInfo;
dateTimeFormat = import ./nix/dateTimeFormat.nix;
dateTime = dateTimeFormat sourceInfo.lastModified;
shortRev = sourceInfo.shortRev or "dirty";
in {
prettyRev = shortRev + "/" + dateTime;
tag = "";
};
filteredSource = let
pathsToIgnore = [
"flake.nix"
"flake.lock"
"nix"
"assets"
"README.md"
"CONTRIBUTING.md"
"CHANGELOG.md"
"CODE_OF_CONDUCT.md"
"clippy.toml"
".cargo"
];
ignorePaths = path: type: let
split = lib.splitString "/" path;
actual = lib.drop 4 split;
_path = lib.concatStringsSep "/" actual;
in
lib.all (n: ! (lib.hasPrefix n _path)) pathsToIgnore;
in
builtins.path {
name = "veloren-source";
path = toString ./.;
# filter out unnecessary paths
filter = ignorePaths;
};
wrapWithAssets = common: _: old: let
pkgs = common.pkgs;
runtimeLibs = with pkgs; [
xorg.libX11
xorg.libXi
xorg.libxcb
xorg.libXcursor
xorg.libXrandr
libxkbcommon
shaderc.lib
udev
alsa-lib
vulkan-loader
];
assets = pkgs.runCommand "veloren-assets" {} ''
mkdir $out
ln -sf ${./assets} $out/assets
# check if LFS was setup properly
checkFile="$out/assets/voxygen/background/bg_main.jpg"
result="$(${pkgs.file}/bin/file --mime-type $checkFile)"
if [ "$result" = "$checkFile: image/jpeg" ]; then
echo "Git LFS seems to be setup properly."
else
echo "
Git Large File Storage (git-lfs) has not been set up correctly.
Most common reasons:
- git-lfs was not installed before cloning this repository.
- This repository was not cloned from the primary GitLab mirror.
- The GitHub mirror does not support LFS.
See the book at https://book.veloren.net/ for details.
Run 'nix-shell -p git git-lfs --run \"git lfs install --local && git lfs fetch && git lfs checkout\"'
or 'nix shell nixpkgs#git-lfs nixpkgs#git -c sh -c \"git lfs install --local && git lfs fetch && git lfs checkout\"'.
"
false
fi
'';
wrapped =
common.internal.nci-pkgs.utils.wrapDerivation old
{nativeBuildInputs = [pkgs.makeWrapper];}
''
rm -rf $out/bin
mkdir $out/bin
ln -sf ${old}/bin/* $out/bin/
wrapProgram $out/bin/* \
${lib.optionalString (old.pname == "veloren-voxygen") "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibs}"} \
--set VELOREN_ASSETS ${assets} \
--set VELOREN_GIT_VERSION "${git.prettyRev}" \
--set VELOREN_GIT_TAG "${git.tag}"
'';
in
wrapped;
in
inputs.nci.lib.makeOutputs {
root = ./.;
buildPlatform = "crate2nix";
defaultOutputs = {
package = "veloren-voxygen";
app = "veloren-voxygen";
};
overrides = {
build = common: prev: {
runTests = !prev.release && prev.runTests;
rootFeatures =
if prev.release && common.cargoPkg.name == "veloren-voxygen"
then [ "default-publish" ]
else prev.rootFeatures;
};
crateOverrides = common: prev:
let
pkgs = common.pkgs;
lib = common.lib;
gitLfsCheckFile = ./assets/voxygen/background/bg_main.jpg;
utils = import ./nix/utils.nix { inherit pkgs; };
sourceInfo =
if inputs.self.sourceInfo ? rev
then inputs.self.sourceInfo // {
# Tag would have to be set manually for stable releases flake
# because there's currently no way to get the tag via the interface.
# tag = v0.9.0;
}
else (throw "Can't get revision because the git tree is dirty");
prettyRev = with sourceInfo; builtins.substring 0 8 rev + "/" + utils.dateTimeFormat lastModified;
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 tag != "" then tag
else if prettyRev != "" then prettyRev
else throw "Need a tag or pretty revision in order to determine version";
veloren-assets = pkgs.runCommand "makeAssetsDir" { } ''
mkdir $out
ln -sf ${./assets} $out/assets
'';
in
{
# 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-voxygen-i18n = oldAttrs: {
crateBin = lib.filter (bin: bin.name != "i18n-check") 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" && bin.name != "recipe_graphviz") oldAttrs.crateBin;
};
veloren-voxygen = oldAttrs: {
VELOREN_USERDATA_STRATEGY = "system";
preConfigure = ''
substituteInPlace src/audio/soundcache.rs \
--replace \
"../../../assets/voxygen/audio/null.ogg" \
"${./assets/voxygen/audio/null.ogg}"
'';
postInstall = ''
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
'';
};
veloren-server-cli = oldAttrs: {
VELOREN_USERDATA_STRATEGY = "system";
postInstall = ''
if [ -f $out/bin/veloren-server-cli ]; then
wrapProgram $out/bin/veloren-server-cli --set VELOREN_ASSETS ${veloren-assets}
fi
'';
perCrateOverrides = {
veloren-voxygen = {
packageMetadata = _: {
features = rec {
release = ["default-publish"];
debug = release;
test = release;
};
};
wrapper = wrapWithAssets;
};
veloren-server-cli.wrapper = wrapWithAssets;
};
disableVendoredCrateOverrides = true;
overrides = {
cCompiler = common: common.pkgs.clang;
crates = common: prev: let
pkgs = common.pkgs;
configMoldLinker = ''
touch $CARGO_HOME/config.toml
cat >>$CARGO_HOME/config.toml <<EOF
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
EOF
'';
in rec {
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 = true;
# We don't add in any information here because otherwise anything
# that depends on common will be recompiled. We will set these in
# our wrapper instead.
NIX_GIT_HASH = "";
NIX_GIT_TAG = "";
};
veloren-voxygen-deps = oldAttrs: {
buildInputs = ncl.addBuildInputs prev (
with pkgs; [
alsa-lib
libxkbcommon
udev
xorg.libxcb
]
);
nativeBuildInputs =
ncl.addNativeBuildInputs prev (with pkgs; [python3 pkg-config mold]);
SHADERC_LIB_DIR = "${pkgs.shaderc.lib}/lib";
doCheck = false;
postConfigure = ''
${oldAttrs.postConfigure or ""}
${configMoldLinker}
'';
};
veloren-voxygen = prev:
ncl.computeOverridesResult prev [
veloren-voxygen-deps
(oldAttrs: {
src = filteredSource;
VELOREN_USERDATA_STRATEGY = "system";
dontUseCmakeConfigure = true;
preConfigure = ''
${oldAttrs.preConfigure or ""}
substituteInPlace voxygen/src/audio/soundcache.rs \
--replace \
"../../../assets/voxygen/audio/null.ogg" \
"${./assets/voxygen/audio/null.ogg}"
'';
})
];
veloren-server-cli-deps = oldAttrs: {
nativeBuildInputs = ncl.addNativeBuildInputs prev [pkgs.mold];
doCheck = false;
postConfigure = ''
${oldAttrs.postConfigure or ""}
${configMoldLinker}
'';
};
veloren-server-cli = prev:
ncl.computeOverridesResult prev [
veloren-server-cli-deps
(oldAttrs: {
src = filteredSource;
VELOREN_USERDATA_STRATEGY = "system";
})
];
};
};
};
}

View File

@ -190,11 +190,10 @@ Modify the relevant `rev` field in `flake.lock` to what you need - you can use `
## Formatting
Use [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) to format files.
Use [alejandra](https://github.com/kamadorueda/alejandra) to format files.
To format every Nix file:
```shell
nixpkgs-fmt flake.nix nix/*.nix
# or
nixpkgs-fmt **/**.nix
# From repository root
alejandra .
```

21
nix/dateTimeFormat.nix Normal file
View File

@ -0,0 +1,21 @@
t: let
rem = x: y: x - x / y * y;
days = t / 86400;
secondsInDay = rem t 86400;
hours = secondsInDay / 3600;
minutes = (rem secondsInDay 3600) / 60;
# Courtesy of https://stackoverflow.com/a/32158604.
z = days + 719468;
era = (if z >= 0 then z else z - 146096) / 146097;
doe = z - era * 146097;
yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
y = yoe + era * 400;
doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
mp = (5 * doy + 2) / 153;
d = doy - (153 * mp + 2) / 5 + 1;
m = mp + (if mp < 10 then 3 else -9);
y' = y + (if m <= 2 then 1 else 0);
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)}"

View File

@ -3,4 +3,5 @@
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "sha256:0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
})
{ src = ../.; }).defaultNix
{src = ../.;})
.defaultNix

View File

@ -3,4 +3,5 @@
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "sha256:0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
})
{ src = ../.; }).shellNix
{src = ../.;})
.shellNix

View File

@ -1,48 +0,0 @@
{ pkgs }: {
isGitLfsSetup = checkFile:
let
gitLfsCheckOutput =
builtins.readFile (pkgs.runCommand "gitLfsCheck" { } ''
([ "$(${pkgs.file}/bin/file --mime-type ${checkFile})" = "${checkFile}: image/jpeg" ] && printf "0" || printf "1") > $out
'');
in
if gitLfsCheckOutput == "0" then
true
else
abort ''
Git Large File Storage (`git-lfs`) has not been set up correctly.
Most common reasons:
- `git-lfs` was not installed before cloning this repository.
- This repository was not cloned from the primary GitLab mirror.
- The GitHub mirror does not support LFS.
See the book at https://book.veloren.net/ for details.
Run `nix-shell -p git git-lfs --run "git lfs install --local && git lfs fetch && git lfs checkout"`
or `nix shell nixpkgs#git-lfs nixpkgs#git -c sh -c "git lfs install --local && git lfs fetch && git lfs checkout"`.
'';
# Format number of seconds in the Unix epoch as %Y-%m-%d-%H:%M.
dateTimeFormat = t:
let
rem = x: y: x - x / y * y;
days = t / 86400;
secondsInDay = rem t 86400;
hours = secondsInDay / 3600;
minutes = (rem secondsInDay 3600) / 60;
seconds = rem t 60;
# Courtesy of https://stackoverflow.com/a/32158604.
z = days + 719468;
era = (if z >= 0 then z else z - 146096) / 146097;
doe = z - era * 146097;
yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
y = yoe + era * 400;
doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
mp = (5 * doy + 2) / 153;
d = doy - (153 * mp + 2) / 5 + 1;
m = mp + (if mp < 10 then 3 else -9);
y' = y + (if m <= 2 then 1 else 0);
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)}";
}

View File

@ -18,8 +18,6 @@ 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", "vulkan-loader", "vulkan-extension-layer"]
buildInputs = ["xorg.libxcb"]
[features]
hot-anim = ["anim/use-dyn-lib"]