Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylix: init droid #778

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

stylix: init droid #778

wants to merge 9 commits into from

Conversation

brckd
Copy link
Contributor

@brckd brckd commented Jan 18, 2025

This PR adds nix-on-droid as a new target platform and exposes the nixOnDroidModules.stylix module. It uses a temporary workaround for nix-community/nix-on-droid#436 by adding the missing config.lib option. Closes #775.

It also adds the terminal module which themes the nix-on-droid terminal via terminal.colors. Should this actually be a separate target, or a stylix/ module like fonts.nix?

Font support is not yet implemented, because the terminal.font requires the path to the actual font file. Support may be added in this PR in case a way is found to acquire the correct path.

Testbeds also weren't added yet because it would probably require emulating an android device.

@brckd brckd mentioned this pull request Jan 18, 2025
@brckd
Copy link
Contributor Author

brckd commented Jan 18, 2025

Currently, terminal.colors uses the tinted-kitty theme. The colors look slightly off though.

Fastfetch on nix-on-droid with Catppuccin Mocha theme

image

Fastfetch on Kitty with Catppuccin Mocha theme

image

The base16 palette seems fine though, so perhaps the issue is with the foreground colors or missing base24 palette.

My previous solution not using tinted-kitty worked better, but was adopted from the linked template.
https://github.com/brckd/nixdots/blob/b3f58fa47ba7efdeb80db8a18e1e50f083a5c5fe/configs/droid/phone/default.nix#L17-42

@brckd brckd changed the title Droid/init Init nix-on-droid support Jan 18, 2025
Copy link
Collaborator

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

It also adds the terminal module which themes the nix-on-droid terminal via terminal.colors. Should this actually be a separate target, or a stylix/ module like fonts.nix?

If the terminal.colors option is specific to nix-on-droid and not expected to be ported to any of our supported platforms (NixOS, Home Manager, or nix-darwin) in the foreseeable future, then it might be better to "hide" it inside /stylix/droid/terminal.nix.

Sidenote: I have already thought about changing the current /stylix/<PLATFORM>/ and /modules/<MODULE>/<PLATFORM>.nix platform abstraction. Whether this is actually a good idea should be evaluated once there is a PoC.

Font support is not yet implemented, because the terminal.font requires the path to the actual font file. Support may be added in this PR in case a way is found to acquire the correct path.

Can this be deduced by the stylix.fonts.<FONT>.package values?

Testbeds also weren't added yet because it would probably require emulating an android device.

Do you know if this could be achievable? If not, it should hopefully be fine since we would mostly be re-testing our Home Manager modules.

Currently, terminal.colors uses the tinted-kitty theme. The colors look slightly off though.

Are the generated configuration files the same?

modules/terminal/droid.nix Outdated Show resolved Hide resolved
modules/terminal/droid.nix Outdated Show resolved Hide resolved
modules/terminal/droid.nix Outdated Show resolved Hide resolved
modules/terminal/droid.nix Outdated Show resolved Hide resolved
@trueNAHO trueNAHO changed the title Init nix-on-droid support stylix: init droid Jan 18, 2025
@voronind-com
Copy link

I use this to get the font file:

font = pkgs.runCommandNoCC "font" { } ''
    cp ${
      pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }
    }/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out
  '';

Unsure how to expose it better for the user tho.

@brckd
Copy link
Contributor Author

brckd commented Jan 18, 2025

If the terminal.colors option is specific to nix-on-droid and not expected to be ported to any of our supported platforms (NixOS, Home Manager, or nix-darwin) in the foreseeable future, then it might be better to "hide" it inside /stylix/droid/terminal.nix.

That is indeed the case, so I'll move that functionality!

Font support is not yet implemented, because the terminal.font requires the path to the actual font file. Support may be added in this PR in case a way is found to acquire the correct path.

Can this be deduced by the stylix.fonts.<FONT>.package values?

The font package is a directory containing one or multiple font files anywhere inside of share/fonts. Other platforms use Fontconfig which loads the correct font given the font name. Nix-on-droid doesn't and thus needs to be supplied the actual e.g. .ttf file AFAIK.

Testbeds also weren't added yet because it would probably require emulating an android device.

Do you know if this could be achievable? If not, it should hopefully be fine since we would mostly be re-testing our Home Manager modules.

I don't know, but since there are currently no target applications besides the builtin terminal, I think it wouldn't be worth it.

Currently, terminal.colors uses the tinted-kitty theme. The colors look slightly off though.

Are the generated configuration files the same?

AFAIK nix-on-droid generates a colors.property file for the underlying Termux terminal. I will check whether the values match the ones of the Kitty config though.

I use this to get the font file:

font = pkgs.runCommandNoCC "font" { } ''
    cp ${
      pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }
    }/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out
  '';

Fonts that aren't nerd fonts might be located in any sub directory of share/fonts. Hard coding these wouldn't work. Most fonts also provide multiple variants which may be defined by stylix.fonts.<FONT>.name, so always using the -Regular version also wouldn't work.

@brckd
Copy link
Contributor Author

brckd commented Jan 18, 2025

I will check whether the values match the ones of the Kitty config though.

Everything looks correct.

> cat .termux/colors.properties
background=#1e1e2e
color1=#f38ba8
color10=#181825
color11=#313244
color12=#585b70
color13=#f5e0dc
color14=#f2cdcd
color15=#b4befe
color2=#a6e3a1
color3=#f9e2af
color4=#89b4fa
color5=#cba6f7
color6=#90c0e4
color7=#cdd6f4
color8=#45475a
color9=#fab387
cursor=#cdd6f4
foreground=#cdd6f4

@brckd
Copy link
Contributor Author

brckd commented Jan 18, 2025

I just ran a quick color test on both systems and it seems that only color 0 differs. Turns out I forgot to configure that. Terminal applications still seem to use the wrong colors though.

Color test on nix-on-droid with Catppuccin Mocha theme

image

Color test on Kitty with Catppuccin Mocha theme

image

brckd and others added 6 commits January 18, 2025 22:47
Adds support for the nix-on-droid platform. Exposes the
nixOnDroidModules.stylix module. Uses a temporary workaround for
nix-community/nix-on-droid#436.
Adds theming support for the builtin terminal on nix-on-droid.
@danth
Copy link
Owner

danth commented Jan 18, 2025

It's possible to use fc-match to get the path to a font file given the font name and a directory of possible sources. This is used in the GRUB module:

# Grub requires fonts to be converted to "PFF2 format"
# This function takes a font { name, package } and produces a .pf2 file
mkGrubFont =
font:
pkgs.runCommand "${font.package.name}.pf2"
{
FONTCONFIG_FILE = pkgs.makeFontsConf { fontDirectories = [ font.package ]; };
}
''
# Use fontconfig to select the correct .ttf or .otf file based on name
font=$(
${lib.getExe' pkgs.fontconfig "fc-match"} \
${lib.escapeShellArg font.name} \
--format=%{file}
)
# Convert to .pf2
${pkgs.grub2}/bin/grub-mkfont $font --output $out --size ${toString sizes.applications}
'';

For nix-on-droid the conversion step wouldn't be necessary, we can just do something like ln -s "$font" "$out".

@brckd
Copy link
Contributor Author

brckd commented Jan 19, 2025

Thank you, that looks perfect! I'll try using that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nix-on-droid support
4 participants