Skip to content

Commit

Permalink
Updated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-kirk committed Jan 13, 2025
1 parent 5b963c1 commit afde8b1
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 76 deletions.
4 changes: 0 additions & 4 deletions configurations/home-manager/work/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ in {
slack
signal-desktop

# Fonts
(nerdfonts.override {fonts = ["FiraCode"];})
fira-code

# Document handling
texlive.combined.scheme-full
pandoc
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
};

homeManagerModules = rec {
kirk = import ./modules/home-manager;
kirk = {
imports = [ ./modules/home-manager ];
config._module.args = {inherit inputs;};
};
default = kirk;
};

Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/fonts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ in {

home.packages = with pkgs; [
# Fonts
(nerdfonts.override {fonts = ["FiraCode"];})
nerd-fonts.fira-code
fira-code
];
};
Expand Down
169 changes: 109 additions & 60 deletions modules/home-manager/homeManagerScripts/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
inputs,
config,
pkgs,
lib,
Expand All @@ -11,56 +12,106 @@ with lib; let
then cfg.configDir
else "${config.xdg.configHome}/home-manager";

hm-clean = pkgs.writeShellApplication {
name = "hm-clean";
hm = pkgs.writeShellApplication {
name = "hm";
runtimeInputs = with pkgs; [ fzf git ];
text = ''
# Delete old home-manager profiles
home-manager expire-generations '-30 days' &&
# Delete old nix profiles
nix profile wipe-history --older-than 30d &&
# Optimize space
nix store gc &&
nix store optimise
'';
};
command="''${1:-}"
# Check if a parameter is provided
if [ -z "$command" ]; then
echo "Usage: hm <command>"
echo ""
echo "Commands:"
echo " rebuild Rebuild the Home Manager configuration."
echo " upgrade Upgrade Home Manager packages. Note that this also rebuilds the configuration."
echo " options Shows available Home Manager configuration options."
echo " garbage-collect Garbage collects, freeing up unused hard drive space allocated to unused Nix packages."
echo " update Updating Nix flake inputs. This updates packages for the next rebuild..."
echo " test Test the Home Manager configuration."
echo " rollback Roll back to the previous configuration."
echo ""
echo "Garbage collecting will:"
echo "- Delete Home Manager configurations and nix profiles older than 30 days"
echo "- Delete unused packages in the Nix store"
echo "- Optimize the Nix store, by replacing identical files in the store by hard links"
exit 1
fi
hm-update = pkgs.writeShellApplication {
name = "hm-update";
text = ''
nix flake update --flake ${configDir}
'';
};
update() {
echo "[HM-INFO]: Updating packages for the next rebuild, by updating the Nix flake inputs..."
echo ""
nix flake update --flake ${configDir}
}
hm-upgrade = pkgs.writeShellApplication {
name = "hm-upgrade";
text = ''
# Update, switch to new config, and cleanup
${hm-update}/bin/hm-update &&
${hm-rebuild}/bin/hm-rebuild &&
${hm-clean}/bin/hm-clean
'';
};
rebuild() {
echo "[HM-INFO]: Rebuilding Home Manager configuration..."
echo ""
pushd "${configDir}"
git add .
home-manager switch -b backup --flake .#${cfg.machine}
popd
}
hm-rebuild = pkgs.writeShellApplication {
name = "hm-rebuild";
text = ''
pushd ${configDir}
git add .
# Switch configuration, backing up files
home-manager switch -b backup --flake .#${cfg.machine}
popd
'';
};
garbage_collect() {
echo "[HM-INFO]: Garbage collecting the Nix store..."
echo ""
home-manager expire-generations '-30 days'
nix profile wipe-history --older-than 30d
nix store gc
nix store optimise
}
hm-rollback = pkgs.writeShellApplication {
name = "hm-rollback";
runtimeInputs = [pkgs.fzf];
text = ''
gen=$(home-manager generations | grep -P "^[0-9]{4}-[0-9]{2}-[0-9]{2}" | fzf)
genPath=$(echo "$gen" | grep -oP "/nix/store/.*")
rollback() {
echo ""
gen=$(home-manager generations | grep -P "^[0-9]{4}-[0-9]{2}-[0-9]{2}" | fzf)
genPath=$(echo "$gen" | grep -oP "/nix/store/.*")
genId=$(echo "$gen" | grep -oP "(?<=id )\d+")
echo -e '\033[1mActivating selected generation:\n\033[0m'
"$genPath"/activate
if [ -z "$gen" ]; then
echo "[HM-ERROR]: No generation selected. Aborting."
exit 1
fi
echo "[HM-INFO]: Activating generation $genId:"
"$genPath"/activate
}
# Handle the command
case "$1" in
rebuild)
rebuild
;;
upgrade)
echo "[HM-INFO]: Upgrading Home Manager packages..."
echo ""
update &&
rebuild &&
garbage-collect
;;
options)
man home-configuration.nix
;;
garbage-collect)
garbage-collect
;;
update)
update
;;
rollback)
rollback
;;
test)
tmpdir=$(mktemp -d) &&
echo "[HM-INFO]: Building the test configuration to \"$tmpdir\"..." &&
cd "$tmpdir" &&
home-manager build --show-trace --flake ${configDir}#${cfg.machine}
;;
*)
echo "[HM-ERROR]: Unknown command: $1"
echo "Valid commands are: rebuild, upgrade, options, garbage-collect, rollback, update, test"
exit 1
;;
esac
'';
};
in {
Expand All @@ -70,17 +121,13 @@ in {
managing home-manager easier. These scripts are lean bash scripts that
compose a couple of nix and home-manager commands:
- `hm-update`: Updates the available packages, usually, you don't need
to run this, but the other scripts use it.
- `hm-clean`: Cleans up older configurations and garbage collects the
nix store, cleaning up unused packages and freeing up harddisk space
- `hm-rebuild`: Builds your configuration. Backs up files; if you
fx have a `.bashrc` and home-manager needs to overwrite it, the old
`.bashrc` is renamed to `.bashrc.bck`
- `hm-upgrade`: Updates all packages, rebuilds and finally older
configurations/garbage collects
- `hm-rollback`: Use this command to roll back to a previous working
home manager configuration.
- `hm rebuild`: Rebuild the Home Manager configuration."
- `hm upgrade`: Upgrade Home Manager packages. Note that this also rebuilds the configuration."
- `hm options`: Shows available Home Manager configuration options."
- `hm garbage-collect`: Garbage collects, freeing up unused hard drive space allocated to unused Nix packages."
- `hm update`: Updating Nix flake inputs. This updates packages for the next rebuild..."
- `hm test`: Test the Home Manager configuration."
- `hm rollback`: Roll back to the previous configuration."
'';

configDir = mkOption {
Expand Down Expand Up @@ -115,12 +162,14 @@ in {
entries = lib.mkForce [];
};

# Use the pinned nixpkgs version that is already used, when using `nix shell nixpkgs#package`
nix.registry.nixpkgs = {
from = { id = "nixpkgs"; type = "indirect"; };
flake = inputs.nixpkgs;
};

home.packages = [
hm-update
hm-upgrade
hm-rebuild
hm-clean
hm-rollback
hm
];
};
}
14 changes: 12 additions & 2 deletions modules/home-manager/jiten/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ in {
config = mkIf cfg.enable {
home.packages = with pkgs; [jiten];

programs.zsh.initExtra = mkIf cfg.dailyWord "cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt";
programs.bash.initExtra = mkIf cfg.dailyWord "cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt";
programs.zsh.initExtra = mkIf cfg.dailyWord ''
if [[ -z "$ZSH_WORD_DISPLAYED" ]]; then
export ZSH_WORD_DISPLAYED=true
cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt
fi
'';
programs.bash.initExtra = mkIf cfg.dailyWord ''
if [[ -z "$BASH_WORD_DISPLAYED" ]]; then
export BASH_WORD_DISPLAYED=true
cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt
fi
'';

systemd.user = mkIf cfg.dailyWord {
timers = {
Expand Down
27 changes: 22 additions & 5 deletions modules/home-manager/yazi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ with lib; let
cp -r "${name}".yazi/* "$out"
'';
src = pkgs.fetchgit {
rev = "5e65389d1308188e5a990059c06729e2edb18f8a";
rev = "600614a9dc59a12a63721738498c5541c7923873";
url = "https://github.com/yazi-rs/plugins.git";
hash = "sha256-XHaQjudV9YSMm4vF7PQrKGJ078oVF1U1Du10zXEJ9I0=";
hash = "sha256-mQkivPt9tOXom78jgvSwveF/8SD8M2XCXxGY8oijl+o=";
};
};
mkYaziPluginGithub = x:
Expand All @@ -38,8 +38,8 @@ with lib; let
gruvbox-dark = mkYaziPluginGithub {
name = "gruvbox-dark";
url = "https://github.com/bennyyip/gruvbox-dark.yazi.git";
rev = "c204853de7a78bc99ea628e51857ce65506468db";
hash = "sha256-NBco10MINyAJk1YWHwYUzvI9mnTJl9aYyDtQSTUP3Hs=";
rev = "b4cc9f2a3016f9b5a9bbb5aeb4619d029ee61397";
hash = "sha256-9ZZHXP0Junaj6r80nE8oDNEU5WIKVdtz4g72BFzcSAM=";
};
exifaudio = mkYaziPluginGithub {
name = "exifaudio";
Expand Down Expand Up @@ -81,8 +81,11 @@ in {
enableZshIntegration = true;
shellWrapperName = "j";
initLua = ''
require("full-border"):setup()
require("git"):setup()
require("full-border"):setup()
require("session"):setup {
sync_yanked = true,
}
'';
keymap = {
manager.prepend_keymap =
Expand Down Expand Up @@ -112,6 +115,20 @@ in {
run = "create";
desc = "Create a file";
}
{
on = ["m" "t"];
run = ''shell "foot </dev/null &>/dev/null &"'';
desc = "Create a new terminal";
}
{
on = ["m" "j"];
run = ''shell "foot </dev/null &>/dev/null zsh -c 'source ~/.zshrc; j; zsh'& "'';
desc = "Create a new terminal with yazi open";
}
{
on = [ "2" ];
run = "plugin switch-create-tab --args=1";
}
# Selection
{
on = ";";
Expand Down
9 changes: 9 additions & 0 deletions modules/home-manager/yazi/plugins/auto-tab/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- @sync entry
local function entry(_, args)
for _ = #cx.tabs, args[1] do
ya.manager_emit("tab_create", { current = true })
end
ya.manager_emit("tab_switch", { args[1] })
end

return { entry = entry }

0 comments on commit afde8b1

Please sign in to comment.