Skip to content

Commit 28a27fc

Browse files
authored
chore: redo nix flake (#521)
1 parent 823e3df commit 28a27fc

File tree

4 files changed

+138
-23
lines changed

4 files changed

+138
-23
lines changed

flake.lock

+32-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+101-16
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,108 @@
22
description = "The Tokio console: a debugger for async Rust.";
33

44
inputs = {
5-
# nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
6-
flake-utils = {
7-
url = "github:numtide/flake-utils";
8-
inputs.nixpkgs.follows = "nixpkgs";
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
rust-overlay = {
8+
url = "github:oxalica/rust-overlay";
9+
inputs = {
10+
nixpkgs.follows = "nixpkgs";
11+
flake-utils.follows = "flake-utils";
12+
};
913
};
1014
};
1115

12-
outputs = { self, nixpkgs, flake-utils }:
13-
flake-utils.lib.eachDefaultSystem (system:
14-
let
15-
pkgs = import nixpkgs { inherit system; };
16-
tokio-console = import ./nix { inherit pkgs; };
17-
devShell = import ./nix/shell.nix { inherit pkgs; };
18-
in
19-
{
20-
inherit devShell;
21-
packages = { inherit tokio-console; };
22-
defaultPackage = tokio-console;
23-
});
16+
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
17+
flake-utils.lib.eachDefaultSystem
18+
(system:
19+
let
20+
overlays = [ (import rust-overlay) ];
21+
pkgs = import nixpkgs { inherit system overlays; };
22+
23+
####################################################################
24+
#### tokio-console package ####
25+
####################################################################
26+
tokio-console = with pkgs; let
27+
inherit (nix-gitignore) gitignoreFilterPure withGitignoreFile;
28+
# Workaround for the builtins.filterSource issue mentioned in
29+
# https://nixos.org/manual/nix/unstable/expressions/builtins.html
30+
# Since this might be built from a flake, the source path may be a store path,
31+
# so we need to provide our own version of gitignoreSource that avoids
32+
# builtins.filterSource in favor of builtins.path.
33+
gitignoreSource = patterns: path:
34+
builtins.path {
35+
filter =
36+
gitignoreFilterPure (_: _: true) (withGitignoreFile patterns path) path;
37+
path = path;
38+
name = "src";
39+
};
40+
41+
# Ignore some extra things that don't factor into the main build to help with
42+
# caching.
43+
extraIgnores = ''
44+
/.envrc
45+
/*.nix
46+
/flake.*
47+
/netlify.toml
48+
/.github
49+
/assets
50+
/*.md
51+
/.gitignore
52+
/LICENSE
53+
'';
54+
55+
src = gitignoreSource extraIgnores ./.;
56+
57+
cargoTOML = lib.importTOML "${src}/tokio-console/Cargo.toml";
58+
rustToolchain = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
59+
rust = makeRustPlatform {
60+
cargo = rustToolchain;
61+
rustc = rustToolchain;
62+
};
63+
in
64+
rust.buildRustPackage
65+
{
66+
pname = cargoTOML.package.name;
67+
version = cargoTOML.package.version;
68+
69+
nativeBuildInputs = [ protobuf ];
70+
71+
inherit src;
72+
73+
cargoLock = { lockFile = "${src}/Cargo.lock"; };
74+
75+
meta = {
76+
inherit (cargoTOML.package) description homepage license;
77+
maintainers = cargoTOML.package.authors;
78+
};
79+
};
80+
81+
####################################################################
82+
#### dev shell ####
83+
####################################################################
84+
devShell = with pkgs;
85+
mkShell {
86+
name = "tokio-console-env";
87+
buildInputs = tokio-console.buildInputs ++ lib.optional stdenv.isDarwin libiconv;
88+
nativeBuildInputs = tokio-console.nativeBuildInputs;
89+
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
90+
CARGO_TERM_COLOR = "always";
91+
RUST_BACKTRACE = "full";
92+
};
93+
in
94+
{
95+
apps = {
96+
tokio-console = {
97+
type = "app";
98+
program = "${tokio-console}/bin/tokio-console";
99+
description = "The Tokio console: a debugger for async Rust.";
100+
};
101+
default = self.apps.${system}.tokio-console;
102+
};
103+
devShells.default = devShell;
104+
packages = {
105+
inherit tokio-console;
106+
default = self.packages.${system}.tokio-console;
107+
};
108+
});
24109
}

nix/tokio-console.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ let
3131
src = gitignoreSource extraIgnores ../.;
3232

3333
cargoTOML = lib.importTOML "${src}/tokio-console/Cargo.toml";
34-
in rustPlatform.buildRustPackage rec {
34+
in
35+
rustPlatform.buildRustPackage rec {
3536
pname = cargoTOML.package.name;
3637
version = cargoTOML.package.version;
3738

rust-toolchain.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "stable"
3+
profile = "default"

0 commit comments

Comments
 (0)