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
Show file tree
Hide file tree
Changes from all commits
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
128 changes: 41 additions & 87 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,102 +11,56 @@
};
};

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [];
outputs = inputs @ { flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ];

systems = import inputs.systems;

perSystem = {
config,
self',
inputs',
pkgs,
system,
lib,
...
}: let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
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
]);
perSystem =
{ config
, self'
, inputs'
, pkgs
, system
, lib
, ...
}:
let
rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [ "rust-src" "rust-analyzer" ];
};

buildDeps = with pkgs;
[
ncurses
]
++ lib.optionals stdenv.isLinux [
pkg-config
cmake
autoPatchelfHook
];
mkRio = import ./pkgRio.nix;

rustPackage = rust-toolchain:
pkgs.rustPlatform.buildRustPackage {
inherit (cargoToml.workspace.package) version;
name = "rio";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
cargoBuildFlags = "-p rioterm";
buildInputs = runtimeDeps ++ buildDeps;
nativeBuildInputs = buildDeps;
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";
mkDevShell = rust-toolchain:
let
dependencies = self'.packages.rio.nativeBuildInputs ++ self'.packages.rio.buildInputs;
in
pkgs.mkShell {
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath dependencies}:$LD_LIBRARY_PATH";
packages = dependencies ++ [ rust-toolchain ];
};
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};

mkDevShell = rust-toolchain:
pkgs.mkShell {
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (runtimeDeps ++ buildDeps)}:$LD_LIBRARY_PATH";
packages = buildDeps ++ runtimeDeps ++ [rust-toolchain];
};
in {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [(import inputs.rust-overlay)];
};

formatter = pkgs.alejandra;
packages.default = self'.packages.rio;
devShells.default = self'.devShells.msrv;
formatter = pkgs.alejandra;
packages.default = self'.packages.rio;
devShells.default = self'.devShells.msrv;

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

devShells.msrv = mkDevShell rust-toolchain;
devShells.stable = mkDevShell pkgs.rust-bin.stable.latest.default;
devShells.nightly = mkDevShell (pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default));
};
devShells.msrv = mkDevShell rust-toolchain;
devShells.stable = mkDevShell pkgs.rust-bin.stable.latest.default;
devShells.nightly = mkDevShell (pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default));
};
};
}
84 changes: 84 additions & 0 deletions pkgRio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{ 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
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
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 = rlinkLibs;
runtimeDependencies = rlinkLibs;

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

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";
};
}