Skip to content

Commit 62fd38a

Browse files
authored
Fix Nix build & direnv config (#70)
- **flake: Update inputs** - **fix(direnv): Specify shell w/shebang + use direnv stdlib + use correct syntax** - **flake: Simplify input dependencies** - **refactor(flake): Add formatter for nix + tidy up flake** - **fix(flake): Nix builds release + always specifies target triple** ## Description of changes - Updated inputs used in nix flake (tool that defines the nix package of nufmt) - Added formatter for nix flake/nix code - Simplified nix flake's inputs/dependencies (synchronized and deduplicated) - Tidied up/fixed .envrc file/direnv - Fixed build broken by new tests added in #69 ## Relevant Issues None
1 parent e6b2531 commit 62fd38a

File tree

4 files changed

+98
-55
lines changed

4 files changed

+98
-55
lines changed

.envrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# If nix is installed hook into it.
2-
if [ $(which nix) ]
3-
then
1+
#!/usr/bin/env bash
2+
3+
if has nix; then
4+
# If nix is installed hook into it.
45
use flake
56
fi
67

78
# If nu is the current shell use toolkit.nu
8-
if [ $(echo $SHELL) == $(which nu) ]
9-
then
9+
if [ $(echo $SHELL) == $(which nu) ]; then
1010
nu -e "use toolkit.nu"
1111
fi

flake.lock

Lines changed: 34 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,72 @@
55
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
77

8-
rust-overlay.url = "github:oxalica/rust-overlay";
8+
rust-overlay = {
9+
url = "github:oxalica/rust-overlay";
10+
inputs.nixpkgs.follows = "nixpkgs";
11+
};
12+
13+
treefmt-nix = {
14+
url = "github:numtide/treefmt-nix";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
917
};
1018

11-
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
12-
flake-utils.lib.eachDefaultSystem (system:
19+
outputs =
20+
{ self, ... }@inputs:
21+
inputs.flake-utils.lib.eachDefaultSystem (
22+
system:
1323
let
14-
overlays = [ (import rust-overlay) ];
15-
pkgs = import nixpkgs {
24+
overlays = [ (import inputs.rust-overlay) ];
25+
pkgs = import inputs.nixpkgs {
1626
inherit system overlays;
1727
};
28+
integrationTestPatch = pkgs.writeTextFile {
29+
name = "integration-tests-nix-fix.patch";
30+
text =
31+
# patch
32+
''
33+
diff --git a/tests/main.rs b/tests/main.rs
34+
index c3a2b64..173aea0 100644
35+
--- a/tests/main.rs
36+
+++ b/tests/main.rs
37+
@@ -8,7 +8,7 @@ let one = 1
38+
const VALID: &str = "# beginning of script comment
39+
let one = 1
40+
";
41+
-const TEST_BINARY: &'static str = "target/debug/nufmt";
42+
+const TEST_BINARY: &'static str = "target/@target_triple@/release/nufmt";
43+
44+
#[test]
45+
fn failure_with_invalid_config() {
46+
'';
47+
};
1848
in
1949
{
2050
devShells.default = pkgs.mkShell {
21-
nativeBuildInputs = with pkgs; [
22-
rust-bin.stable.latest.default
23-
rust-analyzer
24-
51+
inputsFrom = [ self.packages.${system}.default ];
52+
packages = with pkgs; [
2553
nushell
26-
];
2754

28-
buildInputs = with pkgs; [ ];
55+
# Not included in the package dependencies, but used for development
56+
rust-analyzer
57+
];
2958
};
3059

31-
packages.default = pkgs.rustPlatform.buildRustPackage rec {
60+
packages.default = self.packages.${system}.nufmt;
61+
packages.nufmt = pkgs.rustPlatform.buildRustPackage {
3262
name = "nufmt";
33-
3463
src = ./.;
64+
patches = [
65+
(pkgs.replaceVars "${integrationTestPatch}" {
66+
target_triple = pkgs.stdenv.hostPlatform.rust.rustcTarget;
67+
})
68+
];
69+
cargoLock.lockFile = ./Cargo.lock;
70+
};
3571

36-
cargoLock = {
37-
lockFile = ./Cargo.lock;
38-
};
72+
formatter = inputs.treefmt-nix.lib.mkWrapper pkgs {
73+
programs.nixfmt.enable = true;
3974
};
4075
}
4176
);

tests/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ let one = 1
88
const VALID: &str = "# beginning of script comment
99
let one = 1
1010
";
11+
const TEST_BINARY: &str = "target/debug/nufmt";
1112

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

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

3031
#[test]
3132
fn failure_with_invalid_config_file() {
32-
let output = Command::new("target/debug/nufmt")
33+
let output = Command::new(TEST_BINARY)
3334
.arg("--config")
3435
.arg("path/that/does/not/exist/nufmt.nuon")
3536
.output()
@@ -42,7 +43,7 @@ fn failure_with_invalid_config_file() {
4243

4344
#[test]
4445
fn failure_with_invalid_file_to_format() {
45-
let output = Command::new("target/debug/nufmt")
46+
let output = Command::new(TEST_BINARY)
4647
.arg("path/that/does/not/exist/a.nu")
4748
.output()
4849
.unwrap();
@@ -56,7 +57,7 @@ fn failure_with_invalid_file_to_format() {
5657
fn warning_when_no_files_are_detected() {
5758
let dir = tempdir().unwrap();
5859

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

78-
let output = Command::new("target/debug/nufmt")
79+
let output = Command::new(TEST_BINARY)
7980
.arg("--config")
8081
.arg(config_file.to_str().unwrap())
8182
.arg("--dry-run")
@@ -98,7 +99,7 @@ fn files_are_reformatted() {
9899
fs::write(&file_a, INVALID).unwrap();
99100
fs::write(&file_b, INVALID).unwrap();
100101

101-
let output = Command::new("target/debug/nufmt")
102+
let output = Command::new(TEST_BINARY)
102103
.arg("--config")
103104
.arg(config_file.to_str().unwrap())
104105
.arg(dir.path().to_str().unwrap())
@@ -122,7 +123,7 @@ fn files_are_checked() {
122123
fs::write(&file_a, INVALID).unwrap();
123124
fs::write(&file_b, INVALID).unwrap();
124125

125-
let output = Command::new("target/debug/nufmt")
126+
let output = Command::new(TEST_BINARY)
126127
.arg("--config")
127128
.arg(config_file.to_str().unwrap())
128129
.arg("--dry-run")

0 commit comments

Comments
 (0)