From 68df59ad25563b812829651e90ae1865bbeb42b0 Mon Sep 17 00:00:00 2001 From: cy Date: Wed, 7 May 2025 17:14:25 -0400 Subject: [PATCH 1/9] use & instead of as_slice() --- src/push.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/push.rs b/src/push.rs index bf25ea1..7c23e39 100644 --- a/src/push.rs +++ b/src/push.rs @@ -132,10 +132,7 @@ impl Push { let inflight_permits = inflight_permits.clone(); tokio::spawn(async move { let _permit = inflight_permits.acquire().await.unwrap(); - if !path - .check_upstream_hit(self.upstream_caches.as_slice()) - .await - { + if !path.check_upstream_hit(&self.upstream_caches).await { if path.check_if_already_exists(&self.s3).await { debug!("skip {} (already exists)", path.absolute_path()); self.already_exists_count.fetch_add(1, Ordering::Relaxed); From ce0e70f95a5c45ad5082364bece63bb3883191dd Mon Sep 17 00:00:00 2001 From: cy Date: Wed, 7 May 2025 17:14:25 -0400 Subject: [PATCH 2/9] add option to disable cache.nixos.org --- README.md | 4 ++-- src/lib.rs | 3 ++- src/push.rs | 13 +++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 55fdaef..f9317c8 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Options: If unspecified, will get it form AWS_DEFAULT_REGION envar or default to us-east-1 --endpoint If unspecifed, will get it from AWS_ENDPOINT envar e.g. https://s3.example.com - --skip-signature-check - + --no-default-upstream + Do not include cache.nixos.org as upstream -h, --help Print help ``` diff --git a/src/lib.rs b/src/lib.rs index dfbab4f..fa4a43d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,8 +55,9 @@ pub struct PushArgs { #[arg(long)] endpoint: Option, + /// Do not include cache.nixos.org as upstream #[arg(long)] - skip_signature_check: bool, + no_default_upstream: bool, /// Path to upload /// e.g. ./result or /nix/store/y4qpcibkj767szhjb58i2sidmz8m24hb-hello-2.12.1 diff --git a/src/push.rs b/src/push.rs index 7c23e39..9fc043d 100644 --- a/src/push.rs +++ b/src/push.rs @@ -1,7 +1,6 @@ use std::{ collections::HashSet, fs, - iter::once, path::PathBuf, sync::{ Arc, @@ -39,11 +38,13 @@ pub struct Push { impl Push { pub async fn new(cli: &PushArgs, store: Store) -> Result { let mut upstreams = Vec::with_capacity(cli.upstreams.len() + 1); - for upstream in cli - .upstreams - .iter() - .chain(once(&"https://cache.nixos.org".to_string())) - { + if !cli.no_default_upstream { + upstreams.push( + Url::parse("https://cache.nixos.org") + .expect("default upstream must be a valid url"), + ); + } + for upstream in &cli.upstreams { upstreams .push(Url::parse(upstream).context(format!("failed to parse {upstream} as url"))?); } From 112654f4480596d9a22014d0fa6b2065ef4c7ea6 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 00:32:41 -0400 Subject: [PATCH 3/9] add flake checks and formatter, run some formatters --- flake.nix | 50 ++++++++++++++++++++++++++++++++++++--------- rust-toolchain.toml | 7 +------ src/cli.rs | 2 -- src/lib.rs | 1 - 4 files changed, 41 insertions(+), 19 deletions(-) delete mode 100644 src/cli.rs diff --git a/flake.nix b/flake.nix index 2d1191f..6e1b9d6 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,15 @@ }; }; - outputs = inputs@{ nixpkgs, flake-utils, crane, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + inputs@{ + nixpkgs, + flake-utils, + crane, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = import nixpkgs { inherit system; @@ -21,13 +28,12 @@ ]; }; toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - craneLib = (crane.mkLib pkgs).overrideToolchain(_: toolchain); + craneLib = (crane.mkLib pkgs).overrideToolchain (_: toolchain); lib = pkgs.lib; # don't clean cpp files cppFilter = path: _type: builtins.match ".*(cpp|hpp)$" path != null; - cppOrCargo = path: type: - (cppFilter path type) || (craneLib.filterCargoSources path type); + cppOrCargo = path: type: (cppFilter path type) || (craneLib.filterCargoSources path type); src = lib.cleanSourceWith { src = ./.; filter = cppOrCargo; @@ -48,16 +54,38 @@ ]; # for cpp bindings to work NIX_INCLUDE_PATH = "${lib.getDev pkgs.nix}/include"; - # skip integration tests (they need a connection to the nix store) - cargoTestExtraArgs = "--bins"; + # skip integration tests (they need a connection to the nix store) + cargoTestExtraArgs = "--bins"; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; - nixcp = craneLib.buildPackage (commonArgs // { - inherit cargoArtifacts; - }); + nixcp = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + } + ); in { + checks = { + # clippy with all warnings denied + clippy = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + # check formatting + cargoFmt = craneLib.cargoFmt { + inherit src; + }; + tomlFmt = craneLib.taploFmt { + src = lib.sources.sourceFilesBySuffices src [ ".toml" ]; + }; + }; + devShells.default = craneLib.devShell { inputsFrom = [ nixcp ]; @@ -71,6 +99,8 @@ ]; }; + formatter = pkgs.nixfmt-rfc-style; + packages.default = nixcp; } ); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index eceaf24..c96aa24 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,9 +1,4 @@ [toolchain] channel = "nightly" profile = "minimal" -components = [ - "rust-src", - "rust-analyzer", - "rustfmt", - "clippy", -] \ No newline at end of file +components = ["rust-src", "rust-analyzer", "rustfmt", "clippy"] diff --git a/src/cli.rs b/src/cli.rs deleted file mode 100644 index 139597f..0000000 --- a/src/cli.rs +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src/lib.rs b/src/lib.rs index fa4a43d..8b1fc18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; mod bindings; -mod cli; pub mod make_nar; pub mod path_info; pub mod push; From 2b52792959ab518b1ef097c71d97b1412138c3f3 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 01:01:01 -0400 Subject: [PATCH 4/9] add flake check workflow --- .github/workflows/check.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..896aad1 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,25 @@ +name: check +on: + workflow_dispatch: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Install Nix + uses: cachix/install-nix-action@v30 + with: + enable_kvm: true + extra_nix_config: | + show-trace = true + experimental-features = nix-command flakes + extra-substituters = https://nixcache.cy7.sh + extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8= + + - uses: actions/checkout@v4 + + - name: Run checks + run: nix flake check -L From a9957162128440ca41917054a413b8041230523b Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 01:04:15 -0400 Subject: [PATCH 5/9] pin workflows by sha --- .github/workflows/build.yml | 7 +++---- .github/workflows/check.yml | 6 ++++-- .github/workflows/test.yml | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8332f1c..090eec8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: run: echo -n "${{ secrets.NIX_CACHE_SECRET_KEY }}" | xxd -p -r > ${{ runner.temp }}/cache-priv-key.pem - name: Install Nix - uses: cachix/install-nix-action@v30 + uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641 with: enable_kvm: true extra_nix_config: | @@ -35,8 +35,7 @@ jobs: extra-substituters = https://nixcache.cy7.sh extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8= - - name: Sync repository - uses: actions/checkout@v4 + - uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 with: persist-credentials: false @@ -54,7 +53,7 @@ jobs: run: nix run github:nixos/nixpkgs#gnutar hcvf result.tar result - name: upload result - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47 with: name: ${{ matrix.os }}.tar path: result.tar diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 896aad1..0b9ac66 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Install Nix - uses: cachix/install-nix-action@v30 + uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641 with: enable_kvm: true extra_nix_config: | @@ -19,7 +19,9 @@ jobs: extra-substituters = https://nixcache.cy7.sh extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8= - - uses: actions/checkout@v4 + - uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 + with: + persist-credentials: false - name: Run checks run: nix flake check -L diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 12ef747..cc7fabc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Install Nix - uses: cachix/install-nix-action@v30 + uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641 with: enable_kvm: true extra_nix_config: | @@ -22,7 +22,9 @@ jobs: extra-substituters = https://nixcache.cy7.sh extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8= - - uses: actions/checkout@v4 + - uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 + with: + persist-credentials: false - name: Run tests run: nix develop -c cargo test --verbose From ab1fcc820760b93dd87e74a4a5652c726d7d6566 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 01:19:53 -0400 Subject: [PATCH 6/9] run builds on mac --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 090eec8..a9864f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,9 @@ jobs: os: - ubuntu-latest - ubuntu-24.04-arm + - macos-latest # arm64 + - macos-13 # x86 + runs-on: ${{ matrix.os }} steps: From 8ba2c6cc9bf7004eb812dafc971a321e108eef84 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 01:22:03 -0400 Subject: [PATCH 7/9] cache devshell in ci --- .github/workflows/build.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9864f3..b9be0e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,17 @@ jobs: with: persist-credentials: false - - run: nix build -L . + - name: cache devshell + run: | + nix build .#devShells.$(nix eval --impure --raw --expr 'builtins.currentSystem').default + nix run \ + github:cything/nixcp/test-in-ci -- push \ + --bucket nixcache \ + --signing-key ${{ runner.temp }}/cache-priv-key.pem \ + result + + - name: build + run: nix build -L . - name: cache run: | From 139dcf2fe73c51b73158a6dbda132dcf5c2728d3 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 01:22:51 -0400 Subject: [PATCH 8/9] use main branch in ci --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9be0e9..a4560bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: run: | nix build .#devShells.$(nix eval --impure --raw --expr 'builtins.currentSystem').default nix run \ - github:cything/nixcp/test-in-ci -- push \ + github:cything/nixcp -- push \ --bucket nixcache \ --signing-key ${{ runner.temp }}/cache-priv-key.pem \ result @@ -57,7 +57,7 @@ jobs: - name: cache run: | nix run \ - github:cything/nixcp/test-in-ci -- push \ + github:cything/nixcp -- push \ --bucket nixcache \ --signing-key ${{ runner.temp }}/cache-priv-key.pem \ result From 885a49701c8f0de204467fcbe0089b67a5cf1c09 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 01:34:12 -0400 Subject: [PATCH 9/9] add cargo-audit to devshell --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 6e1b9d6..16b57e6 100644 --- a/flake.nix +++ b/flake.nix @@ -96,6 +96,7 @@ packages = with pkgs; [ tokio-console cargo-udeps + cargo-audit ]; };