build(nix): format nix files, fix git lfs error

This commit is contained in:
Yusuf Bera Ertan 2022-04-28 20:35:27 +03:00
parent b9586673d5
commit a0b7446f58
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
4 changed files with 121 additions and 99 deletions

View File

@ -11,8 +11,7 @@
app = "veloren-voxygen";
};
overrides = {
crates = common: prev:
let
crates = common: prev: let
pkgs = common.pkgs;
lib = common.lib;
@ -21,7 +20,9 @@
sourceInfo =
if inputs.self.sourceInfo ? rev
then inputs.self.sourceInfo // {
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;
@ -40,16 +41,17 @@
# 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
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
{
in {
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

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,15 +1,14 @@
{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
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
if gitLfsCheckOutput == "0"
then true
else
abort ''
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.
@ -21,8 +20,7 @@
'';
# Format number of seconds in the Unix epoch as %Y-%m-%d-%H:%M.
dateTimeFormat = t:
let
dateTimeFormat = t: let
rem = x: y: x - x / y * y;
days = t / 86400;
secondsInDay = rem t 86400;
@ -32,17 +30,37 @@
# Courtesy of https://stackoverflow.com/a/32158604.
z = days + 719468;
era = (if z >= 0 then z else z - 146096) / 146097;
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);
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)}";
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)}";
}