From 430308a2de80961a10f8db330bba776dafbd6929 Mon Sep 17 00:00:00 2001 From: electria Date: Sat, 21 Nov 2026 17:30:12 -0800 Subject: [PATCH] build: use flake from templates --- flake.lock | 36 ++++---------- flake.nix | 144 ++++++++++++++++++++++------------------------------- 2 files changed, 70 insertions(+), 110 deletions(-) diff --git a/flake.lock b/flake.lock index 0251326..9ee5d77 100644 --- a/flake.lock +++ b/flake.lock @@ -1,30 +1,15 @@ { "nodes": { - "crane": { - "locked": { - "lastModified": 1785782307, - "narHash": "sha256-MPaRdVkf6zZP5fCPxYCi8Dr4pZzgmXzg8T9nVEbp3Mw=", - "owner": "ipetkov", - "repo": "crane", - "rev": "2c71e194474d13de031d729b729c968ddbe3507f", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "lastModified": 1794427683, + "narHash": "sha256-o7ey9gEilsxaifqJWnBDlYSKbNWYQYtKwDyXeZU2kaU=", "owner": "numtide", "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "rev": "cd489559845d81f673a12885576016c65cbe9363", "type": "github" }, "original": { @@ -35,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1786862985, - "narHash": "sha256-kSR/jfpR4cE26YRZ8exQkoRbEA30vyWimajwZANYYaE=", - "rev": "e5bdc4a41d4c072fe1e3787eaa0320a384741d44", + "lastModified": 1795234589, + "narHash": "sha256-pAEASBc6wof0S58XcSEdZoQ2iFQDkCnZwH+wFLrkd1Q=", + "rev": "2786a2a72088ecf32aea5b3ec52099e6a7cff78f", "type": "tarball", - "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1055335.e5bdc4a41d4c/nixexprs.tar.zst?lastModified=1786862985&rev=e5bdc4a41d4c072fe1e3787eaa0320a384741d44" + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1125864.2786a2a72088/nixexprs.tar.zst?lastModified=1795234589&rev=2786a2a72088ecf32aea5b3ec52099e6a7cff78f" }, "original": { "type": "tarball", @@ -48,18 +33,17 @@ }, "root": { "inputs": { - "crane": "crane", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }, "systems": { "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "lastModified": 1791244623, + "narHash": "sha256-uuanbkFk8a313Zfrxdcz8Us/yQtaxNnKJtX8v0ZPpd8=", "owner": "nix-systems", "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "rev": "d36eeed142f88b5a636f2e3856a53c61654cf29b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 2551926..ebf4765 100644 --- a/flake.nix +++ b/flake.nix @@ -2,8 +2,6 @@ inputs = { nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst"; - crane.url = "github:ipetkov/crane"; - flake-utils.url = "github:numtide/flake-utils"; }; @@ -12,105 +10,83 @@ inputs.flake-utils.lib.eachDefaultSystem ( system: let - pkgs = import inputs.nixpkgs { inherit system; }; - lib = pkgs.lib; - craneLib = inputs.crane.mkLib pkgs; + pkgs = inputs.nixpkgs.legacyPackages.${system}; + lib = inputs.nixpkgs.lib; - cargoToml = fromTOML (builtins.readFile ./Cargo.toml); + src = lib.sourceFilesBySuffices ./. [ + "Cargo.toml" + "Cargo.lock" + ".rs" + ]; + + cargoToml = fromTOML (builtins.readFile "${src}/Cargo.toml"); name = cargoToml.package.name; - dlDeps = - with pkgs; - [ - # needed for both x11 and wayland - libxkbcommon - libGL + bin = + { + rustPlatform, - libx11 - libxcursor - libxi - libxcb - ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ - vulkan-loader - wayland + autoPatchelfHook, - dbus.lib - ]; + libxkbcommon, + wayland, + vulkan-loader, - commonArgs = { - # all that's needed for artifacts and checks - nativeBuildInputs = with pkgs; [ - # pkg-config - ]; - buildInputs = with pkgs; [ - ]; + moreSupport ? false, + libGL, + libx11, + libxcursor, + libxi, - strictDeps = true; - __structuredAttrs = true; + libgcc, + }: + rustPlatform.buildRustPackage { + inherit name src; - src = ./.; - }; + nativeBuildInputs = [ + autoPatchelfHook + ]; + buildInputs = [ + libgcc + ]; + runtimeDependencies = [ + libxkbcommon + wayland + vulkan-loader + ] + ++ lib.optionals moreSupport [ + libGL + libx11 + libxcursor + libxi + ]; - # Build *just* the cargo dependencies, - # to reuse them for build and test derivations. - cargoArtifacts = craneLib.buildDepsOnly commonArgs; + cargoLock.lockFile = "${src}/Cargo.lock"; - # Build the actual crate itself, - # reusing the dependency artifacts from above. - crate = - let - desktopItem = pkgs.makeDesktopItem { - inherit name; - desktopName = name; - exec = name; - }; - in - craneLib.buildPackage ( - commonArgs - // { - inherit cargoArtifacts; + strictDeps = true; + __structuredAttrs = true; + }; - nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ - pkgs.autoPatchelfHook - ]; - - buildInputs = commonArgs.buildInputs ++ [ - pkgs.libgcc - ]; - - runtimeDependencies = dlDeps; - - doCheck = false; - - postFixup = '' - cp -rs "${desktopItem}"/* "$out" - ''; - } - ); + default = pkgs.callPackage bin { }; in { - packages.default = crate; + packages.default = default; - checks = { - crate-clippy = craneLib.cargoClippy ( - commonArgs - // { - inherit cargoArtifacts; + devShells.default = pkgs.mkShell { + inputsFrom = [ default ]; - cargoClippyExtraArgs = "-- --deny warnings"; - } - ); - }; + env.RUSTFLAGS = builtins.concatStringsSep " " [ + "-Clink-arg=-Wl,-rpath,${lib.makeLibraryPath default.runtimeDependencies}" + "-Clink-arg=-fuse-ld=mold" + ]; - devShells.default = craneLib.devShell { - env.LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps; + packages = with pkgs; [ + clippy + rustfmt + rust-analyzer - inputsFrom = [ crate ]; - packages = [ pkgs.rust-analyzer ]; - - strictDeps = true; - __structuredAttrs = true; + mold + ]; }; } );