Skip to content

Add Nix Flake #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
116 changes: 116 additions & 0 deletions flake.lock

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

188 changes: 188 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
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-s1RPtyvDGJaX/BisLT+ifVfuhDT1nZkZ1NcK8sbwELM=";
};

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
webkitgtk_4_1
]
++ 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;
keywords = ["discord" "chat"];
categories = ["Network" "InstantMessaging"];
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.lib.makeLibraryPath commonArgs.buildInputs}"
'';
});
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.lib.makeLibraryPath commonArgs.buildInputs}";

# Extra inputs can be added here; cargo and rustc are provided by default.
packages = [
# pkgs.ripgrep
];
};
});
}
17 changes: 0 additions & 17 deletions shell.nix

This file was deleted.