Skip to content

Commit 9069a3a

Browse files
committed
fixup! build: add check workflow
1 parent 56aeb20 commit 9069a3a

File tree

3 files changed

+88
-189
lines changed

3 files changed

+88
-189
lines changed

flake.lock

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

flake.nix

Lines changed: 61 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@
44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
7-
8-
# rust
9-
crane.url = "github:ipetkov/crane";
10-
11-
rust-overlay = {
12-
url = "github:oxalica/rust-overlay";
13-
inputs.nixpkgs.follows = "nixpkgs";
14-
};
15-
16-
# checks/formatting
17-
advisory-db = {
18-
url = "github:rustsec/advisory-db";
19-
flake = false;
20-
};
217
treefmt-nix = {
228
url = "github:numtide/treefmt-nix";
239
inputs.nixpkgs.follows = "nixpkgs";
@@ -26,133 +12,74 @@
2612

2713
outputs =
2814
{
29-
self,
3015
nixpkgs,
31-
advisory-db,
32-
crane,
33-
flake-utils,
34-
rust-overlay,
16+
flake-parts,
3517
treefmt-nix,
3618
...
37-
}:
38-
flake-utils.lib.eachDefaultSystem (
39-
system:
40-
let
41-
pkgs = import nixpkgs {
42-
inherit system;
43-
overlays = [ (import rust-overlay) ];
44-
};
45-
46-
inherit (pkgs) lib;
47-
48-
rustToolchainWith =
49-
extensions:
50-
pkgs.rust-bin.selectLatestNightlyWith (
51-
toolchain: toolchain.default.override { inherit extensions; }
52-
);
53-
rustToolchain = rustToolchainWith [ ];
54-
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
55-
src = lib.cleanSourceWith {
56-
src = craneLib.path ./cli;
57-
filter =
58-
path: type: builtins.match "^src/test.*" path != null || (craneLib.filterCargoSources path type);
59-
};
60-
61-
commonArgs = {
62-
inherit src;
63-
strictDeps = true;
64-
nativeBuildInputs = (
65-
with pkgs;
66-
(
67-
[ pkg-config ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ]
68-
)
69-
);
70-
buildInputs = (with pkgs; [ openssl ]);
71-
};
72-
73-
# Build *just* the cargo dependencies
74-
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
75-
76-
# Build the actual crate itself, reusing the dependency artifacts from
77-
# above
78-
platformio2nix = craneLib.buildPackage (
79-
commonArgs
80-
// {
81-
inherit cargoArtifacts;
82-
doCheck = false;
19+
}@inputs:
20+
flake-parts.lib.mkFlake { inherit inputs; } {
21+
systems = [
22+
"aarch64-darwin"
23+
"aarch64-linux"
24+
"x86_64-darwin"
25+
"x86_64-linux"
26+
];
27+
imports = [ inputs.treefmt-nix.flakeModule ];
28+
29+
perSystem =
30+
{
31+
config,
32+
system,
33+
inputs',
34+
pkgs,
35+
lib,
36+
...
37+
}:
38+
(
39+
let
40+
platformio2nix = pkgs.rustPlatform.buildRustPackage {
41+
pname = "platformio2nix";
42+
version = "0.1.1";
43+
src = ./cli;
44+
cargoLock.lockFile = ./cli/Cargo.lock;
45+
46+
nativeBuildInputs =
47+
with pkgs;
48+
[ pkg-config ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ];
49+
buildInputs = with pkgs; [ openssl ];
50+
};
51+
in
52+
{
53+
packages = rec {
54+
default = platformio2nix;
55+
inherit platformio2nix;
56+
};
57+
58+
treefmt = import ./treefmt.nix;
59+
60+
devShells.default = pkgs.mkShell {
61+
inherit (platformio2nix) nativeBuildInputs buildInputs;
62+
packages = (
63+
with pkgs;
64+
[
65+
cargo
66+
clippy
67+
config.treefmt.build.wrapper
68+
rust-analyzer
69+
rustfmt
70+
]
71+
);
72+
73+
LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.openssl ];
74+
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
75+
};
8376
}
8477
);
8578

86-
treefmt = treefmt-nix.lib.evalModule pkgs (
87-
import ./treefmt.nix { rustfmt = rustToolchain.passthru.availableComponents.rustfmt; }
88-
);
89-
in
90-
{
91-
checks = {
92-
# Build the crate as part of `nix flake check` for convenience
93-
crate = platformio2nix;
94-
95-
# Note that this is done as a separate derivation so that
96-
# we can block the CI if there are issues here, but not
97-
# prevent downstream consumers from building our crate by itself.
98-
clippy = craneLib.cargoClippy (
99-
commonArgs
100-
// {
101-
inherit cargoArtifacts;
102-
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
103-
}
104-
);
105-
106-
crate-doc = craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; });
107-
108-
# Check formatting
109-
formatting = treefmt.config.build.check self;
110-
111-
# Audit dependencies
112-
audit = craneLib.cargoAudit { inherit src advisory-db; };
113-
114-
# Audit licenses
115-
deny = craneLib.cargoDeny { inherit src; };
116-
117-
# Run tests with cargo-nextest. Set `doCheck = false` to prevent tests running twice
118-
nextest = craneLib.cargoNextest (commonArgs // { inherit cargoArtifacts; });
119-
120-
# Ensure that example builds
79+
flake = {
80+
overlays.default = final: prev: {
81+
makePlatformIOSetupHook = final.callPackage ./setup-hook.nix { };
12182
};
122-
123-
packages = rec {
124-
default = platformio2nix;
125-
inherit platformio2nix;
126-
};
127-
128-
makePlatformIOSetupHook = pkgs.callPackage ./setup-hook.nix { };
129-
130-
apps.default = flake-utils.lib.mkApp { drv = platformio2nix; };
131-
132-
formatter = treefmt.config.build.wrapper;
133-
134-
devShells.default =
135-
let
136-
rustToolchain = (
137-
rustToolchainWith [
138-
"rust-src"
139-
"rust-analyzer"
140-
]
141-
);
142-
in
143-
(craneLib.overrideToolchain rustToolchain).devShell {
144-
checks = self.checks.${system}; # inherit inputs from checks
145-
packages = [
146-
treefmt.config.build.programs.nixfmt
147-
pkgs.platformio
148-
];
149-
RUST_SRC_PATH = "${rustToolchain.passthru.availableComponents.rust-src}";
150-
};
151-
}
152-
)
153-
// {
154-
overlays.default = final: prev: {
155-
makePlatformIOSetupHook = final.callPackage ./setup-hook.nix { };
15683
};
15784
};
15885
}

treefmt.nix

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
{ rustfmt }:
21
{ ... }:
32
{
43
projectRootFile = "flake.nix";
54

6-
programs.rustfmt = {
7-
enable = true;
8-
package = rustfmt;
5+
programs = {
6+
nixfmt.enable = true;
7+
rustfmt.enable = true;
8+
taplo.enable = true;
99
};
10-
11-
programs.taplo.enable = true;
12-
13-
programs.nixfmt.enable = true;
1410
}

0 commit comments

Comments
 (0)