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

nix: Restrict OMNIX_SOURCE further to avoid rebuilds #335

Merged
merged 3 commits into from
Oct 26, 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
11 changes: 1 addition & 10 deletions crates/omnix-cli/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ in
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 {
src = inputs.self;
filter = path: type:
rust-project.crane-lib.filterCargoSources path type
|| lib.hasSuffix ".nix" path
|| lib.hasSuffix "flake.lock" path
|| lib.hasSuffix "registry.json" path
;
};
OMNIX_SOURCE = rust-project.src;

# Disable tests due to sandboxing issues; we run them on CI
# instead.
Expand Down
8 changes: 4 additions & 4 deletions nix/modules/flake-parts/om.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
# name = "default";
args = [ "show" "." ];
};
build-omnix-source = {
type = "app";
name = "build-omnix-source";
};
binary-size-is-small = {
type = "app";
name = "check-closure-size";
systems = [ "x86_64-linux" ]; # We have static binary for Linux only.
};
omnix-source-is-buildable = {
type = "app";
name = "omnix-source-is-buildable";
};
cargo-tests = {
type = "devshell";
command = [ "just" "cargo-test" ];
Expand Down
56 changes: 43 additions & 13 deletions nix/modules/flake-parts/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,42 @@
inputs.process-compose-flake.flakeModule
inputs.cargo-doc-live.flakeModule
];
perSystem = { config, self', pkgs, ... }: {
perSystem = { config, self', pkgs, lib, ... }: {
cargo-doc-live.crateName = "omnix-gui";

rust-project = {
# See /crates/*/crate.nix for the crate-specific Nix configuration
crateNixFile = "crate.nix";

# 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.
src =
let
# Like crane's filterCargoSources, but doesn't blindly include all TOML files!
filterCargoSources = path: type:
config.rust-project.crane-lib.filterCargoSources path type
&& !(lib.hasSuffix ".toml" path && !lib.hasSuffix "Cargo.toml" path);
in
lib.cleanSourceWith {
src = inputs.self;
filter = path: type:
filterCargoSources path type
|| lib.hasSuffix "registry.json" path
|| lib.hasSuffix "crate.nix" path
|| "${inputs.self}/flake.nix" == path
|| "${inputs.self}/flake.lock" == path
|| "${inputs.self}/rust-toolchain.toml" == path
# Select *only* the non-Rust files necessary to build omnix package.
|| lib.hasSuffix "flake-parts/nixpkgs.nix" path
|| lib.hasSuffix "flake-parts/rust.nix" path
|| lib.hasSuffix "tests/flake.nix" path
|| lib.hasSuffix "tests/flake.lock" path
|| lib.hasSuffix "failing/flake.nix" path
|| lib.hasSuffix "registry/flake.nix" path
|| lib.hasSuffix "registry/flake.lock" path
|| lib.hasSuffix "flake-schemas/flake.nix" path
|| lib.hasSuffix "flake-schemas/flake.lock" path
;
};
};

packages =
Expand All @@ -33,18 +63,18 @@
});
};

# Make sure that `OMNIX_SOURCE` is buildable.
# We must check this in CI, because it is built only during runtime otherwise (as part of `om ci run --on`).
apps.build-omnix-source = {
meta.description = "Build OMNIX_SOURCE";
program = pkgs.writeShellApplication {
name = "build-omnix-source";
runtimeInputs = [ pkgs.nix ];
text = ''
set -x
nix build -L --no-link --print-out-paths ${self'.packages.omnix-cli.OMNIX_SOURCE.outPath}
'';
};
apps.omnix-source-is-buildable.program = pkgs.writeShellApplication {
name = "omnix-source-is-buildable";
runtimeInputs = [
pkgs.jq
];
text = ''
set -e
cd ${self'.packages.omnix-cli.OMNIX_SOURCE.outPath}
# Make sure the drv evaluates (to test that no files are accidentally excluded)
nix --accept-flake-config --extra-experimental-features "flakes nix-command" \
derivation show "." | jq -r '.[].outputs.out.path'
'';
};
};
}