-
Notifications
You must be signed in to change notification settings - Fork 12
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
justDeeevin
wants to merge
7
commits into
scopeclient:main
Choose a base branch
from
justDeeevin:flake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
64eb21a
add Nix Flake
justDeeevin 7a5d79b
remove redundant `shell.nix`
justDeeevin 5b62dc0
update rust-toolchain hash
justDeeevin e52a1df
add some new deps + comprehensive `LD_LIBRARY_PATH` to flake
justDeeevin dd4e484
remove unneeded dependencies from flake
justDeeevin 32c53d8
add keywords and categories to nix-generated desktop entry
justDeeevin 8ce3560
update hash of toolchain file
justDeeevin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
}; | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.