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";
|
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 {
|
autoPush = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
|
|
|
||||||
|
|
@ -4,46 +4,78 @@ let
|
||||||
nyxCfg = config.nyx;
|
nyxCfg = config.nyx;
|
||||||
cfg = nyxCfg."nyx-rebuild";
|
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
|
# Read template and inject values
|
||||||
rebuiltScript =
|
rebuiltScript =
|
||||||
let
|
let
|
||||||
src = builtins.readFile ./bash/nyx-rebuild.sh; # uses @TOKENS@, not ${...}
|
src = builtins.readFile ./bash/nyx-rebuild.sh;
|
||||||
in
|
in
|
||||||
builtins.replaceStrings
|
builtins.replaceStrings
|
||||||
[
|
[
|
||||||
"@NIX_DIR@" "@LOG_DIR@" "@START_EDITOR@" "@ENABLE_FORMATTING@"
|
"@FLAKE_DIRECTORY@"
|
||||||
"@EDITOR@" "@FORMATTER@" "@GIT_BIN@" "@NOM_BIN@" "@AUTO_PUSH@" "@VERSION@"
|
"@LOG_DIR@"
|
||||||
]
|
"@ENABLE_FORMATTING@"
|
||||||
[
|
"@FORMATTER@"
|
||||||
(toString nyxCfg.nixDirectory)
|
"@GIT_BIN@"
|
||||||
(toString nyxCfg.logDir)
|
"@NOM_BIN@"
|
||||||
(if cfg.startEditor then "true" else "false")
|
"@AUTO_STAGE@"
|
||||||
(if cfg.enableFormatting then "true" else "false")
|
"@AUTO_COMMIT@"
|
||||||
cfg.editor
|
"@AUTO_PUSH@"
|
||||||
cfg.formatter
|
"@VERSION@"
|
||||||
"${pkgs.git}/bin/git"
|
]
|
||||||
"${pkgs.nix-output-monitor}/bin/nom"
|
[
|
||||||
(if nyxCfg.autoPush then "true" else "false")
|
(toString nyxCfg.nixDirectory)
|
||||||
"1.2.0"
|
(toString nyxCfg.logDir)
|
||||||
]
|
(if cfg.enableFormatting then "true" else "false")
|
||||||
src;
|
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
|
in
|
||||||
{
|
{
|
||||||
options.nyx."nyx-rebuild" = {
|
options.nyx."nyx-rebuild" = {
|
||||||
enable = lib.mkEnableOption "Enable nyx-rebuild script";
|
enable = lib.mkEnableOption "Enable nyx-rebuild script";
|
||||||
|
formatter = lib.mkOption { type = lib.types.str; default = "alejandra"; };
|
||||||
editor = lib.mkOption { type = lib.types.str; default = "nvim"; };
|
enableFormatting = lib.mkOption { type = lib.types.bool; default = false; };
|
||||||
formatter = lib.mkOption { type = lib.types.str; default = "alejandra"; };
|
enableAlias = lib.mkOption { type = lib.types.bool; default = true; };
|
||||||
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) {
|
config = lib.mkIf (nyxCfg.enable && cfg.enable) {
|
||||||
environment.systemPackages =
|
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)
|
(pkgs.writeShellScriptBin "nyx-rebuild" rebuiltScript)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue