diff --git a/flake.lock b/flake.lock index ec510fb..c82843b 100644 --- a/flake.lock +++ b/flake.lock @@ -19,6 +19,26 @@ "url": "https://flakehub.com/f/ipetkov/crane/0.16.3.tar.gz" } }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1722493751, + "narHash": "sha256-l7/yMehbrL5d4AI8E2hKtNlT50BlUAau4EKTgPg9KcY=", + "rev": "60ab4a085ef6ee40f2ef7921ca4061084dd8cf26", + "revCount": 1955, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.1955%2Brev-60ab4a085ef6ee40f2ef7921ca4061084dd8cf26/01910d03-2462-7e48-b72e-439d1152bd11/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/nix-community/fenix/0.1.1727.tar.gz" + } + }, "flake-compat": { "locked": { "lastModified": 1696426674, @@ -85,24 +105,6 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "libgit2": { "flake": false, "locked": { @@ -138,7 +140,7 @@ }, "original": { "type": "tarball", - "url": "https://flakehub.com/f/NixOS/nix/2.20.tar.gz" + "url": "https://flakehub.com/f/NixOS/nix/%3D2.22.1.tar.gz" } }, "nixpkgs": { @@ -222,45 +224,26 @@ "root": { "inputs": { "crane": "crane", + "fenix": "fenix", "flake-compat": "flake-compat", "nix": "nix", - "nixpkgs": "nixpkgs_2", - "rust-overlay": "rust-overlay" + "nixpkgs": "nixpkgs_2" } }, - "rust-overlay": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": [ - "nixpkgs" - ] - }, + "rust-analyzer-src": { + "flake": false, "locked": { - "lastModified": 1716862669, - "narHash": "sha256-7oTPM9lcdwiI1cpRC313B+lHawocgpY5F07N+Rbm5Uk=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "47b2d15658b37716393b2463a019000dbd6ce4bc", + "lastModified": 1722449213, + "narHash": "sha256-1na4m2PNH99syz2g/WQ+Hr3RfY7k4H8NBnmkr5dFDXw=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "c8e41d95061543715b30880932ec3dc24c42d7ae", "type": "github" }, "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", "type": "github" } } diff --git a/flake.nix b/flake.nix index 0eb1d20..6f3384b 100644 --- a/flake.nix +++ b/flake.nix @@ -4,8 +4,8 @@ inputs = { nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2311.tar.gz"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; + fenix = { + url = "https://flakehub.com/f/nix-community/fenix/0.1.1727.tar.gz"; inputs.nixpkgs.follows = "nixpkgs"; }; @@ -16,32 +16,84 @@ flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.0.1.tar.gz"; - nix.url = "https://flakehub.com/f/NixOS/nix/2.20.tar.gz"; + nix.url = "https://flakehub.com/f/NixOS/nix/=2.22.1.tar.gz"; }; - outputs = { self, nixpkgs, nix, ... }@inputs: + outputs = { self, nixpkgs, fenix, crane, ... }@inputs: let - overlays = [ inputs.rust-overlay.overlays.default nix.overlays.default ]; supportedSystems = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec { - pkgs = import nixpkgs { inherit overlays system; }; - cranePkgs = pkgs.callPackage ./crane.nix { - inherit supportedSystems; - inherit (inputs) crane; - nix-flake = nix; + pkgs = import nixpkgs { + inherit system; + overlays = [ + inputs.nix.overlays.default + self.overlays.default + ]; }; inherit (pkgs) lib; + inherit system; }); + + fenixToolchain = system: with fenix.packages.${system}; + combine ([ + stable.clippy + stable.rustc + stable.cargo + stable.rustfmt + stable.rust-src + ] ++ 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 { - packages = forEachSupportedSystem ({ pkgs, cranePkgs, ... }: rec { - magic-nix-cache = pkgs.callPackage ./package.nix { }; - #inherit (cranePkgs) magic-nix-cache; + + overlays.default = final: prev: + let + toolchain = fenixToolchain final.hostPlatform.system; + craneLib = (crane.mkLib final).overrideToolchain toolchain; + crateName = craneLib.crateNameFromCargoToml { + cargoToml = ./magic-nix-cache/Cargo.toml; + }; + + commonArgs = { + inherit (crateName) pname version; + src = self; + + nativeBuildInputs = with final; [ + pkg-config + ]; + + buildInputs = [ + final.nix + 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 { + magic-nix-cache = pkgs.magic-nix-cache; default = magic-nix-cache; veryLongChain = @@ -75,12 +127,18 @@ createChain 200 startFile; }); - devShells = forEachSupportedSystem ({ pkgs, cranePkgs, lib }: { + devShells = forEachSupportedSystem ({ system, pkgs, lib }: + let + toolchain = fenixToolchain system; + in + { default = pkgs.mkShell { - inputsFrom = [ cranePkgs.magic-nix-cache ]; packages = with pkgs; [ + toolchain + + nix # for linking attic + boost # for linking attic bashInteractive - cranePkgs.rustNightly pkg-config cargo-bloat @@ -90,108 +148,14 @@ bacon age - ] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ - SystemConfiguration - ]); + ] ++ 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"; }; - - /* - cross = pkgs.mkShell ({ - inputsFrom = [ cranePkgs.magic-nix-cache ]; - packages = with pkgs; [ - bashInteractive - cranePkgs.rustNightly - - cargo-bloat - cargo-edit - cargo-udeps - cargo-watch - - age - ]; - shellHook = - let - crossSystems = lib.filter (s: s != pkgs.system) (builtins.attrNames cranePkgs.crossPlatforms); - in - '' - # Returns compiler environment variables for a platform - # - # getTargetFlags "suffixSalt" "nativeBuildInputs" "buildInputs" - getTargetFlags() { - # Here we only call the setup-hooks of nativeBuildInputs. - # - # What's off-limits for us: - # - # - findInputs - # - activatePackage - # - Other functions in stdenv setup that depend on the private accumulator variables - ( - suffixSalt="$1" - nativeBuildInputs="$2" - buildInputs="$3" - - # Offsets for the nativeBuildInput (e.g., gcc) - hostOffset=-1 - targetOffset=0 - - # In stdenv, the hooks are first accumulated before being called. - # Here we call them immediately - addEnvHooks() { - local depHostOffset="$1" - # For simplicity, we only call the hook on buildInputs - for pkg in $buildInputs; do - depTargetOffset=1 - $2 $pkg - done - } - - unset _PATH - unset NIX_CFLAGS_COMPILE - unset NIX_LDFLAGS - - # For simplicity, we only call the setup-hooks of nativeBuildInputs - for nbi in $nativeBuildInputs; do - addToSearchPath _PATH "$nbi/bin" - - if [ -e "$nbi/nix-support/setup-hook" ]; then - source "$nbi/nix-support/setup-hook" - fi - done - - echo "export NIX_CFLAGS_COMPILE_''${suffixSalt}='$NIX_CFLAGS_COMPILE'" - echo "export NIX_LDFLAGS_''${suffixSalt}='$NIX_LDFLAGS'" - echo "export PATH=$PATH''${_PATH+:$_PATH}" - ) - } - - target_flags=$(mktemp) - ${lib.concatMapStrings (system: let - crossPlatform = cranePkgs.crossPlatforms.${system}; - in '' - getTargetFlags \ - "${crossPlatform.cc.suffixSalt}" \ - "${crossPlatform.cc} ${crossPlatform.cc.bintools}" \ - "${builtins.concatStringsSep " " (crossPlatform.buildInputs ++ crossPlatform.pkgs.stdenv.defaultBuildInputs)}" >$target_flags - . $target_flags - '') crossSystems} - rm $target_flags - - # Suffix flags for current system as well - export NIX_CFLAGS_COMPILE_${pkgs.stdenv.cc.suffixSalt}="$NIX_CFLAGS_COMPILE" - export NIX_LDFLAGS_${pkgs.stdenv.cc.suffixSalt}="$NIX_LDFLAGS" - unset NIX_CFLAGS_COMPILE - unset NIX_LDFLAGS - ''; - } // cranePkgs.cargoCrossEnvs); - - keygen = pkgs.mkShellNoCC { - packages = with pkgs; [ - age - ]; - }; - */ }); }; }