fix(nix): Simplify nix flake and fix dependencies

Could get the project running by removing most of the hard-coded values
and replace them with simplified directives.

This new flake incantation should also be easier to maintain in the
future.
This commit is contained in:
8roken 2025-05-28 08:01:24 -04:00 committed by Michael Murphy
parent 24e6e2f28f
commit 0e651e2d4e
2 changed files with 42 additions and 234 deletions

View file

@ -3,46 +3,32 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
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";
};
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, nix-filter, crane, fenix }:
flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
outputs = { self, nixpkgs, utils }:
utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
let
pkgs = nixpkgs.legacyPackages.${system};
craneLib = crane.lib.${system}.overrideToolchain fenix.packages.${system}.stable.toolchain;
crateNameFromCargoToml = craneLib.crateNameFromCargoToml {cargoToml = ./app/Cargo.toml;};
pkgDef = {
inherit (crateNameFromCargoToml) pname version;
src = nix-filter.lib.filter {
root = ./.;
include = [
./app
./page
./pages
./Cargo.toml
./Cargo.lock
./i18n
./i18n.toml
./justfile
./resources
];
};
pkgs = import nixpkgs { inherit system; };
runtimeDependencies = with pkgs; [
wayland
# libglvnd # For libEGL
vulkan-loader
];
in {
devShells.default = with pkgs; mkShell rec {
nativeBuildInputs = with pkgs; [
just
pkg-config
autoPatchelfHook
];
buildInputs = with pkgs; [
clang
cargo
rustc
rustfmt
systemdMinimal
bashInteractive
libxkbcommon
@ -53,40 +39,15 @@
desktop-file-utils
stdenv.cc.cc.lib
libinput
];
runtimeDependencies = with pkgs; [
wayland
libglvnd # For libEGL
libpulseaudio.dev
pipewire.dev
];
};
cargoArtifacts = craneLib.buildDepsOnly pkgDef;
cosmic-settings= craneLib.buildPackage (pkgDef // {
inherit cargoArtifacts;
});
in {
checks = {
inherit cosmic-settings;
RUST_SRC_PATH = rustPlatform.rustLibSrc;
RUSTFLAGS = "-C link-arg=-Wl,-rpath,${pkgs.lib.makeLibraryPath runtimeDependencies}";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
};
apps.default = flake-utils.lib.mkApp {
drv = cosmic-settings;
};
packages.default = cosmic-settings.overrideAttrs (oldAttrs: rec {
installPhase = ''
just prefix=$out install
'';
});
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=" ];
};
}
);
}