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 #159 from Mic92/nix-2.24

attic-client: fix build against Nix 2.24

authored by

Zhaofeng Li and committed by
GitHub
acf3c351 26b9417b

+138 -40
+9 -3
.github/workflows/build.yml
··· 12 12 os: 13 13 - ubuntu-latest 14 14 - macos-latest 15 + nix: 16 + - "2.20" 17 + - "2.24" 18 + - "default" 15 19 runs-on: ${{ matrix.os }} 16 20 permissions: 17 21 contents: read ··· 45 49 run: | 46 50 system=$(nix-instantiate --eval -E 'builtins.currentSystem') 47 51 echo system=$system >>$GITHUB_ENV 48 - tests=$(nix build .#internal."$system".attic-tests --no-link --print-out-paths -L) 52 + tests=$(nix build .#internalMatrix."$system".\"${{ matrix.nix }}\".attic-tests --no-link --print-out-paths -L) 49 53 find "$tests/bin" -exec {} \; 50 54 51 55 # TODO: Just take a diff of the list of store paths, also abstract all of this out ··· 53 57 run: | 54 58 export PATH=$HOME/.nix-profile/bin:$PATH # FIXME 55 59 if [ -n "$ATTIC_TOKEN" ]; then 56 - nix build .#internal."$system".attic-tests .#internal."$system".cargoArtifacts --no-link --print-out-paths -L | \ 57 - xargs attic push "ci:$ATTIC_CACHE" 60 + nix build --no-link --print-out-paths -L \ 61 + .#internalMatrix."$system".\"${{ matrix.nix }}\".attic-tests \ 62 + .#internalMatrix."$system".\"${{ matrix.nix }}\".cargoArtifacts \ 63 + | xargs attic push "ci:$ATTIC_CACHE" 58 64 fi 59 65 - name: Log in to the Container registry 60 66 uses: docker/login-action@v3.0.0
+17 -3
Cargo.lock
··· 230 230 "async-stream", 231 231 "base64 0.22.1", 232 232 "bytes", 233 + "cc", 233 234 "cxx", 234 235 "cxx-build", 235 236 "digest", ··· 250 251 "tempfile", 251 252 "tokio", 252 253 "tokio-test", 254 + "version-compare", 253 255 "wildmatch", 254 256 "xdg", 255 257 ] ··· 1050 1052 1051 1053 [[package]] 1052 1054 name = "cc" 1053 - version = "1.0.98" 1055 + version = "1.1.13" 1054 1056 source = "registry+https://github.com/rust-lang/crates.io-index" 1055 - checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" 1057 + checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" 1056 1058 dependencies = [ 1057 1059 "jobserver", 1058 1060 "libc", 1059 - "once_cell", 1061 + "shlex", 1060 1062 ] 1061 1063 1062 1064 [[package]] ··· 3961 3963 checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" 3962 3964 3963 3965 [[package]] 3966 + name = "shlex" 3967 + version = "1.3.0" 3968 + source = "registry+https://github.com/rust-lang/crates.io-index" 3969 + checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 3970 + 3971 + [[package]] 3964 3972 name = "signal-hook-registry" 3965 3973 version = "1.4.2" 3966 3974 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 4890 4898 version = "0.2.15" 4891 4899 source = "registry+https://github.com/rust-lang/crates.io-index" 4892 4900 checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 4901 + 4902 + [[package]] 4903 + name = "version-compare" 4904 + version = "0.2.0" 4905 + source = "registry+https://github.com/rust-lang/crates.io-index" 4906 + checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" 4893 4907 4894 4908 [[package]] 4895 4909 name = "version_check"
+2
attic/Cargo.toml
··· 43 43 tokio-test = "0.4.2" 44 44 45 45 [build-dependencies] 46 + cc = "1.1.13" 46 47 cxx-build = { version = "1.0", optional = true } 47 48 pkg-config = "0.3.27" 48 49 tempfile = "3" 50 + version-compare = "0.2.0" 49 51 50 52 [features] 51 53 default = [ "nix_store", "tokio" ]
+51 -12
attic/build.rs
··· 2 2 //! 3 3 //! We link against libnixstore to perform actions on the Nix Store. 4 4 5 + use cc::Build; 6 + use version_compare::Version; 7 + 8 + struct NixDependency { 9 + version: String, 10 + } 11 + 12 + impl NixDependency { 13 + fn detect() -> Self { 14 + let library = pkg_config::Config::new() 15 + .cargo_metadata(false) 16 + .atleast_version("2.4") 17 + .probe("nix-main") 18 + .expect("Failed to find nix-main >=2.4 through pkg-config"); 19 + 20 + Self { 21 + version: library.version, 22 + } 23 + } 24 + 25 + fn apply_version_flags(&self, build: &mut Build) { 26 + let version = Version::from(&self.version).unwrap(); 27 + 28 + if version >= Version::from("2.20").unwrap() { 29 + build.flag("-DATTIC_NIX_2_20"); 30 + } 31 + } 32 + 33 + fn emit_cargo_metadata(&self) { 34 + pkg_config::Config::new() 35 + .atleast_version("2.4") 36 + .probe("nix-store") 37 + .unwrap(); 38 + 39 + pkg_config::Config::new() 40 + .atleast_version("2.4") 41 + .probe("nix-main") 42 + .unwrap(); 43 + } 44 + } 45 + 5 46 fn main() { 6 47 #[cfg(feature = "nix_store")] 7 48 build_bridge(); ··· 9 50 10 51 #[cfg(feature = "nix_store")] 11 52 fn build_bridge() { 53 + let nix_dep = NixDependency::detect(); 54 + 12 55 // Temporary workaround for issue in <https://github.com/NixOS/nix/pull/8484> 13 56 let hacky_include = { 14 57 let dir = tempfile::tempdir().expect("Failed to create temporary directory for workaround"); ··· 16 59 dir 17 60 }; 18 61 19 - cxx_build::bridge("src/nix_store/bindings/mod.rs") 62 + let mut build = cxx_build::bridge("src/nix_store/bindings/mod.rs"); 63 + build 20 64 .file("src/nix_store/bindings/nix.cpp") 21 65 .flag("-std=c++2a") 22 66 .flag("-O2") ··· 26 70 .flag(hacky_include.path().to_str().unwrap()) 27 71 // 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 28 72 .flag("-I") 29 - .flag(concat!(env!("NIX_INCLUDE_PATH"), "/nix")) 30 - .compile("nixbinding"); 73 + .flag(concat!(env!("NIX_INCLUDE_PATH"), "/nix")); 74 + 75 + nix_dep.apply_version_flags(&mut build); 76 + 77 + build.compile("nixbinding"); 31 78 32 79 println!("cargo:rerun-if-changed=src/nix_store/bindings"); 33 80 34 81 // the -l flags must be after -lnixbinding 35 - pkg_config::Config::new() 36 - .atleast_version("2.4") 37 - .probe("nix-store") 38 - .unwrap(); 39 - 40 - pkg_config::Config::new() 41 - .atleast_version("2.4") 42 - .probe("nix-main") 43 - .unwrap(); 82 + nix_dep.emit_cargo_metadata(); 44 83 }
+9 -1
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 + 21 29 // ======== 22 30 // RustSink 23 31 // ======== ··· 44 52 RHashSlice CPathInfo::nar_sha256_hash() { 45 53 auto &hash = this->pi->narHash; 46 54 47 - if (hash.type != nix::htSHA256) { 55 + if (!hash_is_sha256(hash)) { 48 56 throw nix::Error("Only SHA-256 hashes are supported at the moment"); 49 57 } 50 58
+33 -15
flake.lock
··· 7 7 ] 8 8 }, 9 9 "locked": { 10 - "lastModified": 1717025063, 11 - "narHash": "sha256-dIubLa56W9sNNz0e8jGxrX3CAkPXsq7snuFA/Ie6dn8=", 10 + "lastModified": 1722960479, 11 + "narHash": "sha256-NhCkJJQhD5GUib8zN9JrmYGMwt4lCRp6ZVNzIiYCl0Y=", 12 12 "owner": "ipetkov", 13 13 "repo": "crane", 14 - "rev": "480dff0be03dac0e51a8dfc26e882b0d123a450e", 14 + "rev": "4c6c77920b8d44cd6660c1621dea6b3fc4b4c4f4", 15 15 "type": "github" 16 16 }, 17 17 "original": { ··· 23 23 "flake-compat": { 24 24 "flake": false, 25 25 "locked": { 26 - "lastModified": 1673956053, 27 - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", 26 + "lastModified": 1696426674, 27 + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", 28 28 "owner": "edolstra", 29 29 "repo": "flake-compat", 30 - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", 30 + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", 31 31 "type": "github" 32 32 }, 33 33 "original": { ··· 37 37 } 38 38 }, 39 39 "flake-utils": { 40 + "inputs": { 41 + "systems": "systems" 42 + }, 40 43 "locked": { 41 - "lastModified": 1667395993, 42 - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", 44 + "lastModified": 1710146030, 45 + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 43 46 "owner": "numtide", 44 47 "repo": "flake-utils", 45 - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", 48 + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 46 49 "type": "github" 47 50 }, 48 51 "original": { ··· 53 56 }, 54 57 "nixpkgs": { 55 58 "locked": { 56 - "lastModified": 1711401922, 57 - "narHash": "sha256-QoQqXoj8ClGo0sqD/qWKFWezgEwUL0SUh37/vY2jNhc=", 59 + "lastModified": 1723827930, 60 + "narHash": "sha256-EU+W5F6y2CVNxGrGIMpY7nSVYq72WRChYxF4zpjx0y4=", 58 61 "owner": "NixOS", 59 62 "repo": "nixpkgs", 60 - "rev": "07262b18b97000d16a4bdb003418bd2fb067a932", 63 + "rev": "d4a7a4d0e066278bfb0d77bd2a7adde1c0ec9e3d", 61 64 "type": "github" 62 65 }, 63 66 "original": { ··· 69 72 }, 70 73 "nixpkgs-stable": { 71 74 "locked": { 72 - "lastModified": 1711460390, 73 - "narHash": "sha256-akSgjDZL6pVHEfSE6sz1DNSXuYX6hq+P/1Z5IoYWs7E=", 75 + "lastModified": 1720535198, 76 + "narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=", 74 77 "owner": "NixOS", 75 78 "repo": "nixpkgs", 76 - "rev": "44733514b72e732bd49f5511bd0203dea9b9a434", 79 + "rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5", 77 80 "type": "github" 78 81 }, 79 82 "original": { ··· 90 93 "flake-utils": "flake-utils", 91 94 "nixpkgs": "nixpkgs", 92 95 "nixpkgs-stable": "nixpkgs-stable" 96 + } 97 + }, 98 + "systems": { 99 + "locked": { 100 + "lastModified": 1681028828, 101 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 102 + "owner": "nix-systems", 103 + "repo": "default", 104 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 105 + "type": "github" 106 + }, 107 + "original": { 108 + "owner": "nix-systems", 109 + "repo": "default", 110 + "type": "github" 93 111 } 94 112 } 95 113 },
+17 -6
flake.nix
··· 30 30 }; 31 31 cranePkgs = makeCranePkgs pkgs; 32 32 33 + internalMatrix = lib.mapAttrs (_: nix: let 34 + cranePkgs' = cranePkgs.override { inherit nix; }; 35 + in { 36 + inherit (cranePkgs') attic-tests cargoArtifacts; 37 + }) { 38 + "2.20" = pkgs.nixVersions.nix_2_20; 39 + "2.24" = pkgs.nixVersions.nix_2_24; 40 + "default" = pkgs.nix; 41 + }; 42 + 33 43 pkgsStable = import nixpkgs-stable { 34 44 inherit system; 35 45 overlays = []; ··· 38 48 39 49 inherit (pkgs) lib; 40 50 in rec { 51 + inherit internalMatrix; 52 + 41 53 packages = { 42 54 default = packages.attic; 43 55 ··· 113 125 rustc 114 126 115 127 rustfmt clippy 116 - cargo-expand cargo-outdated cargo-edit 128 + cargo-expand 129 + # Temporary broken: https://github.com/NixOS/nixpkgs/pull/335152 130 + # cargo-outdated 131 + cargo-edit 117 132 tokio-console 118 133 119 134 sqlite-interactive ··· 131 146 RUST_SRC_PATH = "${pkgs.rustPlatform.rustcSrc}/library"; 132 147 133 148 # See comment in `attic/build.rs` 134 - NIX_INCLUDE_PATH = "${lib.getDev pkgs.nix}/include"; 149 + NIX_INCLUDE_PATH = "${lib.getDev pkgs.nixVersions.nix_2_24}/include"; 135 150 136 151 ATTIC_DISTRIBUTOR = "dev"; 137 152 }; ··· 149 164 }; 150 165 }; 151 166 devShell = devShells.default; 152 - 153 - internal = { 154 - inherit (cranePkgs) attic-tests cargoArtifacts; 155 - }; 156 167 157 168 checks = let 158 169 makeIntegrationTests = pkgs: import ./integration-tests {