Skip to content

Commit f6f01a1

Browse files
committed
build: add check workflow; prune flake inputs
1 parent 76e58af commit f6f01a1

File tree

6 files changed

+137
-196
lines changed

6 files changed

+137
-196
lines changed

.github/workflows/check.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Check PR
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
cli:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@main
14+
- uses: DeterminateSystems/nix-installer-action@b92f66560d6f97d6576405a7bae901ab57e72b6a # pin@main
15+
# with:
16+
# nix-installer-tag: v0.16.1 # https://github.com/DeterminateSystems/nix-installer/tags
17+
- uses: DeterminateSystems/magic-nix-cache-action@a76a83091cd8728db8c37312dbdd0eeb1177a6c0 # pin@main
18+
- uses: DeterminateSystems/flake-checker-action@078f5f7f47ee188aa6cb472527ca5984e195222d # pin@main
19+
- name: Check flake
20+
run: nix flake check
21+
22+
examples:
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
example:
27+
- external-deps
28+
- marlin
29+
steps:
30+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@main
31+
- uses: DeterminateSystems/nix-installer-action@b92f66560d6f97d6576405a7bae901ab57e72b6a # pin@main
32+
# with:
33+
# nix-installer-tag: v0.16.1 # https://github.com/DeterminateSystems/nix-installer/tags
34+
- uses: DeterminateSystems/magic-nix-cache-action@a76a83091cd8728db8c37312dbdd0eeb1177a6c0 # pin@main
35+
- name: Check flake
36+
working-directory: examples/${{ matrix.example }}
37+
run: nix flake check

examples/external-deps/flake.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
packages = forAllSystems (
2323
system:
2424
let
25-
pkgs = nixpkgs.legacyPackages.${system};
25+
pkgs = import nixpkgs {
26+
inherit system;
27+
overlays = [ platformio2nix.overlays.default ];
28+
};
2629
in
2730
{
28-
default = pkgs.callPackage ./package.nix {
29-
# TODO: provide an overlay
30-
inherit (platformio2nix.packages.${system}) makePlatformIOSetupHook;
31-
};
31+
default = pkgs.callPackage ./package.nix { };
3232
}
3333
);
3434
};

examples/marlin/flake.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
packages = forAllSystems (
2323
system:
2424
let
25-
pkgs = nixpkgs.legacyPackages.${system};
25+
pkgs = import nixpkgs {
26+
inherit system;
27+
overlays = [ platformio2nix.overlays.default ];
28+
};
2629
in
2730
{
28-
default = pkgs.callPackage ./package.nix {
29-
# TODO: provide an overlay
30-
inherit (platformio2nix.packages.${system}) makePlatformIOSetupHook;
31-
};
31+
default = pkgs.callPackage ./package.nix { };
3232
}
3333
);
3434
};

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: 63 additions & 131 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,128 +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
121-
};
122-
123-
packages = rec {
124-
default = platformio2nix;
125-
inherit platformio2nix;
126-
127-
makePlatformIOSetupHook = pkgs.callPackage ./setup-hook.nix { };
79+
flake = {
80+
overlays.default = final: prev: {
81+
makePlatformIOSetupHook = final.callPackage ./setup-hook.nix { };
12882
};
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-
);
83+
};
84+
};
15385
}

0 commit comments

Comments
 (0)