Skip to content

Commit

Permalink
Add nix flake (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
valeth authored Apr 24, 2024
1 parent ad23a7b commit bf0ec7f
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/hook/target
/.idea
/.idea
/result
96 changes: 96 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
description = "Mint development shell";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = { nixpkgs, rust-overlay, ... }:
let
system = "x86_64-linux";

lib = nixpkgs.lib;
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};

rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [ "rust-src" "rust-analyzer" ];
};
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};

mingwPkgs = pkgs.pkgsCross.mingwW64;
mingwCompiler = mingwPkgs.buildPackages.gcc;
mingwRustflags = "-L ${mingwPkgs.windows.pthreads}/lib";
mingwTool = name: "${mingwCompiler}/bin/${mingwCompiler.targetPrefix}${name}";

libs = with pkgs; [
gtk3
libGL
openssl
atk
libxkbcommon
wayland
];

buildTools = with pkgs; [
rustToolchain
pkg-config
mingwCompiler
];

libraryPath = lib.makeLibraryPath libs;

manifest = lib.importTOML ./Cargo.toml;
packageName = manifest.package.name;
packageVersion = manifest.workspace.package.version;

package = rustPlatform.buildRustPackage {
nativeBuildInputs = buildTools;
buildInputs = libs;

pname = packageName;
version = packageVersion;
src = lib.cleanSource ./.;

verbose = true;

cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};

doCheck = false;

preConfigure = ''
export LD_LIBRARY_PATH="${libraryPath}"
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS="${mingwRustflags}";
'';

meta = with lib; {
description = "Deep Rock Galactic mod loader and integration";
license = licenses.mit;
homepage = "https://github.com/trumank/mint";
};
};

devShell = pkgs.mkShell {
name = "mint";

buildInputs = buildTools ++ libs;

LD_LIBRARY_PATH = libraryPath;
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS = mingwRustflags;

# Necessary for cross compiled build scripts, otherwise it will build as ELF format
# https://docs.rs/cc/latest/cc/#external-configuration-via-environment-variables
CC_x86_64_pc_windows_gnu = mingwTool "cc";
AR_x86_64_pc_windows_gnu = mingwTool "ar";
};
in {
packages.${system} = {
${packageName} = package;
default = package;
};

devShells.${system}.default = devShell;
};
}
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[toolchain]
channel = "nightly"
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-gnu",
]

0 comments on commit bf0ec7f

Please sign in to comment.