Skip to content
Open
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
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 74 additions & 23 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
};

outputs =
{ self, nixpkgs, crane }:
{
self,
nixpkgs,
crane,
}:
let
supportedSystems = [
"x86_64-linux"
Expand Down Expand Up @@ -35,8 +39,8 @@

package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.ratty;
defaultText = lib.literalExpression "self.packages.\${pkgs.stdenv.hostPlatform.system}.ratty";
default = pkgs.ratty;
defaultText = lib.literalExpression "pkgs.ratty";
description = "The ratty package to install.";
};

Expand All @@ -57,7 +61,22 @@
};

gpuBackend = lib.mkOption {
type = lib.types.nullOr (lib.types.enum [ "vulkan" "gl" "gles" ]);
type = lib.types.nullOr (
lib.types.enum (
if pkgs.stdenv.isDarwin then
[
"metal"
"gl"
"gles"
]
else
[
"vulkan"
"gl"
"gles"
]
)
);
default = null;
description = ''
Force the wgpu backend.
Expand All @@ -79,6 +98,15 @@
'';
example = "RTX 3060";
};
defaultShell = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = null;
description = ''
Default shell to use when no -e/--command flag is passed.
Set to null to use the package's built-in default (bash).
'';
example = lib.literalExpression "pkgs.zsh";
};
};
};
in
Expand Down Expand Up @@ -130,6 +158,11 @@

formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);

# Overlay — adds pkgs.ratty for use with the NixOS/HM modules.
overlays.default = final: prev: {
ratty = self.packages.${final.stdenv.hostPlatform.system}.ratty;
};

checks = forEachSystem (
system:
let
Expand Down Expand Up @@ -173,13 +206,20 @@
{
inherit (opts) options;
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.package != null;
message = "programs.ratty.package must not be null when programs.ratty.enable is true";
}
];
home.packages = [ cfg.package ];
xdg.configFile."ratty/ratty.toml" = lib.mkIf (cfg.settings != { }) {
source = tomlFormat.generate "ratty.toml" cfg.settings;
};
home.sessionVariables = lib.mkMerge [
(lib.mkIf (cfg.gpuBackend != null) { WGPU_BACKEND = cfg.gpuBackend; })
(lib.mkIf (cfg.gpuAdapter != null) { WGPU_ADAPTER_NAME = cfg.gpuAdapter; })
(lib.mkIf (cfg.defaultShell != null) { SHELL = lib.getExe cfg.defaultShell; })
];
};
};
Expand Down Expand Up @@ -215,26 +255,37 @@
{
inherit (opts) options;
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.package != null;
message = "programs.ratty.package must not be null when programs.ratty.enable is true";
}
];
environment.systemPackages = [
(let
hasSettings = cfg.settings != { };
hasGpuOpts = cfg.gpuBackend != null || cfg.gpuAdapter != null;
in
if !(hasSettings || hasGpuOpts) then
cfg.package
else
pkgs.symlinkJoin {
name = "ratty-system-wrapped";
paths = [ cfg.package ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
rm -f $out/bin/ratty
makeWrapper ${lib.getExe cfg.package} $out/bin/ratty \
${lib.optionalString hasSettings "--add-flags \"--config-file /etc/ratty/ratty.toml\""} \
${lib.optionalString (cfg.gpuBackend != null) "--set WGPU_BACKEND '${cfg.gpuBackend}'"} \
${lib.optionalString (cfg.gpuAdapter != null) "--set WGPU_ADAPTER_NAME '${cfg.gpuAdapter}'"}
'';
})
(
let
hasSettings = cfg.settings != { };
hasGpuOpts = cfg.gpuBackend != null || cfg.gpuAdapter != null;
in
if !(hasSettings || hasGpuOpts) then
cfg.package
else
pkgs.symlinkJoin {
name = "ratty-system-wrapped";
paths = [ cfg.package ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
rm -f $out/bin/ratty
makeWrapper ${lib.getExe cfg.package} $out/bin/ratty \
${lib.optionalString hasSettings "--add-flags \"--config-file /etc/ratty/ratty.toml\""} \
${lib.optionalString (cfg.gpuBackend != null) "--set WGPU_BACKEND '${cfg.gpuBackend}'"} \
${lib.optionalString (cfg.gpuAdapter != null) "--set WGPU_ADAPTER_NAME '${cfg.gpuAdapter}'"} \
${lib.optionalString (
cfg.defaultShell != null
) "--set-default SHELL '${lib.getExe cfg.defaultShell}'"}
'';
}
)
];

environment.etc."ratty/ratty.toml" = lib.mkIf (cfg.settings != { }) {
Expand Down
111 changes: 57 additions & 54 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let
# cache hit rate — dependency hashes don't change when assets/docs change.
commonArgs = {
pname = "ratty";
version = "0.4.1";
version = "0.4.2";

src = craneLib.cleanCargoSource ../.;

Expand Down Expand Up @@ -95,62 +95,65 @@ let

in
# Build the full package, reusing cached dependency artifacts.
craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;

# The full source (including assets, config, website) is needed for
# postInstall below. buildDepsOnly already handled the filtered source.
src = ../.;
# The full source (including assets, config, website) is needed for
# postInstall below. buildDepsOnly already handled the filtered source.
src = ../.;

desktopItems = [
(makeDesktopItem {
name = "ratty";
desktopName = "Ratty";
comment = "A GPU-rendered terminal emulator with inline 3D graphics";
exec = "ratty";
terminal = false;
categories = [
"System"
"TerminalEmulator"
"Utility"
];
icon = "ratty";
})
];
desktopItems = [
(makeDesktopItem {
name = "ratty";
desktopName = "Ratty";
comment = "A GPU-rendered terminal emulator with inline 3D graphics";
exec = "ratty";
terminal = false;
categories = [
"System"
"TerminalEmulator"
"Utility"
];
icon = "ratty";
})
];

# Assets are embedded at compile time via rust-embed.
# Copy them to $out/share for reference and custom model discovery fallback.
postInstall = ''
# Step 1: Copy assets
mkdir -p $out/share/ratty
cp -r assets/objects $out/share/ratty/
install -Dm644 config/ratty.toml $out/share/ratty/ratty.toml
install -Dm644 website/assets/images/ratty-logo.png \
$out/share/icons/hicolor/512x512/apps/ratty.png
# Assets are embedded at compile time via rust-embed.
# Copy them to $out/share for reference and custom model discovery fallback.
postInstall = ''
# Step 1: Copy assets
mkdir -p $out/share/ratty
cp -r assets/objects $out/share/ratty/
install -Dm644 config/ratty.toml $out/share/ratty/ratty.toml
install -Dm644 website/assets/images/ratty-logo.png \
$out/share/icons/hicolor/512x512/apps/ratty.png

# Step 2: wrapProgram for env var management
wrapProgram $out/bin/ratty \
--set SHELL '${bash}/bin/bash' \
--prefix LD_LIBRARY_PATH : '${runtimeLibraryPath}' \
${lib.optionalString stdenv.isDarwin ''
--prefix DYLD_LIBRARY_PATH : '${runtimeLibraryPath}' \
--prefix DYLD_FALLBACK_LIBRARY_PATH : '${runtimeLibraryPath}' \
''}
# Step 2: wrapProgram for env var management
wrapProgram $out/bin/ratty \
--set-default SHELL '${bash}/bin/bash' \
--prefix LD_LIBRARY_PATH : '${runtimeLibraryPath}' \
${lib.optionalString stdenv.isDarwin ''
--prefix DYLD_LIBRARY_PATH : '${runtimeLibraryPath}' \
--prefix DYLD_FALLBACK_LIBRARY_PATH : '${runtimeLibraryPath}' \
''}

# Step 3: Thin wrapper for conditional -e "$SHELL" injection.
# The --run script is defined as a separate Nix string to avoid
# the nested double-tick problem (Nix does not support nested double-tick strings).
mv $out/bin/ratty $out/bin/.ratty-env-wrapped
makeWrapper $out/bin/.ratty-env-wrapped $out/bin/ratty \
--run '${runScript}'
'';
# Step 3: Thin wrapper for conditional -e "$SHELL" injection.
# The --run script is defined as a separate Nix string to avoid
# the nested double-tick problem (Nix does not support nested double-tick strings).
mv $out/bin/ratty $out/bin/.ratty-env-wrapped
makeWrapper $out/bin/.ratty-env-wrapped $out/bin/ratty \
--run '${runScript}'
'';

meta = {
description = "GPU-rendered terminal emulator with inline 3D graphics";
homepage = "https://github.com/orhun/ratty";
license = lib.licenses.mit;
maintainers = [ "daniejbolt" ];
mainProgram = "ratty";
platforms = lib.platforms.unix;
};
})
meta = {
description = "GPU-rendered terminal emulator with inline 3D graphics";
homepage = "https://github.com/orhun/ratty";
license = lib.licenses.mit;
maintainers = [ "daniejbolt" ];
mainProgram = "ratty";
platforms = lib.platforms.unix;
};
}
)
Loading