diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 122 |
1 files changed, 72 insertions, 50 deletions
@@ -1,80 +1,102 @@ | |||
1 | { | 1 | { |
2 | inputs = { | 2 | inputs = { |
3 | utils.url = "github:numtide/flake-utils"; | 3 | |
4 | naersk.url = "github:nmattia/naersk"; | 4 | nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; |
5 | |||
5 | mozillapkgs = { | 6 | mozillapkgs = { |
6 | url = "github:mozilla/nixpkgs-mozilla"; | 7 | url = "github:mozilla/nixpkgs-mozilla"; |
7 | flake = false; | 8 | flake = false; |
8 | }; | 9 | }; |
10 | |||
9 | flake-compat = { | 11 | flake-compat = { |
10 | url = "github:edolstra/flake-compat"; | 12 | url = "github:edolstra/flake-compat"; |
11 | flake = false; | 13 | flake = false; |
12 | }; | 14 | }; |
15 | |||
16 | import-cargo.url = github:edolstra/import-cargo; | ||
17 | |||
13 | }; | 18 | }; |
14 | 19 | ||
15 | outputs = | 20 | outputs = |
16 | { self | 21 | { self |
17 | , nixpkgs | 22 | , nixpkgs |
18 | , utils | ||
19 | , naersk | ||
20 | , mozillapkgs | 23 | , mozillapkgs |
24 | , import-cargo | ||
21 | , ... | 25 | , ... |
22 | }: | 26 | }: |
23 | utils.lib.eachDefaultSystem (system: | ||
24 | let | 27 | let |
25 | pkgs = nixpkgs.legacyPackages."${system}"; | 28 | inherit (import-cargo.builders) importCargo; |
26 | 29 | supportedSystems = [ "x86_64-linux" ]; | |
27 | # Get a specific rust version | 30 | forAllSystems = nixpkgs.lib.genAttrs supportedSystems; |
28 | mozilla = pkgs.callPackage (mozillapkgs + "/package-set.nix") { }; | 31 | nixpkgsFor = forAllSystems (system: |
32 | import nixpkgs { | ||
33 | inherit system; | ||
34 | overlays = [ self.overlay ]; | ||
35 | }); | ||
36 | mozilla = p: p.callPackage (mozillapkgs + "/package-set.nix") { }; | ||
29 | chanspec = { | 37 | chanspec = { |
30 | date = "2021-03-31"; | 38 | date = "2021-09-30"; |
31 | channel = "nightly"; | 39 | channel = "nightly"; |
32 | sha256 = "oK5ebje09MRn988saJMT3Zze/tRE7u9zTeFPV1CEeLc="; # set zeros after modifying channel or date | 40 | sha256 = "Elqn7GDBDE/QT1XTDyj0EvivbC//uwjWX8d+J3Pi0dY="; # set zeros after modifying channel or date |
33 | }; | 41 | }; |
42 | in | ||
43 | { | ||
34 | 44 | ||
35 | rustChannel = mozilla.rustChannelOf chanspec; | 45 | overlay = final: prev: |
36 | rust = rustChannel.rust; | 46 | let |
37 | rust-src = rustChannel.rust-src; | 47 | rustChannel = (mozilla final.pkgs).rustChannelOf chanspec; |
48 | inherit (rustChannel) rust rustc rust-src; | ||
49 | in | ||
50 | { | ||
38 | 51 | ||
39 | naersk-lib = naersk.lib."${system}".override { | 52 | statix = with final; pkgs.stdenv.mkDerivation { |
40 | cargo = rust; | 53 | pname = "statix"; |
41 | rustc = rust; | 54 | version = "v0.1.0"; |
42 | }; | 55 | src = ./.; |
56 | nativeBuildInputs = [ | ||
57 | (importCargo { lockFile = ./Cargo.lock; inherit pkgs; }).cargoHome | ||
58 | rust | ||
59 | cargo | ||
60 | ]; | ||
61 | buildPhase = '' | ||
62 | cargo build -p statix --release --offline | ||
63 | ''; | ||
64 | installPhase = '' | ||
65 | install -Dm775 ./target/release/statix $out/bin/statix | ||
66 | ''; | ||
67 | }; | ||
43 | 68 | ||
44 | nativeBuildInputs = with pkgs; [ ]; | 69 | }; |
45 | 70 | ||
46 | in | 71 | packages = forAllSystems (system: { |
47 | rec { | 72 | inherit (nixpkgsFor."${system}") statix; |
48 | packages.statix = naersk-lib.buildPackage { | 73 | }); |
49 | pname = "statix"; | ||
50 | version = "0.1.0"; | ||
51 | root = ./.; | ||
52 | inherit nativeBuildInputs; | ||
53 | }; | ||
54 | 74 | ||
55 | defaultPackage = packages.statix; | 75 | defaultPackage = |
56 | apps.statix = utils.lib.mkApp { | 76 | forAllSystems (system: self.packages."${system}".statix); |
57 | drv = packages.statix; | ||
58 | }; | ||
59 | 77 | ||
60 | apps.check = { | 78 | devShell = forAllSystems (system: |
61 | type = "app"; | 79 | let |
62 | program = "${pkgs.cargo-watch}/bin/cargo-watch"; | 80 | pkgs = nixpkgsFor.${system}; |
63 | }; | 81 | rustChannel = (mozilla pkgs).rustChannelOf chanspec; |
82 | in | ||
83 | with pkgs; | ||
84 | mkShell rec { | ||
85 | buildInputs = | ||
86 | (with pkgs; [ | ||
87 | rust-analyzer | ||
88 | rustfmt | ||
89 | cargo | ||
90 | cargo-watch | ||
91 | ]) ++ (with rustChannel; [ | ||
92 | rust | ||
93 | rust-src | ||
94 | ]); | ||
95 | RUST_SRC_PATH = "${rustChannel.rust-src}/lib/rustlib/src/rust/library"; | ||
96 | RUST_LOG = "info"; | ||
97 | RUST_BACKTRACE = 1; | ||
98 | }); | ||
64 | 99 | ||
65 | defaultApp = apps.statix; | 100 | |
66 | devShell = pkgs.mkShell { | 101 | }; |
67 | nativeBuildInputs = nativeBuildInputs ++ [ | ||
68 | rust | ||
69 | rust-src | ||
70 | pkgs.rust-analyzer | ||
71 | pkgs.rustfmt | ||
72 | pkgs.cargo | ||
73 | pkgs.cargo-watch | ||
74 | ]; | ||
75 | RUST_SRC_PATH = "${rust-src}/lib/rustlib/src/rust/library"; | ||
76 | RUST_LOG = "info"; | ||
77 | RUST_BACKTRACE = 1; | ||
78 | }; | ||
79 | }); | ||
80 | } | 102 | } |