|
5 | 5 | inputs.crane.inputs.flake-utils.follows = "flake-utils"; |
6 | 6 | inputs.crane.inputs.nixpkgs.follows = "nixpkgs"; |
7 | 7 | inputs.crane.url = github:ipetkov/crane; |
8 | | - inputs.enarx.url = github:enarx/enarx; |
| 8 | + inputs.enarx.url = github:rvolosatovs/enarx/build/crane; # TODO: Remove fork once https://github.com/enarx/enarx/pull/2269 is merged |
9 | 9 | inputs.flake-compat.flake = false; |
10 | 10 | inputs.flake-compat.url = github:edolstra/flake-compat; |
11 | 11 | inputs.flake-utils.url = github:numtide/flake-utils; |
|
23 | 23 | rust-overlay, |
24 | 24 | ... |
25 | 25 | }: |
26 | | - with flake-utils.lib.system; |
27 | | - flake-utils.lib.eachSystem [ |
| 26 | + with flake-utils.lib.system; let |
| 27 | + version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version; |
| 28 | + |
| 29 | + overlay = final: prev: let |
| 30 | + src = |
| 31 | + final.nix-gitignore.gitignoreRecursiveSource [ |
| 32 | + "*.nix" |
| 33 | + "*.yml" |
| 34 | + "/.github" |
| 35 | + "flake.lock" |
| 36 | + "LICENSE" |
| 37 | + "rust-toolchain.toml" |
| 38 | + ] |
| 39 | + ./.; |
| 40 | + |
| 41 | + rustToolchain = prev.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
| 42 | + |
| 43 | + craneLib = (crane.mkLib final).overrideToolchain rustToolchain; |
| 44 | + |
| 45 | + commonArgs = { |
| 46 | + inherit |
| 47 | + src |
| 48 | + version |
| 49 | + ; |
| 50 | + pname = "steward"; |
| 51 | + }; |
| 52 | + |
| 53 | + cargoArtifacts = craneLib.buildDepsOnly commonArgs; |
| 54 | + |
| 55 | + commonArtifactArgs = commonArgs // {inherit cargoArtifacts;}; |
| 56 | + |
| 57 | + checks.clippy = craneLib.cargoClippy (commonArtifactArgs // {cargoClippyExtraArgs = "--all-targets --workspace -- --deny warnings";}); |
| 58 | + checks.fmt = craneLib.cargoFmt commonArtifactArgs; |
| 59 | + checks.nextest = craneLib.cargoNextest commonArtifactArgs; |
| 60 | + |
| 61 | + buildPackage = extraArgs: |
| 62 | + craneLib.buildPackage (commonArtifactArgs |
| 63 | + // { |
| 64 | + cargoExtraArgs = "-j $NIX_BUILD_CORES"; |
| 65 | + } |
| 66 | + // extraArgs); |
| 67 | + |
| 68 | + nativeBin = buildPackage {}; |
| 69 | + aarch64LinuxMuslBin = buildPackage { |
| 70 | + CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl"; |
| 71 | + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; |
| 72 | + }; |
| 73 | + wasm32WasiBin = buildPackage { |
| 74 | + nativeBuildInputs = [final.enarx]; |
| 75 | + |
| 76 | + CARGO_BUILD_TARGET = "wasm32-wasi"; |
| 77 | + CARGO_TARGET_WASM_WASI32_RUNNER = "enarx run --wasmcfgfile ${self}/Enarx.toml"; |
| 78 | + }; |
| 79 | + x86_64LinuxMuslBin = buildPackage { |
| 80 | + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; |
| 81 | + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; |
| 82 | + }; |
| 83 | + |
| 84 | + buildImage = bin: |
| 85 | + final.dockerTools.buildImage { |
| 86 | + name = "steward"; |
| 87 | + tag = version; |
| 88 | + contents = [ |
| 89 | + bin |
| 90 | + ]; |
| 91 | + config.Cmd = ["steward"]; |
| 92 | + config.Env = ["PATH=${bin}/bin"]; |
| 93 | + }; |
| 94 | + in { |
| 95 | + steward = nativeBin; |
| 96 | + steward-aarch64-unknown-linux-musl = aarch64LinuxMuslBin; |
| 97 | + steward-aarch64-unknown-linux-musl-oci = buildImage aarch64LinuxMuslBin; |
| 98 | + steward-wasm32-wasi = wasm32WasiBin; |
| 99 | + steward-x86_64-unknown-linux-musl = x86_64LinuxMuslBin; |
| 100 | + steward-x86_64-unknown-linux-musl-oci = buildImage x86_64LinuxMuslBin; |
| 101 | + |
| 102 | + stewardChecks = checks; |
| 103 | + stewardRustToolchain = rustToolchain; |
| 104 | + }; |
| 105 | + in |
| 106 | + { |
| 107 | + overlays.default = overlay; |
| 108 | + } |
| 109 | + // flake-utils.lib.eachSystem [ |
28 | 110 | aarch64-darwin |
29 | 111 | aarch64-linux |
30 | 112 | powerpc64le-linux |
|
34 | 116 | system: let |
35 | 117 | pkgs = import nixpkgs { |
36 | 118 | inherit system; |
37 | | - overlays = [(import rust-overlay)]; |
38 | | - }; |
39 | | - |
40 | | - # TODO: Add and use an overlay |
41 | | - enarxBin = enarx.packages.${system}.default; |
42 | | - |
43 | | - rust = pkgs.rust-bin.fromRustupToolchainFile "${self}/rust-toolchain.toml"; |
44 | | - |
45 | | - cargo.toml = builtins.fromTOML (builtins.readFile "${self}/Cargo.toml"); |
46 | | - src = |
47 | | - pkgs.nix-gitignore.gitignoreRecursiveSource [ |
48 | | - "*.nix" |
49 | | - "*.yml" |
50 | | - "/.github" |
51 | | - "flake.lock" |
52 | | - "LICENSE" |
53 | | - "rust-toolchain.toml" |
54 | | - ] |
55 | | - self; |
56 | | - |
57 | | - craneLib = (crane.mkLib pkgs).overrideToolchain rust; |
58 | | - |
59 | | - commonArgs = { |
60 | | - pname = cargo.toml.package.name; |
61 | | - inherit (cargo.toml.package) version; |
62 | | - inherit src; |
| 119 | + overlays = [ |
| 120 | + rust-overlay.overlays.default |
| 121 | + enarx.overlays.default |
| 122 | + overlay |
| 123 | + ]; |
63 | 124 | }; |
64 | | - |
65 | | - cargoArtifacts = craneLib.buildDepsOnly commonArgs; |
66 | | - |
67 | | - commonArtifactArgs = commonArgs // {inherit cargoArtifacts;}; |
68 | | - |
69 | | - cargoClippy = craneLib.cargoClippy (commonArtifactArgs // {cargoClippyExtraArgs = "--all-targets --workspace -- --deny warnings";}); |
70 | | - cargoFmt = craneLib.cargoFmt commonArtifactArgs; |
71 | | - cargoNextest = craneLib.cargoNextest commonArtifactArgs; |
72 | | - |
73 | | - buildPackage = extraArgs: craneLib.buildPackage (commonArtifactArgs // extraArgs); |
74 | | - nativeBin = buildPackage {}; |
75 | | - wasm32WasiBin = buildPackage { |
76 | | - nativeBuildInputs = [enarxBin]; |
77 | | - |
78 | | - CARGO_BUILD_TARGET = "wasm32-wasi"; |
79 | | - CARGO_TARGET_WASM_WASI32_RUNNER = "enarx run --wasmcfgfile ${self}/Enarx.toml"; |
80 | | - }; |
81 | | - x86_64LinuxMuslBin = buildPackage { |
82 | | - CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; |
83 | | - CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; |
84 | | - }; |
85 | | - |
86 | | - buildImage = bin: |
87 | | - pkgs.dockerTools.buildImage { |
88 | | - inherit (cargo.toml.package) name; |
89 | | - tag = cargo.toml.package.version; |
90 | | - contents = [ |
91 | | - bin |
92 | | - ]; |
93 | | - config.Cmd = [cargo.toml.package.name]; |
94 | | - config.Env = ["PATH=${bin}/bin"]; |
95 | | - }; |
96 | 125 | in { |
97 | 126 | formatter = pkgs.alejandra; |
98 | 127 |
|
99 | | - checks.clippy = cargoClippy; |
100 | | - checks.fmt = cargoFmt; |
101 | | - checks.nextest = cargoNextest; |
| 128 | + checks = pkgs.stewardChecks; |
102 | 129 |
|
103 | 130 | packages = |
104 | 131 | { |
105 | | - default = nativeBin; |
106 | | - |
107 | | - "${cargo.toml.package.name}" = nativeBin; |
108 | | - "${cargo.toml.package.name}-x86_64-unknown-linux-musl" = x86_64LinuxMuslBin; |
109 | | - "${cargo.toml.package.name}-x86_64-unknown-linux-musl-oci" = buildImage x86_64LinuxMuslBin; |
| 132 | + default = pkgs.steward; |
110 | 133 | } |
111 | | - # TODO: Remove once an overlay is created in enarx |
112 | | - // (pkgs.lib.optionalAttrs (system != powerpc64le-linux) { |
113 | | - "${cargo.toml.package.name}-wasm32-wasi" = wasm32WasiBin; |
114 | | - }); |
| 134 | + // pkgs.lib.genAttrs [ |
| 135 | + "steward" |
| 136 | + "steward-aarch64-unknown-linux-musl" |
| 137 | + "steward-aarch64-unknown-linux-musl-oci" |
| 138 | + "steward-wasm32-wasi" |
| 139 | + "steward-x86_64-unknown-linux-musl" |
| 140 | + "steward-x86_64-unknown-linux-musl-oci" |
| 141 | + ] (name: pkgs.${name}); |
115 | 142 |
|
116 | 143 | devShells.default = pkgs.mkShell { |
117 | | - buildInputs = |
118 | | - [ |
119 | | - pkgs.openssl |
120 | | - pkgs.wasmtime |
121 | | - |
122 | | - rust |
123 | | - ] |
124 | | - # TODO: Add Enarx, once an overlay is created in enarx |
125 | | - ++ (pkgs.lib.optional (system != powerpc64le-linux) enarxBin); |
| 144 | + buildInputs = [ |
| 145 | + pkgs.enarx |
| 146 | + pkgs.openssl |
| 147 | + pkgs.stewardRustToolchain |
| 148 | + pkgs.wasmtime |
| 149 | + ]; |
126 | 150 | }; |
127 | 151 | } |
128 | 152 | ); |
|
0 commit comments