From b4acb6e15f6dca2a0994d017fc36f48742d9b6dd Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 24 Mar 2024 13:18:51 +0100 Subject: [PATCH] Restructure home-manager config --- home/default.nix | 27 +++--- home/packages/cli/shared.nix | 78 +++++++--------- home/programs/terminal/shell/zsh/aliases.nix | 98 ++++++++++---------- home/programs/terminal/shell/zsh/default.nix | 14 +-- home/programs/terminal/shell/zsh/plugins.nix | 66 +++++++------ system/system.nix | 6 +- 6 files changed, 138 insertions(+), 151 deletions(-) diff --git a/home/default.nix b/home/default.nix index ebc4bc0..9092308 100644 --- a/home/default.nix +++ b/home/default.nix @@ -4,11 +4,6 @@ let username = config.myOptions.system.username; in { - imports = [ - ./packages - ./programs - ]; - home-manager = lib.mkIf myHmConf.enabled { # Use verbose mode for home-manager verbose = true; @@ -31,13 +26,23 @@ in extraSpecialArgs = { inherit inputs self; }; users.${username} = { - # Let home-manager manage itself in standalone mode - programs.home-manager.enable = true; + # These imports will be scoped under this key so all settings + # in them will be added to `home-manager.users.${username}`.. + imports = [ + ./packages + ./programs + ]; - home = { - inherit username; - homeDirectory = "/home/${username}"; - stateVersion = myHmConf.stateVersion; + config = { + # Let home-manager manage itself in standalone mode + programs.home-manager.enable = true; + + # Basic user config + home = { + inherit username; + homeDirectory = "/home/${username}"; + stateVersion = myHmConf.stateVersion; + }; }; }; }; diff --git a/home/packages/cli/shared.nix b/home/packages/cli/shared.nix index 8cea4b2..08c003c 100644 --- a/home/packages/cli/shared.nix +++ b/home/packages/cli/shared.nix @@ -1,45 +1,39 @@ -{ config, pkgs, lib, ... }: -let - username = config.myOptions.system.username; -in -{ - home-manager.users.${username} = { - home.packages = with pkgs; [ - fzf # fuzzy finder - jq # JSON processor - zip # compression/archiver for creating .zip files - unzip # extraction util for .zip files - file # show type of file - rsync # incremental file transfer util - btop # system monitor - hyperfine # benchmarker - delta # git delta viewer - gnupg # encryption - bc # GNU calculator - mediainfo # shows tags/info about video/audio files - usbutils # tools for working with usb devices (like lsusb) - hexyl # hex viewer - strace # linux system call tracer - yt-dlp # media downloader - glow # markdown renderer - xdg-ninja # check $HOME for unwanted files - nettools # Various tools for controlling the network - dnsutils # DNS utilities - dig # DNS utilities - curl # CLI tool for transfering data with URLs +{ pkgs, ... }: { + home.packages = with pkgs; [ + fzf # fuzzy finder + jq # JSON processor + zip # compression/archiver for creating .zip files + unzip # extraction util for .zip files + file # show type of file + rsync # incremental file transfer util + btop # system monitor + hyperfine # benchmarker + delta # git delta viewer + gnupg # encryption + bc # GNU calculator + mediainfo # shows tags/info about video/audio files + usbutils # tools for working with usb devices (like lsusb) + hexyl # hex viewer + strace # linux system call tracer + yt-dlp # media downloader + glow # markdown renderer + xdg-ninja # check $HOME for unwanted files + nettools # Various tools for controlling the network + dnsutils # DNS utilities + dig # DNS utilities + curl # CLI tool for transfering data with URLs - # Rust replacements - procs # better ps - ripgrep # better grep - fd # better find - du-dust # better du - bat # better cat + # Rust replacements + procs # better ps + ripgrep # better grep + fd # better find + du-dust # better du + bat # better cat - # Development - gcc # GNU C compiler - cmake # build system generator - meson # C/C++ build system - gh # GitHub CLI tool - ]; - }; + # Development + gcc # GNU C compiler + cmake # build system generator + meson # C/C++ build system + gh # GitHub CLI tool + ]; } diff --git a/home/programs/terminal/shell/zsh/aliases.nix b/home/programs/terminal/shell/zsh/aliases.nix index 3808a80..5562d4f 100644 --- a/home/programs/terminal/shell/zsh/aliases.nix +++ b/home/programs/terminal/shell/zsh/aliases.nix @@ -1,64 +1,60 @@ { config, pkgs, lib, ... }: let - username = config.myOptions.system.username; - inherit (lib.meta) getExe getExe'; in { - home-manager.users.${username} = { - programs.zsh.shellAliases = { - # I'm not the greatest typist - sl = "ls"; - mdkir = "mkdir"; - soruce = "source"; - suod = "sudo"; - sduo = "sudo"; + programs.zsh.shellAliases = { + # I'm not the greatest typist + sl = "ls"; + mdkir = "mkdir"; + soruce = "source"; + suod = "sudo"; + sduo = "sudo"; - # Directory changing - ".." = "cd .."; - "..." = "cd ../../"; - "...." = "cd ../../../"; - "....." = "cd ../../../../"; - ".2" = "cd ../../"; - ".3" = "cd ../../../"; - ".4" = "cd ../../../../"; - ".5" = "cd ../../../../../"; + # Directory changing + ".." = "cd .."; + "..." = "cd ../../"; + "...." = "cd ../../../"; + "....." = "cd ../../../../"; + ".2" = "cd ../../"; + ".3" = "cd ../../../"; + ".4" = "cd ../../../../"; + ".5" = "cd ../../../../../"; - # Files/Directories utilities - fcd = "cd $(find -type d | fzf)"; - mkdir = "mkdir -p"; - md = "mkdir"; - fhere = "find . -name"; - rr = "rm -r"; - rf = "rm -f"; - rrf = "rm -rf"; - vimdiff = "nvim -d"; + # Files/Directories utilities + fcd = "cd $(find -type d | fzf)"; + mkdir = "mkdir -p"; + md = "mkdir"; + fhere = "find . -name"; + rr = "rm -r"; + rf = "rm -f"; + rrf = "rm -rf"; + vimdiff = "nvim -d"; - # Directory listing aliases - ls = "ls --color=auto"; - l = "ls -lahX --classify"; - ll = "ls -lahX --classify --group-directories-first"; - ldir = "ls -lahX --classify | grep --color=never ^d"; - dotall = "ls -lahXd .[a-z]*"; - dotfiles = "dotall | grep -v ^d"; - dotdirs = "dotall | grep --color=never ^d"; + # Directory listing aliases + ls = "ls --color=auto"; + l = "ls -lahX --classify"; + ll = "ls -lahX --classify --group-directories-first"; + ldir = "ls -lahX --classify | grep --color=never ^d"; + dotall = "ls -lahXd .[a-z]*"; + dotfiles = "dotall | grep -v ^d"; + dotdirs = "dotall | grep --color=never ^d"; - # File validation and manipulation - yamlcheck = "${getExe pkgs.python3} -c 'import sys, yaml as y; y.safe_load(open(sys.argv[1]))'"; # Validate YAML - jsoncheck = "${getExe pkgs.jq} "." >/dev/null <"; # Validate JSON - urlencode = "${getExe pkgs.python3} -c 'import sys, urllib.parse as ul; print(ul.quote_plus(sys.argv[1]));'"; # Encode strings as URLs (space->%20, etc.) - mergepdf = "${getExe pkgs.gnostscript} -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf"; # Usage: `mergepdf input{1,2,3}.pdf`` - encrypt = "${getExe pkgs.gnupg} -c --no-symkey-cache --cipher-algo AES256"; # Encrypt file with AES256 symetric encryption + # File validation and manipulation + yamlcheck = "${getExe pkgs.python3} -c 'import sys, yaml as y; y.safe_load(open(sys.argv[1]))'"; # Validate YAML + jsoncheck = "${getExe pkgs.jq} "." >/dev/null <"; # Validate JSON + urlencode = "${getExe pkgs.python3} -c 'import sys, urllib.parse as ul; print(ul.quote_plus(sys.argv[1]));'"; # Encode strings as URLs (space->%20, etc.) + mergepdf = "${getExe pkgs.gnostscript} -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf"; # Usage: `mergepdf input{1,2,3}.pdf`` + encrypt = "${getExe pkgs.gnupg} -c --no-symkey-cache --cipher-algo AES256"; # Encrypt file with AES256 symetric encryption - # Get global IP address by querying opendns directly - # (much better than using some random "what is my ip" service) - # - canihazip = "${getExe pkgs.dig} @resolver4.opendns.com myip.opendns.com +short"; - canihazip4 = "${getExe pkgs.dig} @resolver4.opendns.com myip.opendns.com +short -4"; - canihazip6 = "${getExe pkgs.dig} @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6"; + # Get global IP address by querying opendns directly + # (much better than using some random "what is my ip" service) + # + canihazip = "${getExe pkgs.dig} @resolver4.opendns.com myip.opendns.com +short"; + canihazip4 = "${getExe pkgs.dig} @resolver4.opendns.com myip.opendns.com +short -4"; + canihazip6 = "${getExe pkgs.dig} @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6"; - # Expand aliases from sudo - sudo = "sudo "; - }; + # Expand aliases from sudo + sudo = "sudo "; }; } diff --git a/home/programs/terminal/shell/zsh/default.nix b/home/programs/terminal/shell/zsh/default.nix index b439c12..308c9fc 100644 --- a/home/programs/terminal/shell/zsh/default.nix +++ b/home/programs/terminal/shell/zsh/default.nix @@ -1,18 +1,10 @@ -{ config, pkgs, ... }: -let - username = config.myOptions.system.username; - hmCfg = config.home-manager.users.${username}; -in -{ +{ config, pkgs, ... }: { imports = [ ./plugins.nix ./aliases.nix ]; - programs.zsh.enable = true; - users.users.${username}.shell = pkgs.zsh; - - home-manager.users.${username} = { + config = { programs.zsh = { enable = true; dotDir = ".config/zsh"; @@ -25,7 +17,7 @@ in share = true; # don't clutter $HOME - path = "${hmCfg.xdg.dataHome}/zsh/zsh_history"; + path = "${config.xdg.dataHome}/zsh/zsh_history"; # save timestamps to histfile extended = true; diff --git a/home/programs/terminal/shell/zsh/plugins.nix b/home/programs/terminal/shell/zsh/plugins.nix index 4b97a8a..5c3728b 100644 --- a/home/programs/terminal/shell/zsh/plugins.nix +++ b/home/programs/terminal/shell/zsh/plugins.nix @@ -1,41 +1,37 @@ { config, pkgs, ... }: let - username = config.myOptions.system.username; inherit (pkgs) fetchFromGitHub; in { - - home-manager.users.${username} = { - programs.zsh.plugins = [ - { - name = "zsh-nix-shell"; - src = pkgs.zsh-nix-shell; - file = "share/zsh-nix-shell/nix-shell.plugin.zsh"; - } - { - name = "zsh-vi-mode"; - src = pkgs.zsh-vi-mode; - file = "share/zsh-vi-mode/zsh-vi-mode.plugin.zsh"; - } - { - name = "fast-syntax-highlighting"; - src = "${pkgs.zsh-fast-syntax-highlighting}/share/zsh/site-functions"; - } - { - name = "zsh-autosuggestions"; - src = pkgs.zsh-autosuggestions; - file = "share/zsh-autosuggestions/zsh-autosuggestions.zsh"; - } - { - name = "zsh-autopair"; - file = "zsh-autopair.plugin.zsh"; - src = fetchFromGitHub { - owner = "hlissner"; - repo = "zsh-autopair"; - rev = "2ec3fd3c9b950c01dbffbb2a4d191e1d34b8c58a"; - hash = "sha256-Y7fkpvCOC/lC2CHYui+6vOdNO8dNHGrVYTGGNf9qgdg="; - }; - } - ]; - }; + programs.zsh.plugins = [ + { + name = "zsh-nix-shell"; + src = pkgs.zsh-nix-shell; + file = "share/zsh-nix-shell/nix-shell.plugin.zsh"; + } + { + name = "zsh-vi-mode"; + src = pkgs.zsh-vi-mode; + file = "share/zsh-vi-mode/zsh-vi-mode.plugin.zsh"; + } + { + name = "fast-syntax-highlighting"; + src = "${pkgs.zsh-fast-syntax-highlighting}/share/zsh/site-functions"; + } + { + name = "zsh-autosuggestions"; + src = pkgs.zsh-autosuggestions; + file = "share/zsh-autosuggestions/zsh-autosuggestions.zsh"; + } + { + name = "zsh-autopair"; + file = "zsh-autopair.plugin.zsh"; + src = fetchFromGitHub { + owner = "hlissner"; + repo = "zsh-autopair"; + rev = "2ec3fd3c9b950c01dbffbb2a4d191e1d34b8c58a"; + hash = "sha256-Y7fkpvCOC/lC2CHYui+6vOdNO8dNHGrVYTGGNf9qgdg="; + }; + } + ]; } diff --git a/system/system.nix b/system/system.nix index 17a17f2..31d21f4 100644 --- a/system/system.nix +++ b/system/system.nix @@ -1,9 +1,12 @@ -{ config, lib, ... }: with lib; let +{ config, lib, pkgs, ... }: with lib; let cfg = config.myOptions.system; in { networking.hostName = cfg.hostname; + # Default shell for the user + programs.zsh.enable = true; + users = { # Prevent mutating users outside of our configurations. # TODO: Solve this, currentry it fails with no password @@ -15,6 +18,7 @@ in users.${cfg.username} = { isNormalUser = true; extraGroups = [ "wheel" ]; + shell = pkgs.zsh; }; }; }