A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #231 from zhaofengli/nix-2.26

Update bindings build for Nix 2.26

authored by

Zhaofeng Li and committed by
GitHub
e11f630a 896ad88f

+124 -233
+2 -1
.github/workflows/build.yml
··· 73 73 - ubuntu-latest 74 74 - macos-latest 75 75 nix: 76 - - "2.20" 77 76 - "2.24" 77 + - "2.25" 78 + - "2.26" 78 79 - "default" 79 80 runs-on: ${{ matrix.os }} 80 81 steps:
+33 -4
Cargo.lock
··· 1 1 # This file is automatically @generated by Cargo. 2 2 # It is not intended for manual editing. 3 - version = 3 3 + version = 4 4 4 5 5 [[package]] 6 6 name = "addr2line" ··· 249 249 "lazy_static", 250 250 "log", 251 251 "nix-base32", 252 - "pkg-config", 253 252 "regex", 254 253 "serde", 255 254 "serde_json", 256 255 "serde_with", 257 256 "serde_yaml", 258 257 "sha2", 258 + "system-deps", 259 259 "tempfile", 260 260 "tokio", 261 261 "version-compare", ··· 1075 1075 ] 1076 1076 1077 1077 [[package]] 1078 + name = "cfg-expr" 1079 + version = "0.17.2" 1080 + source = "registry+https://github.com/rust-lang/crates.io-index" 1081 + checksum = "8d4ba6e40bd1184518716a6e1a781bf9160e286d219ccdb8ab2612e74cfe4789" 1082 + dependencies = [ 1083 + "smallvec", 1084 + "target-lexicon", 1085 + ] 1086 + 1087 + [[package]] 1078 1088 name = "cfg-if" 1079 1089 version = "1.0.0" 1080 1090 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1623 1633 1624 1634 [[package]] 1625 1635 name = "displaydoc" 1626 - version = "0.2.4" 1636 + version = "0.2.5" 1627 1637 source = "registry+https://github.com/rust-lang/crates.io-index" 1628 - checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" 1638 + checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" 1629 1639 dependencies = [ 1630 1640 "proc-macro2", 1631 1641 "quote", ··· 4587 4597 checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" 4588 4598 4589 4599 [[package]] 4600 + name = "system-deps" 4601 + version = "7.0.3" 4602 + source = "registry+https://github.com/rust-lang/crates.io-index" 4603 + checksum = "66d23aaf9f331227789a99e8de4c91bf46703add012bdfd45fdecdfb2975a005" 4604 + dependencies = [ 4605 + "cfg-expr", 4606 + "heck 0.5.0", 4607 + "pkg-config", 4608 + "toml", 4609 + "version-compare", 4610 + ] 4611 + 4612 + [[package]] 4590 4613 name = "tap" 4591 4614 version = "1.0.1" 4592 4615 source = "registry+https://github.com/rust-lang/crates.io-index" 4593 4616 checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" 4617 + 4618 + [[package]] 4619 + name = "target-lexicon" 4620 + version = "0.12.16" 4621 + source = "registry+https://github.com/rust-lang/crates.io-index" 4622 + checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" 4594 4623 4595 4624 [[package]] 4596 4625 name = "tempfile"
+6 -2
attic/Cargo.toml
··· 46 46 [build-dependencies] 47 47 cc = "1.1.13" 48 48 cxx-build = { version = "1.0", optional = true } 49 - pkg-config = "0.3.27" 50 - tempfile = "3" 49 + system-deps = { version = "7.0", optional = true } 51 50 version-compare = "0.2.0" 51 + 52 + [package.metadata.system-deps] 53 + nix-store = { version = "2.24", feature = "nix_store" } 54 + nix-main = { version = "2.24", feature = "nix_store" } 52 55 53 56 [features] 54 57 default = [ ··· 70 73 "tokio/process", 71 74 "dep:cxx", 72 75 "dep:cxx-build", 76 + "dep:system-deps", 73 77 ] 74 78 75 79 # Stream utilities.
+19 -52
attic/build.rs
··· 10 10 #[cfg(feature = "nix_store")] 11 11 mod nix_store { 12 12 use cc::Build; 13 + use system_deps::Dependencies; 13 14 use version_compare::Version; 14 15 15 - struct NixDependency { 16 - version: String, 17 - } 18 - 19 - impl NixDependency { 20 - fn detect() -> Self { 21 - let library = pkg_config::Config::new() 22 - .cargo_metadata(false) 23 - .atleast_version("2.4") 24 - .probe("nix-main") 25 - .expect("Failed to find nix-main >=2.4 through pkg-config"); 26 - 27 - Self { 28 - version: library.version, 29 - } 30 - } 31 - 32 - fn apply_version_flags(&self, build: &mut Build) { 33 - let version = Version::from(&self.version).unwrap(); 16 + fn apply_variant_flags(build: &mut Build, deps: &Dependencies) { 17 + let nix_main = deps 18 + .get_by_name("nix-main") 19 + .expect("Failed to get version of nix-main"); 20 + let version = Version::from(&nix_main.version).unwrap(); 34 21 35 - if version >= Version::from("2.20").unwrap() { 36 - build.flag("-DATTIC_NIX_2_20"); 37 - } 38 - } 22 + build.define("ATTIC_VARIANT_NIX", None); 39 23 40 - fn emit_cargo_metadata(&self) { 41 - pkg_config::Config::new() 42 - .atleast_version("2.4") 43 - .probe("nix-store") 44 - .unwrap(); 45 - 46 - pkg_config::Config::new() 47 - .atleast_version("2.4") 48 - .probe("nix-main") 49 - .unwrap(); 50 - } 24 + let version = if version >= Version::from("2.26").unwrap() { 25 + 226 26 + } else { 27 + 225 28 + }; 29 + build.define("NIX_VERSION", &*format!("{version}")); 51 30 } 52 31 53 32 pub fn build_bridge() { 54 - let nix_dep = NixDependency::detect(); 55 - 56 - // Temporary workaround for issue in <https://github.com/NixOS/nix/pull/8484> 57 - let hacky_include = { 58 - let dir = 59 - tempfile::tempdir().expect("Failed to create temporary directory for workaround"); 60 - std::fs::write(dir.path().join("uds-remote-store.md"), "\"\"").unwrap(); 61 - dir 62 - }; 33 + let deps = system_deps::Config::new().probe().unwrap(); 63 34 64 35 let mut build = cxx_build::bridge("src/nix_store/bindings/mod.rs"); 65 36 build 66 37 .file("src/nix_store/bindings/nix.cpp") 67 38 .flag("-std=c++2a") 68 39 .flag("-O2") 69 - .flag("-include") 70 - .flag("nix/config.h") 71 - .flag("-idirafter") 72 - .flag(hacky_include.path().to_str().unwrap()) 73 - // In Nix 2.19+, nix/args/root.hh depends on being able to #include "args.hh" (which is in its parent directory), for some reason 74 - .flag("-I") 75 - .flag(concat!(env!("NIX_INCLUDE_PATH"), "/nix")); 40 + .includes(deps.all_include_paths()); 76 41 77 - nix_dep.apply_version_flags(&mut build); 42 + apply_variant_flags(&mut build, &deps); 78 43 79 44 build.compile("nixbinding"); 80 45 81 46 println!("cargo:rerun-if-changed=src/nix_store/bindings"); 82 47 83 48 // the -l flags must be after -lnixbinding 84 - nix_dep.emit_cargo_metadata(); 49 + 50 + // HACK: system_deps emits -lnixmain before cc emits -lnixbinding 51 + system_deps::Config::new().probe().unwrap(); 85 52 } 86 53 }
+19
attic/src/nix_store/bindings/nix-includes.hpp
··· 1 + #if defined(ATTIC_VARIANT_NIX) 2 + #if NIX_VERSION >= 226 3 + #include <nix/config-main.hh> 4 + #include <nix/config-store.hh> 5 + #else 6 + #include <nix/config.h> 7 + #endif 8 + 9 + #include <nix/store-api.hh> 10 + #include <nix/local-store.hh> 11 + #include <nix/remote-store.hh> 12 + #include <nix/uds-remote-store.hh> 13 + #include <nix/hash.hh> 14 + #include <nix/path.hh> 15 + #include <nix/serialise.hh> 16 + #include <nix/shared.hh> 17 + #else 18 + #error Unsupported variant 19 + #endif
+5 -8
attic/src/nix_store/bindings/nix.cpp
··· 18 18 return nix::StorePath(sv); 19 19 } 20 20 21 - static bool hash_is_sha256(const nix::Hash &hash) { 22 - #ifdef ATTIC_NIX_2_20 23 - return hash.algo == nix::HashAlgorithm::SHA256; 24 - #else 25 - return hash.type == nix::htSHA256; 26 - #endif 27 - } 28 - 29 21 // ======== 30 22 // RustSink 31 23 // ======== ··· 148 140 nix::StorePath store_path(sv); 149 141 150 142 // exceptions will be thrown into Rust 143 + #ifdef ATTIC_VARIANT_LIX 144 + sink << this->store->narFromPath(store_path); 145 + #else 151 146 this->store->narFromPath(store_path, sink); 147 + #endif 148 + 152 149 sink.eof(); 153 150 } 154 151
+5 -8
attic/src/nix_store/bindings/nix.hpp
··· 13 13 #include <memory> 14 14 #include <mutex> 15 15 #include <set> 16 - #include <nix/store-api.hh> 17 - #include <nix/local-store.hh> 18 - #include <nix/remote-store.hh> 19 - #include <nix/uds-remote-store.hh> 20 - #include <nix/hash.hh> 21 - #include <nix/path.hh> 22 - #include <nix/serialise.hh> 23 - #include <nix/shared.hh> 24 16 #include <rust/cxx.h> 17 + #include "nix-includes.hpp" 25 18 26 19 template<class T> using RVec = rust::Vec<T>; 27 20 template<class T> using RBox = rust::Box<T>; ··· 30 23 using RStr = rust::Str; 31 24 using RBasePathSlice = RSlice<const unsigned char>; 32 25 using RHashSlice = RSlice<const unsigned char>; 26 + 27 + static bool hash_is_sha256(const nix::Hash &hash) { 28 + return hash.algo == nix::HashAlgorithm::SHA256; 29 + } 33 30 34 31 struct AsyncWriteSender; 35 32
+11 -20
crane.nix
··· 1 1 # For distribution from this repository as well as CI, we use Crane to build 2 2 # Attic. 3 - # 4 - # For a nixpkgs-acceptable form of the package expression, see `package.nixpkgs.nix` 5 - # which will be submitted when the Attic API is considered stable. However, that 6 - # expression is not tested by CI so to not slow down the hot path. 7 3 8 4 { stdenv 9 5 , lib ··· 18 14 19 15 , nix 20 16 , boost 21 - , darwin 22 - , libiconv 17 + , libarchive 23 18 24 19 , extraPackageArgs ? {} 25 20 }: ··· 49 44 50 45 buildInputs = [ 51 46 nix boost 52 - ] ++ lib.optionals stdenv.isDarwin [ 53 - darwin.apple_sdk.frameworks.SystemConfiguration 54 - libiconv 47 + libarchive 55 48 ]; 56 49 57 50 crossArgs = let ··· 79 72 installCargoArtifactsMode = "use-zstd"; 80 73 } // extraArgs); 81 74 82 - mkAttic = args: craneLib.buildPackage ({ 75 + mkAttic = { 76 + packages, 77 + }: let 78 + cargoPackageArgs = map (p: "-p ${p}") packages; 79 + in craneLib.buildPackage ({ 83 80 pname = "attic"; 84 81 inherit src version nativeBuildInputs buildInputs cargoArtifacts; 85 82 86 83 ATTIC_DISTRIBUTOR = "attic"; 87 84 88 - # See comment in `attic/build.rs` 89 - NIX_INCLUDE_PATH = "${lib.getDev nix}/include"; 90 - 91 85 # See comment in `attic-tests` 92 86 doCheck = false; 93 87 94 - cargoExtraArgs = "-p attic-client -p attic-server"; 88 + cargoExtraArgs = lib.concatStringsSep " " cargoPackageArgs; 95 89 96 90 postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' 97 91 if [[ -f $out/bin/attic ]]; then ··· 114 108 passthru = { 115 109 inherit nix; 116 110 }; 117 - } // args // extraArgs); 111 + } // extraArgs); 118 112 119 113 attic = mkAttic { 120 - cargoExtraArgs = "-p attic-client -p attic-server"; 114 + packages = ["attic-client" "attic-server"]; 121 115 }; 122 116 123 117 # Client-only package. 124 118 attic-client = mkAttic { 125 - cargoExtraArgs = " -p attic-client"; 119 + packages = ["attic-client"]; 126 120 }; 127 121 128 122 # Server-only package with fat LTO enabled. ··· 170 164 buildPhaseCargoCommand = ""; 171 165 checkPhaseCargoCommand = "cargoWithProfile test --no-run --message-format=json >cargo-test.json"; 172 166 doInstallCargoArtifacts = false; 173 - 174 - # See comment in `attic/build.rs` 175 - NIX_INCLUDE_PATH = "${lib.getDev nix}/include"; 176 167 177 168 installPhase = '' 178 169 runHook preInstall
+6 -11
flake.lock
··· 1 1 { 2 2 "nodes": { 3 3 "crane": { 4 - "inputs": { 5 - "nixpkgs": [ 6 - "nixpkgs" 7 - ] 8 - }, 9 4 "locked": { 10 - "lastModified": 1722960479, 11 - "narHash": "sha256-NhCkJJQhD5GUib8zN9JrmYGMwt4lCRp6ZVNzIiYCl0Y=", 5 + "lastModified": 1742143293, 6 + "narHash": "sha256-8oKPsMlqlOQ7qnTWvhBEcfVFY1WqHIcSilGVtaLAquw=", 12 7 "owner": "ipetkov", 13 8 "repo": "crane", 14 - "rev": "4c6c77920b8d44cd6660c1621dea6b3fc4b4c4f4", 9 + "rev": "de3bb0155823298161c1c0a7805f10d4b4074bbb", 15 10 "type": "github" 16 11 }, 17 12 "original": { ··· 78 73 }, 79 74 "nixpkgs": { 80 75 "locked": { 81 - "lastModified": 1726042813, 82 - "narHash": "sha256-LnNKCCxnwgF+575y0pxUdlGZBO/ru1CtGHIqQVfvjlA=", 76 + "lastModified": 1741865919, 77 + "narHash": "sha256-4thdbnP6dlbdq+qZWTsm4ffAwoS8Tiq1YResB+RP6WE=", 83 78 "owner": "NixOS", 84 79 "repo": "nixpkgs", 85 - "rev": "159be5db480d1df880a0135ca0bfed84c2f88353", 80 + "rev": "573c650e8a14b2faa0041645ab18aed7e60f0c9a", 86 81 "type": "github" 87 82 }, 88 83 "original": {
+1 -4
flake.nix
··· 10 10 inputs.nixpkgs-lib.follows = "nixpkgs"; 11 11 }; 12 12 13 - crane = { 14 - url = "github:ipetkov/crane"; 15 - inputs.nixpkgs.follows = "nixpkgs"; 16 - }; 13 + crane.url = "github:ipetkov/crane"; 17 14 18 15 nix-github-actions = { 19 16 url = "github:nix-community/nix-github-actions";
-5
flake/devshells.nix
··· 65 65 flyctl 66 66 skopeo 67 67 manifest-tool 68 - ] ++ lib.optionals pkgs.stdenv.isLinux [ 69 - wrangler 70 68 ]; 71 69 72 70 bench = [ ··· 95 93 RUST_SRC_PATH = "${pkgs.rustPlatform.rustcSrc}/library"; 96 94 97 95 NIX_PATH = "nixpkgs=${pkgs.path}"; 98 - 99 - # See comment in `attic/build.rs` 100 - NIX_INCLUDE_PATH = "${lib.getDev self'.packages.attic.passthru.nix}/include"; 101 96 102 97 # Used by `just with-nix` to build/test with alternative Nix versions. 103 98 NIX_VERSIONS = config.attic.nix-versions.manifestFile;
+2 -3
flake/nix-versions.nix
··· 36 36 attic.nix-versions = { 37 37 versions = { 38 38 default = pkgs.nix; 39 - "2.20" = pkgs.nixVersions.nix_2_20; 40 39 "2.24" = pkgs.nixVersions.nix_2_24; 40 + "2.25" = pkgs.nixVersions.nix_2_25; 41 + "2.26" = pkgs.nixVersions.nix_2_26; 41 42 }; 42 43 43 44 manifestFile = let 44 45 manifest = lib.mapAttrs (_: nix: { 45 46 inherit nix; 46 47 shellHook = '' 47 - export NIX_INCLUDE_PATH="${lib.getDev nix}/include" 48 - export NIX_CFLAGS_COMPILE="-isystem $NIX_INCLUDE_PATH $NIX_CFLAGS_COMPILE" 49 48 export NIX_LDFLAGS="-L${nix}/lib $NIX_LDFLAGS" 50 49 export PKG_CONFIG_PATH="${lib.getDev nix}/lib/pkgconfig:$PKG_CONFIG_PATH" 51 50 export PATH="${lib.getBin nix}/bin:$PATH"
+15 -40
flake/packages.nix
··· 59 59 inherit (perSystemConfig.attic) extraPackageArgs; 60 60 }); 61 61 62 - perSystem = { self', pkgs, config, cranePkgs, ... }: (lib.mkMerge [ 62 + perSystem = { 63 + self', 64 + pkgs, 65 + config, 66 + cranePkgs, 67 + cranePkgsStatic, 68 + ... 69 + }: (lib.mkMerge [ 63 70 { 64 - _module.args.cranePkgs = makeCranePkgs pkgs; 71 + _module.args = { 72 + cranePkgs = makeCranePkgs pkgs; 73 + cranePkgsStatic = makeCranePkgs pkgs.pkgsStatic; 74 + }; 65 75 66 76 packages = { 67 77 default = self'.packages.attic; ··· 72 82 attic-server 73 83 ; 74 84 75 - attic-nixpkgs = pkgs.callPackage ../package.nix { }; 85 + attic-static = cranePkgsStatic.attic; 86 + attic-client-static = cranePkgsStatic.attic-client; 87 + attic-server-static = cranePkgsStatic.attic-server; 76 88 77 89 attic-ci-installer = pkgs.callPackage ../ci-installer.nix { 78 90 inherit self; ··· 117 129 }; 118 130 119 131 in eval.config.packages.attic-server-image; 120 - }; 121 - }) 122 - 123 - # Unfortunately, x86_64-darwin fails to evaluate static builds 124 - (lib.mkIf (pkgs.system != "x86_64-darwin") { 125 - packages = { 126 - # TODO: Make this work with Crane 127 - attic-static = (pkgs.pkgsStatic.callPackage ../package.nix { 128 - nix = pkgs.pkgsStatic.nixVersions.nix_2_18.overrideAttrs (old: { 129 - patches = (old.patches or []) ++ [ 130 - # Diff: https://github.com/zhaofengli/nix/compare/501a805fcd4a90e2bc112e9547417cfc4e04ca66...1dbe9899a8acb695f5f08197f1ff51c14bcc7f42 131 - (pkgs.fetchpatch { 132 - url = "https://github.com/zhaofengli/nix/compare/501a805fcd4a90e2bc112e9547417cfc4e04ca66...1dbe9899a8acb695f5f08197f1ff51c14bcc7f42.diff"; 133 - hash = "sha256-bxBZDUUNTBUz6F4pwxx1ZnPcOKG3EhV+kDBt8BrFh6k="; 134 - }) 135 - ]; 136 - }); 137 - }).overrideAttrs (old: { 138 - nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ 139 - pkgs.nukeReferences 140 - ]; 141 - 142 - # Read by pkg_config crate (do some autodetection in build.rs?) 143 - PKG_CONFIG_ALL_STATIC = "1"; 144 - 145 - "NIX_CFLAGS_LINK_${pkgs.pkgsStatic.stdenv.cc.suffixSalt}" = "-lc"; 146 - RUSTFLAGS = "-C relocation-model=static"; 147 - 148 - postFixup = (old.postFixup or "") + '' 149 - rm -f $out/nix-support/propagated-build-inputs 150 - nuke-refs $out/bin/attic 151 - ''; 152 - }); 153 - 154 - attic-client-static = self'.packages.attic-static.override { 155 - clientOnly = true; 156 - }; 157 132 }; 158 133 }) 159 134 ]);
-75
package.nix
··· 1 - # This is an alternative package expression of Attic in a nixpkgs-acceptable 2 - # form. It will be submitted when the Attic API is considered stable. 3 - # 4 - # For the expression used for CI as well as distribution from this repo, see 5 - # `crane.nix`. 6 - 7 - { lib, stdenv, rustPlatform 8 - , pkg-config 9 - , installShellFiles 10 - , nix 11 - , boost 12 - , darwin 13 - 14 - # Only build the client 15 - , clientOnly ? false 16 - 17 - # Only build certain crates 18 - , crates ? if clientOnly then [ "attic-client" ] else [ "attic-client" "attic-server" ] 19 - }: 20 - 21 - let 22 - ignoredPaths = [ ".github" "target" "book" ]; 23 - 24 - in rustPlatform.buildRustPackage rec { 25 - pname = "attic"; 26 - version = "0.1.0"; 27 - 28 - src = lib.cleanSourceWith { 29 - filter = name: type: !(type == "directory" && builtins.elem (baseNameOf name) ignoredPaths); 30 - src = lib.cleanSource ./.; 31 - }; 32 - 33 - nativeBuildInputs = [ 34 - pkg-config 35 - installShellFiles 36 - ]; 37 - 38 - buildInputs = [ 39 - nix boost 40 - ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ 41 - SystemConfiguration 42 - ]); 43 - 44 - cargoLock = { 45 - lockFile = ./Cargo.lock; 46 - allowBuiltinFetchGit = true; 47 - }; 48 - cargoBuildFlags = lib.concatMapStrings (c: "-p ${c} ") crates; 49 - 50 - ATTIC_DISTRIBUTOR = "attic"; 51 - 52 - # See comment in `attic/build.rs` 53 - NIX_INCLUDE_PATH = "${lib.getDev nix}/include"; 54 - 55 - # Recursive Nix is not stable yet 56 - doCheck = false; 57 - 58 - postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' 59 - if [[ -f $out/bin/attic ]]; then 60 - installShellCompletion --cmd attic \ 61 - --bash <($out/bin/attic gen-completions bash) \ 62 - --zsh <($out/bin/attic gen-completions zsh) \ 63 - --fish <($out/bin/attic gen-completions fish) 64 - fi 65 - ''; 66 - 67 - meta = with lib; { 68 - description = "Multi-tenant Nix binary cache system"; 69 - homepage = "https://github.com/zhaofengli/attic"; 70 - license = licenses.asl20; 71 - maintainers = with maintainers; [ zhaofengli ]; 72 - platforms = platforms.linux ++ platforms.darwin; 73 - mainProgram = "attic"; 74 - }; 75 - }