diff --git a/flake.lock b/flake.lock index 832b3fe..ee8027c 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1777954456, - "narHash": "sha256-hGdgeU2Nk87RAuZyYjyDjFL6LK7dAZN5RE9+hrDTkDU=", + "lastModified": 1784356753, + "narHash": "sha256-12KrbMiWLcf8m7pCvAtZh1ZrgF85ZXDXvfR/fWTKy84=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "549bd84d6279f9852cae6225e372cc67fb91a4c1", + "rev": "61b7c44c4073f0b827768aff0049561b5110ea5a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index aa83a63..e592cbb 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,11 @@ }; outputs = - { self, nixpkgs, crane }: + { + self, + nixpkgs, + crane, + }: let supportedSystems = [ "x86_64-linux" @@ -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."; }; @@ -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. @@ -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 @@ -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 @@ -173,6 +206,12 @@ { 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; @@ -180,6 +219,7 @@ 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; }) ]; }; }; @@ -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 != { }) { diff --git a/nix/default.nix b/nix/default.nix index 2c63e34..1ca8e7d 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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 ../.; @@ -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; + }; + } +)