Home Explore Blog Models CI



nixpkgs

1st chunk of `doc/languages-frameworks/cosmic.section.md`
2c5b583f582e3f4af00fef26fb6e7fa7fd00f1f6ba9584a20000000100000a96
# COSMIC {#sec-language-cosmic}

## Packaging COSMIC applications {#ssec-cosmic-packaging}

COSMIC (Computer Operating System Main Interface Components) is a desktop environment developed by
System76, primarily for the Pop!_OS Linux distribution. Applications in the COSMIC ecosystem are
written in Rust and use libcosmic, which builds on the Iced GUI framework. This section explains
how to properly package and integrate COSMIC applications within Nix.

### libcosmicAppHook {#ssec-cosmic-libcosmic-app-hook}

The `libcosmicAppHook` is a setup hook that helps with this by automatically configuring
and wrapping applications based on libcosmic. It handles many common requirements like:

- Setting up proper linking for libraries that may be dlopen'd by libcosmic/iced apps
- Configuring XDG paths for settings schemas, icons, and other resources
- Managing Vergen environment variables for build-time information
- Setting up Rust linker flags for specific libraries

To use the hook, simply add it to your package's `nativeBuildInputs`:

```nix
{
  lib,
  rustPlatform,
  libcosmicAppHook,
}:
rustPlatform.buildRustPackage {
  # ...
  nativeBuildInputs = [ libcosmicAppHook ];
  # ...
}
```

### Settings fallback {#ssec-cosmic-settings-fallback}

COSMIC applications use libcosmic's UI components, which may need access to theme settings. The
`cosmic-settings` package provides default theme settings as a fallback in its `share` directory.
By default, `libcosmicAppHook` includes this fallback path in `XDG_DATA_DIRS`, ensuring that COSMIC
applications will have access to theme settings even if they aren't available elsewhere in the
system.

This fallback behavior can be disabled by setting `includeSettings = false` when including the hook:

```nix
{
  lib,
  rustPlatform,
  libcosmicAppHook,
}:
let
  # Get build-time version of libcosmicAppHook
  libcosmicAppHook' = (libcosmicAppHook.__spliced.buildHost or libcosmicAppHook).override {
    includeSettings = false;
  };
in
rustPlatform.buildRustPackage {
  # ...
  nativeBuildInputs = [ libcosmicAppHook' ];
  # ...
}
```

Note that `cosmic-settings` is a separate application and not a part of the libcosmic settings
system itself. It's included by default in `libcosmicAppHook` only to provide these fallback theme
settings.

### Icons {#ssec-cosmic-icons}

COSMIC applications can use icons from the COSMIC icon theme. While COSMIC applications can build
and run without these icons, they would be missing visual elements. The `libcosmicAppHook`
automatically includes `cosmic-icons` in the wrapped application's `XDG_DATA_DIRS` as a fallback,
ensuring that the application has access to its required icons even if the system doesn't have the

Title: Packaging COSMIC Applications in Nix using libcosmicAppHook
Summary
This section details how to package COSMIC applications, developed by System76 using Rust and libcosmic (based on Iced GUI), within the Nix ecosystem. The primary tool for this is `libcosmicAppHook`, a setup hook that simplifies configuration and wrapping of these applications. It automatically manages aspects like library linking, XDG path setup for resources, Vergen environment variables, and Rust linker flags. Users can integrate it by adding it to their package's `nativeBuildInputs`. The hook also provides fallback mechanisms for theme settings by including `cosmic-settings` and for icons by including `cosmic-icons` in the application's `XDG_DATA_DIRS`, both of which can be optionally disabled.