diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33579df..17f291e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,26 +27,31 @@ jobs: uses: DeterminateSystems/magic-nix-cache-action@v2 - name: Build ${{ matrix.target }} binary run: | - nix build -L .#${{matrix.target}}.release.SyncDisBoi + nix build -L .#${{matrix.target.derivation}} mkdir artifacts/ cp result/bin/* artifacts cd artifacts - ls | xargs -I{} mv {} ${{matrix.target}}-{} + ls | xargs -I{} mv {} ${{matrix.target.name}}-{} - uses: actions/upload-artifact@v4 with: - name: "${{ matrix.target }}-sync_dis_boi" + name: "${{ matrix.target.name }}-sync_dis_boi" path: "artifacts/*" strategy: matrix: os: - ubuntu-latest target: - - x86_64-linux-musl - - aarch64-linux-musl - - mingw64 + - derivation: x86_64-unknown-linux-musl + name: linux-x86_64 + - derivation: aarch64-unknown-linux-musl + name: linux-aarch64 + - derivation: x86_64-pc-windows-gnu + name: windows-x86_64 include: - os: macos-latest - target: aarch64-darwin + target: + derivation: "" + name: mac-aarch64 release: name: Release needs: build diff --git a/flake.lock b/flake.lock index 88132b2..1af580f 100644 --- a/flake.lock +++ b/flake.lock @@ -1,88 +1,18 @@ { "nodes": { - "android-nixpkgs": { - "inputs": { - "devshell": "devshell", - "flake-utils": "flake-utils_3", - "nixpkgs": [ - "flakebox", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1719001124, - "narHash": "sha256-JXrMwYlQarZPyjN5UkD4fS9mrHSE1PUa7P//1Z5Sqr0=", - "owner": "tadfisher", - "repo": "android-nixpkgs", - "rev": "7fa1348249564e43185d3053f579f9fa923d46cc", - "type": "github" - }, - "original": { - "owner": "tadfisher", - "repo": "android-nixpkgs", - "rev": "7fa1348249564e43185d3053f579f9fa923d46cc", - "type": "github" - } - }, - "crane": { - "inputs": { - "nixpkgs": [ - "flakebox", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1717383740, - "narHash": "sha256-559HbY4uhNeoYvK3H6AMZAtVfmR3y8plXZ1x6ON/cWU=", - "owner": "ipetkov", - "repo": "crane", - "rev": "b65673fce97d277934488a451724be94cc62499a", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "rev": "b65673fce97d277934488a451724be94cc62499a", - "type": "github" - } - }, - "devshell": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": [ - "flakebox", - "android-nixpkgs", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1717408969, - "narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=", - "owner": "numtide", - "repo": "devshell", - "rev": "1ebbe68d57457c8cae98145410b164b5477761f4", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, "fenix": { "inputs": { "nixpkgs": [ - "flakebox", "nixpkgs" ], "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1717827974, - "narHash": "sha256-ixopuTeTouxqTxfMuzs6IaRttbT8JqRW5C9Q/57WxQw=", + "lastModified": 1728455642, + "narHash": "sha256-abYGwrL6ak5sBRqwPh+V3CPJ6Pa89p378t51b7BO1lE=", "owner": "nix-community", "repo": "fenix", - "rev": "ab655c627777ab5f9964652fe23bbb1dfbd687a8", + "rev": "3b47535a5c782e4f4ad59cd4bdb23636b6926e03", "type": "github" }, "original": { @@ -109,85 +39,23 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "inputs": { - "systems": "systems_3" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_4": { + "naersk": { "inputs": { - "systems": [ - "flakebox", - "systems" - ] - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flakebox": { - "inputs": { - "android-nixpkgs": "android-nixpkgs", - "crane": "crane", - "fenix": "fenix", - "flake-utils": "flake-utils_4", "nixpkgs": [ "nixpkgs" - ], - "systems": "systems_4" + ] }, "locked": { - "lastModified": 1719905300, - "narHash": "sha256-7qna1Hi0jDQG/V8OJhMLYyW5e3wq+XyIKxpxTJm0cFE=", - "owner": "SilentVoid13", - "repo": "flakebox", - "rev": "924c18e776613ac4a430b2537b092497eafe6145", + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", + "owner": "nix-community", + "repo": "naersk", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", "type": "github" }, "original": { - "owner": "SilentVoid13", - "repo": "flakebox", + "owner": "nix-community", + "repo": "naersk", "type": "github" } }, @@ -208,19 +76,20 @@ }, "root": { "inputs": { + "fenix": "fenix", "flake-utils": "flake-utils", - "flakebox": "flakebox", + "naersk": "naersk", "nixpkgs": "nixpkgs" } }, "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1717583671, - "narHash": "sha256-+lRAmz92CNUxorqWusgJbL9VE1eKCnQQojglRemzwkw=", + "lastModified": 1728386838, + "narHash": "sha256-Lk64EoJkvp3WMGVJK3CR1TYcNghX0/BqHPLW5zdvmLE=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "48bbdd6a74f3176987d5c809894ac33957000d19", + "rev": "efaf8bd5de34e2f47bd57425b83e0c7974902176", "type": "github" }, "original": { @@ -244,51 +113,6 @@ "repo": "default", "type": "github" } - }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_3": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_4": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index d65e78f..f848fcb 100644 --- a/flake.nix +++ b/flake.nix @@ -4,99 +4,129 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; - flakebox = { - url = "github:SilentVoid13/flakebox"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + naersk = { + url = "github:nix-community/naersk"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { + self, nixpkgs, flake-utils, - flakebox, - ... + naersk, + fenix, }: flake-utils.lib.eachDefaultSystem ( system: let - pkgs = import nixpkgs {inherit system;}; - - shellPackages = with pkgs; [ - python311Packages.ytmusicapi - ]; + pkgs = import nixpkgs { + inherit system; + overlays = [fenix.overlays.default]; + }; - flakeboxLib = flakebox.lib.${system} { - config = { - github.ci.enable = false; - just.enable = false; - convco.enable = false; - git.commit-msg.enable = false; - git.commit-template.enable = false; - git.pre-commit.enable = false; + toolchain = with fenix.packages.${system}; + combine [ + minimal.rustc + minimal.cargo + targets.x86_64-unknown-linux-musl.latest.rust-std + targets.x86_64-pc-windows-gnu.latest.rust-std + targets.aarch64-unknown-linux-musl.latest.rust-std + ]; - env.shellPackages = shellPackages; - }; + naersk' = naersk.lib.${system}.override { + cargo = toolchain; + rustc = toolchain; }; - project_name = "SyncDisBoi"; - buildPaths = [ - "Cargo.toml" - "Cargo.lock" - "src" - ]; + naerskBuildPackage = args: + naersk'.buildPackage ( + args + // cargoConfig + ); + naerskBuildPackageT = target: args: naerskBuildPackage (args // {CARGO_BUILD_TARGET = target;}); - buildInputs = pkgs: - with pkgs; - # if the target is windows, we don't use the musl static openssl - ( - if (stdenv.isLinux || stdenv.isDarwin) - then [ - pkgsStatic.openssl - ] - else [openssl] - ) - ++ lib.optionals stdenv.isDarwin - [ - darwin.apple_sdk.frameworks.CoreFoundation - darwin.apple_sdk.frameworks.CoreServices - darwin.apple_sdk.frameworks.SystemConfiguration - darwin.apple_sdk.frameworks.Security - ]; + cargoConfig = { + # Tells Cargo to enable static compilation. + # (https://doc.rust-lang.org/cargo/reference/config.html#targettriplerustflags) + # + # Note that the resulting binary might still be considered dynamically + # linked by ldd, but that's just because the binary might have + # position-independent-execution enabled. + # (see: https://github.com/rust-lang/rust/issues/79624#issuecomment-737415388) + CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS = "-C target-feature=+crt-static"; - nativeBuildInputs = pkgs: - with pkgs; - [ - pkgsBuildTarget.pkg-config - ]; + # Tells Cargo that it should use Wine to run tests. + # (https://doc.rust-lang.org/cargo/reference/config.html#targettriplerunner) + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = pkgs.writeScript "wine-wrapper" '' + export WINEPREFIX="$(mktemp -d)" + exec wine64 $@ + ''; + }; - buildSrc = flakeboxLib.filterSubPaths { - root = builtins.path { - name = project_name; - path = ./.; - }; - paths = buildPaths; + fnBuildInputs = pkgs: with pkgs; [openssl]; + shellPkgs = with pkgs; [ + wineWowPackages.stable + ]; + in rec { + defaultPackage = naerskBuildPackage { + src = ./.; + buildInputs = + (fnBuildInputs pkgs) + ++ (with pkgs; + lib.optionals stdenv.isDarwin + [ + darwin.apple_sdk.frameworks.CoreFoundation + darwin.apple_sdk.frameworks.CoreServices + darwin.apple_sdk.frameworks.SystemConfiguration + darwin.apple_sdk.frameworks.Security + ]); }; - multiBuild = - (flakeboxLib.craneMultiBuild { - inherit buildInputs; - inherit nativeBuildInputs; - }) (craneLib': let - craneLib = craneLib'.overrideArgs { - pname = project_name; - src = buildSrc; - }; - in { - ${project_name} = craneLib.buildPackage {}; - }); - in { - packages.default = multiBuild.${project_name}; + packages.x86_64-unknown-linux-musl = naerskBuildPackageT "x86_64-unknown-linux-musl" { + src = ./.; + nativeBuildInputs = with pkgs; [pkgsStatic.stdenv.cc]; + buildInputs = fnBuildInputs pkgs.pkgsCross.musl64.pkgsStatic; + }; - legacyPackages = multiBuild; + packages.aarch64-unknown-linux-musl = with pkgs.pkgsCross.aarch64-multiplatform-musl; + naerskBuildPackageT "aarch64-unknown-linux-musl" { + src = ./.; + strictDeps = true; + depsBuildBuild = [ + stdenv.cc + ]; + "CC_aarch64_unknown_linux_musl" = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; + "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER" = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; + buildInputs = fnBuildInputs pkgsStatic; + }; - devShells = flakeboxLib.mkShells { - buildInputs = buildInputs pkgs; - nativeBuildInputs = nativeBuildInputs pkgs; + packages.x86_64-pc-windows-gnu = naerskBuildPackageT "x86_64-pc-windows-gnu" { + src = ./.; + strictDeps = true; + depsBuildBuild = with pkgs; [ + pkgsCross.mingwW64.stdenv.cc + pkgsCross.mingwW64.windows.pthreads + ]; + nativeBuildInputs = with pkgs; [ + # We need Wine to run tests: + wineWowPackages.stable + ]; + buildInputs = fnBuildInputs pkgs.pkgsCross.mingwW64; }; + + devShell = pkgs.mkShell ( + { + inputsFrom = [defaultPackage]; + packages = shellPkgs; + #CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu"; + LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (fnBuildInputs pkgs)}"; + } + // cargoConfig + ); } ); }