diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index c7f99cb..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,3 +0,0 @@ -# For -Zbuild-std -[target.aarch64-unknown-linux-musl] -rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc"] diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index 0951dc5..0a07579 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -21,10 +21,8 @@ jobs: - name: Check health of flake.lock uses: DeterminateSystems/flake-checker-action@main - # TODO: re-enable fail mode when we find a way to bump Nixpkgs to 24.05 - # without breaking the static Rust build - #with: - # fail-mode: true + with: + fail-mode: true - name: Check Rust formatting run: nix develop --command cargo fmt --check diff --git a/Cargo.lock b/Cargo.lock index 385f252..e4bbe1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,7 +239,7 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "attic" version = "0.1.0" -source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#0a8d39427498b33c6fac4610faa2406ba83653aa" +source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#f789ed4a186e136ea938c28551eaaf8081cc4496" dependencies = [ "async-stream", "base64 0.22.1", @@ -254,12 +254,12 @@ dependencies = [ "lazy_static", "log", "nix-base32", - "pkg-config", "regex", "serde", "serde_with", "serde_yaml", "sha2", + "system-deps", "tempfile", "tokio", "tracing", @@ -270,7 +270,7 @@ dependencies = [ [[package]] name = "attic-client" version = "0.1.0" -source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#0a8d39427498b33c6fac4610faa2406ba83653aa" +source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#f789ed4a186e136ea938c28551eaaf8081cc4496" dependencies = [ "anyhow", "async-channel", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "attic-server" version = "0.1.0" -source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#0a8d39427498b33c6fac4610faa2406ba83653aa" +source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#f789ed4a186e136ea938c28551eaaf8081cc4496" dependencies = [ "anyhow", "async-compression", @@ -353,7 +353,7 @@ dependencies = [ [[package]] name = "attic-token" version = "0.1.0" -source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#0a8d39427498b33c6fac4610faa2406ba83653aa" +source = "git+https://github.com/DeterminateSystems/attic?branch=fixups-for-magic-nix-cache#f789ed4a186e136ea938c28551eaaf8081cc4496" dependencies = [ "attic", "base64 0.22.1", @@ -1074,6 +1074,16 @@ dependencies = [ "shlex", ] +[[package]] +name = "cfg-expr" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d4ba6e40bd1184518716a6e1a781bf9160e286d219ccdb8ab2612e74cfe4789" +dependencies = [ + "smallvec", + "target-lexicon", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -4775,12 +4785,31 @@ dependencies = [ "syn 2.0.98", ] +[[package]] +name = "system-deps" +version = "7.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d23aaf9f331227789a99e8de4c91bf46703add012bdfd45fdecdfb2975a005" +dependencies = [ + "cfg-expr", + "heck 0.5.0", + "pkg-config", + "toml", + "version-compare", +] + [[package]] name = "tap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + [[package]] name = "tempfile" version = "3.17.1" @@ -5374,6 +5403,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version-compare" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" + [[package]] name = "version_check" version = "0.9.5" diff --git a/README.md b/README.md index 4a0674b..c86bab0 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,8 @@ For local development, see `gha-cache/README.md` for more details on how to obta ```shell cargo run -- -c creds.json --upstream https://cache.nixos.org -cargo build --release --target x86_64-unknown-linux-musl -cargo build --release --target aarch64-unknown-linux-musl +cargo build --release --target x86_64-unknown-linux-gnu +cargo build --release --target aarch64-unknown-linux-gnu nix copy --to 'http://127.0.0.1:3000' $(which bash) nix-store --store $PWD/test-root --extra-substituters 'http://localhost:3000' --option require-sigs false -r $(which bash) ``` diff --git a/flake.lock b/flake.lock index ddb94bc..04a1796 100644 --- a/flake.lock +++ b/flake.lock @@ -1,59 +1,21 @@ { "nodes": { "crane": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, "locked": { - "lastModified": 1714842444, - "narHash": "sha256-z4HeSYtEdYxKurrbxCMb8v/I1LYDHR/aFrZtGtgUgHw=", - "rev": "c5ee4371eea1728ef04bb09c79577c84d5e67a48", - "revCount": 557, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/ipetkov/crane/0.16.6/018f4495-627e-7385-b537-81f1c1d4003b/source.tar.gz" + "lastModified": 1739936662, + "narHash": "sha256-x4syUjNUuRblR07nDPeLDP7DpphaBVbUaSoeZkFbGSk=", + "owner": "ipetkov", + "repo": "crane", + "rev": "19de14aaeb869287647d9461cbd389187d8ecdb7", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://flakehub.com/f/ipetkov/crane/0.16.3.tar.gz" - } - }, - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1738391509, - "narHash": "sha256-TC3xA++KgprECm/WPsLUd+a77MObZPElCW6eAsjVW1k=", - "rev": "de3ea31eb651b663449361f77d9c1e8835290470", - "revCount": 2156, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.2156%2Brev-de3ea31eb651b663449361f77d9c1e8835290470/0194c095-0041-7b9c-b19e-cf1c4a2adaad/source.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://flakehub.com/f/nix-community/fenix/0.1.1727.tar.gz" + "owner": "ipetkov", + "repo": "crane", + "type": "github" } }, "flake-compat": { - "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", - "revCount": 69, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://flakehub.com/f/edolstra/flake-compat/1.0.1.tar.gz" - } - }, - "flake-compat_2": { "flake": false, "locked": { "lastModified": 1733328505, @@ -123,7 +85,7 @@ }, "nix": { "inputs": { - "flake-compat": "flake-compat_2", + "flake-compat": "flake-compat", "flake-parts": "flake-parts", "git-hooks-nix": "git-hooks-nix", "nixpkgs": "nixpkgs", @@ -208,28 +170,9 @@ "root": { "inputs": { "crane": "crane", - "fenix": "fenix", - "flake-compat": "flake-compat", "nix": "nix", "nixpkgs": "nixpkgs_2" } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1738224931, - "narHash": "sha256-1zhfA5NBqin0Z79Se85juvqQteq7uClJMEb7l2pdDUY=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "3c2aca1e5e9fbabb4e05fc4baa62e807aadc476a", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 464f28c..1d40235 100644 --- a/flake.nix +++ b/flake.nix @@ -4,22 +4,14 @@ inputs = { nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.tar.gz"; - fenix = { - url = "https://flakehub.com/f/nix-community/fenix/0.1.1727.tar.gz"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - crane = { - url = "https://flakehub.com/f/ipetkov/crane/0.16.3.tar.gz"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.0.1.tar.gz"; + # Pinned to `master` until a release containing + # is cut. + crane.url = "github:ipetkov/crane"; nix.url = "https://flakehub.com/f/NixOS/nix/2.tar.gz"; }; - outputs = { self, nixpkgs, fenix, crane, ... }@inputs: + outputs = { self, nixpkgs, crane, ... }@inputs: let supportedSystems = [ "aarch64-linux" @@ -38,27 +30,12 @@ inherit (pkgs) lib; inherit system; }); - - fenixToolchain = system: with fenix.packages.${system}; - combine ([ - stable.clippy - stable.rustc - stable.cargo - stable.rustfmt - stable.rust-src - stable.rust-analyzer - ] ++ nixpkgs.lib.optionals (system == "x86_64-linux") [ - targets.x86_64-unknown-linux-musl.stable.rust-std - ] ++ nixpkgs.lib.optionals (system == "aarch64-linux") [ - targets.aarch64-unknown-linux-musl.stable.rust-std - ]); in { overlays.default = final: prev: let - toolchain = fenixToolchain final.hostPlatform.system; - craneLib = (crane.mkLib final).overrideToolchain toolchain; + craneLib = crane.mkLib final; crateName = craneLib.crateNameFromCargoToml { cargoToml = ./magic-nix-cache/Cargo.toml; }; @@ -74,22 +51,15 @@ buildInputs = [ inputs.nix.packages.${final.stdenv.system}.default final.boost - ] ++ final.lib.optionals final.stdenv.isDarwin [ - final.darwin.apple_sdk.frameworks.SystemConfiguration - (final.libiconv.override { enableStatic = true; enableShared = false; }) ]; - - NIX_CFLAGS_LINK = final.lib.optionalString final.stdenv.isDarwin "-lc++abi"; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; in - rec { + { magic-nix-cache = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); - - default = magic-nix-cache; }; packages = forEachSupportedSystem ({ pkgs, ... }: rec { @@ -127,16 +97,16 @@ createChain 200 startFile; }); - devShells = forEachSupportedSystem ({ system, pkgs, lib }: - let - toolchain = fenixToolchain system; - in - { + devShells = forEachSupportedSystem ({ system, pkgs, lib }: { default = pkgs.mkShell { packages = with pkgs; [ - toolchain + rustc + cargo + clippy + rustfmt + rust-analyzer - nix # for linking attic + inputs.nix.packages.${stdenv.system}.default # for linking attic boost # for linking attic bashInteractive pkg-config @@ -148,13 +118,9 @@ bacon age - ] ++ lib.optionals pkgs.stdenv.isDarwin [ - libiconv - darwin.apple_sdk.frameworks.SystemConfiguration ]; - NIX_CFLAGS_LINK = lib.optionalString pkgs.stdenv.isDarwin "-lc++abi"; - RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustcSrc}/library"; }; }); }; diff --git a/nix.patch b/nix.patch deleted file mode 100644 index 60f2a5f..0000000 --- a/nix.patch +++ /dev/null @@ -1,48 +0,0 @@ -diff --git a/mk/libraries.mk b/mk/libraries.mk -index 6541775f329..5118b957608 100644 ---- a/mk/libraries.mk -+++ b/mk/libraries.mk -@@ -130,7 +130,15 @@ define build-library - - $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) - -- $(1)_INSTALL_PATH := $$(libdir)/$$($(1)_NAME).a -+ $(1)_INSTALL_PATH := $(DESTDIR)$$($(1)_INSTALL_DIR)/$$($(1)_NAME).a -+ -+ $$(eval $$(call create-dir, $$($(1)_INSTALL_DIR))) -+ -+ $$($(1)_INSTALL_PATH): $$($(1)_OBJS) | $(DESTDIR)$$($(1)_INSTALL_DIR)/ -+ +$$(trace-ld) $(LD) -Ur -o $$(_d)/$$($(1)_NAME).o $$^ -+ $$(trace-ar) $(AR) crs $$@ $$(_d)/$$($(1)_NAME).o -+ -+ install: $$($(1)_INSTALL_PATH) - - endif - -diff --git a/src/libstore/local.mk b/src/libstore/local.mk -index 8f28bec6c1d..0d41e3c2cac 100644 ---- a/src/libstore/local.mk -+++ b/src/libstore/local.mk -@@ -69,6 +69,13 @@ $(d)/build.cc: - - clean-files += $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh - -+$(d)/nix-store.pc: $(d)/nix-store.pc.in -+ $(trace-gen) rm -f $@ && ./config.status --quiet --file=$@ -+ifeq ($(BUILD_SHARED_LIBS), 1) -+ sed -i 's|@LIBS_PRIVATE@||' $@ -+else -+ sed -i 's|@LIBS_PRIVATE@|Libs.private: $(libstore_LDFLAGS) $(libstore_LDFLAGS_PROPAGATED) $(foreach lib, $(libstore_LIBS), $($(lib)_LDFLAGS))|' $@ -+endif - $(eval $(call install-file-in, $(d)/nix-store.pc, $(libdir)/pkgconfig, 0644)) - - $(foreach i, $(wildcard src/libstore/builtins/*.hh), \ -diff --git a/src/libstore/nix-store.pc.in b/src/libstore/nix-store.pc.in -index 6d67b1e0380..738991d307b 100644 ---- a/src/libstore/nix-store.pc.in -+++ b/src/libstore/nix-store.pc.in -@@ -7,3 +7,4 @@ Description: Nix Package Manager - Version: @PACKAGE_VERSION@ - Libs: -L${libdir} -lnixstore -lnixutil - Cflags: -I${includedir}/nix -std=c++2a -+@LIBS_PRIVATE@