From 64b9282b72fffa05bbc216f74bb63edf777a35dd Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:16:55 +0530 Subject: Added ability to add convenience scripts. --- home.nix | 6 +++++- modules/default.nix | 10 +++++++++- modules/scripts/default.nix | 29 +++++++++++++++++++++++++++++ modules/scripts/scripts/restart-network.sh | 3 +++ modules/shell/bash/default.nix | 3 +++ modules/shell/zsh/default.nix | 3 +++ 6 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 modules/scripts/default.nix create mode 100644 modules/scripts/scripts/restart-network.sh diff --git a/home.nix b/home.nix index f8dc0aa..e789333 100644 --- a/home.nix +++ b/home.nix @@ -1,10 +1,12 @@ -{ pkgs, ... }: +{ config, ... }: { home.username = "arpit"; home.homeDirectory = "/home/arpit"; home.stateVersion = "23.11"; + baseDirectory = "${config.home.homeDirectory}/home-manager"; + # Desktop desktop.display-server.x11.xclip.enable = true; desktop.display-server.x11.xinit.enable = true; @@ -22,6 +24,8 @@ # Fonts fonts.nerdfont.fira-code.enable = true; + scripts.enable = true; + # Shell shell.bash.enable = true; shell.zsh.enable = true; diff --git a/modules/default.nix b/modules/default.nix index b697a2c..5e01083 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,10 +1,18 @@ -{ ... }: +{ lib, ... }: { imports = [ ./desktop ./fonts + ./scripts ./shell ./tools ]; + + options = { + baseDirectory = lib.mkOption { + type = lib.types.str; + description = "Path to the base of the current home manager configuration."; + }; + }; } diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix new file mode 100644 index 0000000..c933a5e --- /dev/null +++ b/modules/scripts/default.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: + +{ + options.scripts = { + enable = lib.mkEnableOption "Enable scripts."; + }; + + config = lib.mkIf config.scripts.enable { + home.file."scripts" = { + source = ./scripts; + recursive = true; + }; + + home.file."scripts/home-manager-switch" = { + text = '' +#!/bin/sh +home-manager switch --flake ${config.baseDirectory}/#${config.home.username} + ''; + executable = true; + }; + + home.activation.modifyScripts = lib.mkAfter '' + for script in ${config.home.homeDirectory}/scripts/*.sh; do + [ -f "$script" ] && mv "$script" "''${script%.sh}" + done + chmod -R u+x ${config.home.homeDirectory}/scripts + ''; + }; +} diff --git a/modules/scripts/scripts/restart-network.sh b/modules/scripts/scripts/restart-network.sh new file mode 100644 index 0000000..fc2b712 --- /dev/null +++ b/modules/scripts/scripts/restart-network.sh @@ -0,0 +1,3 @@ +#!/bin/sh +sudo ip link set $1 down +sudo ip link set $1 up diff --git a/modules/shell/bash/default.nix b/modules/shell/bash/default.nix index b845ced..b14669e 100644 --- a/modules/shell/bash/default.nix +++ b/modules/shell/bash/default.nix @@ -22,6 +22,9 @@ programs.bash.bashrcExtra = '' ${if config.tools.utils.fzf.enable then "eval \"$(fzf --bash)\"" +else ""} +${if config.scripts.enable then + "export PATH=${config.home.homeDirectory}/scripts:$PATH" else ""} ''; diff --git a/modules/shell/zsh/default.nix b/modules/shell/zsh/default.nix index d599196..96df967 100644 --- a/modules/shell/zsh/default.nix +++ b/modules/shell/zsh/default.nix @@ -21,6 +21,9 @@ ${if config.tools.utils.fzf.enable then "eval \"$(fzf --zsh)\"" else ""} ${builtins.readFile ./zshrc} +${if config.scripts.enable then + "export PATH=${config.home.homeDirectory}/scripts:$PATH" +else ""} ''; }; } -- cgit v1.2.3