|
4 | 4 | inputs = { |
5 | 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
6 | 6 | 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 | | - }; |
21 | 7 | treefmt-nix = { |
22 | 8 | url = "github:numtide/treefmt-nix"; |
23 | 9 | inputs.nixpkgs.follows = "nixpkgs"; |
|
26 | 12 |
|
27 | 13 | outputs = |
28 | 14 | { |
29 | | - self, |
30 | 15 | nixpkgs, |
31 | | - advisory-db, |
32 | | - crane, |
33 | | - flake-utils, |
34 | | - rust-overlay, |
| 16 | + flake-parts, |
35 | 17 | treefmt-nix, |
36 | 18 | ... |
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 | + }; |
83 | 76 | } |
84 | 77 | ); |
85 | 78 |
|
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 { }; |
128 | 82 | }; |
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 | + }; |
153 | 85 | } |
0 commit comments