Skip to content

Commit

Permalink
chore: redo nix flake (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Feb 13, 2024
1 parent 823e3df commit 28a27fc
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 23 deletions.
38 changes: 32 additions & 6 deletions flake.lock

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

117 changes: 101 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,108 @@
description = "The Tokio console: a debugger for async Rust.";

inputs = {
# nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
tokio-console = import ./nix { inherit pkgs; };
devShell = import ./nix/shell.nix { inherit pkgs; };
in
{
inherit devShell;
packages = { inherit tokio-console; };
defaultPackage = tokio-console;
});
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };

####################################################################
#### tokio-console package ####
####################################################################
tokio-console = with pkgs; let
inherit (nix-gitignore) gitignoreFilterPure withGitignoreFile;
# Workaround for the builtins.filterSource issue mentioned in
# https://nixos.org/manual/nix/unstable/expressions/builtins.html
# Since this might be built from a flake, the source path may be a store path,
# so we need to provide our own version of gitignoreSource that avoids
# builtins.filterSource in favor of builtins.path.
gitignoreSource = patterns: path:
builtins.path {
filter =
gitignoreFilterPure (_: _: true) (withGitignoreFile patterns path) path;
path = path;
name = "src";
};

# Ignore some extra things that don't factor into the main build to help with
# caching.
extraIgnores = ''
/.envrc
/*.nix
/flake.*
/netlify.toml
/.github
/assets
/*.md
/.gitignore
/LICENSE
'';

src = gitignoreSource extraIgnores ./.;

cargoTOML = lib.importTOML "${src}/tokio-console/Cargo.toml";
rustToolchain = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rust = makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
in
rust.buildRustPackage
{
pname = cargoTOML.package.name;
version = cargoTOML.package.version;

nativeBuildInputs = [ protobuf ];

inherit src;

cargoLock = { lockFile = "${src}/Cargo.lock"; };

meta = {
inherit (cargoTOML.package) description homepage license;
maintainers = cargoTOML.package.authors;
};
};

####################################################################
#### dev shell ####
####################################################################
devShell = with pkgs;
mkShell {
name = "tokio-console-env";
buildInputs = tokio-console.buildInputs ++ lib.optional stdenv.isDarwin libiconv;
nativeBuildInputs = tokio-console.nativeBuildInputs;
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
CARGO_TERM_COLOR = "always";
RUST_BACKTRACE = "full";
};
in
{
apps = {
tokio-console = {
type = "app";
program = "${tokio-console}/bin/tokio-console";
description = "The Tokio console: a debugger for async Rust.";
};
default = self.apps.${system}.tokio-console;
};
devShells.default = devShell;
packages = {
inherit tokio-console;
default = self.packages.${system}.tokio-console;
};
});
}
3 changes: 2 additions & 1 deletion nix/tokio-console.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ let
src = gitignoreSource extraIgnores ../.;

cargoTOML = lib.importTOML "${src}/tokio-console/Cargo.toml";
in rustPlatform.buildRustPackage rec {
in
rustPlatform.buildRustPackage rec {
pname = cargoTOML.package.name;
version = cargoTOML.package.version;

Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
profile = "default"

0 comments on commit 28a27fc

Please sign in to comment.