From cd9fc43af454d47e04391dd94503e780f2689591 Mon Sep 17 00:00:00 2001 From: onelock <180497738+onelocked@users.noreply.github.com> Date: Tue, 24 Mar 2026 11:55:31 +0000 Subject: [PATCH] fix: nix evaluation warnings + flake improvements (#395) * fix: nix evaluation warning * nix: minor flake improvements/maintenance * nix: fix macos build errors * nix: minor cleanup/fixes * nix: remove redundant deps * nix: remove reliance on systems input --- flake.lock | 12 ++--- flake.nix | 139 +++++++++++++++++++++++++++++------------------- nix/default.nix | 46 ++++++++-------- 3 files changed, 113 insertions(+), 84 deletions(-) diff --git a/flake.lock b/flake.lock index 3badc2b..bd6f5ff 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1752687322, - "narHash": "sha256-RKwfXA4OZROjBTQAl9WOZQFm7L8Bo93FQwSJpAiSRvo=", + "lastModified": 1772963539, + "narHash": "sha256-9jVDGZnvCckTGdYT53d/EfznygLskyLQXYwJLKMPsZs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6e987485eb2c77e5dcc5af4e3c70843711ef9251", + "rev": "9dcb002ca1690658be4a04645215baea8b95f31d", "type": "github" }, "original": { @@ -29,11 +29,11 @@ ] }, "locked": { - "lastModified": 1752806774, - "narHash": "sha256-4cHeoR2roN7d/3J6gT+l6o7J2hTrBIUiCwVdDNMeXzE=", + "lastModified": 1773025773, + "narHash": "sha256-Wik8+xApNfldpUFjPmJkPdg0RrvUPSWGIZis+A/0N1w=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "3c90219b3ba1c9790c45a078eae121de48a39c55", + "rev": "3c06fdbbd36ff60386a1e590ee0cd52dcd1892bf", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 2ad40b5..5cf260f 100644 --- a/flake.nix +++ b/flake.nix @@ -7,60 +7,87 @@ inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = { - self, - nixpkgs, - rust-overlay, - ... - }: let - inherit (nixpkgs) lib; - genSystems = lib.genAttrs [ - "aarch64-darwin" - "aarch64-linux" - "x86_64-darwin" - "x86_64-linux" - ]; - pkgsFor = system: - import nixpkgs { - inherit system; - - overlays = [ - rust-overlay.overlays.default - ]; - }; - mkRustToolchain = pkgs: - pkgs.rust-bin.stable.latest.default.override { - extensions = ["rust-src"]; - }; - pkgs = genSystems (system: import nixpkgs {inherit system;}); - in { - packages = genSystems (system: rec { - default = pkgs.${system}.callPackage ./nix {}; - lan-mouse = default; - }); - homeManagerModules.default = import ./nix/hm-module.nix self; - devShells = genSystems (system: let - pkgs = pkgsFor system; - rust = mkRustToolchain pkgs; - in { - default = pkgs.mkShell { - packages = with pkgs; [ - rust - rust-analyzer-unwrapped - pkg-config - xorg.libX11 - gtk4 - libadwaita - librsvg - xorg.libXtst - ] ++ lib.optionals stdenv.isDarwin - (with darwin.apple_sdk_11_0.frameworks; [ - CoreGraphics - ApplicationServices - ]); - - RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; - }; - }); - }; + outputs = + { + nixpkgs, + rust-overlay, + self, + ... + }: + let + inherit (nixpkgs) lib; + forEachPkgs = + f: + lib.genAttrs + [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ] + ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + # Default toolchain for devshell + rustToolchain = pkgs.rust-bin.stable.latest.default.override { + extensions = [ + # includes already: + # rustc + # cargo + # rust-std + # rust-docs + # rustfmt-preview + # clippy-preview + "rust-analyzer" + "rust-src" + ]; + }; + # Minimal toolchain for builds (rustc + cargo + rust-std only) + rustToolchainForBuild = pkgs.rust-bin.stable.latest.minimal; + in + f { inherit pkgs rustToolchain rustToolchainForBuild; } + ); + in + { + packages = forEachPkgs ( + { pkgs, rustToolchainForBuild, ... }: + let + customRustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchainForBuild; + rustc = rustToolchainForBuild; + }; + lan-mouse = pkgs.callPackage ./nix { rustPlatform = customRustPlatform; }; + in + { + default = lan-mouse; + inherit lan-mouse; + } + ); + devShells = forEachPkgs ( + { pkgs, rustToolchain, ... }: + { + default = pkgs.mkShell { + packages = + with pkgs; + [ + rustToolchain + pkg-config + gtk4 + libadwaita + librsvg + ] + ++ lib.optionals pkgs.stdenv.isLinux [ + libX11 + libXtst + ]; + env.RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + }; + } + ); + homeManagerModules.default = import ./nix/hm-module.nix self; + }; } diff --git a/nix/default.nix b/nix/default.nix index 901adbb..54d4789 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,34 +1,40 @@ { + stdenv, rustPlatform, lib, - pkgs, -}: let - cargoToml = builtins.fromTOML (builtins.readFile ../Cargo.toml); + pkg-config, + libX11, + gtk4, + libadwaita, + libXtst, + wrapGAppsHook4, + librsvg, + git, +}: +let + cargoToml = fromTOML (builtins.readFile ../Cargo.toml); pname = cargoToml.package.name; version = cargoToml.package.version; in rustPlatform.buildRustPackage { - pname = pname; - version = version; + inherit pname; + inherit version; - nativeBuildInputs = with pkgs; [ - git + nativeBuildInputs = [ pkg-config - cmake - makeWrapper - buildPackages.gtk4 + wrapGAppsHook4 + git ]; - buildInputs = with pkgs; [ - xorg.libX11 + buildInputs = [ gtk4 libadwaita - xorg.libXtst - ] ++ lib.optionals stdenv.isDarwin - (with darwin.apple_sdk_11_0.frameworks; [ - CoreGraphics - ApplicationServices - ]); + librsvg + ] + ++ lib.optionals stdenv.isLinux [ + libX11 + libXtst + ]; src = builtins.path { name = pname; @@ -40,11 +46,7 @@ rustPlatform.buildRustPackage { # Set Environment Variables RUST_BACKTRACE = "full"; - # Needed to enable support for SVG icons in GTK postInstall = '' - wrapProgram "$out/bin/lan-mouse" \ - --set GDK_PIXBUF_MODULE_FILE ${pkgs.librsvg.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache - install -Dm444 *.desktop -t $out/share/applications install -Dm444 lan-mouse-gtk/resources/*.svg -t $out/share/icons/hicolor/scalable/apps '';