diff --git a/.envrc b/.envrc index 664e752..304e777 100644 --- a/.envrc +++ b/.envrc @@ -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 diff --git a/flake.lock b/flake.lock index 93d06ac..2b07bb3 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -20,27 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1728538411, - "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "lastModified": 1747426788, + "narHash": "sha256-N4cp0asTsJCnRMFZ/k19V9akkxb7J/opG+K+jU57JGc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1718428119, - "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "rev": "12a55407652e04dcf2309436eb06fef0d3713ef3", "type": "github" }, "original": { @@ -54,19 +38,22 @@ "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "treefmt-nix": "treefmt-nix" } }, "rust-overlay": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1728959392, - "narHash": "sha256-fp4he1QQjE+vasDMspZYeXrwTm9otwEqLwEN6FKZ5v0=", + "lastModified": 1747449297, + "narHash": "sha256-veyXchTz6eWwvuW5X49UluHkheHkFcqHJSwGuKBhrmQ=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "4c6e317300f05b8871f585b826b6f583e7dc4a9b", + "rev": "f44db7d7cea4528288780c6347756173a8248225", "type": "github" }, "original": { @@ -89,6 +76,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747469671, + "narHash": "sha256-bo1ptiFoNqm6m1B2iAhJmWCBmqveLVvxom6xKmtuzjg=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "ab0378b61b0d85e73a8ab05d5c6029b5bd58c9fb", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 032683c..faa7952 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } ); diff --git a/tests/main.rs b/tests/main.rs index c19811d..569f791 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -8,6 +8,7 @@ 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() { @@ -15,7 +16,7 @@ fn failure_with_invalid_config() { 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()) @@ -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() @@ -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(); @@ -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() @@ -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") @@ -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()) @@ -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")