From 64eb21a9f18462b4eba63b3bd0b0ce5a87eb38d6 Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Fri, 15 Nov 2024 17:10:59 -0500 Subject: [PATCH 1/7] add Nix Flake adds some extra metadata to `Cargo.toml` that's necessary for Crane to work --- Cargo.toml | 6 ++ flake.lock | 116 +++++++++++++++++++++++++++++++++ flake.nix | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/Cargo.toml b/Cargo.toml index 9409fce..efcbbb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,9 @@ gpui = { git = "https://github.com/scopeclient/zed.git", branch = "feature/expor ] } components = { package = "ui", git = "https://github.com/scopeclient/components", version = "0.1.0" } reqwest_client = { git = "https://github.com/scopeclient/zed.git", branch = "feature/export-platform-window", version = "0.1.0" } + +[workspace.metadata.crane] +name = "scope" + +[workspace.package] +version = "0.1.0" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e645316 --- /dev/null +++ b/flake.lock @@ -0,0 +1,116 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1731271136, + "narHash": "sha256-VsrCHM1gP8YqBTQWBQ0TmFNAFv3lBA0PvtWh8/sA9n4=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "509528f6775ad69ab114f1e4b37b4359cae5cef4", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1731098351, + "narHash": "sha256-HQkYvKvaLQqNa10KEFGgWHfMAbWBfFp+4cAgkut+NNE=", + "owner": "ipetkov", + "repo": "crane", + "rev": "ef80ead953c1b28316cc3f8613904edc2eb90c28", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": [] + }, + "locked": { + "lastModified": 1731652660, + "narHash": "sha256-vau17dcGvfEWX9DLWuSPC0dfE0XcDe9ZNlsqXy46P88=", + "owner": "nix-community", + "repo": "fenix", + "rev": "664e2f335aa5ae28c8759ff206444edb198dc1c9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1731531548, + "narHash": "sha256-sz8/v17enkYmfpgeeuyzniGJU0QQBfmAjlemAUYhfy8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "24f0d4acd634792badd6470134c387a3b039dace", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7056d91 --- /dev/null +++ b/flake.nix @@ -0,0 +1,187 @@ +{ + description = "Build a cargo project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane.url = "github:ipetkov/crane"; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.rust-analyzer-src.follows = ""; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = { + self, + nixpkgs, + crane, + fenix, + flake-utils, + advisory-db, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + + inherit (pkgs) lib; + toolchain = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "sha256-3jVIIf5XPnUU1CRaTyAiO0XHVbJl12MSx3eucTXCjtE="; + }; + + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + src = craneLib.cleanCargoSource ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + buildInputs = with pkgs; + [ + libxkbcommon + xorg.libX11 + vulkan-loader + vulkan-validation-layers + vulkan-headers + ] + ++ lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + + nativeBuildInputs = with pkgs; [copyDesktopItems pkg-config makeWrapper]; + + # Additional environment variables can be set directly + # MY_CUSTOM_VAR = "some value"; + }; + + craneLibLLvmTools = + craneLib.overrideToolchain + (toolchain.withComponents [ + "cargo" + "llvm-tools" + "rustc" + ]); + + # Build *just* the cargo dependencies, so we can reuse + # all of that work (e.g. via cachix) when running in CI + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + scope = craneLib.buildPackage (commonArgs + // { + inherit cargoArtifacts; + desktopItems = [ + (pkgs.makeDesktopItem { + name = "Scope"; + desktopName = "Scope"; + exec = "scope"; + icon = "Scope"; + terminal = false; + # TODO: keywords + keywords = []; + startupWMClass = "Scope"; + }) + ]; + + postInstall = let + icon = pkgs.fetchurl { + url = "https://avatars.githubusercontent.com/u/188419158?s=200&v=4"; + hash = "sha256-6ujCCaIqt4N0wj98YislhhLX3yB8eh2TAl671GJ8bR4="; + }; + in '' + install -Dm644 ${icon} $out/share/icons/hicolor/128x128/apps/Scope.png + wrapProgram $out/bin/scope --prefix LD_LIBRARY_PATH : "${pkgs.vulkan-loader}/lib" + ''; + }); + in { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit scope; + + # Run clippy (and deny all warnings) on the crate source, + # again, reusing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + my-crate-clippy = craneLib.cargoClippy (commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + my-crate-doc = craneLib.cargoDoc (commonArgs + // { + inherit cargoArtifacts; + }); + + # Check formatting + my-crate-fmt = craneLib.cargoFmt { + inherit src; + }; + + my-crate-toml-fmt = craneLib.taploFmt { + src = pkgs.lib.sources.sourceFilesBySuffices src [".toml"]; + # taplo arguments can be further customized below as needed + # taploExtraArgs = "--config ./taplo.toml"; + }; + + # Audit dependencies + my-crate-audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # Run tests with cargo-nextest + # Consider setting `doCheck = false` on `my-crate` if you do not want + # the tests to run twice + my-crate-nextest = craneLib.cargoNextest (commonArgs + // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + }); + }; + + packages = + { + default = scope; + } + // lib.optionalAttrs (!pkgs.stdenv.isDarwin) { + my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs + // { + inherit cargoArtifacts; + }); + }; + + apps.default = flake-utils.lib.mkApp { + drv = scope; + }; + + devShells.default = craneLib.devShell { + # Inherit inputs from checks. + checks = self.checks.${system}; + + # Additional dev-shell environment variables can be set directly + # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; + VK_LAYER_PATH = "${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d"; + LD_LIBRARY_PATH = "${pkgs.vulkan-loader}/lib:$LD_LIBRARY_PATH"; + + # Extra inputs can be added here; cargo and rustc are provided by default. + packages = [ + # pkgs.ripgrep + ]; + }; + }); +} From 7a5d79b94a50be470b73d1034d53a10572bdeedc Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Fri, 15 Nov 2024 17:11:27 -0500 Subject: [PATCH 2/7] remove redundant `shell.nix` --- shell.nix | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 shell.nix diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 6dcadfd..0000000 --- a/shell.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ pkgs ? import {} }: - -pkgs.mkShell { - nativeBuildInputs = [ pkgs.pkg-config ]; - buildInputs = with pkgs; [ - libxkbcommon - xorg.libX11 - vulkan-loader - vulkan-validation-layers - vulkan-headers - ]; - - shellHook = '' - export VK_LAYER_PATH="${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d" - export LD_LIBRARY_PATH="${pkgs.vulkan-loader}/lib:$LD_LIBRARY_PATH" - ''; -} From 5b62dc0c50468f4ab97f1ad43b5650f0823b0e58 Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Mon, 18 Nov 2024 08:34:39 -0500 Subject: [PATCH 3/7] update rust-toolchain hash --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 7056d91..6b6e08e 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ inherit (pkgs) lib; toolchain = fenix.packages.${system}.fromToolchainFile { file = ./rust-toolchain.toml; - sha256 = "sha256-3jVIIf5XPnUU1CRaTyAiO0XHVbJl12MSx3eucTXCjtE="; + sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk="; }; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; From e52a1df831267340400d1eb06f10ec0fc1f8a88a Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Mon, 18 Nov 2024 08:35:08 -0500 Subject: [PATCH 4/7] add some new deps + comprehensive `LD_LIBRARY_PATH` to flake --- flake.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 6b6e08e..b75cb8f 100644 --- a/flake.nix +++ b/flake.nix @@ -53,6 +53,9 @@ vulkan-loader vulkan-validation-layers vulkan-headers + glib + gtk3 + webkitgtk_4_1 ] ++ lib.optionals pkgs.stdenv.isDarwin [ # Additional darwin specific inputs can be set here @@ -102,7 +105,7 @@ }; in '' install -Dm644 ${icon} $out/share/icons/hicolor/128x128/apps/Scope.png - wrapProgram $out/bin/scope --prefix LD_LIBRARY_PATH : "${pkgs.vulkan-loader}/lib" + wrapProgram $out/bin/scope --prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath commonArgs.buildInputs}" ''; }); in { @@ -176,7 +179,7 @@ # Additional dev-shell environment variables can be set directly # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; VK_LAYER_PATH = "${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d"; - LD_LIBRARY_PATH = "${pkgs.vulkan-loader}/lib:$LD_LIBRARY_PATH"; + LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath commonArgs.buildInputs}"; # Extra inputs can be added here; cargo and rustc are provided by default. packages = [ From dd4e48441085990ec14eac97b5a4bb3ca8c613a3 Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Mon, 18 Nov 2024 08:42:03 -0500 Subject: [PATCH 5/7] remove unneeded dependencies from flake --- flake.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/flake.nix b/flake.nix index b75cb8f..9dcedb6 100644 --- a/flake.nix +++ b/flake.nix @@ -53,8 +53,6 @@ vulkan-loader vulkan-validation-layers vulkan-headers - glib - gtk3 webkitgtk_4_1 ] ++ lib.optionals pkgs.stdenv.isDarwin [ From 32c53d8847ff6ab2a6ad68cb1964a8cf65b3f5e7 Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Thu, 12 Dec 2024 12:49:11 -0500 Subject: [PATCH 6/7] add keywords and categories to nix-generated desktop entry --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 9dcedb6..d21c9b3 100644 --- a/flake.nix +++ b/flake.nix @@ -90,8 +90,8 @@ exec = "scope"; icon = "Scope"; terminal = false; - # TODO: keywords - keywords = []; + keywords = ["discord" "chat"]; + categories = ["Network" "InstantMessaging"]; startupWMClass = "Scope"; }) ]; From 8ce35604120544efab2effd0c899c8c6e13e0706 Mon Sep 17 00:00:00 2001 From: Devin Droddy Date: Wed, 18 Dec 2024 12:36:20 -0500 Subject: [PATCH 7/7] update hash of toolchain file --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d21c9b3..2f44586 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ inherit (pkgs) lib; toolchain = fenix.packages.${system}.fromToolchainFile { file = ./rust-toolchain.toml; - sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk="; + sha256 = "sha256-s1RPtyvDGJaX/BisLT+ifVfuhDT1nZkZ1NcK8sbwELM="; }; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;