Skip to content

Commit

Permalink
flake: add apps entry and fix runtime error (#412)
Browse files Browse the repository at this point in the history
* flake: add `apps` entry and fix runtime error

flake: fix package creation

* flake: update program path for default app

Co-authored-by: Steve Mathew Joy <[email protected]>

* flake: move rio package creation to external file

---------

Co-authored-by: Steve Mathew Joy <[email protected]>
  • Loading branch information
TornaxO7 and RaySlash authored Jan 20, 2024
1 parent 1de4cb1 commit eb296f6
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 87 deletions.
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";
};
}

0 comments on commit eb296f6

Please sign in to comment.