|
1 | 1 | { |
2 | 2 | description = "A monorepo build system and task runner for the web ecosystem"; |
3 | 3 |
|
| 4 | + nixConfig = { |
| 5 | + extra-substituters = [ "https://moonrepo.cachix.org" ]; |
| 6 | + extra-trusted-public-keys = [ |
| 7 | + "moonrepo.cachix.org-1:n4zm4mkV1Eoqck4mQvAhJM28EQwFLU7kW4dEbtAXbD8=" |
| 8 | + ]; |
| 9 | + }; |
| 10 | + |
4 | 11 | inputs = { |
5 | 12 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; |
6 | 13 | flake-utils.url = "github:numtide/flake-utils"; |
| 14 | + crane.url = "github:ipetkov/crane"; |
7 | 15 | rust-overlay = { |
8 | 16 | url = "github:oxalica/rust-overlay"; |
9 | 17 | inputs.nixpkgs.follows = "nixpkgs"; |
10 | 18 | }; |
11 | 19 | }; |
12 | 20 |
|
13 | | - outputs = { self, nixpkgs, flake-utils, rust-overlay }: |
14 | | - flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: |
15 | | - let |
16 | | - pkgs = import nixpkgs { |
17 | | - inherit system; |
18 | | - overlays = [ rust-overlay.overlays.default ]; |
19 | | - }; |
20 | | - |
21 | | - rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
22 | | - |
23 | | - devRustToolchain = rustToolchain.override { |
24 | | - extensions = [ "rust-src" ]; |
25 | | - }; |
26 | | - |
27 | | - moonVersion = (builtins.fromTOML |
28 | | - (builtins.readFile ./crates/cli/Cargo.toml)).package.version; |
29 | | - |
30 | | - nativeDeps = with pkgs; [ pkg-config protobuf ]; |
31 | | - buildDeps = with pkgs; [ openssl ]; |
32 | | - in |
33 | | - { |
34 | | - packages.default = (pkgs.makeRustPlatform { |
35 | | - cargo = rustToolchain; |
36 | | - rustc = rustToolchain; |
37 | | - }).buildRustPackage { |
38 | | - pname = "moon"; |
39 | | - version = moonVersion; |
40 | | - src = ./.; |
41 | | - |
42 | | - cargoLock.lockFile = ./Cargo.lock; |
43 | | - |
44 | | - nativeBuildInputs = nativeDeps ++ (with pkgs; [ |
45 | | - installShellFiles |
46 | | - writableTmpDirAsHomeHook |
47 | | - ]); |
48 | | - buildInputs = buildDeps; |
49 | | - |
50 | | - env = { |
51 | | - RUSTFLAGS = "-C strip=symbols"; |
52 | | - OPENSSL_NO_VENDOR = "1"; |
| 21 | + outputs = |
| 22 | + { |
| 23 | + self, |
| 24 | + nixpkgs, |
| 25 | + flake-utils, |
| 26 | + crane, |
| 27 | + rust-overlay, |
| 28 | + }: |
| 29 | + flake-utils.lib.eachSystem |
| 30 | + [ |
| 31 | + "x86_64-linux" |
| 32 | + "aarch64-linux" |
| 33 | + "aarch64-darwin" |
| 34 | + ] |
| 35 | + ( |
| 36 | + system: |
| 37 | + let |
| 38 | + pkgs = import nixpkgs { |
| 39 | + inherit system; |
| 40 | + overlays = [ rust-overlay.overlays.default ]; |
53 | 41 | }; |
54 | 42 |
|
55 | | - postInstall = pkgs.lib.optionalString |
56 | | - (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages) |
57 | | - ( |
58 | | - let emulator = pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages; |
59 | | - in '' |
60 | | - installShellCompletion --cmd moon \ |
61 | | - --bash <(${emulator} $out/bin/moon completions --shell bash) \ |
62 | | - --fish <(${emulator} $out/bin/moon completions --shell fish) \ |
63 | | - --zsh <(${emulator} $out/bin/moon completions --shell zsh) |
64 | | - '' |
65 | | - ); |
66 | | - |
67 | | - doCheck = false; |
68 | | - |
69 | | - meta = with pkgs.lib; { |
70 | | - description = "A monorepo build system and task runner for the web ecosystem"; |
71 | | - mainProgram = "moon"; |
72 | | - homepage = "https://github.com/moonrepo/moon"; |
73 | | - changelog = "https://github.com/moonrepo/moon/releases/tag/v${moonVersion}"; |
74 | | - license = licenses.mit; |
75 | | - maintainers = [ ]; |
76 | | - platforms = platforms.linux; |
| 43 | + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
| 44 | + |
| 45 | + devRustToolchain = rustToolchain.override { |
| 46 | + extensions = [ "rust-src" ]; |
77 | 47 | }; |
78 | | - }; |
79 | 48 |
|
80 | | - devShells.default = pkgs.mkShell { |
81 | | - nativeBuildInputs = nativeDeps ++ [ |
82 | | - devRustToolchain |
83 | | - pkgs.just |
84 | | - pkgs.cargo-nextest |
| 49 | + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; |
| 50 | + |
| 51 | + moonVersion = (builtins.fromTOML (builtins.readFile ./crates/cli/Cargo.toml)).package.version; |
| 52 | + |
| 53 | + nativeDeps = with pkgs; [ |
| 54 | + pkg-config |
| 55 | + protobuf |
| 56 | + ]; |
| 57 | + buildDeps = with pkgs; [ openssl ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]; |
| 58 | + |
| 59 | + cargoFiles = pkgs.lib.fileset.unions [ |
| 60 | + ./Cargo.toml |
| 61 | + ./Cargo.lock |
| 62 | + ./.cargo/config.toml |
| 63 | + (craneLib.fileset.commonCargoSources ./crates) |
85 | 64 | ]; |
86 | | - buildInputs = buildDeps; |
87 | 65 |
|
88 | | - env = { |
89 | | - OPENSSL_NO_VENDOR = "1"; |
90 | | - RUST_SRC_PATH = "${devRustToolchain}/lib/rustlib/src/rust/library"; |
| 66 | + cargoSource = pkgs.lib.fileset.toSource { |
| 67 | + root = ./.; |
| 68 | + fileset = cargoFiles; |
| 69 | + }; |
| 70 | + |
| 71 | + source = pkgs.lib.fileset.toSource { |
| 72 | + root = ./.; |
| 73 | + fileset = pkgs.lib.fileset.unions [ |
| 74 | + cargoFiles |
| 75 | + ./crates/daemon-proto/proto |
| 76 | + ./crates/config-loader/res |
| 77 | + ./crates/docker/templates/Dockerfile.tera |
| 78 | + ./crates/app/src/commands/graph/html.tera |
| 79 | + ./crates/query/src/mql.pest |
| 80 | + ]; |
| 81 | + }; |
| 82 | + |
| 83 | + commonArgs = { |
| 84 | + pname = "moon"; |
| 85 | + version = moonVersion; |
| 86 | + src = source; |
| 87 | + |
| 88 | + cargoExtraArgs = "--locked --package moon_cli --bins"; |
| 89 | + strictDeps = true; |
| 90 | + doCheck = false; |
| 91 | + |
| 92 | + nativeBuildInputs = nativeDeps; |
| 93 | + buildInputs = buildDeps; |
| 94 | + |
| 95 | + env = { |
| 96 | + RUSTFLAGS = "-C strip=symbols"; |
| 97 | + OPENSSL_NO_VENDOR = "1"; |
| 98 | + }; |
| 99 | + }; |
| 100 | + |
| 101 | + cargoArtifacts = craneLib.buildDepsOnly ( |
| 102 | + commonArgs |
| 103 | + // { |
| 104 | + src = cargoSource; |
| 105 | + buildPhaseCargoCommand = "cargo build --release --locked --package moon_cli --bins"; |
| 106 | + } |
| 107 | + ); |
| 108 | + |
| 109 | + moon = craneLib.buildPackage ( |
| 110 | + commonArgs |
| 111 | + // { |
| 112 | + inherit cargoArtifacts; |
| 113 | + |
| 114 | + nativeBuildInputs = |
| 115 | + nativeDeps |
| 116 | + ++ (with pkgs; [ |
| 117 | + installShellFiles |
| 118 | + writableTmpDirAsHomeHook |
| 119 | + ]); |
| 120 | + |
| 121 | + postInstall = |
| 122 | + pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages) |
| 123 | + ( |
| 124 | + let |
| 125 | + emulator = pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages; |
| 126 | + in |
| 127 | + '' |
| 128 | + installShellCompletion --cmd moon \ |
| 129 | + --bash <(${emulator} $out/bin/moon completions --shell bash) \ |
| 130 | + --fish <(${emulator} $out/bin/moon completions --shell fish) \ |
| 131 | + --zsh <(${emulator} $out/bin/moon completions --shell zsh) |
| 132 | + '' |
| 133 | + ); |
| 134 | + |
| 135 | + meta = with pkgs.lib; { |
| 136 | + description = "A monorepo build system and task runner for the web ecosystem"; |
| 137 | + mainProgram = "moon"; |
| 138 | + homepage = "https://github.com/moonrepo/moon"; |
| 139 | + changelog = "https://github.com/moonrepo/moon/releases/tag/v${moonVersion}"; |
| 140 | + license = licenses.mit; |
| 141 | + maintainers = [ ]; |
| 142 | + platforms = platforms.linux ++ [ "aarch64-darwin" ]; |
| 143 | + }; |
| 144 | + } |
| 145 | + ); |
| 146 | + in |
| 147 | + { |
| 148 | + packages = { |
| 149 | + inherit moon; |
| 150 | + moon-deps = cargoArtifacts; |
| 151 | + default = moon; |
| 152 | + }; |
| 153 | + |
| 154 | + apps.default = { |
| 155 | + type = "app"; |
| 156 | + program = "${moon}/bin/moon"; |
| 157 | + }; |
| 158 | + |
| 159 | + devShells.default = pkgs.mkShell { |
| 160 | + nativeBuildInputs = nativeDeps ++ [ |
| 161 | + devRustToolchain |
| 162 | + pkgs.just |
| 163 | + pkgs.cargo-nextest |
| 164 | + ]; |
| 165 | + buildInputs = buildDeps; |
| 166 | + |
| 167 | + env = { |
| 168 | + OPENSSL_NO_VENDOR = "1"; |
| 169 | + RUST_SRC_PATH = "${devRustToolchain}/lib/rustlib/src/rust/library"; |
| 170 | + }; |
91 | 171 | }; |
92 | | - }; |
93 | | - } |
94 | | - ); |
| 172 | + } |
| 173 | + ); |
95 | 174 | } |
0 commit comments