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
This commit is contained in:
parent
bdcb803efa
commit
92932e0c3e
3 changed files with 169 additions and 127 deletions
131
flake.nix
131
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=" ];
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue