Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hack): Make cachix available at compile time #331

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/omnix-ci/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ in
INSPECT_FLAKE
NIX_SYSTEMS
;
inherit (rust-project.crates."omnix-health".crane.args)
CACHIX_BIN
;
DEVOUR_FLAKE = inputs.devour-flake;

# This value is set in omnix-cli/crate.nix.
Expand Down
4 changes: 3 additions & 1 deletion crates/omnix-cli/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ in
# > error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin`
(if (stdenv.isDarwin && stdenv.isAarch64) then pkgsStatic.libiconv else pkgs.libiconv)
pkgs.pkg-config
pkgs.cachix
];
buildInputs = lib.optionals pkgs.stdenv.isDarwin
(
Expand All @@ -49,6 +48,9 @@ in
inherit (rust-project.crates."omnix-init".crane.args)
OM_INIT_REGISTRY
;
inherit (rust-project.crates."omnix-health".crane.args)
CACHIX_BIN
;

# To avoid unnecessary rebuilds, start from cleaned source, and then add the Nix files necessary to `nix run` it. Finally, add any files required by the Rust build.
OMNIX_SOURCE = lib.cleanSourceWith {
Expand Down
4 changes: 3 additions & 1 deletion crates/omnix-hack/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
IOKit
]
);
nativeBuildInputs = [ pkgs.cachix ];
inherit (rust-project.crates."nix_rs".crane.args)
DEFAULT_FLAKE_SCHEMAS
INSPECT_FLAKE
NIX_SYSTEMS
;
inherit (rust-project.crates."omnix-health".crane.args)
CACHIX_BIN
;
};
}
1 change: 1 addition & 0 deletions crates/omnix-health/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in
INSPECT_FLAKE
NIX_SYSTEMS
;
CACHIX_BIN = lib.getExe pkgs.cachix;
nativeBuildInputs = with pkgs; [
nix # Tests need nix cli
];
Expand Down
2 changes: 1 addition & 1 deletion crates/omnix-health/src/check/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl CachixCache {

/// Run `cachix use` for this cache
pub async fn cachix_use(&self) -> anyhow::Result<()> {
let mut cmd = tokio::process::Command::new("cachix");
let mut cmd = tokio::process::Command::new(env!("CACHIX_BIN"));
cmd.arg("use").arg(&self.0);
let status = cmd.spawn()?.wait().await?;
if !status.success() {
Expand Down
10 changes: 8 additions & 2 deletions nix/modules/flake-parts/closure-size.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{ ... }:

let
maxSizeInMB = 60;

maxSize = 1000000 * maxSizeInMB.total;
maxSizeInMB = rec {
total = omnix + cachix;
omnix = 60;
cachix = 150;
};
in
{
perSystem = { pkgs, ... }: {
Expand All @@ -13,7 +19,7 @@ in
meta.description = "Check that omnix's nix closure size remains reasonably small";
text = ''
set -o pipefail
MAX_CLOSURE_SIZE=$(echo "${builtins.toString maxSizeInMB} * 1000000" | bc)
MAX_CLOSURE_SIZE=${builtins.toString maxSize}
CLOSURE_SIZE=$(nix path-info --json -S .#default | jq '.[0]'.closureSize)
echo "Omnix closure size: $CLOSURE_SIZE"
echo " Max closure size: $MAX_CLOSURE_SIZE"
Expand Down
1 change: 1 addition & 0 deletions nix/modules/flake-parts/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ in
INSPECT_FLAKE
OMNIX_SOURCE
OM_INIT_REGISTRY
CACHIX_BIN
;

packages = with pkgs; [
Expand Down