Compare commits
9 commits
76e6c6c537
...
885a49701c
Author | SHA1 | Date | |
---|---|---|---|
885a49701c | |||
139dcf2fe7 | |||
8ba2c6cc9b | |||
ab1fcc8207 | |||
a995716212 | |||
2b52792959 | |||
112654f448 | |||
ce0e70f95a | |||
68df59ad25 |
9 changed files with 103 additions and 40 deletions
24
.github/workflows/build.yml
vendored
24
.github/workflows/build.yml
vendored
|
@ -18,6 +18,9 @@ jobs:
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- ubuntu-24.04-arm
|
- ubuntu-24.04-arm
|
||||||
|
- macos-latest # arm64
|
||||||
|
- macos-13 # x86
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -25,7 +28,7 @@ jobs:
|
||||||
run: echo -n "${{ secrets.NIX_CACHE_SECRET_KEY }}" | xxd -p -r > ${{ runner.temp }}/cache-priv-key.pem
|
run: echo -n "${{ secrets.NIX_CACHE_SECRET_KEY }}" | xxd -p -r > ${{ runner.temp }}/cache-priv-key.pem
|
||||||
|
|
||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: cachix/install-nix-action@v30
|
uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641
|
||||||
with:
|
with:
|
||||||
enable_kvm: true
|
enable_kvm: true
|
||||||
extra_nix_config: |
|
extra_nix_config: |
|
||||||
|
@ -35,17 +38,26 @@ jobs:
|
||||||
extra-substituters = https://nixcache.cy7.sh
|
extra-substituters = https://nixcache.cy7.sh
|
||||||
extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8=
|
extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8=
|
||||||
|
|
||||||
- name: Sync repository
|
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
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 -- push \
|
||||||
|
--bucket nixcache \
|
||||||
|
--signing-key ${{ runner.temp }}/cache-priv-key.pem \
|
||||||
|
result
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
run: nix build -L .
|
||||||
|
|
||||||
- name: cache
|
- name: cache
|
||||||
run: |
|
run: |
|
||||||
nix run \
|
nix run \
|
||||||
github:cything/nixcp/test-in-ci -- push \
|
github:cything/nixcp -- push \
|
||||||
--bucket nixcache \
|
--bucket nixcache \
|
||||||
--signing-key ${{ runner.temp }}/cache-priv-key.pem \
|
--signing-key ${{ runner.temp }}/cache-priv-key.pem \
|
||||||
result
|
result
|
||||||
|
@ -54,7 +66,7 @@ jobs:
|
||||||
run: nix run github:nixos/nixpkgs#gnutar hcvf result.tar result
|
run: nix run github:nixos/nixpkgs#gnutar hcvf result.tar result
|
||||||
|
|
||||||
- name: upload result
|
- name: upload result
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.os }}.tar
|
name: ${{ matrix.os }}.tar
|
||||||
path: result.tar
|
path: result.tar
|
||||||
|
|
27
.github/workflows/check.yml
vendored
Normal file
27
.github/workflows/check.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
name: check
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install Nix
|
||||||
|
uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641
|
||||||
|
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@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Run checks
|
||||||
|
run: nix flake check -L
|
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: cachix/install-nix-action@v30
|
uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641
|
||||||
with:
|
with:
|
||||||
enable_kvm: true
|
enable_kvm: true
|
||||||
extra_nix_config: |
|
extra_nix_config: |
|
||||||
|
@ -22,7 +22,9 @@ jobs:
|
||||||
extra-substituters = https://nixcache.cy7.sh
|
extra-substituters = https://nixcache.cy7.sh
|
||||||
extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8=
|
extra-trusted-public-keys = nixcache.cy7.sh:DN3d1dt0wnXfTH03oVmTee4KgmdNdB0NY3SuzA8Fwx8=
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: nix develop -c cargo test --verbose
|
run: nix develop -c cargo test --verbose
|
||||||
|
|
|
@ -30,8 +30,8 @@ Options:
|
||||||
If unspecified, will get it form AWS_DEFAULT_REGION envar or default to us-east-1
|
If unspecified, will get it form AWS_DEFAULT_REGION envar or default to us-east-1
|
||||||
--endpoint <ENDPOINT>
|
--endpoint <ENDPOINT>
|
||||||
If unspecifed, will get it from AWS_ENDPOINT envar e.g. https://s3.example.com
|
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
|
-h, --help
|
||||||
Print help
|
Print help
|
||||||
```
|
```
|
||||||
|
|
51
flake.nix
51
flake.nix
|
@ -11,8 +11,15 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs@{ nixpkgs, flake-utils, crane, ... }:
|
outputs =
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
inputs@{
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
crane,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
@ -21,13 +28,12 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||||
craneLib = (crane.mkLib pkgs).overrideToolchain(_: toolchain);
|
craneLib = (crane.mkLib pkgs).overrideToolchain (_: toolchain);
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
|
|
||||||
# don't clean cpp files
|
# don't clean cpp files
|
||||||
cppFilter = path: _type: builtins.match ".*(cpp|hpp)$" path != null;
|
cppFilter = path: _type: builtins.match ".*(cpp|hpp)$" path != null;
|
||||||
cppOrCargo = path: type:
|
cppOrCargo = path: type: (cppFilter path type) || (craneLib.filterCargoSources path type);
|
||||||
(cppFilter path type) || (craneLib.filterCargoSources path type);
|
|
||||||
src = lib.cleanSourceWith {
|
src = lib.cleanSourceWith {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
filter = cppOrCargo;
|
filter = cppOrCargo;
|
||||||
|
@ -48,16 +54,38 @@
|
||||||
];
|
];
|
||||||
# for cpp bindings to work
|
# for cpp bindings to work
|
||||||
NIX_INCLUDE_PATH = "${lib.getDev pkgs.nix}/include";
|
NIX_INCLUDE_PATH = "${lib.getDev pkgs.nix}/include";
|
||||||
# skip integration tests (they need a connection to the nix store)
|
# skip integration tests (they need a connection to the nix store)
|
||||||
cargoTestExtraArgs = "--bins";
|
cargoTestExtraArgs = "--bins";
|
||||||
};
|
};
|
||||||
|
|
||||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||||
nixcp = craneLib.buildPackage (commonArgs // {
|
nixcp = craneLib.buildPackage (
|
||||||
inherit cargoArtifacts;
|
commonArgs
|
||||||
});
|
// {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
}
|
||||||
|
);
|
||||||
in
|
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 {
|
devShells.default = craneLib.devShell {
|
||||||
inputsFrom = [ nixcp ];
|
inputsFrom = [ nixcp ];
|
||||||
|
|
||||||
|
@ -68,9 +96,12 @@
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
tokio-console
|
tokio-console
|
||||||
cargo-udeps
|
cargo-udeps
|
||||||
|
cargo-audit
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
formatter = pkgs.nixfmt-rfc-style;
|
||||||
|
|
||||||
packages.default = nixcp;
|
packages.default = nixcp;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly"
|
channel = "nightly"
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
components = [
|
components = ["rust-src", "rust-analyzer", "rustfmt", "clippy"]
|
||||||
"rust-src",
|
|
||||||
"rust-analyzer",
|
|
||||||
"rustfmt",
|
|
||||||
"clippy",
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::path::PathBuf;
|
||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
|
|
||||||
mod bindings;
|
mod bindings;
|
||||||
mod cli;
|
|
||||||
pub mod make_nar;
|
pub mod make_nar;
|
||||||
pub mod path_info;
|
pub mod path_info;
|
||||||
pub mod push;
|
pub mod push;
|
||||||
|
@ -55,8 +54,9 @@ pub struct PushArgs {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
endpoint: Option<String>,
|
endpoint: Option<String>,
|
||||||
|
|
||||||
|
/// Do not include cache.nixos.org as upstream
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
skip_signature_check: bool,
|
no_default_upstream: bool,
|
||||||
|
|
||||||
/// Path to upload
|
/// Path to upload
|
||||||
/// e.g. ./result or /nix/store/y4qpcibkj767szhjb58i2sidmz8m24hb-hello-2.12.1
|
/// e.g. ./result or /nix/store/y4qpcibkj767szhjb58i2sidmz8m24hb-hello-2.12.1
|
||||||
|
|
18
src/push.rs
18
src/push.rs
|
@ -1,7 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fs,
|
fs,
|
||||||
iter::once,
|
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{
|
sync::{
|
||||||
Arc,
|
Arc,
|
||||||
|
@ -39,11 +38,13 @@ pub struct Push {
|
||||||
impl Push {
|
impl Push {
|
||||||
pub async fn new(cli: &PushArgs, store: Store) -> Result<Self> {
|
pub async fn new(cli: &PushArgs, store: Store) -> Result<Self> {
|
||||||
let mut upstreams = Vec::with_capacity(cli.upstreams.len() + 1);
|
let mut upstreams = Vec::with_capacity(cli.upstreams.len() + 1);
|
||||||
for upstream in cli
|
if !cli.no_default_upstream {
|
||||||
.upstreams
|
upstreams.push(
|
||||||
.iter()
|
Url::parse("https://cache.nixos.org")
|
||||||
.chain(once(&"https://cache.nixos.org".to_string()))
|
.expect("default upstream must be a valid url"),
|
||||||
{
|
);
|
||||||
|
}
|
||||||
|
for upstream in &cli.upstreams {
|
||||||
upstreams
|
upstreams
|
||||||
.push(Url::parse(upstream).context(format!("failed to parse {upstream} as url"))?);
|
.push(Url::parse(upstream).context(format!("failed to parse {upstream} as url"))?);
|
||||||
}
|
}
|
||||||
|
@ -132,10 +133,7 @@ impl Push {
|
||||||
let inflight_permits = inflight_permits.clone();
|
let inflight_permits = inflight_permits.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let _permit = inflight_permits.acquire().await.unwrap();
|
let _permit = inflight_permits.acquire().await.unwrap();
|
||||||
if !path
|
if !path.check_upstream_hit(&self.upstream_caches).await {
|
||||||
.check_upstream_hit(self.upstream_caches.as_slice())
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
if path.check_if_already_exists(&self.s3).await {
|
if path.check_if_already_exists(&self.s3).await {
|
||||||
debug!("skip {} (already exists)", path.absolute_path());
|
debug!("skip {} (already exists)", path.absolute_path());
|
||||||
self.already_exists_count.fetch_add(1, Ordering::Relaxed);
|
self.already_exists_count.fetch_add(1, Ordering::Relaxed);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue