Skip to content

superfile: init - #2398

Open
ReeSilva wants to merge 8 commits into
nix-community:masterfrom
ReeSilva:feat/superfile-module
Open

superfile: init#2398
ReeSilva wants to merge 8 commits into
nix-community:masterfrom
ReeSilva:feat/superfile-module

Conversation

@ReeSilva

@ReeSilva ReeSilva commented Jul 4, 2026

Copy link
Copy Markdown
Member

Closes: #2397

Add a Home Manager target for Superfile, a modern terminal file manager written in Go.

The target maps the entire superfile theme TOML configuration to base16 colors — covering the file panel, sidebar, footer, modals, help menu, and special state colors (cursor, error, correct, hint, cancel).

Syntax highlighting in file previews is handled automatically: a nixpkgs overlay generates a chroma syntax style from the Stylix palette at build time, then injects a small Go file into superfile's source that registers it at startup via //go:embed, so code highlighting always matches the system theme with no user configuration.

The implementation takes the built-in tokyonight theme from superfile's source as a reference for the UI color mappings, and the catppuccin and tokyonight chroma styles as references for the syntax highlighting color mappings.

Also includes a testbed for the target — it disables the first-use check, auto-update, and nerdfonts, and sets ignore_missing_fields = true to prevent warnings from the options that superfile requires to work (but are not required to test the appearance).


AI Usage Disclosure

This PR description and the code for the automatic syntax highlighting were written with assistance from the AI agent Opencode via CodeCompanion.nvim, using the model DeepSeek V4 Pro through Opencode Zen. The rest of the code was written entirely by me.

@stylix-automation stylix-automation Bot added topic: home-manager Home Manager target topic: testbed Testbed changes topic: modules /modules/ subsystem topic: stylix /stylix/ subsystem labels Jul 4, 2026
@ReeSilva

ReeSilva commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Well, tbh, I dunno what's going on with nix run .#all-maintainers or with the precommit. I've added myself to maintainers.nix and I'm able to run the command to generate the file. But, when I try to commit the updated version, the precommit hook fails and update the generated all-maintainers file to a version without me ❓

Any help here would be much appreciated 🙇

Comment thread modules/superfile/testbeds/superfile.nix Outdated
Comment thread modules/superfile/hm.nix Outdated
Comment thread modules/superfile/hm.nix Outdated
Comment thread modules/superfile/hm.nix Outdated
Comment thread modules/superfile/hm.nix Outdated
Comment thread modules/superfile/hm.nix Outdated
Comment on lines +4 to +7
code_syntax_highlight = lib.mkOption {
description = "The syntax highlighting theme for code.";
type = lib.types.str;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A mandatory stylix.targets.superfile.code_syntax_highlight option is introduced for the syntax highlighting theme in file previews, since there is no automatic way to map a base16 colorscheme to a valid chroma syntax style. Users must set this to a chroma-compatible style name (e.g. "catppuccin-macchiato").

What about adapting and applying the upstream Tokyonight style to remove this option:

The implementation takes the built-in tokyonight theme from superfile's source as a reference for the color mappings.

@ReeSilva ReeSilva Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trueNAHO The point is that this option should be customizable, because chroma has several colorschemes, and from my POV (feel free to just say "shut-up, you have no idea what you're talking about") one should be able to choose it. Here is the list: https://github.com/alecthomas/chroma/blob/master/styles

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The point is that this option should be customizable, because chroma has several colorschemes, and from my POV (feel free to just say "shut-up, you have no idea what you're talking about") one should be able to choose it. Here is the list: https://github.com/alecthomas/chroma/blob/master/styles

End-users can override this option with lib.mkForce.

IMHO, declaring an appropriate syntax highlighter should be handled by Stylix. I was hoping it would be possible to inject our own style, which could be derived from catppuccin-macchiato.

@ReeSilva ReeSilva Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trueNAHO Unfortunately we can't set the highlight colors through Stylix (it would be the dream).

As you can see here: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/ui/preview/render.go#L131, it calls ansichroma passing the value from the variable code_syntax_highlight: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/common/config_type.go#L6C2-L6C26

But I agree with the usage of lib.mkForce. A good middle ground here could be applying a more neutral default value, could be catppuccin or tokyonight (or any other from the chroma available styles) and allow users to overwrite with lib.mkForce. Wdyt?

In that case, do you have any suggestions in term of a theme that could blend "kinda well" with any theme? If not, I'll follow with tokyonight. It is not a theme of strong colors, looks very neutral to me.

Let me know what you think, I have the commit ready to push.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately we can't set the highlight colors through Stylix (it would be the dream).

As you can see here: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/ui/preview/render.go#L131, it calls ansichroma passing the value from the variable code_syntax_highlight: https://github.com/yorukot/superfile/blob/983ca9e98ca1f0836e5a7e8e6948247d9c6bc194/src/internal/common/config_type.go#L6C2-L6C26

[...] A good middle ground here could be applying a more neutral default value, could be catppuccin or tokyonight (or any other from the chroma available styles) and allow users to overwrite with lib.mkForce. Wdyt?

In that case, do you have any suggestions in term of a theme that could blend "kinda well" with any theme? If not, I'll follow with tokyonight. It is not a theme of strong colors, looks very neutral to me.

From where is code_syntax_highlight reading the file contents? Ideally, code_syntax_highlight would support an absolute file path. If code_syntax_highlight accesses styles from a runtime directory, our style could be injected by installing it there. If code_syntax_highlight bundles the set of available styles into the static binary, we might consider patching pkgs.superfile to include our style into the build pipeline.

@ReeSilva ReeSilva Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trueNAHO Did some research and created an approach based on what you suggested (great guidance, btw, huge thanks). The changes are live for your review now.

Did a whole research on how Superfile calls ansichroma and how ansichroma itself uses styles from chroma v2.

I've added some details to the PR description and to the commit msg, but a ;tldr;:
chroma has a global Registry variable that allows us to use it to "publish" new colorschemes. I've put that together with your suggestion to patch the superfile binary with the XML and found a solution.

I've tested on the testbed and it worked nice, also is running nice on my setup too.

Please, drop any feedbacks and I'll take a look ASAP.

Cheers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trueNAHO ping 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did some research and created an approach based on what you suggested (great guidance, btw, huge thanks). The changes are live for your review now.

[...]

[...] chroma has a global Registry variable that allows us to use it to "publish" new colorschemes. I've put that together with your suggestion to patch the superfile binary with the XML and found a solution.

Despite my limited Go knowledge, there are various potential future problems with the current overlay implementation. However, if your research concludes this is the best solution without major upstream changes, I am fine with this approach.

I've tested on the testbed and it worked nice, also is running nice on my setup too.

Seems to currently work in the testbed:

Tested-by: Noah Biewesch <dev@noahbiewesch.com>

@trueNAHO

trueNAHO commented Jul 7, 2026

Copy link
Copy Markdown
Member

Well, tbh, I dunno what's going on with nix run .#all-maintainers or with the precommit. I've added myself to maintainers.nix and I'm able to run the command to generate the file. But, when I try to commit the updated version, the precommit hook fails and update the generated all-maintainers file to a version without me ❓

Refresh the pre-commit cache:

rm .pre-commit-config.yaml && nix develop

@ReeSilva

ReeSilva commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

@trueNAHO Addressed all points except for one: the implementation of tokyonight is using the hardcoded catppuccin-mocha, but chroma has several colorschemes to be choose, and one should be able to do it.

@ReeSilva
ReeSilva force-pushed the feat/superfile-module branch 2 times, most recently from 8d1c707 to 572c318 Compare July 7, 2026 16:41
@ReeSilva

ReeSilva commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Also, squashed the commits.

@ReeSilva
ReeSilva requested a review from trueNAHO July 7, 2026 16:42
ReeSilva added 2 commits July 8, 2026 01:11
superfile: use maintainer last name

Update modules/superfile/testbeds/superfile.nix

Co-authored-by: Noah Biewesch <dev@noahbiewesch.com>

superfile: address comments and gen all-maintainers

superfile: remove code_syntax_highlight option
Generates a chroma XML syntax style from the Stylix palette at
build time via a nixpkgs overlay, and injects it into superfile
using go:embed to register at startup. So code highlighting
always matches the system theme with no user configuration.
@ReeSilva
ReeSilva force-pushed the feat/superfile-module branch from c9ae9c8 to a88fd41 Compare July 7, 2026 23:11
@stylix-automation stylix-automation Bot added the topic: overlay Overlay changes label Jul 7, 2026
@0xda157

0xda157 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@ReeSilva the pre-commit checks are failing

@ReeSilva

ReeSilva commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@ReeSilva the pre-commit checks are failing

ooh, has been some time hehe 😅 let me take a quick look and get back to you

@ReeSilva

ReeSilva commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@0xda157 fixed :)

@0xda157

0xda157 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

It looks like something got messed up when merging, as 1c283f2 should not be part of this pr.

@ReeSilva
ReeSilva force-pushed the feat/superfile-module branch from 46aeab9 to bb5f96c Compare August 7, 2026 19:38
@ReeSilva

ReeSilva commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@0xda157 fixed

@0xda157 0xda157 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LLM written PR descriptions are not helpful. If I wanted a LLM summary of your PR I could get a LLM to summarize it myself.

Comment thread modules/superfile/hm.nix Outdated
settings.theme = "stylix";
themes.${theme} = {
code_syntax_highlight = "stylix";
full_screen_fg = colors.withHashtag.base05;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this would be more readable with with color.withHashtag

Comment thread modules/superfile/hm.nix Outdated
({ colors, ... }: {
programs.superfile =
let
theme = "stylix";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you inline this please

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The better fix might be to use the variable to indicate the relation:

-            code_syntax_highlight = "stylix";
+            code_syntax_highlight = theme;

Comment thread modules/superfile/hm.nix Outdated
{ mkTarget, ... }:
mkTarget {
config = [
({ colors, ... }: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mkTarget modules should only specify what they require

Suggested change
({ colors, ... }: {
({ colors }: {

Comment thread modules/superfile/hm.nix Outdated
Comment on lines +3 to +4
config = [
({ colors, ... }: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
config = [
({ colors, ... }: {
config = { colors, ... }: {

Comment thread modules/superfile/overlay.nix Outdated

chromaXml = pkgs.writeText "stylix-chroma.xml" ''
<style name="stylix">
<entry type="Background" style="bg:#${colors.base00}"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use with colors.withHashtag here please.

Comment thread modules/superfile/hm.nix Outdated
({ colors, ... }: {
programs.superfile =
let
theme = "stylix";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The better fix might be to use the variable to indicate the relation:

-            code_syntax_highlight = "stylix";
+            code_syntax_highlight = theme;

Comment on lines +135 to +138
postPatch = (old.postPatch or "") + ''
cp ${registerGo} ./register-stylix.go
cp ${chromaXml} ./stylix-chroma.xml
'';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick:

Suggested change
postPatch = (old.postPatch or "") + ''
cp ${registerGo} ./register-stylix.go
cp ${chromaXml} ./stylix-chroma.xml
'';
postPatch = ''
${old.postPatch}
cp ${registerGo} ./register-stylix.go
cp ${chromaXml} ./stylix-chroma.xml
'';

firstUseCheck = false;
settings = {
auto_check_update = false;
ignore_missing_fields = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What fields are missing?

enable = true;
firstUseCheck = false;
settings = {
auto_check_update = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this necessary?

Comment thread modules/superfile/overlay.nix Outdated
inherit (lib) optionalAttrs;
inherit (config.lib.stylix) colors;

chromaXml = pkgs.writeText "stylix-chroma.xml" ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the purpose of duplicating the GenericStrong declaration?

{ lib, pkgs, ... }: {
stylix.testbed.ui = {
command = {
text = lib.getExe pkgs.superfile;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should probably open the flake-parts directory inside the testbed.

Comment on lines +117 to +119
if err != nil {
panic(err)
}

@trueNAHO trueNAHO Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless this is the idiomatic Go formatting, the following might be better:

Suggested change
if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

Comment thread modules/superfile/overlay.nix Outdated
inherit (lib) optionalAttrs;
inherit (config.lib.stylix) colors;

chromaXml = pkgs.writeText "stylix-chroma.xml" ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless the declaration order follows the default upstream themes, what about lexicographically sorting them?

Comment thread modules/superfile/hm.nix Outdated
Comment on lines +4 to +7
code_syntax_highlight = lib.mkOption {
description = "The syntax highlighting theme for code.";
type = lib.types.str;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did some research and created an approach based on what you suggested (great guidance, btw, huge thanks). The changes are live for your review now.

[...]

[...] chroma has a global Registry variable that allows us to use it to "publish" new colorschemes. I've put that together with your suggestion to patch the superfile binary with the XML and found a solution.

Despite my limited Go knowledge, there are various potential future problems with the current overlay implementation. However, if your research concludes this is the best solution without major upstream changes, I am fine with this approach.

I've tested on the testbed and it worked nice, also is running nice on my setup too.

Seems to currently work in the testbed:

Tested-by: Noah Biewesch <dev@noahbiewesch.com>

@trueNAHO trueNAHO mentioned this pull request Aug 7, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: home-manager Home Manager target topic: modules /modules/ subsystem topic: overlay Overlay changes topic: stylix /stylix/ subsystem topic: testbed Testbed changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

superfile: add target

3 participants