From c9ccd3d4d14d1fd37aa0707ddbb3665d2b73ce85 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 13 Jan 2024 19:59:45 +0100 Subject: [PATCH 1/3] flake: add `apps` entry and fix runtime error flake: fix package creation --- flake.nix | 120 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 43 deletions(-) diff --git a/flake.nix b/flake.nix index b375f3094b..c0b4d02d4c 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = { + 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 = { @@ -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 { @@ -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; From 5ce7ab54c61ed68b36c8fb8844708d6f3d958ac2 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sun, 14 Jan 2024 13:42:07 +0100 Subject: [PATCH 2/3] flake: update program path for default app Co-authored-by: Steve Mathew Joy <45141270+RaySlash@users.noreply.github.com> --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index c0b4d02d4c..302d4aca45 100644 --- a/flake.nix +++ b/flake.nix @@ -134,7 +134,7 @@ apps.default = { type = "app"; - program = self'.packages.rio; + program = self'.packages.default; }; packages.rio = pkgs.callPackage mkRio {}; From f651fd61be6e90cdbaaa47345f6e74cbf46b22eb Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Fri, 19 Jan 2024 21:46:08 +0100 Subject: [PATCH 3/3] flake: move rio package creation to external file --- flake.nix | 160 ++++++++++++++--------------------------------------- pkgRio.nix | 84 ++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 120 deletions(-) create mode 100644 pkgRio.nix diff --git a/flake.nix b/flake.nix index 302d4aca45..0b5ffeaf19 100644 --- a/flake.nix +++ b/flake.nix @@ -11,136 +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"]; - }; - - 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 = rlinkLibs; - runtimeDependencies = rlinkLibs; + perSystem = + { config + , self' + , inputs' + , pkgs + , system + , lib + , ... + }: + let + rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { + extensions = [ "rust-src" "rust-analyzer" ]; + }; - nativeBuildInputs = - [ - ncurses - ] - ++ lib.optionals stdenv.isLinux [ - pkg-config - cmake - autoPatchelfHook - ]; + mkRio = import ./pkgRio.nix; - 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 ]; }; - }; - - 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]; + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ (import inputs.rust-overlay) ]; }; - 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; - apps.default = { - type = "app"; - program = self'.packages.default; - }; - packages.rio = pkgs.callPackage mkRio {}; + 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)); + }; }; } diff --git a/pkgRio.nix b/pkgRio.nix new file mode 100644 index 0000000000..8be0643265 --- /dev/null +++ b/pkgRio.nix @@ -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"; + }; +}