diff --git a/Cargo.toml b/Cargo.toml index ad93cf13cf..fec9ce5a35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,6 +115,10 @@ 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 diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index ddbc9fb10d..3aafea07cd 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -8,21 +8,11 @@ pub mod projection; /// entities mod spatial_grid; -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 GIT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/githash")); +pub const GIT_TAG: &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::>().join("-"); @@ -30,12 +20,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.as_str()) + format!("{}-{}", VELOREN_VERSION_STAGE, GIT_TAG) }; 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.as_str()) + format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_VERSION) }; } diff --git a/flake.lock b/flake.lock index d769ed60d5..196d6d02bb 100644 --- a/flake.lock +++ b/flake.lock @@ -1,29 +1,12 @@ { "nodes": { - "crane": { - "flake": false, - "locked": { - "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=", + "lastModified": 1625086391, + "narHash": "sha256-IpNPv1v8s4L3CoxhwcgZIitGpcrnNgnj09X7TA0QV3k=", "owner": "numtide", "repo": "devshell", - "rev": "c2feacb46ee69949124c835419861143c4016fb5", + "rev": "4b5ac7cf7d9a1cc60b965bb51b59922f2210cbc7", "type": "github" }, "original": { @@ -32,69 +15,20 @@ "type": "github" } }, - "dream2nix": { - "inputs": { - "alejandra": [ - "nci", - "nixpkgs" - ], - "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": 1662507674, - "narHash": "sha256-vnXfje4pfTqDEqI837GCT+hNKqzfVwPen++gnLVO9F0=", - "owner": "nix-community", - "repo": "dream2nix", - "rev": "5ba9061857e3e265538c9785bb56bda2bb8f9bca", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "dream2nix", - "type": "github" - } - }, - "nci": { + "nixCargoIntegration": { "inputs": { "devshell": "devshell", - "dream2nix": "dream2nix", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "nixpkgs": [ + "nixpkgs" + ], + "rustOverlay": "rustOverlay" }, "locked": { - "lastModified": 1662507702, - "narHash": "sha256-Q8zfpLNCJublP7t4oHizr5tgsCS4BHFk7Fc7wzWbrzE=", + "lastModified": 1627940369, + "narHash": "sha256-KtY837WKsX9B/pIKFDKzN0wl1t3et1JZjMjGa7SAZxI=", "owner": "yusdacra", "repo": "nix-cargo-integration", - "rev": "97aa58c683ccf628175118052b3306f40ac21ca0", + "rev": "fac8518469e226db4805ff80788979c847b0c322", "type": "github" }, "original": { @@ -105,33 +39,34 @@ }, "nixpkgs": { "locked": { - "lastModified": 1662019588, - "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", + "lastModified": 1627814220, + "narHash": "sha256-P+MDgdZw2CBk9X1ZZaUgHgN+32pTfLFf3XVIBOXirI4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2da64a81275b68fdad38af669afeda43d401e94b", + "rev": "ab5b6828af26215bf2646c31961da5d3749591ef", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "nci": "nci" + "nixCargoIntegration": "nixCargoIntegration", + "nixpkgs": "nixpkgs" } }, - "rust-overlay": { + "rustOverlay": { "flake": false, "locked": { - "lastModified": 1662433378, - "narHash": "sha256-DqMtTtIownl+UIPG1O917IH10UF0Hwql636p22vOJfw=", + "lastModified": 1627870491, + "narHash": "sha256-0Myg04QOIcTN1RhgfRNx0i/iCRyVyf/Z6rJxZUmot5k=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "12aa8ea4381b28b7a3118f96682dc3ffb13fb6b6", + "rev": "71d825269cfaa30605d058bd92381be9af87b0be", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index e584466f7b..8f121f9fda 100644 --- a/flake.nix +++ b/flake.nix @@ -1,205 +1,112 @@ { description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust."; - inputs.nci.url = "github:yusdacra/nix-cargo-integration"; - - 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 = ""; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixCargoIntegration = { + url = "github:yusdacra/nix-cargo-integration"; + inputs.nixpkgs.follows = "nixpkgs"; }; + }; - 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 { + outputs = inputs: + inputs.nixCargoIntegration.lib.makeOutputs { root = ./.; + buildPlatform = "crate2nix"; defaultOutputs = { package = "veloren-voxygen"; app = "veloren-voxygen"; }; - perCrateOverrides = { - veloren-voxygen = { - packageMetadata = _: { - features = rec { - release = ["default-publish"]; - debug = release; - test = release; + 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 + ''; }; }; - 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 <= 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)}" diff --git a/nix/default.nix b/nix/default.nix index c940ee6407..29d4c3807f 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -3,5 +3,4 @@ url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; sha256 = "sha256:0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }) - {src = ../.;}) -.defaultNix + { src = ../.; }).defaultNix diff --git a/nix/shell.nix b/nix/shell.nix index 812b45462a..c68e85b60e 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -3,5 +3,4 @@ url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; sha256 = "sha256:0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }) - {src = ../.;}) -.shellNix + { src = ../.; }).shellNix diff --git a/nix/utils.nix b/nix/utils.nix new file mode 100644 index 0000000000..dd47bc3c21 --- /dev/null +++ b/nix/utils.nix @@ -0,0 +1,48 @@ +{ 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)}"; +} diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 14d65eb8ff..e8b08ba855 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", "vulkan-loader", "vulkan-extension-layer"] +buildInputs = ["xorg.libxcb"] [features] hot-anim = ["anim/use-dyn-lib"]