nix: dont run git-lfs shell hook if its already initialized, add experimental nix-bundle bundling command, add nixGL to shell.nix for non-nixos users, switch to nixpkgs-fmt for formatting, update niv deps and many other minor improvements

This commit is contained in:
Yusuf Bera Ertan 2020-11-30 03:48:00 +03:00
parent 515e444e3d
commit 3c7d682361
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
7 changed files with 572 additions and 415 deletions

View File

@ -2,23 +2,27 @@
# "generate" "-f" "../Cargo.toml" # "generate" "-f" "../Cargo.toml"
# See https://github.com/kolloch/crate2nix for more info. # See https://github.com/kolloch/crate2nix for more info.
{ nixpkgs ? <nixpkgs>, pkgs ? import nixpkgs { config = { }; }, lib ? pkgs.lib { nixpkgs ? <nixpkgs>
, stdenv ? pkgs.stdenv, buildRustCrate ? pkgs.buildRustCrate , pkgs ? import nixpkgs { config = { }; }
, lib ? pkgs.lib
, stdenv ? pkgs.stdenv
, buildRustCrate ? pkgs.buildRustCrate
# This is used as the `crateOverrides` argument for `buildRustCrate`. # This is used as the `crateOverrides` argument for `buildRustCrate`.
, defaultCrateOverrides ? pkgs.defaultCrateOverrides , defaultCrateOverrides ? pkgs.defaultCrateOverrides
# The features to enable for the root_crate or the workspace_members. # The features to enable for the root_crate or the workspace_members.
, rootFeatures ? [ , rootFeatures ? [
"default" "default"
] ]
# If true, throw errors instead of issueing deprecation warnings. # If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false , strictDeprecation ? false
# Whether to perform release builds: longer compile times, faster binaries. # Whether to perform release builds: longer compile times, faster binaries.
, release ? true , release ? true
# Additional crate2nix configuration if it exists. # Additional crate2nix configuration if it exists.
, crateConfig ? if builtins.pathExists ./crate-config.nix then , crateConfig ? if builtins.pathExists ./crate-config.nix then
pkgs.callPackage ./crate-config.nix { } pkgs.callPackage ./crate-config.nix { }
else else
{ } }: { }
}:
rec { rec {
# #
@ -125,7 +129,8 @@ rec {
# A derivation that joins the outputs of all workspace members together. # A derivation that joins the outputs of all workspace members together.
allWorkspaceMembers = pkgs.symlinkJoin { allWorkspaceMembers = pkgs.symlinkJoin {
name = "all-workspace-members"; name = "all-workspace-members";
paths = let members = builtins.attrValues workspaceMembers; paths =
let members = builtins.attrValues workspaceMembers;
in builtins.map (m: m.build) members; in builtins.map (m: m.build) members;
}; };
@ -2258,18 +2263,22 @@ rec {
packageId = "smithay-clipboard 0.6.1"; packageId = "smithay-clipboard 0.6.1";
optional = true; optional = true;
target = { target, features }: target = { target, features }:
(target."unix" && (!((target."os" == "macos") (target."unix" && (
!((target."os" == "macos")
|| (target."os" == "android") || (target."os" == "ios") || (target."os" == "android") || (target."os" == "ios")
|| (target."os" == "emscripten")))); || (target."os" == "emscripten"))
));
} }
{ {
name = "x11-clipboard"; name = "x11-clipboard";
packageId = "x11-clipboard"; packageId = "x11-clipboard";
optional = true; optional = true;
target = { target, features }: target = { target, features }:
(target."unix" && (!((target."os" == "macos") (target."unix" && (
!((target."os" == "macos")
|| (target."os" == "android") || (target."os" == "ios") || (target."os" == "android") || (target."os" == "ios")
|| (target."os" == "emscripten")))); || (target."os" == "emscripten"))
));
} }
]; ];
features = { features = {
@ -16391,17 +16400,21 @@ rec {
name = "clipboard_wayland"; name = "clipboard_wayland";
packageId = "clipboard_wayland"; packageId = "clipboard_wayland";
target = { target, features }: target = { target, features }:
(target."unix" && (!((target."os" == "macos") (target."unix" && (
!((target."os" == "macos")
|| (target."os" == "android") || (target."os" == "emscripten") || (target."os" == "android") || (target."os" == "emscripten")
|| (target."os" == "ios")))); || (target."os" == "ios"))
));
} }
{ {
name = "clipboard_x11"; name = "clipboard_x11";
packageId = "clipboard_x11"; packageId = "clipboard_x11";
target = { target, features }: target = { target, features }:
(target."unix" && (!((target."os" == "macos") (target."unix" && (
!((target."os" == "macos")
|| (target."os" == "android") || (target."os" == "emscripten") || (target."os" == "android") || (target."os" == "emscripten")
|| (target."os" == "ios")))); || (target."os" == "ios"))
));
} }
{ {
name = "raw-window-handle"; name = "raw-window-handle";
@ -16817,14 +16830,16 @@ rec {
# This doesn't appear to be officially documented anywhere yet. # This doesn't appear to be officially documented anywhere yet.
# See https://github.com/rust-lang-nursery/rust-forge/issues/101. # See https://github.com/rust-lang-nursery/rust-forge/issues/101.
os = if stdenv.hostPlatform.isDarwin then os =
if stdenv.hostPlatform.isDarwin then
"macos" "macos"
else else
stdenv.hostPlatform.parsed.kernel.name; stdenv.hostPlatform.parsed.kernel.name;
arch = stdenv.hostPlatform.parsed.cpu.name; arch = stdenv.hostPlatform.parsed.cpu.name;
family = "unix"; family = "unix";
env = "gnu"; env = "gnu";
endian = if stdenv.hostPlatform.parsed.cpu.significantByte.name endian =
if stdenv.hostPlatform.parsed.cpu.significantByte.name
== "littleEndian" then == "littleEndian" then
"little" "little"
else else
@ -16838,7 +16853,8 @@ rec {
# TODO(pkolloch): Substitute with gitignore filter # TODO(pkolloch): Substitute with gitignore filter
sourceFilter = name: type: sourceFilter = name: type:
let baseName = builtins.baseNameOf (builtins.toString name); let baseName = builtins.baseNameOf (builtins.toString name);
in !( in
!(
# Filter out git # Filter out git
baseName == ".gitignore" || (type == "directory" && baseName == ".git") baseName == ".gitignore" || (type == "directory" && baseName == ".git")
@ -16862,7 +16878,8 @@ rec {
|| lib.hasSuffix "~" baseName || builtins.match "^\\.sw[a-z]$$" baseName || lib.hasSuffix "~" baseName || builtins.match "^\\.sw[a-z]$$" baseName
!= null || builtins.match "^\\..*\\.sw[a-z]$$" baseName != null != null || builtins.match "^\\..*\\.sw[a-z]$$" baseName != null
|| lib.hasSuffix ".tmp" baseName || lib.hasSuffix ".bak" baseName || lib.hasSuffix ".tmp" baseName || lib.hasSuffix ".bak" baseName
|| baseName == "tests.nix"); || baseName == "tests.nix"
);
/* Returns a crate which depends on successful test execution /* Returns a crate which depends on successful test execution
of crate given as the second argument. of crate given as the second argument.
@ -16878,8 +16895,11 @@ rec {
# building the actual lib and bin targets We just have to pass `--test` # building the actual lib and bin targets We just have to pass `--test`
# to rustc and it will do the right thing. We execute the tests and copy # to rustc and it will do the right thing. We execute the tests and copy
# their log and the test executables to $out for later inspection. # their log and the test executables to $out for later inspection.
test = let drv = testCrate.override (_: { buildTests = true; }); test =
in pkgs.runCommand "run-tests-${testCrate.name}" { let drv = testCrate.override (_: { buildTests = true; });
in
pkgs.runCommand "run-tests-${testCrate.name}"
{
inherit testCrateFlags; inherit testCrateFlags;
buildInputs = testInputs; buildInputs = testInputs;
} '' } ''
@ -16913,7 +16933,8 @@ rec {
$f $testCrateFlags 2>&1 | tee -a $out $f $testCrateFlags 2>&1 | tee -a $out
done done
''; '';
in crate.overrideAttrs (old: { in
crate.overrideAttrs (old: {
checkPhase = '' checkPhase = ''
test -e ${test} test -e ${test}
''; '';
@ -16921,13 +16942,20 @@ rec {
}); });
# A restricted overridable version of builtRustCratesWithFeatures. # A restricted overridable version of builtRustCratesWithFeatures.
buildRustCrateWithFeatures = { packageId, features ? rootFeatures buildRustCrateWithFeatures =
, crateOverrides ? defaultCrateOverrides, buildRustCrateFunc ? null { packageId
, runTests ? false, testCrateFlags ? [ ], testInputs ? [ ] }: , features ? rootFeatures
, crateOverrides ? defaultCrateOverrides
, buildRustCrateFunc ? null
, runTests ? false
, testCrateFlags ? [ ]
, testInputs ? [ ]
}:
lib.makeOverridable lib.makeOverridable
({ features, crateOverrides, runTests, testCrateFlags, testInputs }: ({ features, crateOverrides, runTests, testCrateFlags, testInputs }:
let let
buildRustCrateFuncOverriden = if buildRustCrateFunc != null then buildRustCrateFuncOverriden =
if buildRustCrateFunc != null then
buildRustCrateFunc buildRustCrateFunc
else else
(if crateOverrides == pkgs.defaultCrateOverrides then (if crateOverrides == pkgs.defaultCrateOverrides then
@ -16948,23 +16976,33 @@ rec {
}; };
drv = builtRustCrates.${packageId}; drv = builtRustCrates.${packageId};
testDrv = builtTestRustCrates.${packageId}; testDrv = builtTestRustCrates.${packageId};
derivation = if runTests then derivation =
crateWithTest { if runTests then
crateWithTest
{
crate = drv; crate = drv;
testCrate = testDrv; testCrate = testDrv;
inherit testCrateFlags testInputs; inherit testCrateFlags testInputs;
} }
else else
drv; drv;
in derivation) { in
derivation)
{
inherit features crateOverrides runTests testCrateFlags testInputs; inherit features crateOverrides runTests testCrateFlags testInputs;
}; };
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc /* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate. for the corresponding crate.
*/ */
builtRustCratesWithFeatures = { packageId, features, crateConfigs ? crates builtRustCratesWithFeatures =
, buildRustCrateFunc, runTests, target ? defaultTarget }@args: { packageId
, features
, crateConfigs ? crates
, buildRustCrateFunc
, runTests
, target ? defaultTarget
}@args:
assert (builtins.isAttrs crateConfigs); assert (builtins.isAttrs crateConfigs);
assert (builtins.isString packageId); assert (builtins.isString packageId);
assert (builtins.isList features); assert (builtins.isList features);
@ -17018,18 +17056,23 @@ rec {
# ]; # ];
# # ... # # ...
# } # }
crateRenames = let crateRenames =
let
grouped = lib.groupBy (dependency: dependency.name) grouped = lib.groupBy (dependency: dependency.name)
dependenciesWithRenames; dependenciesWithRenames;
versionAndRename = dep: versionAndRename = dep:
let package = builtByPackageId."${dep.packageId}"; let package = builtByPackageId."${dep.packageId}";
in { in
{
inherit (dep) rename; inherit (dep) rename;
version = package.version; version = package.version;
}; };
in lib.mapAttrs in
(name: choices: builtins.map versionAndRename choices) grouped; lib.mapAttrs
in buildRustCrateFunc (crateConfig // { (name: choices: builtins.map versionAndRename choices)
grouped;
in
buildRustCrateFunc (crateConfig // {
src = crateConfig.src or (pkgs.fetchurl rec { src = crateConfig.src or (pkgs.fetchurl rec {
name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz"; name = "${crateConfig.crateName}-${crateConfig.version}.tar.gz";
# https://www.pietroalbini.org/blog/downloading-crates-io/ # https://www.pietroalbini.org/blog/downloading-crates-io/
@ -17043,7 +17086,8 @@ rec {
inherit features dependencies buildDependencies crateRenames inherit features dependencies buildDependencies crateRenames
release; release;
}); });
in builtByPackageId; in
builtByPackageId;
# Returns the actual derivations for the given dependencies. # Returns the actual derivations for the given dependencies.
dependencyDerivations = dependencyDerivations =
@ -17056,7 +17100,8 @@ rec {
enabledDependencies = enabledDependencies =
filterEnabledDependencies { inherit dependencies features target; }; filterEnabledDependencies { inherit dependencies features target; };
depDerivation = dependency: builtByPackageId.${dependency.packageId}; depDerivation = dependency: builtByPackageId.${dependency.packageId};
in map depDerivation enabledDependencies; in
map depDerivation enabledDependencies;
/* Returns a sanitized version of val with all values substituted that cannot /* Returns a sanitized version of val with all values substituted that cannot
be serialized as JSON. be serialized as JSON.
@ -17097,7 +17142,8 @@ rec {
diffedDefaultPackageFeatures = diffedDefaultPackageFeatures =
diffDefaultPackageFeatures { inherit packageId target; }; diffDefaultPackageFeatures { inherit packageId target; };
}; };
in { internal = debug; }; in
{ internal = debug; };
/* Returns differences between cargo default features and crate2nix default /* Returns differences between cargo default features and crate2nix default
features. features.
@ -17120,10 +17166,13 @@ rec {
onlyInCrate2Nix = builtins.attrNames onlyInCrate2Nix = builtins.attrNames
(lib.filterAttrs (n: v: (v ? "crate2nix") && !(v ? "cargo")) (lib.filterAttrs (n: v: (v ? "crate2nix") && !(v ? "cargo"))
combined); combined);
differentFeatures = lib.filterAttrs (n: v: differentFeatures = lib.filterAttrs
(n: v:
(v ? "crate2nix") && (v ? "cargo") && (v.crate2nix.features or [ ]) (v ? "crate2nix") && (v ? "cargo") && (v.crate2nix.features or [ ])
!= (v."cargo".resolved_default_features or [ ])) combined; != (v."cargo".resolved_default_features or [ ]))
in builtins.toJSON { combined;
in
builtins.toJSON {
inherit onlyInCargo onlyInCrate2Nix differentFeatures; inherit onlyInCargo onlyInCrate2Nix differentFeatures;
}; };
@ -17132,12 +17181,18 @@ rec {
If multiple paths to a dependency enable different features, the If multiple paths to a dependency enable different features, the
corresponding feature sets are merged. Features in rust are additive. corresponding feature sets are merged. Features in rust are additive.
*/ */
mergePackageFeatures = { crateConfigs ? crates, packageId mergePackageFeatures =
, rootPackageId ? packageId, features ? rootFeatures { crateConfigs ? crates
, packageId
, rootPackageId ? packageId
, features ? rootFeatures
, dependencyPath ? [ crates.${packageId}.crateName ] , dependencyPath ? [ crates.${packageId}.crateName ]
, featuresByPackageId ? { }, target , featuresByPackageId ? { }
, target
# Adds devDependencies to the crate with rootPackageId. # Adds devDependencies to the crate with rootPackageId.
, runTests ? false, ... }@args: , runTests ? false
, ...
}@args:
assert (builtins.isAttrs crateConfigs); assert (builtins.isAttrs crateConfigs);
assert (builtins.isString packageId); assert (builtins.isString packageId);
assert (builtins.isString rootPackageId); assert (builtins.isString rootPackageId);
@ -17155,7 +17210,8 @@ rec {
let let
packageId = dependency.packageId; packageId = dependency.packageId;
features = dependencyFeatures expandedFeatures dependency; features = dependencyFeatures expandedFeatures dependency;
in { inherit packageId features; }; in
{ inherit packageId features; };
resolveDependencies = cache: path: dependencies: resolveDependencies = cache: path: dependencies:
assert (builtins.isAttrs cache); assert (builtins.isAttrs cache);
assert (builtins.isList dependencies); assert (builtins.isList dependencies);
@ -17167,12 +17223,14 @@ rec {
directDependencies = directDependencies =
map depWithResolvedFeatures enabledDependencies; map depWithResolvedFeatures enabledDependencies;
foldOverCache = op: lib.foldl op cache directDependencies; foldOverCache = op: lib.foldl op cache directDependencies;
in foldOverCache (cache: in
foldOverCache (cache:
{ packageId, features }: { packageId, features }:
let let
cacheFeatures = cache.${packageId} or [ ]; cacheFeatures = cache.${packageId} or [ ];
combinedFeatures = sortedUnique (cacheFeatures ++ features); combinedFeatures = sortedUnique (cacheFeatures ++ features);
in if cache ? ${packageId} && cache.${packageId} in
if cache ? ${packageId} && cache.${packageId}
== combinedFeatures then == combinedFeatures then
cache cache
else else
@ -17181,17 +17239,20 @@ rec {
featuresByPackageId = cache; featuresByPackageId = cache;
inherit crateConfigs packageId target runTests rootPackageId; inherit crateConfigs packageId target runTests rootPackageId;
}); });
cacheWithSelf = let cacheWithSelf =
let
cacheFeatures = featuresByPackageId.${packageId} or [ ]; cacheFeatures = featuresByPackageId.${packageId} or [ ];
combinedFeatures = sortedUnique (cacheFeatures ++ expandedFeatures); combinedFeatures = sortedUnique (cacheFeatures ++ expandedFeatures);
in featuresByPackageId // { "${packageId}" = combinedFeatures; }; in
featuresByPackageId // { "${packageId}" = combinedFeatures; };
cacheWithDependencies = resolveDependencies cacheWithSelf "dep" cacheWithDependencies = resolveDependencies cacheWithSelf "dep"
(crateConfig.dependencies or [ ] (crateConfig.dependencies or [ ]
++ lib.optionals (runTests && packageId == rootPackageId) ++ lib.optionals (runTests && packageId == rootPackageId)
(crateConfig.devDependencies or [ ])); (crateConfig.devDependencies or [ ]));
cacheWithAll = resolveDependencies cacheWithDependencies "build" cacheWithAll = resolveDependencies cacheWithDependencies "build"
(crateConfig.buildDependencies or [ ]); (crateConfig.buildDependencies or [ ]);
in cacheWithAll; in
cacheWithAll;
# Returns the enabled dependencies given the enabled features. # Returns the enabled dependencies given the enabled features.
filterEnabledDependencies = { dependencies, features, target }: filterEnabledDependencies = { dependencies, features, target }:
@ -17199,9 +17260,11 @@ rec {
assert (builtins.isList features); assert (builtins.isList features);
assert (builtins.isAttrs target); assert (builtins.isAttrs target);
lib.filter (dep: lib.filter
(dep:
let targetFunc = dep.target or (features: true); let targetFunc = dep.target or (features: true);
in targetFunc { inherit features target; } && (!(dep.optional or false) in
targetFunc { inherit features target; } && (!(dep.optional or false)
|| builtins.any (doesFeatureEnableDependency dep) features)) || builtins.any (doesFeatureEnableDependency dep) features))
dependencies; dependencies;
@ -17212,7 +17275,8 @@ rec {
prefix = "${name}/"; prefix = "${name}/";
len = builtins.stringLength prefix; len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix; startsWithPrefix = builtins.substring 0 len feature == prefix;
in (rename == null && feature == name) in
(rename == null && feature == name)
|| (rename != null && rename == feature) || startsWithPrefix; || (rename != null && rename == feature) || startsWithPrefix;
/* Returns the expanded features for the given inputFeatures by applying the /* Returns the expanded features for the given inputFeatures by applying the
@ -17230,7 +17294,8 @@ rec {
[ feature ] [ feature ]
++ (expandFeatures featureMap (featureMap."${feature}" or [ ])); ++ (expandFeatures featureMap (featureMap."${feature}" or [ ]));
outFeatures = lib.concatMap expandFeature inputFeatures; outFeatures = lib.concatMap expandFeature inputFeatures;
in sortedUnique outFeatures; in
sortedUnique outFeatures;
/* Returns the actual features for the given dependency. /* Returns the actual features for the given dependency.
@ -17243,12 +17308,15 @@ rec {
defaultOrNil = defaultOrNil =
if dependency.usesDefaultFeatures or true then [ "default" ] else [ ]; if dependency.usesDefaultFeatures or true then [ "default" ] else [ ];
explicitFeatures = dependency.features or [ ]; explicitFeatures = dependency.features or [ ];
additionalDependencyFeatures = let additionalDependencyFeatures =
let
dependencyPrefix = (dependency.rename or dependency.name) + "/"; dependencyPrefix = (dependency.rename or dependency.name) + "/";
dependencyFeatures = dependencyFeatures =
builtins.filter (f: lib.hasPrefix dependencyPrefix f) features; builtins.filter (f: lib.hasPrefix dependencyPrefix f) features;
in builtins.map (lib.removePrefix dependencyPrefix) dependencyFeatures; in
in defaultOrNil ++ explicitFeatures ++ additionalDependencyFeatures; builtins.map (lib.removePrefix dependencyPrefix) dependencyFeatures;
in
defaultOrNil ++ explicitFeatures ++ additionalDependencyFeatures;
# Sorts and removes duplicates from a list of strings. # Sorts and removes duplicates from a list of strings.
sortedUnique = features: sortedUnique = features:
@ -17258,7 +17326,8 @@ rec {
outFeaturesSet = outFeaturesSet =
lib.foldl (set: feature: set // { "${feature}" = 1; }) { } features; lib.foldl (set: feature: set // { "${feature}" = 1; }) { } features;
outFeaturesUnique = builtins.attrNames outFeaturesSet; outFeaturesUnique = builtins.attrNames outFeaturesSet;
in builtins.sort (a: b: a < b) outFeaturesUnique; in
builtins.sort (a: b: a < b) outFeaturesUnique;
deprecationWarning = message: value: deprecationWarning = message: value:
if strictDeprecation then if strictDeprecation then

View File

@ -23,6 +23,16 @@ You can configure the crates to be built with debug mode (not recommended, equal
nix-env -f nix/default.nix --arg release false nix-env -f nix/default.nix --arg release false
``` ```
If you aren't on NixOS, you can run `veloren-voxygen` using the provided `nixGLIntel` in the dev shell:
```shell
nixGLIntel veloren-voxygen
```
If you have an Nvidia GPU, you can enter the dev shell like so:
```shell
nix-shell nix/shell.nix --arg nvidia true
```
And you'll be able to use `nixGLNvidia` and `nixGLNvidiaBumblebee`.
### Managing Cargo.nix ### Managing Cargo.nix
Enter the development shell. Enter the development shell.
@ -43,9 +53,9 @@ niv update
### Formatting ### Formatting
Use [nixfmt](https://github.com/serokell/nixfmt) to format files. Use [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) to format files.
To format every Nix file in current working directory: To format every Nix file:
```shell ```shell
nixfmt *.nix nixpkgs-fmt nix/*.nix
``` ```

View File

@ -1,40 +1,52 @@
{ system, nixpkgsMoz, nixpkgs }: { system, sources, nixpkgs }:
let let
mozPkgs = import "${nixpkgsMoz}/package-set.nix" { mozPkgs = import "${sources.nixpkgsMoz}/package-set.nix" {
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
}; };
rustChannel = mozPkgs.rustChannelOf { rustChannel = mozPkgs.rustChannelOf {
rustToolchain = ../rust-toolchain; rustToolchain = ../rust-toolchain;
sha256 = "sha256-P4FTKRe0nM1FRDV0Q+QY2WcC8M9IR7aPMMLWDfv+rEk="; sha256 = "sha256-P4FTKRe0nM1FRDV0Q+QY2WcC8M9IR7aPMMLWDfv+rEk=";
}; };
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ overlays = [
(self: super: { (final: prev: {
rustc = rustChannel.rust; rustc = rustChannel.rust;
inherit (rustChannel) inherit (rustChannel)
; ;
crate2nix = prev.callPackage sources.crate2nix { pkgs = prev; };
nixGL = prev.callPackage sources.nixGL { pkgs = prev; };
}) })
]; ];
}; };
in with pkgs; in
with pkgs;
let let
xorgLibraries = with xorg; [ libX11 libXcursor libXrandr libXi ]; # deps that crates need (for compiling)
otherLibraries = [
libGL
# wayland
/* uncomment above for wayland support (?)
for some reason it doesn't work (triggers `unreachable!()` code in winit!)
so I disabled it by default
*/
];
neededLibPathsVoxygen = lib.concatStringsSep ":"
(map (p: "${p}/lib") (xorgLibraries ++ otherLibraries));
crateDeps = { crateDeps = {
libudev-sys = [ pkg-config libudev ]; libudev-sys = {
alsa-sys = [ pkg-config alsaLib ]; buildInputs = [ libudev ];
veloren-network = [ pkg-config openssl ]; nativeBuildInputs = [ pkg-config ];
veloren-voxygen = [ atk cairo glib gtk3 pango ];
}; };
in { inherit pkgs neededLibPathsVoxygen crateDeps; } alsa-sys = {
buildInputs = [ alsaLib ];
nativeBuildInputs = [ pkg-config ];
};
veloren-network = {
buildInputs = [ openssl ];
nativeBuildInputs = [ pkg-config ];
};
veloren-voxygen = {
buildInputs = [ xorg.libxcb ];
nativeBuildInputs = [ ];
};
};
# deps that voxygen needs to function
voxygenNeededLibs = (with xorg; [ libX11 libXcursor libXrandr libXi ])
++ [ libGL ];
gitLfsCheckFile = ../assets/voxygen/background/bg_main.png;
in
{ inherit pkgs voxygenNeededLibs crateDeps gitLfsCheckFile; }

View File

@ -1,16 +1,15 @@
{ {
/* `crate2nix` doesn't support profiles in `Cargo.toml`, so default to release. # `crate2nix` doesn't support profiles in `Cargo.toml`, so default to release.
Otherwise bad performance (non-release is built with opt level 0) # Otherwise bad performance (non-release is built with opt level 0)
*/ release ? true
release ? true, cratesToBuild ? [ "veloren-voxygen" "veloren-server-cli" ] , cratesToBuild ? [ "veloren-voxygen" "veloren-server-cli" ]
, system ? builtins.currentSystem, nixpkgs ? sources.nixpkgs , system ? builtins.currentSystem
, sources ? import ./sources.nix { inherit system; } }: , nixpkgs ? sources.nixpkgs
, nvidia ? false
, sources ? import ./sources.nix { inherit system; }
}:
let let
common = import ./common.nix { common = import ./common.nix { inherit nixpkgs system sources; };
inherit nixpkgs system;
inherit (sources) nixpkgsMoz;
};
inherit (common) pkgs; inherit (common) pkgs;
meta = with pkgs.stdenv.lib; { meta = with pkgs.stdenv.lib; {
@ -26,13 +25,15 @@ let
platforms = platforms.all; platforms = platforms.all;
}; };
isGitLfsSetup = let isGitLfsSetup =
checkFile = ../assets/voxygen/background/bg_main.png; let
gitLfsCheckOutput = builtins.readFile (pkgs.runCommand "gitLfsCheck" { } '' gitLfsCheckOutput = with common;
[ "$(${pkgs.file}/bin/file --mime-type ${checkFile})" = "${checkFile}: image/png" ] builtins.readFile (pkgs.runCommand "gitLfsCheck" { } ''
[ "$(${pkgs.file}/bin/file --mime-type ${gitLfsCheckFile})" = "${gitLfsCheckFile}: image/png" ]
printf $? > $out printf $? > $out
''); '');
in if gitLfsCheckOutput == "0" then in
if gitLfsCheckOutput == "0" then
true true
else else
abort '' abort ''
@ -69,6 +70,9 @@ let
# If gitTag has a tag (meaning the commit we are on is a *release*), use it as version # If gitTag has a tag (meaning the commit we are on is a *release*), use it as version
# If not, we just use the prettified hash we have # If not, we just use the prettified hash we have
version = if gitTag != "" then gitTag else gitHash; version = if gitTag != "" then gitTag else gitHash;
# Sanitize version string since it contains not allowed characters for a Nix store path
# Only used in the package name
sanitizedVersion = pkgs.stdenv.lib.strings.sanitizeDerivationName version;
veloren-assets = pkgs.runCommand "makeAssetsDir" { } '' veloren-assets = pkgs.runCommand "makeAssetsDir" { } ''
mkdir $out mkdir $out
@ -79,8 +83,12 @@ let
callPackage ./Cargo.nix { callPackage ./Cargo.nix {
defaultCrateOverrides = with common; defaultCrateOverrides = with common;
defaultCrateOverrides // { defaultCrateOverrides // {
libudev-sys = _: { buildInputs = crateDeps.libudev-sys; }; libudev-sys = _: {
alsa-sys = _: { buildInputs = crateDeps.alsa-sys; }; inherit (crateDeps.libudev-sys) nativeBuildInputs buildInputs;
};
alsa-sys = _: {
inherit (crateDeps.alsa-sys) nativeBuildInputs buildInputs;
};
veloren-common = _: { veloren-common = _: {
# Disable `git-lfs` check here since we check it ourselves # Disable `git-lfs` check here since we check it ourselves
DISABLE_GIT_LFS_CHECK = isGitLfsSetup; DISABLE_GIT_LFS_CHECK = isGitLfsSetup;
@ -88,45 +96,49 @@ let
NIX_GIT_HASH = gitHash; NIX_GIT_HASH = gitHash;
NIX_GIT_TAG = gitTag; NIX_GIT_TAG = gitTag;
}; };
veloren-network = _: { buildInputs = crateDeps.veloren-network; }; veloren-network = _: {
inherit (crateDeps.veloren-network) nativeBuildInputs buildInputs;
};
veloren-server-cli = _: { veloren-server-cli = _: {
name = "veloren-server-cli_${sanitizedVersion}";
inherit version;
VELOREN_USERDATA_STRATEGY = "system"; VELOREN_USERDATA_STRATEGY = "system";
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
postInstall = '' postInstall = ''
wrapProgram $out/bin/veloren-server-cli --set VELOREN_ASSETS ${veloren-assets} wrapProgram $out/bin/veloren-server-cli --set VELOREN_ASSETS ${veloren-assets}
''; '';
meta = meta // {
longDescription = ''
${meta.longDescription}
"This package includes the server CLI."
'';
};
}; };
veloren-voxygen = _: { veloren-voxygen = _: {
name = "veloren-voxygen_${sanitizedVersion}";
inherit version;
VELOREN_USERDATA_STRATEGY = "system"; VELOREN_USERDATA_STRATEGY = "system";
buildInputs = crateDeps.veloren-voxygen; inherit (crateDeps.veloren-voxygen) buildInputs;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = crateDeps.veloren-voxygen.nativeBuildInputs
++ [ makeWrapper ];
postInstall = '' postInstall = ''
wrapProgram $out/bin/veloren-voxygen\ wrapProgram $out/bin/veloren-voxygen\
--set LD_LIBRARY_PATH ${neededLibPathsVoxygen}\ --set VELOREN_ASSETS ${veloren-assets}\
--set VELOREN_ASSETS ${veloren-assets} --set LD_LIBRARY_PATH ${
lib.makeLibraryPath common.voxygenNeededLibs
}
''; '';
meta = meta // {
longDescription = ''
${meta.longDescription}
"This package includes the client, Voxygen."
'';
};
}; };
}; };
inherit release pkgs; inherit release pkgs;
}; };
makePkg = name: makePkg = name: veloren-crates.workspaceMembers."${name}".build;
pkgs.symlinkJoin { in
inherit version; (pkgs.lib.genAttrs cratesToBuild makePkg)
name = "${name}_${version}";
paths = [ veloren-crates.workspaceMembers."${name}".build ];
meta = meta // {
longDescription = ''
${meta.longDescription}
${if name == "veloren-voxygen" then
"This package includes the client, Voxygen."
else
""}
${if name == "veloren-server-cli" then
"This package includes the server CLI."
else
""}
'';
};
};
in (pkgs.lib.genAttrs cratesToBuild makePkg)

View File

@ -1,25 +1,51 @@
{ nixpkgs ? <nixpkgs>, sources ? import ./sources.nix { } { nixpkgs ? <nixpkgs>
, system ? builtins.currentSystem }: , sources ? import ./sources.nix { }
, system ? builtins.currentSystem
, nvidia ? false
}:
let common = import ./common.nix { inherit nixpkgs system sources; };
in
with common.pkgs;
let let
common = import ./common.nix { nixGLPackages = ((with nixGL; [ nixGLIntel ]) ++ (lib.optional nvidia
inherit nixpkgs system; (with nixGL; [ nixGLNvidia nixGLNvidiaBumblebee ])));
inherit (sources) nixpkgsMoz;
};
crate2nix = getAllCratesDeps = name:
common.pkgs.callPackage sources.crate2nix { inherit (common) pkgs; }; (lib.concatLists
in with common.pkgs; (map (attrset: attrset."${name}") (lib.attrValues common.crateDeps)));
bundleCrate = writeScriptBin "bundleCrate" ''
#!${stdenv.shell}
${nix-bundle}/bin/nix-bundle "(pkgs.callPackage ./nix/default.nix { }).$1" /bin/$1
'';
in
with common;
mkShell { mkShell {
name = "veloren-shell"; name = "veloren-shell";
nativeBuildInputs = nativeBuildInputs = [
[ git git-lfs niv nixfmt crate2nix cargo rustc rustfmt clippy cachix ]; bundleCrate
buildInputs = lib.concatLists (lib.attrValues common.crateDeps); git
git-lfs
niv
nixpkgs-fmt
crate2nix
cargo
rustc
rustfmt
clippy
cachix
] ++ nixGLPackages ++ (getAllCratesDeps "nativeBuildInputs");
buildInputs = getAllCratesDeps "buildInputs";
shellHook = '' shellHook = ''
# Setup our cachix "substituter"
export NIX_CONFIG=" export NIX_CONFIG="
substituters = https://cache.nixos.org https://veloren-nix.cachix.org substituters = https://cache.nixos.org https://veloren-nix.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc= trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= veloren-nix.cachix.org-1:zokfKJqVsNV6kI/oJdLF6TYBdNPYGSb+diMVQPn/5Rc=
" "
export LD_LIBRARY_PATH=${common.neededLibPathsVoxygen} # We need this so that Voxygen runs
git lfs install --local && git lfs fetch && git lfs checkout export LD_LIBRARY_PATH=${lib.makeLibraryPath voxygenNeededLibs}
# No need to install git-lfs and run fetch / checkout commands if we have it setup
[ "$(${file}/bin/file --mime-type ${gitLfsCheckFile})" = "${gitLfsCheckFile}: image/png" ] || (git lfs install --local && git lfs fetch && git lfs checkout)
''; '';
} }

View File

@ -5,10 +5,22 @@
"homepage": "", "homepage": "",
"owner": "kolloch", "owner": "kolloch",
"repo": "crate2nix", "repo": "crate2nix",
"rev": "df3e4e6570c1058d947d70876712209a1eca6731", "rev": "3701179c8aef0677dab1915457ca0f367f2dc523",
"sha256": "1kn98ckf2h4j3xmc50n6904p5g226qa1c1jgha511d9l6lgks24r", "sha256": "0z5vz3dcbx53a7q6xrm8qjrn62zlvzvaxdisv2axfh70qq4lx4n2",
"type": "tarball", "type": "tarball",
"url": "https://github.com/kolloch/crate2nix/archive/df3e4e6570c1058d947d70876712209a1eca6731.tar.gz", "url": "https://github.com/kolloch/crate2nix/archive/3701179c8aef0677dab1915457ca0f367f2dc523.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixGL": {
"branch": "master",
"description": "A wrapper tool for nix OpenGL application",
"homepage": null,
"owner": "guibou",
"repo": "nixGL",
"rev": "7d6bc1b21316bab6cf4a6520c2639a11c25a220e",
"sha256": "02y38zmdplk7a9ihsxvnrzhhv7324mmf5g8hmxqizaid5k5ydpr3",
"type": "tarball",
"url": "https://github.com/guibou/nixGL/archive/7d6bc1b21316bab6cf4a6520c2639a11c25a220e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"nixpkgs": { "nixpkgs": {
@ -17,10 +29,10 @@
"homepage": "", "homepage": "",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "6625284c397b44bc9518a5a1567c1b5aae455c08", "rev": "1121b2259b7d66e8c7c5131d1588a48c80ef9e58",
"sha256": "1w0czzv53sg35gp7sr506facbmzd33jm34p6cg23fb9kz5rf5c89", "sha256": "0w2i4byhfn8c9lq8a97xnix5alfandqkbyvh6lbpr9zrm63lmyip",
"type": "tarball", "type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/6625284c397b44bc9518a5a1567c1b5aae455c08.tar.gz", "url": "https://github.com/NixOS/nixpkgs/archive/1121b2259b7d66e8c7c5131d1588a48c80ef9e58.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"nixpkgsMoz": { "nixpkgsMoz": {

View File

@ -1,15 +1,15 @@
# This file has been generated by Niv. # This file has been generated by Niv.
let let
# #
# The fetchers. fetch_<type> fetches specs of type <type>. # The fetchers. fetch_<type> fetches specs of type <type>.
# #
fetch_file = pkgs: name: spec: fetch_file = pkgs: name: spec:
let name' = sanitizeName name + "-src"; let name' = sanitizeName name + "-src";
in if spec.builtin or true then in
builtins_fetchurl { if spec.builtin or true then
builtins_fetchurl
{
inherit (spec) url sha256; inherit (spec) url sha256;
name = name'; name = name';
} }
@ -21,8 +21,10 @@ let
fetch_tarball = pkgs: name: spec: fetch_tarball = pkgs: name: spec:
let name' = sanitizeName name + "-src"; let name' = sanitizeName name + "-src";
in if spec.builtin or true then in
builtins_fetchTarball { if spec.builtin or true then
builtins_fetchTarball
{
name = name'; name = name';
inherit (spec) url sha256; inherit (spec) url sha256;
} }
@ -34,7 +36,8 @@ let
fetch_git = name: spec: fetch_git = name: spec:
let let
ref = if spec ? ref then ref =
if spec ? ref then
spec.ref spec.ref
else if spec ? branch then else if spec ? branch then
"refs/heads/${spec.branch}" "refs/heads/${spec.branch}"
@ -43,7 +46,8 @@ let
else else
abort abort
"In git source '${name}': Please specify `ref`, `tag` or `branch`!"; "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
in builtins.fetchGit { in
builtins.fetchGit {
url = spec.repo; url = spec.repo;
inherit (spec) rev; inherit (spec) rev;
inherit ref; inherit ref;
@ -75,12 +79,14 @@ let
mkPkgs = sources: system: mkPkgs = sources: system:
let let
sourcesNixpkgs = import sourcesNixpkgs = import
(builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; })
{
inherit system; inherit system;
}; };
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.; hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in if builtins.hasAttr "nixpkgs" sources then in
if builtins.hasAttr "nixpkgs" sources then
sourcesNixpkgs sourcesNixpkgs
else if hasNixpkgsPath && !hasThisAsNixpkgsPath then else if hasNixpkgsPath && !hasThisAsNixpkgsPath then
import <nixpkgs> { } import <nixpkgs> { }
@ -116,19 +122,23 @@ let
replace = name: drv: replace = name: drv:
let let
saneName = stringAsChars saneName = stringAsChars
(c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c)
name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in if ersatz == "" then drv else ersatz; in
if ersatz == "" then drv else ersatz;
# Ports of functions for older nix versions # Ports of functions for older nix versions
# a Nix version of mapAttrs if the built-in doesn't exist # a Nix version of mapAttrs if the built-in doesn't exist
mapAttrs = builtins.mapAttrs or (f: set: mapAttrs = builtins.mapAttrs or (f: set:
with builtins; with builtins;
listToAttrs (map (attr: { listToAttrs (map
(attr: {
name = attr; name = attr;
value = f attr set.${attr}; value = f attr set.${attr};
}) (attrNames set))); })
(attrNames set)));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = first: last: range = first: last:
@ -152,7 +162,8 @@ let
# fetchTarball version that is compatible between all the versions of Nix # fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name ? null, sha256 }@attrs: builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let inherit (builtins) lessThan nixVersion fetchTarball; let inherit (builtins) lessThan nixVersion fetchTarball;
in if lessThan nixVersion "1.12" then in
if lessThan nixVersion "1.12" then
fetchTarball fetchTarball
({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else else
@ -161,7 +172,8 @@ let
# fetchurl version that is compatible between all the versions of Nix # fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, name ? null, sha256 }@attrs: builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let inherit (builtins) lessThan nixVersion fetchurl; let inherit (builtins) lessThan nixVersion fetchurl;
in if lessThan nixVersion "1.12" then in
if lessThan nixVersion "1.12" then
fetchurl fetchurl
({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else else
@ -169,7 +181,8 @@ let
# Create the final "sources" from the config # Create the final "sources" from the config
mkSources = config: mkSources = config:
mapAttrs (name: spec: mapAttrs
(name: spec:
if builtins.hasAttr "outPath" spec then if builtins.hasAttr "outPath" spec then
abort abort
"The values in sources.json should not have an 'outPath' attribute" "The values in sources.json should not have an 'outPath' attribute"
@ -178,13 +191,15 @@ let
config.sources; config.sources;
# The "config" used by the fetchers # The "config" used by the fetchers
mkConfig = { sourcesFile ? mkConfig =
if builtins.pathExists ./sources.json then ./sources.json else null { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
, sources ? if isNull sourcesFile then , sources ? if isNull sourcesFile then
{ } { }
else else
builtins.fromJSON (builtins.readFile sourcesFile) builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem, pkgs ? mkPkgs sources system }: rec { , system ? builtins.currentSystem
, pkgs ? mkPkgs sources system
}: rec {
# The sources, i.e. the attribute set of spec name to spec # The sources, i.e. the attribute set of spec name to spec
inherit sources; inherit sources;
@ -192,6 +207,7 @@ let
inherit pkgs; inherit pkgs;
}; };
in mkSources (mkConfig { }) // { in
mkSources (mkConfig { }) // {
__functor = _: settings: mkSources (mkConfig settings); __functor = _: settings: mkSources (mkConfig settings);
} }