build(nix): update flake.nix

This commit is contained in:
Yusuf Bera Ertan 2023-02-25 08:53:34 +03:00
parent 01da8b6a82
commit 576b183e20
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
2 changed files with 213 additions and 162 deletions

View File

@ -16,22 +16,6 @@
"type": "github" "type": "github"
} }
}, },
"devshell": {
"flake": false,
"locked": {
"lastModified": 1667210711,
"narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=",
"owner": "numtide",
"repo": "devshell",
"rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"dream2nix": { "dream2nix": {
"inputs": { "inputs": {
"alejandra": [ "alejandra": [
@ -42,10 +26,12 @@
], ],
"crane": "crane", "crane": "crane",
"devshell": [ "devshell": [
"nci", "nci"
"devshell" ],
"flake-parts": [
"nci",
"parts"
], ],
"flake-parts": "flake-parts",
"flake-utils-pre-commit": [ "flake-utils-pre-commit": [
"nci" "nci"
], ],
@ -70,14 +56,17 @@
], ],
"pre-commit-hooks": [ "pre-commit-hooks": [
"nci" "nci"
],
"pruned-racket-catalog": [
"nci"
] ]
}, },
"locked": { "locked": {
"lastModified": 1671323629, "lastModified": 1677289985,
"narHash": "sha256-9KHTPjIDjfnzZ4NjpE3gGIVHVHopy6weRDYO/7Y3hF8=", "narHash": "sha256-lUp06cTTlWubeBGMZqPl9jODM99LpWMcwxRiscFAUJg=",
"owner": "nix-community", "owner": "nix-community",
"repo": "dream2nix", "repo": "dream2nix",
"rev": "2d7d68505c8619410df2c6b6463985f97cbcba6e", "rev": "28b973a8d4c30cc1cbb3377ea2023a76bc3fb889",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -86,37 +75,38 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts": { "mk-naked-shell": {
"inputs": { "flake": false,
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": { "locked": {
"lastModified": 1668450977, "lastModified": 1676572903,
"narHash": "sha256-cfLhMhnvXn6x1vPm+Jow3RiFAUSCw/l1utktCw5rVA4=", "narHash": "sha256-oQoDHHUTxNVSURfkFcYLuAK+btjs30T4rbEUtCUyKy8=",
"owner": "hercules-ci", "owner": "yusdacra",
"repo": "flake-parts", "repo": "mk-naked-shell",
"rev": "d591857e9d7dd9ddbfba0ea02b43b927c3c0f1fa", "rev": "aeca9f8aa592f5e8f71f407d081cb26fd30c5a57",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "hercules-ci", "owner": "yusdacra",
"repo": "flake-parts", "repo": "mk-naked-shell",
"type": "github" "type": "github"
} }
}, },
"nci": { "nci": {
"inputs": { "inputs": {
"devshell": "devshell",
"dream2nix": "dream2nix", "dream2nix": "dream2nix",
"nixpkgs": "nixpkgs", "mk-naked-shell": "mk-naked-shell",
"nixpkgs": [
"nixpkgs"
],
"parts": "parts",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
"lastModified": 1671400340, "lastModified": 1677302541,
"narHash": "sha256-VvRL3w+TbnlB1d9eXNJjuJQOYUL64kXA5508lV9Dq5E=", "narHash": "sha256-FqXEoPXguxpGUbGsPNO5M1NahA2K8O1W94ffHNUtk2c=",
"owner": "yusdacra", "owner": "yusdacra",
"repo": "nix-cargo-integration", "repo": "nix-cargo-integration",
"rev": "7d894cd374f6394482c8de234c8a8cdeaf8908a5", "rev": "30787e470b77f6d76a9d4e5878ab3dbfc28c6984",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -127,15 +117,15 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1671200928, "lastModified": 1677063315,
"narHash": "sha256-mZfzDyzojwj6I0wyooIjGIn81WtGVnx6+avU5Wv+VKU=", "narHash": "sha256-qiB4ajTeAOVnVSAwCNEEkoybrAlA+cpeiBxLobHndE8=",
"owner": "NixOS", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "757b82211463dd5ba1475b6851d3731dfe14d377", "rev": "988cc958c57ce4350ec248d2d53087777f9e1949",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "nixos",
"ref": "nixos-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
@ -144,11 +134,11 @@
"nixpkgs-lib": { "nixpkgs-lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1665349835, "lastModified": 1675183161,
"narHash": "sha256-UK4urM3iN80UXQ7EaOappDzcisYIuEURFRoGQ/yPkug=", "narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "34c5293a71ffdb2fe054eb5288adc1882c1eb0b1", "rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -159,19 +149,60 @@
"type": "github" "type": "github"
} }
}, },
"parts": {
"inputs": {
"nixpkgs-lib": [
"nci",
"nixpkgs"
]
},
"locked": {
"lastModified": 1675933616,
"narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"parts_2": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1675933616,
"narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"nci": "nci" "nci": "nci",
"nixpkgs": "nixpkgs",
"parts": "parts_2"
} }
}, },
"rust-overlay": { "rust-overlay": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1671330075, "lastModified": 1677205778,
"narHash": "sha256-20Pa/jOxfE6QX4bnQReKjXgrnslY6u54wO4tpVkTZQs=", "narHash": "sha256-DFe09uzS+8LjGBAAyHkB/5Axs0j/PQ8RLWFzm2FUZLA=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "31f0276dd8bc0dff576394a985e89be4a4995b4e", "rev": "b91706f9d5a68fecf97b63753da8e9670dff782b",
"type": "github" "type": "github"
}, },
"original": { "original": {

244
flake.nix
View File

@ -1,14 +1,16 @@
{ {
description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust."; description = "Flake providing Veloren, a multiplayer voxel RPG written in Rust.";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.nci.url = "github:yusdacra/nix-cargo-integration"; inputs.nci.url = "github:yusdacra/nix-cargo-integration";
inputs.nci.inputs.nixpkgs.follows = "nixpkgs";
inputs.parts.url = "github:hercules-ci/flake-parts";
outputs = inputs: let outputs = inp: let
lib = inputs.nci.inputs.nixpkgs.lib; lib = inp.nci.inputs.nixpkgs.lib;
ncl = inputs.nci.lib.nci-lib;
git = let git = let
sourceInfo = inputs.self.sourceInfo; sourceInfo = inp.self.sourceInfo;
dateTimeFormat = import ./nix/dateTimeFormat.nix; dateTimeFormat = import ./nix/dateTimeFormat.nix;
dateTime = dateTimeFormat sourceInfo.lastModified; dateTime = dateTimeFormat sourceInfo.lastModified;
shortRev = sourceInfo.shortRev or "dirty"; shortRev = sourceInfo.shortRev or "dirty";
@ -45,46 +47,61 @@
# filter out unnecessary paths # filter out unnecessary paths
filter = ignorePaths; filter = ignorePaths;
}; };
checkIfLfsIsSetup = pkgs: checkFile: ''
checkFile="${checkFile}"
result="$(${pkgs.file}/bin/file --mime-type $checkFile)"
if [ "$result" = "$checkFile: image/jpeg" ]; then
echo "Git LFS seems to be setup properly."
true
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
'';
in in
inputs.nci.lib.makeOutputs { inp.parts.lib.mkFlake {inputs = inp;} {
root = ./.; imports = [inp.nci.flakeModule];
config = common: { systems = ["x86_64-linux"];
cCompiler.package = common.pkgs.clang; perSystem = {
outputs.defaults = { config,
package = "veloren-voxygen"; pkgs,
app = "veloren-voxygen"; lib,
}; ...
shell = { }: let
startup.checkLfsSetup.text = '' checkIfLfsIsSetup = checkFile: ''
${checkIfLfsIsSetup common.pkgs "$PWD/assets/voxygen/background/bg_main.jpg"} checkFile="${checkFile}"
if [ $? -ne 0 ]; then result="$(${pkgs.file}/bin/file --mime-type $checkFile)"
exit 1 if [ "$result" = "$checkFile: image/jpeg" ]; then
fi echo "Git LFS seems to be setup properly."
true
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
'';
assets = pkgs.runCommand "veloren-assets" {} ''
mkdir $out
ln -sf ${./assets} $out/assets
${checkIfLfsIsSetup "$out/assets/voxygen/background/bg_main.jpg"}
'';
wrapWithAssets = old:
pkgs.runCommand
old.name
{
inherit (old) pname version;
meta = old.meta or {};
passthru =
(old.passthru or {})
// {
unwrapped = old;
};
nativeBuildInputs = [pkgs.makeWrapper];
}
''
cp -rs --no-preserve=mode,ownership ${old} $out
wrapProgram $out/bin/* \
--set VELOREN_ASSETS ${assets} \
--set VELOREN_GIT_VERSION "${git.prettyRev}" \
--set VELOREN_GIT_TAG "${git.tag}"
''; '';
};
};
pkgConfig = common: let
inherit (common) pkgs;
veloren-common-ov = { veloren-common-ov = {
# We don't add in any information here because otherwise anything # We don't add in any information here because otherwise anything
# that depends on common will be recompiled. We will set these in # that depends on common will be recompiled. We will set these in
@ -92,12 +109,78 @@
NIX_GIT_HASH = ""; NIX_GIT_HASH = "";
NIX_GIT_TAG = ""; NIX_GIT_TAG = "";
}; };
assets = pkgs.runCommand "veloren-assets" {} '' voxygenOut = config.nci.outputs."veloren-voxygen";
mkdir $out serverCliOut = config.nci.outputs."veloren-server-cli";
ln -sf ${./assets} $out/assets in {
${checkIfLfsIsSetup pkgs "$out/assets/voxygen/background/bg_main.jpg"} packages.veloren-voxygen = wrapWithAssets voxygenOut.packages.release;
''; packages.veloren-voxygen-dev = wrapWithAssets voxygenOut.packages.dev;
wrapWithAssets = _: old: let packages.veloren-server-cli = wrapWithAssets serverCliOut.packages.release;
packages.veloren-server-cli-dev = wrapWithAssets serverCliOut.packages.dev;
packages.default = config.packages."veloren-voxygen";
devShells.default = config.nci.outputs."veloren".devShell.overrideAttrs (old: {
shellHook = ''
${checkIfLfsIsSetup "$PWD/assets/voxygen/background/bg_main.jpg"}
if [ $? -ne 0 ]; then
exit 1
fi
'';
});
nci.projects."veloren".relPath = "";
nci.crates."veloren-server-cli" = let
veloren-server-cli-deps-ov = _: {
doCheck = false;
dontCheck = true;
};
in {
profiles = {
release.features = ["default-publish"];
dev.features = ["default-publish"];
};
depsOverrides.fix-build.overrideAttrs = veloren-server-cli-deps-ov;
overrides = {
fix-veloren-common = veloren-common-ov;
add-deps-reqs.overrideAttrs = veloren-server-cli-deps-ov;
fix-build.override = _: {
src = filteredSource;
VELOREN_USERDATA_STRATEGY = "system";
};
};
};
nci.crates."veloren-voxygen" = let
veloren-voxygen-deps-ov = prev: {
buildInputs =
(prev.buildInputs or [])
++ (
with pkgs; [
alsa-lib
libxkbcommon
udev
xorg.libxcb
]
);
nativeBuildInputs =
(prev.nativeBuildInputs or [])
++ (
with pkgs; [
python3
pkg-config
cmake
gnumake
]
);
SHADERC_LIB_DIR = "${pkgs.shaderc.lib}/lib";
VELOREN_ASSETS = "${assets}";
checkPhase = ":";
};
in {
profiles = {
release.features = ["default-publish"];
dev.features = ["default-publish"];
};
runtimeLibs = with pkgs; [ runtimeLibs = with pkgs; [
xorg.libX11 xorg.libX11
xorg.libXi xorg.libXi
@ -109,48 +192,8 @@
udev udev
alsa-lib alsa-lib
vulkan-loader vulkan-loader
stdenv.cc.cc.lib
]; ];
wrapped =
common.internal.pkgsSet.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 {
veloren-voxygen = let
veloren-voxygen-deps-ov = oldAttrs: {
buildInputs = ncl.addBuildInputs oldAttrs (
with pkgs; [
alsa-lib
libxkbcommon
udev
xorg.libxcb
]
);
nativeBuildInputs =
ncl.addNativeBuildInputs oldAttrs (with pkgs; [python3 pkg-config]);
SHADERC_LIB_DIR = "${pkgs.shaderc.lib}/lib";
VELOREN_ASSETS = "${assets}";
doCheck = false;
dontCheck = true;
};
in {
features = {
release = ["default-publish"];
dev = ["default-publish"];
test = ["default-publish"];
};
depsOverrides.fix-build.overrideAttrs = veloren-voxygen-deps-ov; depsOverrides.fix-build.overrideAttrs = veloren-voxygen-deps-ov;
overrides = { overrides = {
fix-veloren-common = veloren-common-ov; fix-veloren-common = veloren-common-ov;
@ -171,29 +214,6 @@
''; '';
}; };
}; };
wrapper = wrapWithAssets;
};
veloren-server-cli = let
veloren-server-cli-deps-ov = oldAttrs: {
doCheck = false;
dontCheck = true;
};
in {
features = {
release = ["default-publish"];
dev = ["default-publish"];
test = ["default-publish"];
};
depsOverrides.fix-build.overrideAttrs = veloren-server-cli-deps-ov;
overrides = {
fix-veloren-common = veloren-common-ov;
add-deps-reqs.overrideAttrs = veloren-server-cli-deps-ov;
fix-build = {
src = filteredSource;
VELOREN_USERDATA_STRATEGY = "system";
};
};
wrapper = wrapWithAssets;
}; };
}; };
}; };