silicon: init module
This commit is contained in:
parent
f61917cbaa
commit
eb1b94a6c2
|
@ -1618,6 +1618,16 @@ in {
|
||||||
https://github.com/fastfetch-cli/fastfetch for more.
|
https://github.com/fastfetch-cli/fastfetch for more.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2024-05-09T15:12:32+00:00";
|
||||||
|
message = ''
|
||||||
|
A new module is available: 'programs.silicon'.
|
||||||
|
Silicon is an alternative to Carbon implemented in Rust,
|
||||||
|
it can render your source code into a beautiful image.
|
||||||
|
See https://github.com/Aloxaf/silicon for more.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,7 @@ let
|
||||||
./programs/script-directory.nix
|
./programs/script-directory.nix
|
||||||
./programs/senpai.nix
|
./programs/senpai.nix
|
||||||
./programs/sftpman.nix
|
./programs/sftpman.nix
|
||||||
|
./programs/silicon.nix
|
||||||
./programs/sioyek.nix
|
./programs/sioyek.nix
|
||||||
./programs/skim.nix
|
./programs/skim.nix
|
||||||
./programs/sm64ex.nix
|
./programs/sm64ex.nix
|
||||||
|
|
131
modules/programs/silicon.nix
Normal file
131
modules/programs/silicon.nix
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
{ pkgs, lib, config, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let cfg = config.programs.silicon;
|
||||||
|
in {
|
||||||
|
meta.maintainers = with hm.maintainers; [ afresquet ];
|
||||||
|
|
||||||
|
options.programs.silicon = {
|
||||||
|
enable =
|
||||||
|
mkEnableOption "silicon, create beautiful image of your source code";
|
||||||
|
|
||||||
|
package = mkPackageOption pkgs "silicon" { };
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "";
|
||||||
|
example = literalExpression ''
|
||||||
|
--shadow-color '#555'
|
||||||
|
--background '#fff'
|
||||||
|
--shadow-blur-radius 30
|
||||||
|
--no-window-controls
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Silicon configuration.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
themes = mkOption {
|
||||||
|
type = types.attrsOf (types.submodule {
|
||||||
|
options = {
|
||||||
|
src = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to the theme folder.";
|
||||||
|
};
|
||||||
|
|
||||||
|
file = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description =
|
||||||
|
"Subpath of the theme file within the source, if needed.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = { };
|
||||||
|
example = literalExpression ''
|
||||||
|
{
|
||||||
|
dracula = {
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "dracula";
|
||||||
|
repo = "sublime"; # Silicon uses sublime syntax for its themes
|
||||||
|
rev = "26c57ec282abcaa76e57e055f38432bd827ac34e";
|
||||||
|
sha256 = "019hfl4zbn4vm4154hh3bwk6hm7bdxbr1hdww83nabxwjn99ndhv";
|
||||||
|
};
|
||||||
|
file = "Dracula.tmTheme";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Additional themes to provide.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
syntaxes = mkOption {
|
||||||
|
type = types.attrsOf (types.submodule {
|
||||||
|
options = {
|
||||||
|
src = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Path to the syntax folder.";
|
||||||
|
};
|
||||||
|
file = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description =
|
||||||
|
"Subpath of the syntax file within the source, if needed.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = { };
|
||||||
|
example = literalExpression ''
|
||||||
|
{
|
||||||
|
gleam = {
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "molnarmark";
|
||||||
|
repo = "sublime-gleam";
|
||||||
|
rev = "2e761cdb1a87539d827987f997a20a35efd68aa9";
|
||||||
|
hash = "sha256-Zj2DKTcO1t9g18qsNKtpHKElbRSc9nBRE2QBzRn9+qs=";
|
||||||
|
};
|
||||||
|
file = "syntax/gleam.sublime-syntax";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Additional syntaxes to provide.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
|
xdg.configFile = mkMerge ([({
|
||||||
|
"silicon/config" = mkIf (cfg.settings != "") { text = cfg.settings; };
|
||||||
|
})] ++ (flip mapAttrsToList cfg.themes (name: val: {
|
||||||
|
"silicon/themes/${name}.tmTheme" = {
|
||||||
|
source =
|
||||||
|
if isNull val.file then "${val.src}" else "${val.src}/${val.file}";
|
||||||
|
};
|
||||||
|
})) ++ (flip mapAttrsToList cfg.syntaxes (name: val: {
|
||||||
|
"silicon/syntaxes/${name}.sublime-syntax" = {
|
||||||
|
source =
|
||||||
|
if isNull val.file then "${val.src}" else "${val.src}/${val.file}";
|
||||||
|
};
|
||||||
|
})));
|
||||||
|
|
||||||
|
# NOTE: we are ensuring `themes` and `syntaxes` directories exist
|
||||||
|
# because silicon assumes they do when running `--build-cache`
|
||||||
|
# https://github.com/Aloxaf/silicon/issues/242
|
||||||
|
home.activation.siliconCache = hm.dag.entryAfter [ "linkGeneration" ] ''
|
||||||
|
(
|
||||||
|
export XDG_CACHE_HOME=${escapeShellArg config.xdg.cacheHome}
|
||||||
|
verboseEcho "Rebuilding silicon theme cache"
|
||||||
|
mkdir -p ${
|
||||||
|
escapeShellArg config.xdg.configHome
|
||||||
|
}/silicon/{themes,syntaxes}
|
||||||
|
cd ${escapeShellArg config.xdg.configHome}/silicon
|
||||||
|
run ${getExe cfg.package} --build-cache
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -140,6 +140,7 @@ in import nmtSrc {
|
||||||
./modules/programs/scmpuff
|
./modules/programs/scmpuff
|
||||||
./modules/programs/senpai
|
./modules/programs/senpai
|
||||||
./modules/programs/sftpman
|
./modules/programs/sftpman
|
||||||
|
./modules/programs/silicon
|
||||||
./modules/programs/sioyek
|
./modules/programs/sioyek
|
||||||
./modules/programs/sm64ex
|
./modules/programs/sm64ex
|
||||||
./modules/programs/spotify-player
|
./modules/programs/spotify-player
|
||||||
|
|
4
tests/modules/programs/silicon/basic-configuration
Executable file
4
tests/modules/programs/silicon/basic-configuration
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
--shadow-color '#555'
|
||||||
|
--background '#fff'
|
||||||
|
--shadow-blur-radius 30
|
||||||
|
--no-window-controls
|
19
tests/modules/programs/silicon/basic-configuration.nix
Normal file
19
tests/modules/programs/silicon/basic-configuration.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
programs.silicon = {
|
||||||
|
enable = true;
|
||||||
|
settings = ''
|
||||||
|
--shadow-color '#555'
|
||||||
|
--background '#fff'
|
||||||
|
--shadow-blur-radius 30
|
||||||
|
--no-window-controls
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.silicon = { };
|
||||||
|
|
||||||
|
nmt.script = let configFile = "home-files/.config/silicon/config";
|
||||||
|
in ''
|
||||||
|
assertFileExists "${configFile}"
|
||||||
|
assertFileContent "${configFile}" ${./basic-configuration}
|
||||||
|
'';
|
||||||
|
}
|
9
tests/modules/programs/silicon/default-configuration.nix
Normal file
9
tests/modules/programs/silicon/default-configuration.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
programs.silicon.enable = true;
|
||||||
|
|
||||||
|
test.stubs.silicon = { };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertPathNotExists "home-files/.config/silicon/config"
|
||||||
|
'';
|
||||||
|
}
|
6
tests/modules/programs/silicon/default.nix
Normal file
6
tests/modules/programs/silicon/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
silicon-default-configuration = ./default-configuration.nix;
|
||||||
|
silicon-basic-configuration = ./basic-configuration.nix;
|
||||||
|
silicon-themes = ./themes.nix;
|
||||||
|
silicon-syntaxes = ./syntaxes.nix;
|
||||||
|
}
|
30
tests/modules/programs/silicon/syntaxes.nix
Normal file
30
tests/modules/programs/silicon/syntaxes.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let syntaxName = "gleam";
|
||||||
|
in {
|
||||||
|
programs.silicon = {
|
||||||
|
enable = true;
|
||||||
|
syntaxes = {
|
||||||
|
${syntaxName} = {
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "molnarmark";
|
||||||
|
repo = "sublime-gleam";
|
||||||
|
rev = "2e761cdb1a87539d827987f997a20a35efd68aa9";
|
||||||
|
hash = "sha256-Zj2DKTcO1t9g18qsNKtpHKElbRSc9nBRE2QBzRn9+qs=";
|
||||||
|
};
|
||||||
|
file = "syntax/gleam.sublime-syntax";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.silicon = { };
|
||||||
|
|
||||||
|
nmt.script = let
|
||||||
|
syntaxFile =
|
||||||
|
"home-files/.config/silicon/syntaxes/${syntaxName}.sublime-syntax";
|
||||||
|
cacheFile = "home-files/.cache/silicon/syntaxes.bin";
|
||||||
|
in ''
|
||||||
|
assertFileExists "${syntaxFile}"
|
||||||
|
assertFileExists "${cacheFile}"
|
||||||
|
'';
|
||||||
|
}
|
29
tests/modules/programs/silicon/themes.nix
Normal file
29
tests/modules/programs/silicon/themes.nix
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let themeName = "dracula";
|
||||||
|
in {
|
||||||
|
programs.silicon = {
|
||||||
|
enable = true;
|
||||||
|
themes = {
|
||||||
|
${themeName} = {
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "dracula";
|
||||||
|
repo = "sublime";
|
||||||
|
rev = "26c57ec282abcaa76e57e055f38432bd827ac34e";
|
||||||
|
sha256 = "019hfl4zbn4vm4154hh3bwk6hm7bdxbr1hdww83nabxwjn99ndhv";
|
||||||
|
};
|
||||||
|
file = "Dracula.tmTheme";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.silicon = { };
|
||||||
|
|
||||||
|
nmt.script = let
|
||||||
|
themeFile = "home-files/.config/silicon/themes/${themeName}.tmTheme";
|
||||||
|
cacheFile = "home-files/.cache/silicon/themes.bin";
|
||||||
|
in ''
|
||||||
|
assertFileExists "${themeFile}"
|
||||||
|
assertFileExists "${cacheFile}"
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Reference in a new issue