diff --git a/flake.nix b/flake.nix index 1e8d812..cfc6eb2 100644 --- a/flake.nix +++ b/flake.nix @@ -23,13 +23,11 @@ , ... } @ inputs: let - nameValuePair = name: value: { inherit name value; }; - genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names); - allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - forAllSystems = f: genAttrs allSystems (system: f rec { + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec { inherit system; - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; }; lib = pkgs.lib; }); @@ -47,6 +45,56 @@ ]); in { + overlays.default = final: prev: + let + toolchain = fenixToolchain final.hostPlatform.system; + naerskLib = final.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + }; + sharedAttrs = { + pname = "harmonic"; + version = "0.0.0-unreleased"; + src = self; + + nativeBuildInputs = with final; [ ]; + buildInputs = with final; [ ] ++ lib.optionals (final.stdenv.isDarwin) (with final.darwin.apple_sdk.frameworks; [ + SystemConfiguration + ]); + + doCheck = true; + doDoc = true; + doDocFail = true; + RUSTFLAGS = "--cfg tokio_unstable"; + cargoTestOptions = f: f ++ [ "--all" ]; + + override = { preBuild ? "", ... }: { + preBuild = preBuild + '' + # logRun "cargo clippy --all-targets --all-features -- -D warnings" + ''; + }; + postInstall = '' + cp nix-install.sh $out/bin/nix-install.sh + ''; + }; + in + rec { + harmonic = naerskLib.buildPackage sharedAttrs; + } // nixpkgs.lib.optionalAttrs (prev.hostPlatform.system == "x86_64-linux") rec { + default = harmonicStatic; + harmonicStatic = naerskLib.buildPackage + (sharedAttrs // { + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + }); + } // nixpkgs.lib.optionalAttrs (prev.hostPlatform.system == "aarch64-linux") rec { + default = harmonicStatic; + harmonicStatic = naerskLib.buildPackage + (sharedAttrs // { + CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl"; + }); + }; + + devShells = forAllSystems ({ system, pkgs, ... }: let toolchain = fenixToolchain system; @@ -76,9 +124,6 @@ checks = forAllSystems ({ system, pkgs, ... }: let - pkgs = import nixpkgs { - inherit system; - }; toolchain = fenixToolchain system; eclint = import ./nix/eclint.nix { inherit pkgs; }; check = import ./nix/check.nix { inherit pkgs eclint toolchain; }; @@ -106,56 +151,17 @@ ''; }); - packages = forAllSystems - ({ system, pkgs, lib, ... }: - let - naerskLib = pkgs.callPackage naersk { - cargo = fenixToolchain system; - rustc = fenixToolchain system; - }; - - sharedAttrs = { - pname = "harmonic"; - version = "0.0.0-unreleased"; - src = self; - - nativeBuildInputs = with pkgs; [ ]; - buildInputs = with pkgs; [ ] ++ lib.optionals (pkgs.stdenv.isDarwin) (with pkgs.darwin.apple_sdk.frameworks; [ - SystemConfiguration - ]); - - doCheck = true; - doDoc = true; - doDocFail = true; - RUSTFLAGS = "--cfg tokio_unstable"; - cargoTestOptions = f: f ++ [ "--all" ]; - - override = { preBuild ? "", ... }: { - preBuild = preBuild + '' - # logRun "cargo clippy --all-targets --all-features -- -D warnings" - ''; - }; - postInstall = '' - cp nix-install.sh $out/bin/nix-install.sh - ''; - }; - in - rec { - harmonic = naerskLib.buildPackage - (sharedAttrs // { }); - default = self.packages.${system}.harmonic; - } // lib.optionalAttrs (system == "x86_64-linux") rec { - default = harmonicStatic; - harmonicStatic = naerskLib.buildPackage - (sharedAttrs // { - CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; - }); - } // lib.optionalAttrs (system == "aarch64-linux") rec { - default = harmonicStatic; - harmonicStatic = naerskLib.buildPackage - (sharedAttrs // { - CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl"; - }); - }); + packages = forAllSystems ({ system, pkgs, ... }: + { + inherit (pkgs) harmonic; + } // nixpkgs.lib.optionalAttrs (system == "x86_64-linux") { + inherit (pkgs) harmonicStatic; + default = pkgs.harmonicStatic; + } // nixpkgs.lib.optionalAttrs (system == "aarch64-linux") { + inherit (pkgs) harmonicStatic; + default = pkgs.harmonicStatic; + } // nixpkgs.lib.optionalAttrs (pkgs.stdenv.isDarwin) { + default = pkgs.harmonic; + }); }; }