Skip to content

Fix Nix build & direnv config #70

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

Merged
merged 9 commits into from
May 23, 2025
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
10 changes: 5 additions & 5 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# If nix is installed hook into it.
if [ $(which nix) ]
then
#!/usr/bin/env bash

if has nix; then
# If nix is installed hook into it.
use flake
fi

# If nu is the current shell use toolkit.nu
if [ $(echo $SHELL) == $(which nu) ]
then
if [ $(echo $SHELL) == $(which nu) ]; then
nu -e "use toolkit.nu"
fi
61 changes: 34 additions & 27 deletions flake.lock

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

67 changes: 51 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,72 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";

rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};

treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{ self, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
overlays = [ (import inputs.rust-overlay) ];
pkgs = import inputs.nixpkgs {
inherit system overlays;
};
integrationTestPatch = pkgs.writeTextFile {
name = "integration-tests-nix-fix.patch";
text =
# patch
''
diff --git a/tests/main.rs b/tests/main.rs
index c3a2b64..173aea0 100644
--- a/tests/main.rs
+++ b/tests/main.rs
@@ -8,7 +8,7 @@ let one = 1
const VALID: &str = "# beginning of script comment
let one = 1
";
-const TEST_BINARY: &'static str = "target/debug/nufmt";
+const TEST_BINARY: &'static str = "target/@target_triple@/release/nufmt";

#[test]
fn failure_with_invalid_config() {
'';
};
in
{
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rust-bin.stable.latest.default
rust-analyzer

inputsFrom = [ self.packages.${system}.default ];
packages = with pkgs; [
nushell
];

buildInputs = with pkgs; [ ];
# Not included in the package dependencies, but used for development
rust-analyzer
];
};

packages.default = pkgs.rustPlatform.buildRustPackage rec {
packages.default = self.packages.${system}.nufmt;
packages.nufmt = pkgs.rustPlatform.buildRustPackage {
name = "nufmt";

src = ./.;
patches = [
(pkgs.replaceVars "${integrationTestPatch}" {
target_triple = pkgs.stdenv.hostPlatform.rust.rustcTarget;
})
];
cargoLock.lockFile = ./Cargo.lock;
};

cargoLock = {
lockFile = ./Cargo.lock;
};
formatter = inputs.treefmt-nix.lib.mkWrapper pkgs {
programs.nixfmt.enable = true;
};
}
);
Expand Down
15 changes: 8 additions & 7 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ let one = 1
const VALID: &str = "# beginning of script comment
let one = 1
";
const TEST_BINARY: &str = "target/debug/nufmt";

#[test]
fn failure_with_invalid_config() {
let dir = tempdir().unwrap();
let config_file = dir.path().join("nufmt.nuon");
fs::write(&config_file, r#"{unknown: 1}"#).unwrap();

let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("--config")
.arg(config_file.to_str().unwrap())
.arg(dir.path().to_str().unwrap())
Expand All @@ -29,7 +30,7 @@ fn failure_with_invalid_config() {

#[test]
fn failure_with_invalid_config_file() {
let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("--config")
.arg("path/that/does/not/exist/nufmt.nuon")
.output()
Expand All @@ -42,7 +43,7 @@ fn failure_with_invalid_config_file() {

#[test]
fn failure_with_invalid_file_to_format() {
let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("path/that/does/not/exist/a.nu")
.output()
.unwrap();
Expand All @@ -56,7 +57,7 @@ fn failure_with_invalid_file_to_format() {
fn warning_when_no_files_are_detected() {
let dir = tempdir().unwrap();

let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("--dry-run")
.arg(dir.path().to_str().unwrap())
.output()
Expand All @@ -75,7 +76,7 @@ fn warning_is_displayed_when_no_files_are_detected_with_excluded_files() {
fs::write(&config_file, r#"{exclude: ["a*"]}"#).unwrap();
fs::write(&file_a, INVALID).unwrap();

let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("--config")
.arg(config_file.to_str().unwrap())
.arg("--dry-run")
Expand All @@ -98,7 +99,7 @@ fn files_are_reformatted() {
fs::write(&file_a, INVALID).unwrap();
fs::write(&file_b, INVALID).unwrap();

let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("--config")
.arg(config_file.to_str().unwrap())
.arg(dir.path().to_str().unwrap())
Expand All @@ -122,7 +123,7 @@ fn files_are_checked() {
fs::write(&file_a, INVALID).unwrap();
fs::write(&file_b, INVALID).unwrap();

let output = Command::new("target/debug/nufmt")
let output = Command::new(TEST_BINARY)
.arg("--config")
.arg(config_file.to_str().unwrap())
.arg("--dry-run")
Expand Down