From 92932e0c3e8c89f4ced1f280834358a899838c8a Mon Sep 17 00:00:00 2001 From: fortuneteller2k Date: Wed, 5 Jul 2023 02:14:07 +0800 Subject: [PATCH] nix: fix builds and CI Things done: - migrate from flake-utils to flake-parts for easier composability - use rust-overlay from oxalica since it works well with rust-toolchain.toml files --- .github/workflows/build.yml | 2 +- flake.lock | 163 +++++++++++++++++++++++------------- flake.nix | 131 ++++++++++++++--------------- 3 files changed, 169 insertions(+), 127 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d25530ca..f7e22aba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v21 + - uses: cachix/install-nix-action@v22 with: nix_path: nixpkgs=channel:nixpkgs-unstable - run: GIT_LFS_SKIP_SMUDGE=1 nix build diff --git a/flake.lock b/flake.lock index a0e224df..30eed204 100644 --- a/flake.lock +++ b/flake.lock @@ -4,17 +4,15 @@ "inputs": { "flake-compat": "flake-compat", "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ], + "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1684981077, - "narHash": "sha256-68X9cFm0RTZm8u0rXPbeBzOVUH5OoUGAfeHHVoxGd9o=", + "lastModified": 1688425221, + "narHash": "sha256-DhZnju72DuX9GhOnCOBIE94aCGKC2BOaF+kGxbnP/K0=", "owner": "ipetkov", "repo": "crane", - "rev": "35110cccf28823320f4fd697fcafcb5038683982", + "rev": "fc6a236548b31aef0be3b0a0377c4459bb39d923", "type": "github" }, "original": { @@ -23,27 +21,6 @@ "type": "github" } }, - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1685600533, - "narHash": "sha256-7oly5/7xJMtFH44I/Bsrnc2VG4M6HyUVhph3WoZrG64=", - "owner": "nix-community", - "repo": "fenix", - "rev": "360c6a0bc9b78b896fdd60c8803ba98298a37f7c", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, "flake-compat": { "flake": false, "locked": { @@ -65,11 +42,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", "type": "github" }, "original": { @@ -83,11 +60,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", "type": "github" }, "original": { @@ -98,11 +75,11 @@ }, "nix-filter": { "locked": { - "lastModified": 1681154353, - "narHash": "sha256-MCJ5FHOlbfQRFwN0brqPbCunLEVw05D/3sRVoNVt2tI=", + "lastModified": 1687178632, + "narHash": "sha256-HS7YR5erss0JCaUijPeyg2XrisEb959FIct3n2TMGbE=", "owner": "numtide", "repo": "nix-filter", - "rev": "f529f42792ade8e32c4be274af6b6d60857fbee7", + "rev": "d90c75e8319d0dd9be67d933d8eb9d0894ec9174", "type": "github" }, "original": { @@ -112,6 +89,40 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1688221086, + "narHash": "sha256-cdW6qUL71cNWhHCpMPOJjlw0wzSRP0pVlRn2vqX/VVg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cd99c2b3c9f160cd004318e0697f90bbd5960825", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1688049487, + "narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1685591878, "narHash": "sha256-Ib3apaLqIFkZb94q6Q214DXrz0FnJq5C7usywTv63og=", @@ -127,29 +138,65 @@ "type": "github" } }, - "root": { - "inputs": { - "crane": "crane", - "fenix": "fenix", - "flake-utils": "flake-utils_2", - "nix-filter": "nix-filter", - "nixpkgs": "nixpkgs" - } - }, - "rust-analyzer-src": { - "flake": false, + "nixpkgs_3": { "locked": { - "lastModified": 1685541053, - "narHash": "sha256-ck8hhiuxvy8jLIv2cPsQK8bfc/aYZjrIelmLAv16T4o=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "bafa6c4ee5d3acdbb62ec289364564270357c6a2", + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", "type": "github" }, "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1688466019, + "narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nix-filter": "nix-filter", + "nixpkgs": "nixpkgs_2", + "parts": "parts", + "rust": "rust" + } + }, + "rust": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1688438033, + "narHash": "sha256-wOmpZis06pVKTR+5meGwhrW10/buf98lnA26uQLaqek=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c3e43223dece545cfe06ddd92fd782adc73d56c3", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", "type": "github" } }, @@ -165,11 +212,11 @@ ] }, "locked": { - "lastModified": 1683080331, - "narHash": "sha256-nGDvJ1DAxZIwdn6ww8IFwzoHb2rqBP4wv/65Wt5vflk=", + "lastModified": 1688351637, + "narHash": "sha256-CLTufJ29VxNOIZ8UTg0lepsn3X03AmopmaLTTeHDCL4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "d59c3fa0cba8336e115b376c2d9e91053aa59e56", + "rev": "f9b92316727af9e6c7fee4a761242f7f46880329", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index a6b15787..9451bd8f 100644 --- a/flake.nix +++ b/flake.nix @@ -3,78 +3,73 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - flake-utils.url = "github:numtide/flake-utils"; + parts.url = "github:hercules-ci/flake-parts"; + crane.url = "github:ipetkov/crane"; + rust.url = "github:oxalica/rust-overlay"; nix-filter.url = "github:numtide/nix-filter"; - crane = { - url = "github:ipetkov/crane"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; - outputs = { self, nixpkgs, flake-utils, nix-filter, crane, fenix }: - flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - craneLib = crane.lib.${system}.overrideToolchain fenix.packages.${system}.stable.toolchain; + outputs = inputs@{ self, nixpkgs, parts, crane, rust, nix-filter, ... }: + parts.lib.mkFlake { inherit inputs; } { + systems = [ "aarch64-linux" "x86_64-linux" ]; - pkgDef = { - src = nix-filter.lib.filter { - root = ./.; - include = [ - ./src - ./Cargo.toml - ./Cargo.lock - ./resources + perSystem = { self', lib, system, ... }: + let + pkgs = nixpkgs.legacyPackages.${system}.extend rust.overlays.default; + rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = crane.lib.${system}.overrideToolchain rust-toolchain; + craneArgs = { + pname = "cosmic-comp"; + version = self.rev or "dirty"; + + src = nix-filter.lib.filter { + root = ./.; + include = [ + ./src + ./Cargo.toml + ./Cargo.lock + ./resources + ]; + }; + + nativeBuildInputs = with pkgs; [ + pkg-config + autoPatchelfHook + cmake + ]; + + buildInputs = with pkgs; [ + wayland + systemd # For libudev + seatd # For libseat + libxkbcommon + libinput + mesa # For libgbm + fontconfig + stdenv.cc.cc.lib + ]; + + runtimeDependencies = with pkgs; [ + libglvnd # For libEGL ]; }; - nativeBuildInputs = with pkgs; [ - pkg-config - autoPatchelfHook - cmake - ]; - buildInputs = with pkgs; [ - wayland - systemd # For libudev - seatd # For libseat - libxkbcommon - libinput - mesa # For libgbm - fontconfig - stdenv.cc.cc.lib - ]; - runtimeDependencies = with pkgs; [ - libglvnd # For libEGL - ]; + + cargoArtifacts = craneLib.buildDepsOnly craneArgs; + cosmic-comp = craneLib.buildPackage (craneArgs // { inherit cargoArtifacts; }); + in + { + apps.cosmic-comp = { + type = "app"; + program = lib.getExe self'.packages.default; + }; + + checks.cosmic-comp = cosmic-comp; + packages.default = cosmic-comp; + + devShells.default = pkgs.mkShell { + # Should there be packages here or use Nix purely for CI? + LD_LIBRARY_PATH = lib.makeLibraryPath (__concatMap (d: d.runtimeDependencies) (__attrValues self'.checks)); + }; }; - - cargoArtifacts = craneLib.buildDepsOnly pkgDef; - cosmic-comp = craneLib.buildPackage (pkgDef // { - inherit cargoArtifacts; - }); - in { - checks = { - inherit cosmic-comp; - }; - - packages.default = cosmic-comp; - - apps.default = flake-utils.lib.mkApp { - drv = cosmic-comp; - }; - - devShells.default = pkgs.mkShell rec { - inputsFrom = builtins.attrValues self.checks.${system}; - LD_LIBRARY_PATH = pkgs.lib.strings.makeLibraryPath (builtins.concatMap (d: d.runtimeDependencies) inputsFrom); - }; - }); - - nixConfig = { - # Cache for the Rust toolchain in fenix - extra-substituters = [ "https://nix-community.cachix.org" ]; - extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ]; - }; -} + }; +} \ No newline at end of file