Skip to content

Commit

Permalink
chore(nix): refactor for flake support and add package build (#220)
Browse files Browse the repository at this point in the history
* chore(nix): refactor for flake support and add package build

Pins nixpkgs to a known working version for the flake.
Things should be unchanged for non-flake-users.

* chore(nix): trim unnecessary deps from shell.nix

* chore(nix): relocate most nix files to the nix directory

For flake and direnv users, this is a small refactor that won't be
noticeable aside from the locations of the files for editing.

For anyone who was previously using `nix-build` and `nix-shell`, they'll
now have to `nix-build ./nix` and `nix-shell ./nix/shell.nix`.

Co-authored-by: Eliza Weisman <[email protected]>
  • Loading branch information
jrobsonchase and hawkw committed Dec 17, 2021
1 parent e020d66 commit f12429b
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 58 deletions.
6 changes: 5 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
use nix;
if command -v use_flake 2>&1 >/dev/null; then
use flake;
else
use nix ./nix/shell.nix;
fi
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
/.direnv
**/target
**/result
**/*.swp
37 changes: 0 additions & 37 deletions default.nix

This file was deleted.

43 changes: 43 additions & 0 deletions flake.lock

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

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

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;
});
}
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.callPackage ./tokio-console.nix { }
19 changes: 19 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
scope@{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
tokio-console = import ./default.nix { inherit pkgs; };

env = buildEnv {
name = "console-env";
paths = [ ]
++ lib.optional stdenv.isDarwin libiconv
++ tokio-console.buildInputs
++ tokio-console.nativeBuildInputs;
};
in
mkShell {
buildInputs = [ env ];

CARGO_TERM_COLOR = "always";
RUST_BACKTRACE = "full";
}
56 changes: 56 additions & 0 deletions nix/tokio-console.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ lib
, protobuf
, rustPlatform
, nix-gitignore
}:
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}/console/Cargo.toml";
in
rustPlatform.buildRustPackage rec {
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;
};
}
19 changes: 0 additions & 19 deletions shell.nix

This file was deleted.

0 comments on commit f12429b

Please sign in to comment.