feat: add new options for a new Script

This commit is contained in:
Peritia 2025-09-16 15:59:17 +02:00
parent c1cac88a32
commit e584237006
2 changed files with 72 additions and 28 deletions

View file

@ -4,46 +4,78 @@ let
nyxCfg = config.nyx;
cfg = nyxCfg."nyx-rebuild";
# Function to put a file from lib/ into the Nix store
libFile = file:
builtins.toFile
(builtins.baseNameOf file)
(builtins.readFile ./bash/lib/${file});
# List of files you want to source
filesToSource = [
"git.sh"
"logging.sh"
"sudo.sh"
# "nyx-rebuild-logic.sh"
];
# Build sourcing lines dynamically
sourcingLines =
builtins.concatStringsSep "\n"
(map (f: "source ${libFile f}") filesToSource);
# Read template and inject values
rebuiltScript =
let
src = builtins.readFile ./bash/nyx-rebuild.sh; # uses @TOKENS@, not ${...}
src = builtins.readFile ./bash/nyx-rebuild.sh;
in
builtins.replaceStrings
[
"@NIX_DIR@" "@LOG_DIR@" "@START_EDITOR@" "@ENABLE_FORMATTING@"
"@EDITOR@" "@FORMATTER@" "@GIT_BIN@" "@NOM_BIN@" "@AUTO_PUSH@" "@VERSION@"
]
[
(toString nyxCfg.nixDirectory)
(toString nyxCfg.logDir)
(if cfg.startEditor then "true" else "false")
(if cfg.enableFormatting then "true" else "false")
cfg.editor
cfg.formatter
"${pkgs.git}/bin/git"
"${pkgs.nix-output-monitor}/bin/nom"
(if nyxCfg.autoPush then "true" else "false")
"1.2.0"
]
src;
builtins.replaceStrings
[
"@FLAKE_DIRECTORY@"
"@LOG_DIR@"
"@ENABLE_FORMATTING@"
"@FORMATTER@"
"@GIT_BIN@"
"@NOM_BIN@"
"@AUTO_STAGE@"
"@AUTO_COMMIT@"
"@AUTO_PUSH@"
"@VERSION@"
]
[
(toString nyxCfg.nixDirectory)
(toString nyxCfg.logDir)
(if cfg.enableFormatting then "true" else "false")
cfg.formatter
"${pkgs.git}/bin/git"
"${pkgs.nix-output-monitor}/bin/nom"
(if nyxCfg.autoStage then "true" else "false")
(if nyxCfg.autoCommit then "true" else "false")
(if nyxCfg.autoPush then "true" else "false")
"1.2.0"
]
(
"#!/usr/bin/env bash\n"
+ "source_all () {\n"
+ sourcingLines
+ "\n}\n"
+ src
);
in
{
options.nyx."nyx-rebuild" = {
enable = lib.mkEnableOption "Enable nyx-rebuild script";
editor = lib.mkOption { type = lib.types.str; default = "nvim"; };
formatter = lib.mkOption { type = lib.types.str; default = "alejandra"; };
startEditor = lib.mkOption { type = lib.types.bool; default = false; };
enableFormatting = lib.mkOption { type = lib.types.bool; default = false; };
enableAlias = lib.mkOption { type = lib.types.bool; default = true; };
enable = lib.mkEnableOption "Enable nyx-rebuild script";
formatter = lib.mkOption { type = lib.types.str; default = "alejandra"; };
enableFormatting = lib.mkOption { type = lib.types.bool; default = false; };
enableAlias = lib.mkOption { type = lib.types.bool; default = true; };
};
config = lib.mkIf (nyxCfg.enable && cfg.enable) {
environment.systemPackages =
lib.optionals (cfg.enableFormatting && cfg.formatter == "alejandra") [ pkgs.alejandra ]
lib.optionals (cfg.enableFormatting && cfg.formatter == "alejandra") [
pkgs.alejandra
]
++ [
# Ensure nyx-tool exists if you call it in the script
(pkgs.writeShellScriptBin "nyx-rebuild" rebuiltScript)
];