mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
build(nix): refactor, dont pass git hash and tag
This commit is contained in:
parent
12fb3254de
commit
999984d15a
52
flake.nix
52
flake.nix
@ -31,30 +31,6 @@
|
|||||||
pkgs = common.pkgs;
|
pkgs = common.pkgs;
|
||||||
lib = pkgs.lib;
|
lib = pkgs.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 =
|
|
||||||
if sourceInfo ? tag
|
|
||||||
then sourceInfo.tag
|
|
||||||
else "";
|
|
||||||
|
|
||||||
configMoldLinker = ''
|
configMoldLinker = ''
|
||||||
cat >>$CARGO_HOME/config.toml <<EOF
|
cat >>$CARGO_HOME/config.toml <<EOF
|
||||||
[target.x86_64-unknown-linux-gnu]
|
[target.x86_64-unknown-linux-gnu]
|
||||||
@ -90,10 +66,12 @@
|
|||||||
veloren-common = oldAttrs: {
|
veloren-common = oldAttrs: {
|
||||||
# Disable `git-lfs` check here since we check it ourselves
|
# Disable `git-lfs` check here since we check it ourselves
|
||||||
# We have to include the command output here, otherwise Nix won't run it
|
# We have to include the command output here, otherwise Nix won't run it
|
||||||
DISABLE_GIT_LFS_CHECK = utils.isGitLfsSetup gitLfsCheckFile;
|
DISABLE_GIT_LFS_CHECK = true;
|
||||||
# Declare env values here so that `common/build.rs` sees them
|
# We don't add in any information here because otherwise anything
|
||||||
NIX_GIT_HASH = prettyRev;
|
# that depends on common will be recompiled. Ideally we should have
|
||||||
NIX_GIT_TAG = tag;
|
# a way to pass these in a wrapper, at runtime, rather than build time.
|
||||||
|
NIX_GIT_HASH = "";
|
||||||
|
NIX_GIT_TAG = "";
|
||||||
};
|
};
|
||||||
veloren-voxygen-deps = oldAttrs: {
|
veloren-voxygen-deps = oldAttrs: {
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
@ -181,6 +159,24 @@
|
|||||||
assets = pkgs.runCommand "veloren-assets" {} ''
|
assets = pkgs.runCommand "veloren-assets" {} ''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
ln -sf ${./assets} $out/assets
|
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 =
|
wrapped =
|
||||||
pkgs.runCommand "${old.name}-wrapped"
|
pkgs.runCommand "${old.name}-wrapped"
|
||||||
|
21
nix/dateTimeFormat.nix
Normal file
21
nix/dateTimeFormat.nix
Normal 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)}"
|
@ -1,66 +0,0 @@
|
|||||||
{pkgs}: {
|
|
||||||
isGitLfsSetup = checkFile: let
|
|
||||||
gitLfsCheckOutput = builtins.readFile (pkgs.runCommand "gitLfsCheck" {} ''
|
|
||||||
result="$(${pkgs.file}/bin/file --mime-type ${checkFile})"
|
|
||||||
(if [ "$result" = "${checkFile}: image/jpeg" ]; then printf "0"; else printf "1"; fi) > $out
|
|
||||||
'');
|
|
||||||
in
|
|
||||||
if gitLfsCheckOutput == "0"
|
|
||||||
then true
|
|
||||||
else
|
|
||||||
throw ''
|
|
||||||
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)}";
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user