feat: add new options for a new Script
This commit is contained in:
parent
c1cac88a32
commit
e584237006
2 changed files with 72 additions and 28 deletions
|
|
@ -25,6 +25,18 @@ with lib;
|
|||
description = "Directory for Nyx logs";
|
||||
};
|
||||
|
||||
autoStage = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Automatically stage changes after rebuild/cleanup";
|
||||
};
|
||||
|
||||
autoCommit = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Automatically commit changes after rebuild/cleanup";
|
||||
};
|
||||
|
||||
autoPush = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
|
|
|
|||
|
|
@ -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@"
|
||||
"@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.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.autoStage then "true" else "false")
|
||||
(if nyxCfg.autoCommit then "true" else "false")
|
||||
(if nyxCfg.autoPush then "true" else "false")
|
||||
"1.2.0"
|
||||
]
|
||||
src;
|
||||
(
|
||||
"#!/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; };
|
||||
};
|
||||
|
||||
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)
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue