Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake: add apps entry and fix runtime error #412

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 77 additions & 43 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +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
]);

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

rustPackage = rust-toolchain:
pkgs.rustPlatform.buildRustPackage {
mkRio = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an old snippet from old config? What was the motivation for this? However, I just tested this change and seems working on this end. Is this change necessary? I believe that we should not be adding additional functions on functions just for the dependencies. We could add these for PerSystem and see if that would work for us. I did this way of passing function carrying evaluations of dependencies to the function defined by rustPlatform as an experiment mostly. I am not certain if this could cause further breakage. Also, if this is for people to use flakes to generate a package for their config should not be really a concern as nixpkgs is being constantly updated by you and other maintainers as I can see now. I believe nix develop and nix build should be our focus. I would like some clarity regarding this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just adding

pkgs.rustPlatform.buildRustPackage {
   inherit (cargoToml.workspace.package) version;
   name = "rio";
   src = ./.;
   cargoLock.lockFile = ./Cargo.lock;
   
   cargoBuildFlags = "-p rioterm";
   
   buildInputs = runtimeDeps ++ buildDeps;
   nativeBuildInputs = buildDeps;
   runtimeDependencies = runtimeDeps;
   
   buildNoDefaultFeatures = true;
   buildFeatures = ["x11" "wayland"];
   
   meta = {
            description = "A hardware-accelerated GPU terminal emulator focusing to run in desktops and browsers";
            homepage = "https://raphamorim.io/rio";
            license = lib.licenses.mit;
            platforms = lib.platforms.unix;
            changelog = "https://github.com/raphamorim/rio/blob/master/CHANGELOG.md";
            mainProgram = "rio";
    };
};

was not enough to get rid of the issue where it core dumps with NoWaylandLib or NoXCBLib.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an old snippet from old config? What was the motivation for this? (...) Is this change necessary?

I'm not fully understanding this yet as well, but I assume that working with pkgs instead of an isolating function, as with mkRio here, potentially breaks some things, since callPackage does some "black magic" (that's what I got told of from the unofficial nixos-discord server).

However, I asked on the discourse what the preferred way is to declare a package and it seems to be either to move that into an extra file, as suggested in the nix pills (I only have skimmed through it at the time of writing this) or moving this into a variable, as we do here with mkRio.

I believe nix develop and nix build should be our focus.

I agree, but I'd say that nix run is more important than nix build because what's the point of having a succeeding build, if you can't use it? ;)

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 @@ -87,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 @@ -102,7 +132,11 @@
packages.default = self'.packages.rio;
devShells.default = self'.devShells.msrv;

packages.rio = rustPackage "rio";
apps.default = {
type = "app";
program = self'.packages.rio;
};
packages.rio = pkgs.callPackage mkRio {};

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