Skip to content

Commit

Permalink
flake: fix package creation
Browse files Browse the repository at this point in the history
  • Loading branch information
TornaxO7 committed Jan 13, 2024
1 parent b9aa653 commit 557f14b
Showing 1 changed file with 73 additions and 44 deletions.
117 changes: 73 additions & 44 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,78 @@
extensions = ["rust-src" "rust-analyzer"];
};

runtimeDeps = with pkgs;
if stdenv.isDarwin
then [
darwin.libobjc
darwin.apple_sdk_11_0.frameworks.AppKit
darwin.apple_sdk_11_0.frameworks.AVFoundation
darwin.apple_sdk_11_0.frameworks.Vision
]
else
(with pkgs; [
(lib.getLib gcc-unwrapped)
fontconfig
libGL
libxkbcommon
vulkan-loader
wayland
])
++ (with pkgs.xorg; [
libX11
libXcursor
libXi
libXrandr
libxcb
xkbutils
]);

buildDeps = with pkgs;
[
ncurses
]
++ lib.optionals stdenv.isLinux [
pkg-config
cmake
autoPatchelfHook
];

rustPackage = rust-toolchain:
pkgs.rustPlatform.buildRustPackage {
mkRio = {
rustPlatform,
stdenv,
lib,
fontconfig,
darwin,
gcc-unwrapped,
libGL,
libxkbcommon,
vulkan-loader,
libX11,
libXcursor,
libXi,
libXrandr,
libxcb,
wayland,
ncurses,
pkg-config,
cmake,
autoPatchelfHook,
withX11 ? !stdenv.isDarwin,
withWayland ? !stdenv.isDarwin,
...
}: let
rlinkLibs =
if stdenv.isDarwin
then [
darwin.libobjc
darwin.apple_sdk_11_0.frameworks.AppKit
darwin.apple_sdk_11_0.frameworks.AVFoundation
darwin.apple_sdk_11_0.frameworks.Vision
]
else
[
(lib.getLib gcc-unwrapped)
fontconfig
libGL
libxkbcommon
vulkan-loader
]
++ lib.optionals withX11 [
libX11
libXcursor
libXi
libXrandr
libxcb
]
++ lib.optionals withWayland [
wayland
];
in
rustPlatform.buildRustPackage {
inherit (cargoToml.workspace.package) version;
name = "rio";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;

cargoBuildFlags = "-p rioterm";
buildInputs = runtimeDeps ++ buildDeps;
nativeBuildInputs = buildDeps;

buildInputs = rlinkLibs;
runtimeDependencies = rlinkLibs;

nativeBuildInputs =
[
ncurses
]
++ lib.optionals stdenv.isLinux [
pkg-config
cmake
autoPatchelfHook
];

buildNoDefaultFeatures = true;
buildFeatures = ["x11" "wayland"];
meta = {
Expand All @@ -88,10 +115,12 @@
};
};

mkDevShell = rust-toolchain:
mkDevShell = rust-toolchain: let
dependencies = self'.packages.rio.nativeBuildInputs ++ self'.packages.rio.buildInputs;
in
pkgs.mkShell {
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (runtimeDeps ++ buildDeps)}:$LD_LIBRARY_PATH";
packages = buildDeps ++ runtimeDeps ++ [rust-toolchain];
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath dependencies}:$LD_LIBRARY_PATH";
packages = dependencies ++ [rust-toolchain];
};
in {
_module.args.pkgs = import inputs.nixpkgs {
Expand All @@ -107,7 +136,7 @@
type = "app";
program = self'.packages.rio;
};
packages.rio = rustPackage "rio";
packages.rio = pkgs.callPackage mkRio {};

devShells.msrv = mkDevShell rust-toolchain;
devShells.stable = mkDevShell pkgs.rust-bin.stable.latest.default;
Expand Down

0 comments on commit 557f14b

Please sign in to comment.