Skip to content
Merged
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ target/
.vscode/
*.png
*.json
.run/
.run/

# direnv
/.direnv
98 changes: 98 additions & 0 deletions flake.lock

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

154 changes: 154 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};

outputs =
{
self,
flake-utils,
nixpkgs,
rust-overlay,
crane,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
filteredSource =
let
pathsToIgnore = [
".envrc"
".ignore"
".github"
".gitignore"
"rust-toolchain.toml"
"README.MD"
"flake.nix"
"flake.lock"
"target"
"LICENCE"
".direnv"
];
ignorePaths =
path: type:
let
inherit (nixpkgs) lib;
# split the nix store path into its components
components = lib.splitString "/" path;
# drop off the `/nix/hash-source` section from the path
relPathComponents = lib.drop 4 components;
# reassemble the path components
relPath = lib.concatStringsSep "/" relPathComponents;
in
lib.all (p: !(lib.hasPrefix p relPath)) pathsToIgnore;
in
builtins.path {
name = "mania-source";
path = toString ./.;
# filter out unnecessary paths
filter = ignorePaths;
};
stdenv = if pkgs.stdenv.isLinux then pkgs.stdenv else pkgs.clangStdenv;
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
commonArgs = {
inherit stdenv;
inherit
(craneLib.crateNameFromCargoToml {
cargoToml = ./mania/Cargo.toml;
})
pname
;
inherit
(craneLib.crateNameFromCargoToml {
cargoToml = ./Cargo.toml;
})
version
;
src = filteredSource;
strictDeps = true;
nativeBuildInputs = [
pkgs.protobuf
];
doCheck = false;
meta = {
mainProgram = "mania";
homepage = "https://github.com/LagrangeDev/mania";
license = pkgs.lib.licenses.gpl3Only;
};
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
{
packages = {
mania = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
cargoExtraArgs = ''
--example multi-login
'';
postInstall = ''
mkdir -p $out/bin

cp ./target/release/examples/multi-login $out/bin/mania
'';
}
);
default = self.packages."${system}".mania;
};
checks = {
inherit (self.packages."${system}") mania;
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
fmt = craneLib.cargoFmt commonArgs;
doc = craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
}
);
test = craneLib.cargoTest (
commonArgs
// {
inherit cargoArtifacts;
}
);
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [
(rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
rust-analyzer
];
nativeBuildInputs = with pkgs; [ protobuf ];
};
}
)
// {
overlays.default = final: prev: {
inherit (self.packages."${final.system}") mania;
};
};

}