Skip to content

Commit 78a3e20

Browse files
committed
nix: Refactor CLI flake checks into idiomatic Nix derivations
Replace the mkCheck helper with direct check derivations for tests, clippy, and fmt. Update root flake to re-export CLI checks with consistent naming.
1 parent afee7a2 commit 78a3e20

8 files changed

Lines changed: 140 additions & 528 deletions

File tree

cli/flake.nix

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -57,78 +57,96 @@
5757
nativeCheckInputs = [ pkgs.git ];
5858
doCheck = false;
5959
};
60+
in
61+
{
62+
packages = {
63+
sce = scePackage;
64+
default = scePackage;
65+
};
66+
67+
apps.sce = {
68+
type = "app";
69+
program = "${scePackage}/bin/sce";
70+
meta = {
71+
description = "Run the packaged sce CLI";
72+
};
73+
};
6074

61-
mkCheck =
62-
pname: checkPhase:
63-
rustPlatform.buildRustPackage {
64-
inherit pname src;
75+
checks = {
76+
cli-tests = rustPlatform.buildRustPackage {
77+
pname = "sce-cli-tests";
6578
version = "0.1.0";
79+
inherit src;
6680
sourceRoot = "source/cli";
6781

6882
cargoLock = {
6983
lockFile = ./Cargo.lock;
7084
};
7185

7286
nativeBuildInputs = [ rustToolchain ];
87+
nativeCheckInputs = [ pkgs.git ];
7388

7489
buildPhase = ''
7590
runHook preBuild
7691
runHook postBuild
7792
'';
7893

79-
inherit checkPhase;
94+
checkPhase = ''
95+
runHook preCheck
96+
cargo test
97+
runHook postCheck
98+
'';
8099

81100
installPhase = ''
82101
runHook preInstall
83102
mkdir -p "$out"
84103
runHook postInstall
85104
'';
86105
};
87-
in
88-
{
89-
packages = {
90-
sce = scePackage;
91-
default = scePackage;
92-
};
93106

94-
apps.sce = {
95-
type = "app";
96-
program = "${scePackage}/bin/sce";
97-
meta = {
98-
description = "Run the packaged sce CLI";
99-
};
100-
};
101-
102-
apps.clippy = {
103-
type = "app";
104-
program = toString (
105-
pkgs.writeShellScript "sce-clippy" ''
106-
exec ${rustToolchain}/bin/cargo clippy --manifest-path cli/Cargo.toml --all-targets --all-features "$@"
107-
''
108-
);
109-
meta = {
110-
description = "Run clippy for the sce CLI crate";
111-
};
112-
};
107+
cli-clippy = rustPlatform.buildRustPackage {
108+
pname = "sce-cli-clippy";
109+
version = "0.1.0";
110+
inherit src;
111+
sourceRoot = "source/cli";
113112

114-
checks.cli-setup-command-surface = mkCheck "sce-cli-setup-command-surface-check" ''
115-
runHook preCheck
113+
cargoLock = {
114+
lockFile = ./Cargo.lock;
115+
};
116116

117-
cargo fmt --check
118-
cargo test command_surface::tests::help_text_mentions_setup_target_flags
119-
cargo test parser_routes_setup
120-
cargo test run_setup_reports
117+
nativeBuildInputs = [ rustToolchain ];
121118

122-
runHook postCheck
123-
'';
119+
buildPhase = ''
120+
runHook preBuild
121+
runHook postBuild
122+
'';
124123

125-
checks.cli-clippy = mkCheck "sce-cli-clippy-check" ''
126-
runHook preCheck
124+
checkPhase = ''
125+
runHook preCheck
126+
cargo clippy --all-targets --all-features
127+
runHook postCheck
128+
'';
127129

128-
cargo clippy --all-targets --all-features
130+
installPhase = ''
131+
runHook preInstall
132+
mkdir -p "$out"
133+
runHook postInstall
134+
'';
135+
};
129136

130-
runHook postCheck
131-
'';
137+
cli-fmt =
138+
pkgs.runCommand "sce-cli-fmt-check"
139+
{
140+
nativeBuildInputs = [ rustToolchain ];
141+
}
142+
''
143+
cp -r "${src}/cli" ./cli
144+
chmod -R u+w ./cli
145+
cd ./cli
146+
cargo fmt --check
147+
mkdir -p "$out"
148+
'';
149+
};
132150
}
133151
);
134152
}

cli/src/app.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,6 @@ mod tests {
918918
assert_eq!(code, ExitCode::SUCCESS);
919919
}
920920

921-
#[test]
922-
fn sync_command_exits_success() {
923-
let code = run(vec!["sce".to_string(), "sync".to_string()]);
924-
assert_eq!(code, ExitCode::SUCCESS);
925-
}
926-
927921
#[test]
928922
fn unknown_command_exits_non_zero() {
929923
let code = run(vec!["sce".to_string(), "does-not-exist".to_string()]);

0 commit comments

Comments
 (0)