Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 21 additions & 42 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

194 changes: 101 additions & 93 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,123 @@
description = "Compositor for the COSMIC desktop environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# <https://github.com/nix-systems/default-linux>
systems.url = "github:nix-systems/default-linux";

parts.url = "github:hercules-ci/flake-parts";
parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

crane.url = "github:ipetkov/crane";

rust.url = "github:oxalica/rust-overlay";
rust.inputs.nixpkgs.follows = "nixpkgs";

nix-filter.url = "github:numtide/nix-filter";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};

outputs =
inputs@{
self,
nixpkgs,
parts,
crane,
rust,
nix-filter,
...
}:
parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-linux"
"x86_64-linux"
];

perSystem =
{
self',
lib,
system,
...
}:
let
pkgs = nixpkgs.legacyPackages.${system}.extend rust.overlays.default;
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
craneArgs = {
pname = "cosmic-comp";
version = self.rev or "dirty";

src = nix-filter.lib.filter {
root = ./.;
include = [
./src
./i18n.toml
./Cargo.toml
./Cargo.lock
./resources
./cosmic-comp-config
];
};

nativeBuildInputs = with pkgs; [
pkg-config
autoPatchelfHook
cmake
];
outputs = {
self,
crane,
nixpkgs,
rust-overlay,
systems,
...
}: let
inherit (nixpkgs) lib;

buildInputs = with pkgs; [
wayland
systemd # For libudev
seatd # For libseat
libxkbcommon
libinput
mesa # For libgbm
fontconfig
stdenv.cc.cc.lib
pixman
libdisplay-info
];
fs = lib.fileset;
eachSystem = lib.genAttrs (import systems);
pkgsFor = eachSystem (system:
import nixpkgs {
localSystem.system = system;
overlays = [(import rust-overlay)];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
rust-overlay works this way because it contains the default.nix at the repo root. If you want to keep importing it this way, mark the flake input flake = false.

My preference would be to use rust-overlay.overlays.default in this position, and keep the input the way it is.

});
in {
packages =
lib.mapAttrs (system: pkgs: let

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, can be changed later:

If you wish to provide an overlay, for users that want to introduce cosmic-comp into pkgs, and build it with their nixpkgs instead of this flake's transitive input, move the package to a file (nix/package.nix) and make a flake output overlays.default = final: prev: { cosmic-comp = final.callPackage "${self}/nix/package.nix" {}; };, then inherit (pkgsFor.${system}) cosmic-comp; default = self.packages.${system}.cosmic-comp; in flake output packages.

Typing on a phone, sorry for errors.

craneLib = crane.mkLib pkgs;
craneArgs = {
pname = "cosmic-comp";
version = self.rev or "dirty";

runtimeDependencies = with pkgs; [
libglvnd # For libEGL
wayland # winit->wayland-sys wants to dlopen libwayland-egl.so
# for running in X11
xorg.libX11
xorg.libXcursor
xorg.libxcb
xorg.libXi
libxkbcommon
# for vulkan backend
vulkan-loader
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./src
./i18n.toml
./Cargo.toml
./Cargo.lock
./resources
./cosmic-comp-config
];
};

cargoArtifacts = craneLib.buildDepsOnly craneArgs;
cosmic-comp = craneLib.buildPackage (craneArgs // { inherit cargoArtifacts; });
in
{
apps.cosmic-comp = {
type = "app";
program = lib.getExe self'.packages.default;
};
nativeBuildInputs = with pkgs; [
pkg-config
autoPatchelfHook
cmake
];

checks.cosmic-comp = cosmic-comp;
packages.default = cosmic-comp;
buildInputs = with pkgs; [
wayland
systemd # For libudev
seatd # For libseat
libxkbcommon
libinput
mesa # For libgbm
fontconfig
stdenv.cc.cc.lib
pixman
libdisplay-info
];

runtimeDependencies = with pkgs; [
libglvnd # For libEGL
wayland # winit->wayland-sys wants to dlopen libwayland-egl.so
# for running in X11
xorg.libX11
xorg.libXcursor
xorg.libxcb
xorg.libXi
libxkbcommon
# for vulkan backend
vulkan-loader
];
};

devShells.default = craneLib.devShell {
cargoArtifacts = craneLib.buildDepsOnly craneArgs;
in {
cosmic-comp = craneLib.buildPackage (craneArgs // {inherit cargoArtifacts;});

default = self.packages.${system}.cosmic-comp;
})
pkgsFor;

apps = eachSystem (system: {
cosmic-comp = {
type = "app";
program = lib.getExe self.packages.${system}.default;
};

default = self.apps.${system}.cosmic-comp;
});

checks = eachSystem (system: {
inherit (self.packages.${system}) cosmic-comp;
});

devShells =
lib.mapAttrs (
system: pkgs: let
craneLib = crane.mkLib pkgs;
in {
default = craneLib.devShell {
LD_LIBRARY_PATH = lib.makeLibraryPath (
__concatMap (d: d.runtimeDependencies) (__attrValues self'.checks)
builtins.concatMap (d: d.runtimeDependencies) (builtins.attrValues self.checks.${system})
);

# include build inputs
inputsFrom = [ cosmic-comp ];
inputsFrom = [self.packages.${system}.cosmic-comp];
};
};
};
}
)
pkgsFor;
};
}