From 5751958cad64a9edd233ffed6f845c5da0ddd7a2 Mon Sep 17 00:00:00 2001 From: Arnie Date: Sun, 5 Jan 2025 23:10:55 +0100 Subject: [PATCH] Big updates --- .zsh/dingleberry/05-home-manager.zsh | 2 - .zsh/macos/05-home-manager.zsh | 2 - devices/becky-dingleberry.nix | 36 +- devices/lcech-mac-veracode.nix | 31 +- flake.nix | 335 ++++++++++-------- modules/common.nix | 50 +++ {.zsh => modules/zsh}/common/00-colors.zsh | 0 {.zsh => modules/zsh}/common/00-locale.zsh | 0 {.zsh => modules/zsh}/common/01-setopt.zsh | 0 {.zsh => modules/zsh}/common/02-prompt.zsh | 0 .../zsh}/common/03-completion.zsh | 0 {.zsh => modules/zsh}/common/03-manydots.zsh | 0 {.zsh => modules/zsh}/common/04-bindkeys.zsh | 0 {.zsh => modules/zsh}/common/05-functions.zsh | 0 .../zsh}/common/05-home-manager.zsh | 0 {.zsh => modules/zsh}/common/06-history.zsh | 0 {.zsh => modules/zsh}/common/07-zsh_hooks.zsh | 0 .../zsh}/common/09-zsh_aliases.zsh | 0 {.zsh => modules/zsh}/common/10-adminer.zsh | 0 .../zsh}/common/10-docker_aliases.zsh | 0 .../zsh}/common/10-git_aliases.zsh | 0 .../zsh}/common/10-kubernetes_aliases.zsh | 0 {.zsh => modules/zsh}/common/10-templates.zsh | 0 .../common/10-zsh_aliases_connections.zsh | 0 {.zsh => modules/zsh}/common/11-aws.zsh | 0 .../zsh}/dingleberry/09-zsh_aliases.zsh | 0 {.zsh => modules/zsh}/dingleberry/10-ibus.zsh | 0 .../10-zsh_aliases_connections.zsh | 0 28 files changed, 257 insertions(+), 199 deletions(-) delete mode 100644 .zsh/dingleberry/05-home-manager.zsh delete mode 100644 .zsh/macos/05-home-manager.zsh create mode 100644 modules/common.nix rename {.zsh => modules/zsh}/common/00-colors.zsh (100%) rename {.zsh => modules/zsh}/common/00-locale.zsh (100%) rename {.zsh => modules/zsh}/common/01-setopt.zsh (100%) rename {.zsh => modules/zsh}/common/02-prompt.zsh (100%) rename {.zsh => modules/zsh}/common/03-completion.zsh (100%) rename {.zsh => modules/zsh}/common/03-manydots.zsh (100%) rename {.zsh => modules/zsh}/common/04-bindkeys.zsh (100%) rename {.zsh => modules/zsh}/common/05-functions.zsh (100%) rename {.zsh => modules/zsh}/common/05-home-manager.zsh (100%) rename {.zsh => modules/zsh}/common/06-history.zsh (100%) rename {.zsh => modules/zsh}/common/07-zsh_hooks.zsh (100%) rename {.zsh => modules/zsh}/common/09-zsh_aliases.zsh (100%) rename {.zsh => modules/zsh}/common/10-adminer.zsh (100%) rename {.zsh => modules/zsh}/common/10-docker_aliases.zsh (100%) rename {.zsh => modules/zsh}/common/10-git_aliases.zsh (100%) rename {.zsh => modules/zsh}/common/10-kubernetes_aliases.zsh (100%) rename {.zsh => modules/zsh}/common/10-templates.zsh (100%) rename {.zsh => modules/zsh}/common/10-zsh_aliases_connections.zsh (100%) rename {.zsh => modules/zsh}/common/11-aws.zsh (100%) rename {.zsh => modules/zsh}/dingleberry/09-zsh_aliases.zsh (100%) rename {.zsh => modules/zsh}/dingleberry/10-ibus.zsh (100%) rename {.zsh => modules/zsh}/dingleberry/10-zsh_aliases_connections.zsh (100%) diff --git a/.zsh/dingleberry/05-home-manager.zsh b/.zsh/dingleberry/05-home-manager.zsh deleted file mode 100644 index 83cce35..0000000 --- a/.zsh/dingleberry/05-home-manager.zsh +++ /dev/null @@ -1,2 +0,0 @@ -# Impure because of nixgl wrapper -alias hm-switch="home-manager switch --impure --flake ~/.config/nix" diff --git a/.zsh/macos/05-home-manager.zsh b/.zsh/macos/05-home-manager.zsh deleted file mode 100644 index 3b60094..0000000 --- a/.zsh/macos/05-home-manager.zsh +++ /dev/null @@ -1,2 +0,0 @@ -# Impure because of nixgl wrapper -alias hm-switch="darwin-rebuild switch --flake ~/.config/nix" diff --git a/devices/becky-dingleberry.nix b/devices/becky-dingleberry.nix index 9108639..541716c 100644 --- a/devices/becky-dingleberry.nix +++ b/devices/becky-dingleberry.nix @@ -7,17 +7,16 @@ let username = "becky"; homedir = "/home/${username}"; - zshSourceCommon = ../.zsh/common; - zshSourceUser = ../.zsh/dingleberry; + zshSourceDirs = [ + ../modules/zsh/dingleberry + ]; in { - # Let Home Manager install and manage itself. - programs.home-manager.enable = true; + #targets.genericLinux.enable = true; # Enable XDG for non terminal apps # https://github.com/nix-community/home-manager/issues/1439 #programs.bash.enable = true; - #targets.genericLinux.enable = true; #xdg = { # enable = true; # mime = { @@ -35,7 +34,6 @@ in home.stateVersion = "24.11"; home.packages = with pkgs; [ - bat nixd # TODO: Move from system to nix # awscli2 @@ -72,25 +70,27 @@ in }; }; - programs.ghostty = { enable = true; + installBatSyntax = true; installVimSyntax = true; enableZshIntegration = true; package = config.lib.nixGL.wrap pkgs.ghostty; + + settings = { + theme = "catppuccin-mocha"; + font-size = 10; + }; }; programs.zsh = { enable = true; - autocd = true; - shellAliases = { - cat = "bat --paging=never"; + hm-switch = "home-manager switch --impure --flake ~/.config/nix"; }; - dirHashes = { mac = "${homedir}/storage/.macshare"; nix = "${homedir}/.config/nix"; @@ -119,13 +119,13 @@ in }; initExtra = '' - for file in ${zshSourceCommon}/*.zsh; do - source "$file" - done - - for file in ${zshSourceUser}/*.zsh; do - source "$file" - done + ${builtins.concatStringsSep "\n" ( + builtins.map (dir: '' + for file in ${dir}/*.zsh; do + source "$file" + done + '') zshSourceDirs + )} autoload -U +X bashcompinit && bashcompinit diff --git a/devices/lcech-mac-veracode.nix b/devices/lcech-mac-veracode.nix index bd9d3ea..1a50404 100644 --- a/devices/lcech-mac-veracode.nix +++ b/devices/lcech-mac-veracode.nix @@ -1,5 +1,4 @@ { - config, pkgs, ... }: @@ -9,13 +8,10 @@ let zshSourceDirs = [ ../.zsh/common - ../.zsh/macos + ../modules/zsh/macos ]; in { - # Let Home Manager install and manage itself. - programs.home-manager.enable = true; - home.username = username; home.homeDirectory = homedir; @@ -24,7 +20,6 @@ in home.packages = with pkgs; [ awscli2 - bat k9s kubectl nixd @@ -64,29 +59,20 @@ in programs.zsh = { enable = true; - autocd = true; - - shellAliases = { - cat = "bat --paging=never"; - }; - dirHashes = { mac = "${homedir}/storage/.macshare"; nix = "${homedir}/.config/nix"; }; initExtra = '' - ${builtins.concatStringsSep "\n" - (builtins.map (dir: - '' - for file in ${dir}/*.zsh; do - source "$file" - done - '' - ) zshSourceDirs) - } + ${builtins.concatStringsSep "\n" ( + builtins.map (dir: '' + for file in ${dir}/*.zsh; do + source "$file" + done + '') zshSourceDirs + )} - # ${pkgs.keepassxc} autoload -U +X bashcompinit && bashcompinit source <(kubectl completion zsh) @@ -101,7 +87,6 @@ in }; } - # TODO: launchd timers # diff --git a/flake.nix b/flake.nix index 0da68db..0de3930 100644 --- a/flake.nix +++ b/flake.nix @@ -14,165 +14,192 @@ nixgl.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = inputs@{ - self, - home-manager, - mac-app-util, - nix-darwin, - nixgl, - nixpkgs, - }: - let - darwin-common = { pkgs, ... }: + outputs = + inputs@{ + self, + home-manager, + mac-app-util, + nix-darwin, + nixgl, + nixpkgs, + }: let - custom-key-mapping = { - # AI Instructions - # I need a mapping that switches my keyboard keys in the following way: - # the key above TAB and left of number 1 (lets call this key NEWTILDE has a code 30064771172) - # the key between left shift and Z (lets call this key NEWPIPE has a code 30064771125) - # the key above right shift and left of the big enter key (lets call this key NEWPLUSMINUS has a code 30064771121) - # - # Write the mapping in such a way that: - # NEWTILDE switches with NEWPIPE - # NEWPIPE overrides NEWPLUSMINUS - UserKeyMapping = [ - { - HIDKeyboardModifierMappingSrc = 30064771125; - HIDKeyboardModifierMappingDst = 30064771172; - } - { - HIDKeyboardModifierMappingSrc = 30064771172; - HIDKeyboardModifierMappingDst = 30064771121; - } - ]; - }; - in - { - # List packages installed in system profile. To search by name, run: - # $ nix-env -qaP | grep wget - environment.systemPackages = with pkgs; [ - git - vim + systems = nixpkgs.lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" ]; - launchd.user.agents = { - "custom-key-mapping" = { - script = '' - /usr/bin/hidutil property --set '${builtins.toJSON custom-key-mapping}' > /dev/null - ''; - serviceConfig = { - RunAtLoad = true; - }; - }; - }; - - # The platform the configuration will be used on. - nixpkgs.hostPlatform = "aarch64-darwin"; - - # Set Git commit hash for darwin-version. - system.configurationRevision = self.rev or self.dirtyRev or null; - - # Used for backwards compatibility, please read the changelog before changing. - # $ darwin-rebuild changelog - system.stateVersion = 5; - - system.defaults = { - finder = { - _FXShowPosixPathInTitle = true; # show full path in finder title - AppleShowAllExtensions = true; # show all file extensions - FXEnableExtensionChangeWarning = false; # disable warning when changing file extension - QuitMenuItem = true; # enable quit menu item - ShowPathbar = true; # show path bar - ShowStatusBar = true; # show status bar - }; - }; - - # Auto upgrade nix package and the daemon service. - services.nix-daemon.enable = true; - - nix = { - configureBuildUsers = true; - distributedBuilds = true; - - gc = { - automatic = true; - options = "--delete-older-than 7d"; - }; - settings = { - experimental-features = "nix-command flakes"; - }; - }; - - homebrew = { - enable = true; - onActivation = { - autoUpdate = true; - # 'zap': uninstalls all formulae(and related files) not listed here. - cleanup = "zap"; - upgrade = true; - }; - }; - }; - in - { - homeConfigurations = let - pkgs = import nixpkgs { - system = "x86_64-linux"; - overlays = [ - nixgl.overlay - ]; - config = { - allowUnfree = true; - }; - }; - in { - # init with - # nix run home-manager/master -- switch --flake ~/.config/nix - # update with - # home-manager switch --flake ~/.config/nix - "becky@dingleberry" = home-manager.lib.homeManagerConfiguration { - # pkgs = nixpkgs.legacyPackages.x86_64-linux; - inherit pkgs; - - modules = [ - ./devices/becky-dingleberry.nix - ]; - }; - }; - - darwinConfigurations = { - # init with - # nix run nix-darwin -- switch --flake ~/.config/nix - # update with - # darwin-rebuild switch --flake ~/.config/nix - lcech-mac = nix-darwin.lib.darwinSystem { - system = "aarch64-darwin"; - modules = [ - mac-app-util.darwinModules.default - darwin-common - { - # brew install --cask - # these need to be updated manually - homebrew.casks = [ - "ghostty" - "spotify" - "keepassxc" + darwin-common = + { pkgs, ... }: + let + custom-key-mapping = { + # AI Instructions + # I need a mapping that switches my keyboard keys in the following way: + # the key above TAB and left of number 1 (lets call this key NEWTILDE has a code 30064771172) + # the key between left shift and Z (lets call this key NEWPIPE has a code 30064771125) + # the key above right shift and left of the big enter key (lets call this key NEWPLUSMINUS has a code 30064771121) + # + # Write the mapping in such a way that: + # NEWTILDE switches with NEWPIPE + # NEWPIPE overrides NEWPLUSMINUS + UserKeyMapping = [ + { + HIDKeyboardModifierMappingSrc = 30064771125; + HIDKeyboardModifierMappingDst = 30064771172; + } + { + HIDKeyboardModifierMappingSrc = 30064771172; + HIDKeyboardModifierMappingDst = 30064771121; + } ]; - } - home-manager.darwinModules.home-manager - { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - users.lcech.imports = [ - mac-app-util.homeManagerModules.default - ./devices/lcech-mac-veracode.nix - ]; + }; + in + { + # List packages installed in system profile. To search by name, run: + # $ nix-env -qaP | grep wget + environment.systemPackages = with pkgs; [ + git + vim + ]; + + launchd.user.agents = { + "custom-key-mapping" = { + script = '' + /usr/bin/hidutil property --set '${builtins.toJSON custom-key-mapping}' > /dev/null + ''; + serviceConfig = { + RunAtLoad = true; + }; }; - users.users.lcech.home = "/Users/lcech"; - } - ]; + }; + + # The platform the configuration will be used on. + nixpkgs.hostPlatform = "aarch64-darwin"; + + # Set Git commit hash for darwin-version. + system.configurationRevision = self.rev or self.dirtyRev or null; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 5; + + system.defaults = { + finder = { + _FXShowPosixPathInTitle = true; # show full path in finder title + AppleShowAllExtensions = true; # show all file extensions + FXEnableExtensionChangeWarning = false; # disable warning when changing file extension + QuitMenuItem = true; # enable quit menu item + ShowPathbar = true; # show path bar + ShowStatusBar = true; # show status bar + }; + }; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + + nix = { + configureBuildUsers = true; + distributedBuilds = true; + + gc = { + automatic = true; + options = "--delete-older-than 7d"; + }; + settings = { + experimental-features = "nix-command flakes"; + }; + }; + + homebrew = { + enable = true; + onActivation = { + autoUpdate = true; + # 'zap': uninstalls all formulae(and related files) not listed here. + cleanup = "zap"; + upgrade = true; + }; + }; + }; + in + { + lib = { + forAllSystems = + function: + systems ( + system: + function ( + import nixpkgs { + inherit system; + config.allowUnfreePredicate = (pkg: builtins.elem (nixpkgs.lib.getName pkg) [ "nvidia" ]); + } + ) + ); + }; + + formatter = self.lib.forAllSystems (pkgs: pkgs.nixfmt-rfc-style); + + homeConfigurations = + let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ + nixgl.overlay + ]; + config = { + allowUnfree = true; + }; + }; + in + { + # init with + # nix run home-manager/master -- switch --flake ~/.config/nix + # update with + # home-manager switch --flake ~/.config/nix + "becky@dingleberry" = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + + modules = [ + ./modules/common.nix + ./devices/becky-dingleberry.nix + ]; + }; + }; + + darwinConfigurations = { + # init with + # nix run nix-darwin -- switch --flake ~/.config/nix + # update with + # darwin-rebuild switch --flake ~/.config/nix + lcech-mac = nix-darwin.lib.darwinSystem { + system = "aarch64-darwin"; + modules = [ + mac-app-util.darwinModules.default + darwin-common + { + # brew install --cask + # these need to be updated manually + homebrew.casks = [ + "ghostty" + "spotify" + "keepassxc" + ]; + } + ./modules/common.nix + home-manager.darwinModules.home-manager + { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + users.lcech.imports = [ + mac-app-util.homeManagerModules.default + ./devices/lcech-mac-veracode.nix + ]; + }; + users.users.lcech.home = "/Users/lcech"; + } + ]; + }; }; }; - }; } diff --git a/modules/common.nix b/modules/common.nix new file mode 100644 index 0000000..1d16d13 --- /dev/null +++ b/modules/common.nix @@ -0,0 +1,50 @@ +{ + lib, + pkgs, + ... +}: +let + zshSourceCommon = ./zsh/common; + + isDarwin = pkgs.stdenv.hostPlatform.isDarwin; + isLinux = pkgs.stdenv.hostPlatform.isLinux; +in +{ + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; + + programs.bat = { + enable = true; + }; + + programs.zsh = { + enable = true; + + autocd = lib.mkDefault true; + + shellAliases = + { + cat = lib.mkDefault "bat --paging=never"; + nixfix = lib.mkDefault "nix fmt ./**/*.nix"; + } + // ( + if isDarwin then + { + hm-switch = lib.mkDefault "darwin-rebuild switch --flake ~/.config/nix"; + } + else if isLinux then + { + hm-switch = lib.mkDefault "home-manager switch --flake ~/.config/nix"; + } + else + { } + ); + + initExtra = '' + for file in ${zshSourceCommon}/*.zsh; do + source "$file" + done + ''; + }; +} diff --git a/.zsh/common/00-colors.zsh b/modules/zsh/common/00-colors.zsh similarity index 100% rename from .zsh/common/00-colors.zsh rename to modules/zsh/common/00-colors.zsh diff --git a/.zsh/common/00-locale.zsh b/modules/zsh/common/00-locale.zsh similarity index 100% rename from .zsh/common/00-locale.zsh rename to modules/zsh/common/00-locale.zsh diff --git a/.zsh/common/01-setopt.zsh b/modules/zsh/common/01-setopt.zsh similarity index 100% rename from .zsh/common/01-setopt.zsh rename to modules/zsh/common/01-setopt.zsh diff --git a/.zsh/common/02-prompt.zsh b/modules/zsh/common/02-prompt.zsh similarity index 100% rename from .zsh/common/02-prompt.zsh rename to modules/zsh/common/02-prompt.zsh diff --git a/.zsh/common/03-completion.zsh b/modules/zsh/common/03-completion.zsh similarity index 100% rename from .zsh/common/03-completion.zsh rename to modules/zsh/common/03-completion.zsh diff --git a/.zsh/common/03-manydots.zsh b/modules/zsh/common/03-manydots.zsh similarity index 100% rename from .zsh/common/03-manydots.zsh rename to modules/zsh/common/03-manydots.zsh diff --git a/.zsh/common/04-bindkeys.zsh b/modules/zsh/common/04-bindkeys.zsh similarity index 100% rename from .zsh/common/04-bindkeys.zsh rename to modules/zsh/common/04-bindkeys.zsh diff --git a/.zsh/common/05-functions.zsh b/modules/zsh/common/05-functions.zsh similarity index 100% rename from .zsh/common/05-functions.zsh rename to modules/zsh/common/05-functions.zsh diff --git a/.zsh/common/05-home-manager.zsh b/modules/zsh/common/05-home-manager.zsh similarity index 100% rename from .zsh/common/05-home-manager.zsh rename to modules/zsh/common/05-home-manager.zsh diff --git a/.zsh/common/06-history.zsh b/modules/zsh/common/06-history.zsh similarity index 100% rename from .zsh/common/06-history.zsh rename to modules/zsh/common/06-history.zsh diff --git a/.zsh/common/07-zsh_hooks.zsh b/modules/zsh/common/07-zsh_hooks.zsh similarity index 100% rename from .zsh/common/07-zsh_hooks.zsh rename to modules/zsh/common/07-zsh_hooks.zsh diff --git a/.zsh/common/09-zsh_aliases.zsh b/modules/zsh/common/09-zsh_aliases.zsh similarity index 100% rename from .zsh/common/09-zsh_aliases.zsh rename to modules/zsh/common/09-zsh_aliases.zsh diff --git a/.zsh/common/10-adminer.zsh b/modules/zsh/common/10-adminer.zsh similarity index 100% rename from .zsh/common/10-adminer.zsh rename to modules/zsh/common/10-adminer.zsh diff --git a/.zsh/common/10-docker_aliases.zsh b/modules/zsh/common/10-docker_aliases.zsh similarity index 100% rename from .zsh/common/10-docker_aliases.zsh rename to modules/zsh/common/10-docker_aliases.zsh diff --git a/.zsh/common/10-git_aliases.zsh b/modules/zsh/common/10-git_aliases.zsh similarity index 100% rename from .zsh/common/10-git_aliases.zsh rename to modules/zsh/common/10-git_aliases.zsh diff --git a/.zsh/common/10-kubernetes_aliases.zsh b/modules/zsh/common/10-kubernetes_aliases.zsh similarity index 100% rename from .zsh/common/10-kubernetes_aliases.zsh rename to modules/zsh/common/10-kubernetes_aliases.zsh diff --git a/.zsh/common/10-templates.zsh b/modules/zsh/common/10-templates.zsh similarity index 100% rename from .zsh/common/10-templates.zsh rename to modules/zsh/common/10-templates.zsh diff --git a/.zsh/common/10-zsh_aliases_connections.zsh b/modules/zsh/common/10-zsh_aliases_connections.zsh similarity index 100% rename from .zsh/common/10-zsh_aliases_connections.zsh rename to modules/zsh/common/10-zsh_aliases_connections.zsh diff --git a/.zsh/common/11-aws.zsh b/modules/zsh/common/11-aws.zsh similarity index 100% rename from .zsh/common/11-aws.zsh rename to modules/zsh/common/11-aws.zsh diff --git a/.zsh/dingleberry/09-zsh_aliases.zsh b/modules/zsh/dingleberry/09-zsh_aliases.zsh similarity index 100% rename from .zsh/dingleberry/09-zsh_aliases.zsh rename to modules/zsh/dingleberry/09-zsh_aliases.zsh diff --git a/.zsh/dingleberry/10-ibus.zsh b/modules/zsh/dingleberry/10-ibus.zsh similarity index 100% rename from .zsh/dingleberry/10-ibus.zsh rename to modules/zsh/dingleberry/10-ibus.zsh diff --git a/.zsh/dingleberry/10-zsh_aliases_connections.zsh b/modules/zsh/dingleberry/10-zsh_aliases_connections.zsh similarity index 100% rename from .zsh/dingleberry/10-zsh_aliases_connections.zsh rename to modules/zsh/dingleberry/10-zsh_aliases_connections.zsh