Skip to content

Commit

Permalink
chore(refactor): clean up Nix configuration for better readability
Browse files Browse the repository at this point in the history
This commit includes a restructuring of the Nix configuration files to
make them easier to read and manage.
The 'teepotCrate' reference usage has been revised and the explicit
src inheritance has been removed.

Signed-off-by: Harald Hoyer <[email protected]>
  • Loading branch information
haraldh committed Aug 9, 2024
1 parent 8ce8f5b commit 1cac5b9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
21 changes: 17 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,24 @@
};

outputs = inputs:
let src = ./.; in
let
src = ./.;
crate_src = lib: with lib.fileset; toSource {
root = src;
fileset = unions [
./Cargo.lock
./Cargo.toml
./bin
./crates
./rust-toolchain.toml
./deny.toml
./taplo.toml
];
};
inputs_with_src = inputs // { inherit crate_src; };
in
inputs.snowfall-lib.mkFlake {
inherit inputs;
inputs = inputs_with_src;
inherit src;

snowfall.namespace = "teepot";
Expand All @@ -43,8 +58,6 @@
nixsgx-flake.overlays.default
vault-auth-tee-flake.overlays.default
rust-overlay.overlays.default
# somehow the original `src` is not available anymore
(final: prev: { teepotCrate = prev.pkgs.callPackage ./teepot-crate.nix { inherit inputs; inherit src; }; })
];

alias = {
Expand Down
6 changes: 3 additions & 3 deletions packages/cargoClippy/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ teepotCrate }: teepotCrate.craneLib.cargoClippy (
teepotCrate.commonArgs // {
{ teepot }: teepot.teepotCrate.craneLib.cargoClippy (
teepot.teepotCrate.commonArgs // {
pname = "teepot";
inherit (teepotCrate) cargoArtifacts NIX_OUTPATH_USED_AS_RANDOM_SEED;
inherit (teepot.teepotCrate) cargoArtifacts NIX_OUTPATH_USED_AS_RANDOM_SEED;
}
)
4 changes: 2 additions & 2 deletions packages/cargoDeny/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ teepotCrate }: teepotCrate.craneLib.cargoDeny (
teepotCrate.commonArgs // {
{ teepot }: teepot.teepotCrate.craneLib.cargoDeny (
teepot.teepotCrate.commonArgs // {
pname = "teepot";
}
)
4 changes: 2 additions & 2 deletions packages/cargoFmt/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ teepotCrate }: teepotCrate.craneLib.cargoFmt (
teepotCrate.commonArgs // {
{ teepot }: teepot.teepotCrate.craneLib.cargoFmt (
teepot.teepotCrate.commonArgs // {
pname = "teepot";
}
)
17 changes: 4 additions & 13 deletions packages/teepot/default.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
{ teepotCrate }: teepotCrate.craneLib.buildPackage (
teepotCrate.commonArgs // {
{ teepot }: teepot.teepotCrate.craneLib.buildPackage (
teepot.teepotCrate.commonArgs // {
pname = "teepot";
inherit (teepotCrate) cargoArtifacts
inherit (teepot.teepotCrate) cargoArtifacts
NIX_OUTPATH_USED_AS_RANDOM_SEED;


passthru = {
inherit (teepotCrate) rustPlatform
rustVersion
commonArgs
craneLib
cargoArtifacts;
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
};

outputs = [
"out"
"tee_key_preexec"
Expand All @@ -30,6 +20,7 @@
"vault_unseal"
"verify_attestation"
];

postInstall = ''
removeReferencesToVendoredSources "$out" "$cargoVendorDir"
mkdir -p $out/nix-support
Expand Down
27 changes: 8 additions & 19 deletions teepot-crate.nix → packages/teepotCrate/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Matter Labs
#
# Common teepot crate build parameters shared across cargo* checks and main teepot build
#
{ lib
, pkgs
, inputs
, makeRustPlatform
, nixsgx
, pkg-config
, rust-bin
, pkgs
, src
, ...
}:
let
rustVersion = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustVersion = rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml;
rustPlatform = makeRustPlatform {
cargo = rustVersion;
rustc = rustVersion;
Expand All @@ -31,19 +32,7 @@ let

strictDeps = true;


src = with lib.fileset; toSource {
root = src;
fileset = unions [
./Cargo.lock
./Cargo.toml
./bin
./crates
./rust-toolchain.toml
./deny.toml
./taplo.toml
];
};
src = inputs.crate_src lib;

checkType = "debug";
};
Expand All @@ -58,6 +47,6 @@ in
rustVersion
commonArgs
craneLib
cargoArtifacts;
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
cargoArtifacts
NIX_OUTPATH_USED_AS_RANDOM_SEED;
}

0 comments on commit 1cac5b9

Please sign in to comment.