Skip to content

Commit

Permalink
feat: full reproducibility
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Nov 25, 2024
1 parent e71d737 commit 8771ae3
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"rust-analyzer.cargo.features": "all",
"rust-analyzer.check.command": "clippy",
"evenBetterToml.schema.enabled": true,
"files.associations": {
"biome.json": "jsonc"
Expand Down
17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

[workspace]
resolver = "2"
members = [
#
"launcher",
]

[workspace.package]
version = "0.1.0"
edition = "2024"
repository = "https://github.com/unionlabs/tools"

[workspace.lints.rust]
[workspace]
resolver = "2"
members = ["crates/*"]

[workspace.lints]
rust.unreachable_pub = "warn"
rust.unused_must_use = "deny"

[workspace.lints.clippy]

[workspace.metadata.crane]
Expand Down
8 changes: 4 additions & 4 deletions launcher/Cargo.toml → crates/launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ name = "launcher"
version.workspace = true
edition.workspace = true
repository.workspace = true
description = "Launches vscode server in the browser"

[dependencies]
clap = { version = "4.5.21", features = ["derive", "cargo"] }
description = "Full fledged VSCode with everything you need to ship"

[lints]
workspace = true

[dependencies]
clap = { version = "4.5.21", features = ["derive", "cargo"] }
File renamed without changes.
70 changes: 39 additions & 31 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 36 additions & 47 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
inputs.nixpkgs.follows = "nixpkgs";
};

flake-utils.url = "github:numtide/flake-utils";

flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -19,20 +26,9 @@
inputs.nixpkgs.follows = "nixpkgs";
};

crane = {
url = "github:ipetkov/crane";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};

flake-parts.url = "github:hercules-ci/flake-parts";
crane.url = "github:ipetkov/crane";

flake-utils.url = "github:numtide/flake-utils";

advisory-db.url = "github:rustsec/advisory-db";
advisory-db.flake = false;
treefmt-nix.url = "github:numtide/treefmt-nix";
};

outputs =
Expand All @@ -43,29 +39,32 @@
devenv,
nixpkgs,
flake-utils,
advisory-db,
rust-overlay,
...
}@inputs:

flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib;
/**
crane setup start
this follows crane's official "workspace" guide
https://crane.dev/examples/quick-start-workspace.html
- crane setup start
this follows crane's official "workspace" guide
https://crane.dev/examples/quick-start-workspace.html
- in order to use rust nightly, we use fenix to override the toolchain
https://github.com/nix-community/fenix#examples
*/
craneLib = (crane.mkLib pkgs).overrideToolchain fenix.packages.${system}.minimal.toolchain;

src = craneLib.cleanCargoSource ./.;

# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;

buildInputs =
[
# Add additional build inputs here
Expand All @@ -74,13 +73,9 @@
# Additional darwin specific inputs can be set here
pkgs.libiconv
];

# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
ZKGM = "ZKGM";
};

# in order to use rust nightly, we use fenix to override the toolchain
# https://github.com/nix-community/fenix#examples
craneLibLLvmTools = craneLib.overrideToolchain (
fenix.packages.${system}.complete.withComponents [
"cargo"
Expand Down Expand Up @@ -119,9 +114,9 @@
launcher = craneLib.buildPackage (
individualCrateArgs
// {
pname = (lib.importTOML ./launcher/Cargo.toml).package.name;
pname = (lib.importTOML ./crates/launcher/Cargo.toml).package.name;
cargoExtraArgs = "--workspace";
src = fileSetForCrate ./launcher;
src = fileSetForCrate ./crates/launcher;
}
);
in
Expand All @@ -143,23 +138,14 @@
inherit cargoArtifacts;
}
);

my-workspace-fmt = craneLib.cargoFmt {
inherit src;
};

my-workspace-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
};

# TODO: add cargo-hakari and cargo-nextest
};

packages =
{
inherit launcher;
devenv-test = self.devShells.${system}.default.config.test;
devenv-up = self.devShells.${system}.default.config.procfileScript;
}
// lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
my-workspace-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (
Expand All @@ -168,22 +154,25 @@
inherit cargoArtifacts;
}
);

ucode = pkgs.writeShellApplication {
name = "ucode";
runtimeInputs = [
self.packages.${system}.launcher
];
text = ''
launcher "$@"
'';
};
};

apps = {
launcher = flake-utils.lib.mkApp {
drv = launcher;
};
};

ucode = pkgs.writeShellApplication {
name = "ucode";
runtimeInputs = [ pkgs.openvscode-server ];
text = ''
openvscode-server --update-extensions --disable-telemetry --disable-telemetry --accept-server-license-terms --start-server "$@"
'';
};
devenv-test = self.devShells.${system}.default.config.test;
devenv-up = self.devShells.${system}.default.config.procfileScript;
# devenv https://devenv.sh
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
max_width = 100
array_width = 100
comment_width = 100
reorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
format_code_in_doc_comments = true
8 changes: 7 additions & 1 deletion tasks.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
fmt.exec = ''
taplo fmt *.toml
taplo fmt *.tomil
nixfmt *.nix --width=100
biome format . --write
cargo fmt --all -- --config-path=rustfmt.toml
Expand All @@ -20,6 +20,12 @@
spellcheck
build-all
'';
build-crane.exec = ''
nix build .#launcher --accept-flake-config
'';
ucode.exec = ''
nix run .#ucode -- "$@"
'';
# options:
# $WORKSPACE
build.exec = ''
Expand Down

0 comments on commit 8771ae3

Please sign in to comment.