|
1 | 1 | { |
2 | 2 | inputs = { |
3 | | - nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.*"; |
4 | | - rust-overlay = { |
5 | | - url = "https://flakehub.com/f/oxalica/rust-overlay/*"; |
| 3 | + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2411.*"; |
| 4 | + |
| 5 | + fenix = { |
| 6 | + url = "https://flakehub.com/f/nix-community/fenix/0.1.*"; |
6 | 7 | inputs.nixpkgs.follows = "nixpkgs"; |
7 | 8 | }; |
8 | | - crane.url = "https://flakehub.com/f/ipetkov/crane/0.19.*"; |
| 9 | + |
| 10 | + naersk.url = "https://flakehub.com/f/nix-community/naersk/0.1.*"; |
9 | 11 | }; |
10 | 12 |
|
11 | 13 | outputs = { self, ... }@inputs: |
12 | 14 | let |
| 15 | + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; |
| 16 | + version = "${builtins.substring 0 8 lastModifiedDate}-${self.shortRev or "dirty"}"; |
| 17 | + |
13 | 18 | supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; |
14 | | - forAllSystems = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f rec { |
| 19 | + |
| 20 | + forSystems = s: f: inputs.nixpkgs.lib.genAttrs s (system: f rec { |
| 21 | + inherit system; |
15 | 22 | pkgs = import inputs.nixpkgs { |
16 | 23 | inherit system; |
17 | | - overlays = [ |
18 | | - inputs.rust-overlay.overlays.default |
19 | | - ]; |
20 | | - }; |
21 | | - |
22 | | - cranePkgs = pkgs.callPackage ./crane.nix { |
23 | | - inherit (inputs) crane; |
24 | | - inherit supportedSystems; |
| 24 | + overlays = [ self.overlays.default ]; |
25 | 25 | }; |
26 | 26 | }); |
| 27 | + |
| 28 | + forAllSystems = forSystems supportedSystems; |
27 | 29 | in |
28 | 30 | { |
29 | | - packages = forAllSystems ({ cranePkgs, ... }: rec { |
30 | | - inherit (cranePkgs) flake-checker; |
| 31 | + overlays.default = final: prev: |
| 32 | + let |
| 33 | + inherit (final.stdenv.hostPlatform) system; |
| 34 | + |
| 35 | + rustToolchain = with inputs.fenix.packages.${system}; |
| 36 | + combine ([ |
| 37 | + stable.clippy |
| 38 | + stable.rustc |
| 39 | + stable.cargo |
| 40 | + stable.rustfmt |
| 41 | + stable.rust-src |
| 42 | + ] ++ inputs.nixpkgs.lib.optionals (system == "x86_64-linux") [ |
| 43 | + targets.x86_64-unknown-linux-musl.stable.rust-std |
| 44 | + ] ++ inputs.nixpkgs.lib.optionals (system == "aarch64-linux") [ |
| 45 | + targets.aarch64-unknown-linux-musl.stable.rust-std |
| 46 | + ]); |
| 47 | + in |
| 48 | + { |
| 49 | + inherit rustToolchain; |
| 50 | + |
| 51 | + naerskLib = final.callPackage inputs.naersk { |
| 52 | + cargo = rustToolchain; |
| 53 | + rustc = rustToolchain; |
| 54 | + }; |
| 55 | + }; |
| 56 | + |
| 57 | + packages = forAllSystems ({ pkgs, system }: rec { |
31 | 58 | default = flake-checker; |
| 59 | + |
| 60 | + flake-checker = pkgs.naerskLib.buildPackage |
| 61 | + ({ |
| 62 | + name = "flake-checker-${version}"; |
| 63 | + src = self; |
| 64 | + doCheck = true; |
| 65 | + buildInputs = with pkgs; [ ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]); |
| 66 | + nativeBuildInputs = with pkgs; [ ] ++ lib.optionals stdenv.isDarwin [ libiconv ]; |
| 67 | + } // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux { |
| 68 | + CARGO_BUILD_TARGET = |
| 69 | + if system == "x86_64-linux" then |
| 70 | + "x86_64-unknown-linux-musl" |
| 71 | + else if system == "aarch64-linux" then |
| 72 | + "aarch64-unknown-linux-musl" |
| 73 | + else |
| 74 | + throw "Unsupported Linux system: ${system}"; |
| 75 | + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; |
| 76 | + }); |
32 | 77 | }); |
33 | 78 |
|
34 | | - devShells = forAllSystems ({ pkgs, cranePkgs }: { |
| 79 | + devShells = forAllSystems ({ pkgs, ... }: { |
35 | 80 | default = |
36 | 81 | let |
37 | 82 | check-nixpkgs-fmt = pkgs.writeShellApplication { |
38 | 83 | name = "check-nixpkgs-fmt"; |
39 | 84 | runtimeInputs = with pkgs; [ git nixpkgs-fmt ]; |
40 | 85 | text = '' |
41 | | - git ls-files '*.nix' | xargs nixpkgs-fmt --check |
| 86 | + nixpkgs-fmt --check "$(git ls-files '*.nix')" |
42 | 87 | ''; |
43 | 88 | }; |
44 | 89 | check-rustfmt = pkgs.writeShellApplication { |
45 | 90 | name = "check-rustfmt"; |
46 | | - runtimeInputs = [ cranePkgs.rustNightly ]; |
| 91 | + runtimeInputs = with pkgs; [ rustToolchain ]; |
47 | 92 | text = "cargo fmt --check"; |
48 | 93 | }; |
49 | 94 | get-allowed-refs = pkgs.writeShellApplication { |
50 | 95 | name = "get-allowed-refs"; |
51 | | - runtimeInputs = [ cranePkgs.rustNightly ]; |
| 96 | + runtimeInputs = with pkgs; [ rustToolchain ]; |
52 | 97 | text = "cargo run --features allowed-refs -- --get-allowed-refs"; |
53 | 98 | }; |
54 | 99 | in |
|
57 | 102 | bashInteractive |
58 | 103 |
|
59 | 104 | # Rust |
60 | | - cranePkgs.rustNightly |
| 105 | + rustToolchain |
61 | 106 | cargo-bloat |
62 | 107 | cargo-edit |
63 | 108 | cargo-machete |
|
77 | 122 |
|
78 | 123 | env = { |
79 | 124 | # Required by rust-analyzer |
80 | | - RUST_SRC_PATH = "${cranePkgs.rustNightly}/lib/rustlib/src/rust/library"; |
| 125 | + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; |
81 | 126 | }; |
82 | 127 | }; |
83 | 128 | }); |
|
0 commit comments