diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index 3aafea07cd..5ae200d307 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -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::>().join("-"); diff --git a/flake.nix b/flake.nix index e349b0303c..db4b65fa1a 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,15 @@ outputs = inputs: let lib = inputs.nci.inputs.nixpkgs.lib; + git = let + sourceInfo = inputs.self.sourceInfo; + dateTimeFormat = import ./nix/dateTimeFormat.nix; + dateTime = dateTimeFormat sourceInfo.lastModified; + rev = sourceInfo.rev or "dirty"; + in { + prettyRev = (builtins.substring 0 8 rev) + "/" + dateTime; + tag = ""; + }; outputs = inputs.nci.lib.makeOutputs { root = ./.; defaultOutputs = { @@ -68,8 +77,8 @@ # 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. Ideally we should have - # a way to pass these in a wrapper, at runtime, rather than build time. + # that depends on common will be recompiled. We will set these in + # our wrapper instead. NIX_GIT_HASH = ""; NIX_GIT_TAG = ""; }; @@ -192,7 +201,9 @@ 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_ASSETS ${assets} \ + --set VELOREN_GIT_VERSION "${git.prettyRev}" \ + --set VELOREN_GIT_TAG "${git.tag}" ''; in wrapped;