|
1 | 1 | {
|
2 | 2 | inputs = {
|
3 |
| - fenix = { |
4 |
| - url = "github:nix-community/fenix"; |
| 3 | + crane = { |
| 4 | + url = "github:ipetkov/crane"; |
5 | 5 | inputs.nixpkgs.follows = "nixpkgs";
|
| 6 | + inputs.flake-utils.follows = "flake-utils"; |
6 | 7 | };
|
7 | 8 | flake-utils.url = "github:numtide/flake-utils";
|
8 | 9 | gitignore = {
|
9 | 10 | url = "github:hercules-ci/gitignore.nix";
|
10 | 11 | inputs.nixpkgs.follows = "nixpkgs";
|
11 | 12 | };
|
12 |
| - naersk = { |
13 |
| - url = "github:nix-community/naersk"; |
| 13 | + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
| 14 | + pre-commit = { |
| 15 | + url = "github:cachix/pre-commit-hooks.nix"; |
14 | 16 | inputs.nixpkgs.follows = "nixpkgs";
|
| 17 | + inputs.flake-utils.follows = "flake-utils"; |
| 18 | + }; |
| 19 | + rust = { |
| 20 | + url = "github:oxalica/rust-overlay"; |
| 21 | + inputs.nixpkgs.follows = "nixpkgs"; |
| 22 | + inputs.flake-utils.follows = "flake-utils"; |
15 | 23 | };
|
16 |
| - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; |
17 | 24 | };
|
18 | 25 |
|
19 |
| - outputs = { self, fenix, flake-utils, gitignore, naersk, nixpkgs, ... }: |
20 |
| - flake-utils.lib.eachDefaultSystem (localSystem: |
| 26 | + outputs = { self, crane, flake-utils, gitignore, nixpkgs, pre-commit, rust }: |
| 27 | + let |
| 28 | + systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-linux" ]; |
| 29 | + in |
| 30 | + flake-utils.lib.eachSystem systems (hostPlatform: |
21 | 31 | let
|
22 |
| - crossSystem = nixpkgs.lib.systems.examples.aarch64-multiplatform-musl // { useLLVM = true; }; |
| 32 | + targetPlatform = nixpkgs.lib.systems.examples.aarch64-multiplatform-musl; |
23 | 33 |
|
24 | 34 | pkgs = import nixpkgs {
|
25 |
| - inherit localSystem crossSystem; |
26 |
| - overlays = [ fenix.overlay gitignore.overlay naersk.overlay ]; |
| 35 | + localSystem = hostPlatform; |
| 36 | + crossSystem = targetPlatform; |
| 37 | + overlays = [ gitignore.overlay rust.overlays.default ]; |
27 | 38 | };
|
28 | 39 |
|
29 |
| - inherit (pkgs) pkgsBuildBuild pkgsBuildHost; |
| 40 | + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
30 | 41 |
|
31 |
| - llvmToolchain = pkgsBuildHost.llvmPackages_latest; |
32 |
| - |
33 |
| - rustToolchain = pkgsBuildHost.fenix.fromToolchainFile { |
34 |
| - file = ./rust-toolchain.toml; |
35 |
| - sha256 = "sha256-KXx+ID0y4mg2B3LHp7IyaiMrdexF6octADnAtFIOjrY="; |
36 |
| - }; |
| 42 | + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; |
37 | 43 |
|
38 |
| - naerskCross = pkgsBuildHost.naersk.override { |
39 |
| - inherit (llvmToolchain) stdenv; |
40 |
| - cargo = rustToolchain; |
41 |
| - rustc = rustToolchain; |
42 |
| - }; |
43 |
| - |
44 |
| - src = pkgs.gitignoreSource ./.; |
| 44 | + crateExpr = { stdenv, lib, qemu, gitignoreSource }: |
| 45 | + craneLib.buildPackage { |
| 46 | + src = gitignoreSource ./.; |
| 47 | + depsBuildBuild = [ qemu ]; |
| 48 | + nativeBuildInputs = [ |
| 49 | + stdenv.cc |
| 50 | + ]; |
| 51 | + HOST_CC = "${stdenv.cc.nativePrefix}cc"; |
| 52 | + }; |
45 | 53 | in
|
46 | 54 | {
|
47 |
| - packages = { |
48 |
| - default = self.packages.${localSystem}.hyperpixel-init; |
49 |
| - hyperpixel-init = naerskCross.buildPackage { |
50 |
| - name = "hyperpixel-init"; |
51 |
| - |
52 |
| - inherit src; |
53 |
| - |
54 |
| - nativeBuildInputs = with llvmToolchain; [ stdenv.cc lld ]; |
| 55 | + checks = { |
| 56 | + inherit (self.packages.${hostPlatform}) hyperpixel-init; |
| 57 | + pre-commit = pre-commit.lib.${hostPlatform}.run { |
| 58 | + src = pkgs.gitignoreSource ./.; |
| 59 | + hooks = { |
| 60 | + clippy.enable = true; |
| 61 | + nix-linter.enable = true; |
| 62 | + nixpkgs-fmt.enable = true; |
| 63 | + rustfmt.enable = true; |
| 64 | + statix.enable = true; |
| 65 | + }; |
55 | 66 | };
|
56 | 67 | };
|
57 | 68 |
|
58 |
| - devShells.default = pkgs.mkShell { |
59 |
| - name = "hyperpixel-init"; |
| 69 | + packages = { |
| 70 | + default = self.packages.${hostPlatform}.hyperpixel-init; |
| 71 | + hyperpixel-init = pkgs.callPackage crateExpr { }; |
| 72 | + }; |
60 | 73 |
|
61 |
| - inputsFrom = [ self.packages.${localSystem}.default ]; |
62 | 74 |
|
63 |
| - nativeBuildInputs = with pkgsBuildBuild; [ |
| 75 | + devShells.default = self.packages.${hostPlatform}.default.overrideAttrs (old: { |
| 76 | + depsBuildBuild = with pkgs.pkgsBuildBuild; (old.depsBuildBuild or []) ++ [ |
64 | 77 | cargo-audit
|
65 | 78 | cargo-bloat
|
66 | 79 | cargo-edit
|
67 |
| - cargo-udeps |
68 | 80 | nix-linter
|
69 | 81 | nixpkgs-fmt
|
70 |
| - pre-commit |
71 | 82 | rnix-lsp
|
72 |
| - rust-analyzer-nightly |
73 |
| - (pkgs.lib.lowPrio git) |
| 83 | + rust-analyzer |
| 84 | + statix |
74 | 85 | ];
|
75 | 86 |
|
76 |
| - shellHook = '' |
77 |
| - pre-commit install --install-hooks |
| 87 | + shellHook = (old.shellHook or "") + '' |
| 88 | + ${self.checks.${hostPlatform}.pre-commit.shellHook} |
78 | 89 | '';
|
79 |
| - }; |
| 90 | + }); |
80 | 91 | });
|
81 | 92 | }
|
0 commit comments