|
11 | 11 | url = "https://flakehub.com/f/nix-community/naersk/0"; |
12 | 12 | inputs.nixpkgs.follows = "nixpkgs"; |
13 | 13 | }; |
| 14 | + |
| 15 | + easy-template = { |
| 16 | + url = "https://flakehub.com/f/DeterminateSystems/easy-template/0"; |
| 17 | + inputs.nixpkgs.follows = "nixpkgs"; |
| 18 | + }; |
14 | 19 | }; |
15 | 20 |
|
16 | | - outputs = { self, ... }@inputs: |
| 21 | + outputs = |
| 22 | + { self, ... }@inputs: |
17 | 23 | let |
18 | 24 | lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; |
19 | 25 | version = "${builtins.substring 0 8 lastModifiedDate}-${self.shortRev or "dirty"}"; |
20 | 26 |
|
21 | | - supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; |
22 | | - |
23 | | - forSystems = s: f: inputs.nixpkgs.lib.genAttrs s (system: f rec { |
24 | | - inherit system; |
25 | | - pkgs = import inputs.nixpkgs { |
26 | | - inherit system; |
27 | | - overlays = [ self.overlays.default ]; |
28 | | - }; |
29 | | - }); |
| 27 | + supportedSystems = [ |
| 28 | + "x86_64-linux" |
| 29 | + "aarch64-linux" |
| 30 | + "x86_64-darwin" |
| 31 | + "aarch64-darwin" |
| 32 | + ]; |
| 33 | + |
| 34 | + forSystems = |
| 35 | + s: f: |
| 36 | + inputs.nixpkgs.lib.genAttrs s ( |
| 37 | + system: |
| 38 | + f rec { |
| 39 | + inherit system; |
| 40 | + pkgs = import inputs.nixpkgs { |
| 41 | + inherit system; |
| 42 | + overlays = [ self.overlays.default ]; |
| 43 | + }; |
| 44 | + } |
| 45 | + ); |
30 | 46 |
|
31 | 47 | forAllSystems = forSystems supportedSystems; |
32 | 48 | in |
33 | 49 | { |
34 | | - overlays.default = final: prev: |
| 50 | + overlays.default = |
| 51 | + final: prev: |
35 | 52 | let |
36 | 53 | inherit (final.stdenv.hostPlatform) system; |
37 | 54 |
|
38 | | - rustToolchain = with inputs.fenix.packages.${system}; |
39 | | - combine ([ |
40 | | - stable.clippy |
41 | | - stable.rustc |
42 | | - stable.cargo |
43 | | - stable.rustfmt |
44 | | - stable.rust-src |
45 | | - ] ++ inputs.nixpkgs.lib.optionals (system == "x86_64-linux") [ |
46 | | - targets.x86_64-unknown-linux-musl.stable.rust-std |
47 | | - ] ++ inputs.nixpkgs.lib.optionals (system == "aarch64-linux") [ |
48 | | - targets.aarch64-unknown-linux-musl.stable.rust-std |
49 | | - ]); |
| 55 | + rustToolchain = |
| 56 | + with inputs.fenix.packages.${system}; |
| 57 | + combine ( |
| 58 | + [ |
| 59 | + stable.clippy |
| 60 | + stable.rustc |
| 61 | + stable.cargo |
| 62 | + stable.rustfmt |
| 63 | + stable.rust-src |
| 64 | + ] |
| 65 | + ++ inputs.nixpkgs.lib.optionals (system == "x86_64-linux") [ |
| 66 | + targets.x86_64-unknown-linux-musl.stable.rust-std |
| 67 | + ] |
| 68 | + ++ inputs.nixpkgs.lib.optionals (system == "aarch64-linux") [ |
| 69 | + targets.aarch64-unknown-linux-musl.stable.rust-std |
| 70 | + ] |
| 71 | + ); |
50 | 72 | in |
51 | 73 | { |
52 | 74 | inherit rustToolchain; |
|
57 | 79 | }; |
58 | 80 | }; |
59 | 81 |
|
60 | | - packages = forAllSystems ({ pkgs, system }: rec { |
61 | | - default = flake-checker; |
62 | | - |
63 | | - flake-checker = pkgs.naerskLib.buildPackage |
64 | | - ({ |
65 | | - name = "flake-checker"; |
66 | | - src = self; |
67 | | - doCheck = true; |
68 | | - nativeBuildInputs = with pkgs; [ ] ++ lib.optionals stdenv.isDarwin [ libiconv ]; |
69 | | - } // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux { |
70 | | - CARGO_BUILD_TARGET = |
71 | | - if system == "x86_64-linux" then |
72 | | - "x86_64-unknown-linux-musl" |
73 | | - else if system == "aarch64-linux" then |
74 | | - "aarch64-unknown-linux-musl" |
75 | | - else |
76 | | - throw "Unsupported Linux system: ${system}"; |
77 | | - CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; |
78 | | - }); |
79 | | - }); |
80 | | - |
81 | | - devShells = forAllSystems ({ pkgs, ... }: { |
82 | | - default = |
83 | | - let |
84 | | - check-nixpkgs-fmt = pkgs.writeShellApplication { |
85 | | - name = "check-nixpkgs-fmt"; |
86 | | - runtimeInputs = with pkgs; [ git nixpkgs-fmt ]; |
87 | | - text = '' |
88 | | - nixpkgs-fmt --check "$(git ls-files '*.nix')" |
89 | | - ''; |
90 | | - }; |
91 | | - check-rustfmt = pkgs.writeShellApplication { |
92 | | - name = "check-rustfmt"; |
93 | | - runtimeInputs = with pkgs; [ rustToolchain ]; |
94 | | - text = "cargo fmt --check"; |
95 | | - }; |
96 | | - get-ref-statuses = pkgs.writeShellApplication { |
97 | | - name = "get-ref-statuses"; |
98 | | - runtimeInputs = with pkgs; [ rustToolchain ]; |
99 | | - text = "cargo run --features ref-statuses -- --get-ref-statuses"; |
100 | | - }; |
101 | | - in |
102 | | - pkgs.mkShell { |
103 | | - packages = with pkgs; [ |
104 | | - bashInteractive |
105 | | - |
106 | | - # Rust |
107 | | - rustToolchain |
108 | | - cargo-bloat |
109 | | - cargo-edit |
110 | | - cargo-machete |
111 | | - cargo-watch |
112 | | - rust-analyzer |
113 | | - |
114 | | - # Nix |
115 | | - nixpkgs-fmt |
116 | | - |
117 | | - # CI checks |
118 | | - check-nixpkgs-fmt |
119 | | - check-rustfmt |
120 | | - |
121 | | - # Scripts |
122 | | - get-ref-statuses |
123 | | - ]; |
124 | | - |
125 | | - env = { |
126 | | - # Required by rust-analyzer |
127 | | - RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; |
| 82 | + packages = forAllSystems ( |
| 83 | + { pkgs, system }: |
| 84 | + rec { |
| 85 | + default = flake-checker; |
| 86 | + |
| 87 | + flake-checker = pkgs.naerskLib.buildPackage ( |
| 88 | + { |
| 89 | + name = "flake-checker"; |
| 90 | + src = self; |
| 91 | + doCheck = true; |
| 92 | + nativeBuildInputs = with pkgs; [ ] ++ lib.optionals stdenv.isDarwin [ libiconv ]; |
| 93 | + } |
| 94 | + // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux { |
| 95 | + CARGO_BUILD_TARGET = |
| 96 | + if system == "x86_64-linux" then |
| 97 | + "x86_64-unknown-linux-musl" |
| 98 | + else if system == "aarch64-linux" then |
| 99 | + "aarch64-unknown-linux-musl" |
| 100 | + else |
| 101 | + throw "Unsupported Linux system: ${system}"; |
| 102 | + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; |
| 103 | + } |
| 104 | + ); |
| 105 | + } |
| 106 | + ); |
| 107 | + |
| 108 | + devShells = forAllSystems ( |
| 109 | + { pkgs, system }: |
| 110 | + { |
| 111 | + default = |
| 112 | + let |
| 113 | + check-nixpkgs-fmt = pkgs.writeShellApplication { |
| 114 | + name = "check-nixpkgs-fmt"; |
| 115 | + runtimeInputs = with pkgs; [ |
| 116 | + git |
| 117 | + nixpkgs-fmt |
| 118 | + ]; |
| 119 | + text = '' |
| 120 | + nixpkgs-fmt --check "$(git ls-files '*.nix')" |
| 121 | + ''; |
| 122 | + }; |
| 123 | + check-rustfmt = pkgs.writeShellApplication { |
| 124 | + name = "check-rustfmt"; |
| 125 | + runtimeInputs = with pkgs; [ rustToolchain ]; |
| 126 | + text = "cargo fmt --check"; |
| 127 | + }; |
| 128 | + get-ref-statuses = pkgs.writeShellApplication { |
| 129 | + name = "get-ref-statuses"; |
| 130 | + runtimeInputs = with pkgs; [ rustToolchain ]; |
| 131 | + text = "cargo run --features ref-statuses -- --get-ref-statuses"; |
| 132 | + }; |
| 133 | + update-readme = pkgs.writeShellApplication { |
| 134 | + name = "update-readme"; |
| 135 | + runtimeInputs = [ |
| 136 | + inputs.easy-template.packages.${system}.default |
| 137 | + pkgs.jq |
| 138 | + ]; |
| 139 | + text = '' |
| 140 | + tmp=$(mktemp -d) |
| 141 | + inputs="''${tmp}/template-inputs.json" |
| 142 | +
|
| 143 | + jq '{supported: .}' ./ref-statuses.json > "''${inputs}" |
| 144 | + easy-template ./templates/README.md.handlebars "''${inputs}" > README.md |
| 145 | +
|
| 146 | + rm -rf "''${tmp}" |
| 147 | + ''; |
| 148 | + }; |
| 149 | + in |
| 150 | + pkgs.mkShell { |
| 151 | + packages = with pkgs; [ |
| 152 | + bashInteractive |
| 153 | + |
| 154 | + # Rust |
| 155 | + rustToolchain |
| 156 | + cargo-bloat |
| 157 | + cargo-edit |
| 158 | + cargo-machete |
| 159 | + cargo-watch |
| 160 | + rust-analyzer |
| 161 | + |
| 162 | + # Nix |
| 163 | + nixpkgs-fmt |
| 164 | + |
| 165 | + # CI checks |
| 166 | + check-nixpkgs-fmt |
| 167 | + check-rustfmt |
| 168 | + |
| 169 | + # Scripts |
| 170 | + get-ref-statuses |
| 171 | + update-readme |
| 172 | + ]; |
| 173 | + |
| 174 | + env = { |
| 175 | + # Required by rust-analyzer |
| 176 | + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; |
| 177 | + }; |
128 | 178 | }; |
129 | | - }; |
130 | | - }); |
| 179 | + } |
| 180 | + ); |
131 | 181 | }; |
132 | 182 | } |
0 commit comments