diff --git a/.gitignore b/.gitignore index cfd446a..8e1f17d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result *.secret.* +.nvimlog \ No newline at end of file diff --git a/README.md b/README.md index 1f77c5f..76c40be 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ # dotfiles.nix -nix user configuration with home-manager. +nix user configuration for nix-darwin and home-manager. + +spiritually a fork of https://github.com/malob/nixpkgs, but using a repo i already had lying around + +## installation +```shell +$ nix build .#darwinConfigurations.matbook.system +$ ./result/sw/bin/darwin-rebuild switch --flake . +``` diff --git a/Session.vim b/Session.vim deleted file mode 100644 index 15efa88..0000000 --- a/Session.vim +++ /dev/null @@ -1,81 +0,0 @@ -let SessionLoad = 1 -let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0 -let v:this_session=expand(":p") -silent only -cd ~/dotfiles.nix -if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' - let s:wipebuf = bufnr('%') -endif -set shortmess=aoO -badd +28 home.nix -badd +1 assets/i3status.toml -badd +66 assets/i3status-cfg -argglobal -silent! argdel * -$argadd home.nix -edit assets/i3status-cfg -set splitbelow splitright -wincmd _ | wincmd | -vsplit -1wincmd h -wincmd w -set nosplitright -wincmd t -set winminheight=0 -set winheight=1 -set winminwidth=0 -set winwidth=1 -exe 'vert 1resize ' . ((&columns * 66 + 66) / 133) -exe 'vert 2resize ' . ((&columns * 66 + 66) / 133) -argglobal -setlocal fdm=manual -setlocal fde=0 -setlocal fmr={{{,}}} -setlocal fdi=# -setlocal fdl=0 -setlocal fml=1 -setlocal fdn=20 -setlocal fen -silent! normal! zE -let s:l = 66 - ((23 * winheight(0) + 14) / 29) -if s:l < 1 | let s:l = 1 | endif -exe s:l -normal! zt -66 -normal! 0 -wincmd w -argglobal -if bufexists('assets/i3status.toml') | buffer assets/i3status.toml | else | edit assets/i3status.toml | endif -setlocal fdm=manual -setlocal fde=0 -setlocal fmr={{{,}}} -setlocal fdi=# -setlocal fdl=0 -setlocal fml=1 -setlocal fdn=20 -setlocal fen -silent! normal! zE -let s:l = 39 - ((26 * winheight(0) + 14) / 29) -if s:l < 1 | let s:l = 1 | endif -exe s:l -normal! zt -39 -normal! 011| -wincmd w -2wincmd w -exe 'vert 1resize ' . ((&columns * 66 + 66) / 133) -exe 'vert 2resize ' . ((&columns * 66 + 66) / 133) -tabnext 1 -if exists('s:wipebuf') && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal' - silent exe 'bwipe ' . s:wipebuf -endif -unlet! s:wipebuf -set winheight=1 winwidth=20 winminheight=1 winminwidth=1 shortmess=filnxtToOF -let s:sx = expand(":p:r")."x.vim" -if file_readable(s:sx) - exe "source " . fnameescape(s:sx) -endif -let &so = s:so_save | let &siso = s:siso_save -doautoall SessionLoadPost -unlet SessionLoad -" vim: set ft=vim : diff --git a/cachix.nix b/cachix.nix deleted file mode 100644 index 64734c3..0000000 --- a/cachix.nix +++ /dev/null @@ -1,13 +0,0 @@ -# WARN: this file will get overwritten by $ cachix use -{ pkgs, lib, ... }: - -let - folder = ./cachix; - toImport = name: value: folder + ("/" + name); - filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key; - imports = lib.mapAttrsToList toImport - (lib.filterAttrs filterCaches (builtins.readDir folder)); -in { - inherit imports; - nix.binaryCaches = [ "https://cache.nixos.org/" ]; -} diff --git a/darwin/bootstrap.nix b/darwin/bootstrap.nix new file mode 100644 index 0000000..35f3241 --- /dev/null +++ b/darwin/bootstrap.nix @@ -0,0 +1,54 @@ +{ config, pkgs, lib, ... }: +{ + # Nix configuration ------------------------------------------------------------------------------ + + nix.binaryCaches = [ + "https://cache.nixos.org/" + ]; + nix.binaryCachePublicKeys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + ]; + nix.trustedUsers = [ + "@admin" + ]; + users.nix.configureBuildUsers = true; + + nix.buildCores = 1; + nix.maxJobs = 8; + + # Enable experimental nix command and flakes + # nix.package = pkgs.nixUnstable; + nix.extraOptions = '' + auto-optimise-store = true + experimental-features = nix-command flakes + '' + lib.optionalString (pkgs.system == "aarch64-darwin") '' + extra-platforms = x86_64-darwin aarch64-darwin + ''; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + + # Make Fish the default shell + programs.fish.enable = true; + programs.fish.useBabelfish = true; + programs.fish.babelfishPackage = pkgs.babelfish; + # Needed to address bug where $PATH is not properly set for fish: + # https://github.com/LnL7/nix-darwin/issues/122 + programs.fish.shellInit = '' + for p in (string split : ${config.environment.systemPath}) + if not contains $p $fish_user_paths + set -g fish_user_paths $fish_user_paths $p + end + end + ''; + environment.variables.SHELL = "${pkgs.fish}/bin/fish"; + environment.loginShell = "${pkgs.fish}/bin/fish"; + + # Install and setup ZSH to work with nix(-darwin) as well + programs.zsh.enable = true; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; + +} \ No newline at end of file diff --git a/darwin/default.nix b/darwin/default.nix new file mode 100644 index 0000000..cfc9b41 --- /dev/null +++ b/darwin/default.nix @@ -0,0 +1,57 @@ +{pkgs, lib, ... }: + +{ + imports = [ + ./bootstrap.nix + ./homebrew.nix + ./macos-defaults.nix + ]; + + # Apps + # `home-manager` currently has issues adding them to `~/Applications` + # Issue: https://github.com/nix-community/home-manager/issues/1341 + environment.systemPackages = with pkgs; [ + # codium + # discord + # element-desktop + # firefox + kitty + # lagrange + # signal-desktop + # steam + terminal-notifier + ]; + + # https://github.com/nix-community/home-manager/issues/423 + environment.variables = { + TERMINFO_DIRS = "${pkgs.kitty.terminfo.outPath}/share/terminfo"; + }; + programs.nix-index.enable = true; + + environment.shells = with pkgs; [ + bashInteractive + fish + zsh + ]; + # Fonts + fonts.enableFontDir = true; + fonts.fonts = with pkgs; [ + recursive + (nerdfonts.override { + fonts = [ + "FantasqueSansMono" + "JetBrainsMono" + "FiraCode" + "SourceCodePro" + ]; + }) + ]; + + # Keyboard + # system.keyboard.enableKeyMapping = true; + # system.keyboard.remapCapsLockToEscape = true; + + # Add ability to used TouchID for sudo authentication + security.pam.enableSudoTouchIdAuth = true; + +} \ No newline at end of file diff --git a/darwin/homebrew.nix b/darwin/homebrew.nix new file mode 100644 index 0000000..e1f3225 --- /dev/null +++ b/darwin/homebrew.nix @@ -0,0 +1,72 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkIf; + mkIfCaskPresent = cask: mkIf (lib.any (x: x == cask) config.homebrew.casks); + brewEnabled = config.homebrew.enable; +in + +{ + environment.shellInit = mkIf brewEnabled '' + eval "$(${config.homebrew.brewPrefix}/brew shellenv)" + ''; + + # https://docs.brew.sh/Shell-Completion#configuring-completions-in-fish + # For some reason if the Fish completions are added at the end of `fish_complete_path` they don't + # seem to work, but they do work if added at the start. + programs.fish.interactiveShellInit = mkIf brewEnabled '' + if test -d (brew --prefix)"/share/fish/completions" + set -p fish_complete_path (brew --prefix)/share/fish/completions + end + if test -d (brew --prefix)"/share/fish/vendor_completions.d" + set -p fish_complete_path (brew --prefix)/share/fish/vendor_completions.d + end + ''; + + homebrew.enable = true; + homebrew.autoUpdate = true; + homebrew.cleanup = "zap"; + homebrew.global.brewfile = true; + homebrew.global.noLock = true; + + homebrew.taps = [ + "homebrew/cask" + "homebrew/cask-drivers" + "homebrew/cask-fonts" + "homebrew/cask-versions" + "homebrew/core" + "homebrew/services" + "nrlquaker/createzap" + ]; + + # Prefer installing application from the Mac App Store + homebrew.masApps = { + Bitwarden = 1352778147; + Spark = 1176895641; + }; + + # If an app isn't available in the Mac App Store, or the version in the App Store has + # limitiations, e.g., Transmit, install the Homebrew Cask. + homebrew.casks = [ + "alfred" + "discord" + "element" + "firefox" + "gog-galaxy" + "knockknock" + "lagrange" + "lulu" + "rectangle" + "signal" + "steam" + "vscodium" + ]; + + # Configuration related to casks + environment.variables.SSH_AUTH_SOCK = mkIfCaskPresent "secretive" + "/Users/${config.users.primaryUser}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh"; + + # For cli packages that aren't currently available for macOS in `nixpkgs`.Packages should be + # installed in `../home/default.nix` whenever possible. + homebrew.brews = []; +} \ No newline at end of file diff --git a/darwin/macos-defaults.nix b/darwin/macos-defaults.nix new file mode 100644 index 0000000..eb26dc1 --- /dev/null +++ b/darwin/macos-defaults.nix @@ -0,0 +1,55 @@ +{ ... }: + +{ + system.defaults.NSGlobalDomain = { + # "com.apple.trackpad.scaling" = "3.0"; + # AppleInterfaceStyleSwitchesAutomatically = false; + # InitialKeyRepeat = 15; + # KeyRepeat = 2; + NSAutomaticCapitalizationEnabled = false; + _HIHideMenuBar = false; + }; + + # Firewall + system.defaults.alf = { + globalstate = 1; + allowsignedenabled = 1; + allowdownloadsignedenabled = 1; + stealthenabled = 1; + }; + + # Dock and Mission Control + system.defaults.dock = { + autohide = false; + expose-group-by-app = false; + mru-spaces = false; + tilesize = 96; + # Disable all hot corners + wvous-bl-corner = 1; + wvous-br-corner = 1; + wvous-tl-corner = 1; + wvous-tr-corner = 1; + }; + + # Finder + system.defaults.finder = { + AppleShowAllExtensions = true; + FXEnableExtensionChangeWarning = true; + }; + + # Login and lock screen + system.defaults.loginwindow = { + GuestEnabled = false; + DisableConsoleAccess = true; + }; + + # Spaces + system.defaults.spaces.spans-displays = false; + + # Trackpad + system.defaults.trackpad = { + Clicking = true; + TrackpadRightClick = true; + TrackpadThreeFingerDrag = true; + }; +} \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..fa22027 --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +# See https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } +) { + src = ./.; +}).defaultNix \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9c5e508 --- /dev/null +++ b/flake.lock @@ -0,0 +1,120 @@ +{ + "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1642495030, + "narHash": "sha256-u1ZlFbLWzkM6zOfuZ1tr0tzTuDWucOYwALPWDWLorkE=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "bcdb6022b3a300abf59cb5d0106c158940f5120e", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1642882610, + "narHash": "sha256-pmdgeJ9v6y+T0UfNQ/Z+Hdv5tPshFFra5JLF/byUA/Y=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "c47c350f6518ed39c2a16e4fadf9137b6c559ddc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1642814097, + "narHash": "sha256-4H0Pk/x8eKth06f+mVucLO6saavVEqJVqXprTPfFJiA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "fd2624ba104e8b9f9b6b6a7941226b35a58fe41a", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-21.11-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1642791444, + "narHash": "sha256-vVKbyx3g2a4oa1jFbmR1O5emQrK+kSf2lfsYu3OhLSI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f23965369e2d3123b370cc3ba03be835b1e2f5db", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "darwin": "darwin", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ac57b7a --- /dev/null +++ b/flake.nix @@ -0,0 +1,198 @@ +{ + description = "mat's nix configs"; + + inputs = { + # Package sets + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-21.11-darwin"; + nixpkgs-unstable.url = github:NixOS/nixpkgs/nixpkgs-unstable; + + # Environment/system management + darwin.url = "github:lnl7/nix-darwin/master"; + darwin.inputs.nixpkgs.follows = "nixpkgs-unstable"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs-unstable"; + + # Other sources + flake-compat = { url = github:edolstra/flake-compat; flake = false; }; + flake-utils.url = github:numtide/flake-utils; + }; + + outputs = { self, darwin, nixpkgs, home-manager, flake-utils, ... }@inputs: + let + + inherit (darwin.lib) darwinSystem; + inherit (inputs.nixpkgs-unstable.lib) attrValues makeOverridable optionalAttrs singleton; + + # Configuration for `nixpkgs` + nixpkgsConfig = { + config = { allowUnfree = true; }; + # overlays = attrValues self.overlays; + overlays = attrValues self.overlays ++ singleton ( + # Sub in x86 version of packages that don't build on Apple Silicon yet + final: prev: (optionalAttrs (prev.stdenv.system == "aarch64-darwin") { + inherit (final.pkgs-x86) + # idris2 + # nix-index + # purescript; + niv; + }) + ); + }; + + # Shared home-manager configs + homeManagerStateVersion = "22.05"; + homeManagerCommonConfig = { + imports = attrValues self.homeManagerModules ++ [ + ./home + { home.stateVersion = homeManagerStateVersion; } + ]; + }; + + # Modules shared by most `nix-darwin` personal configurations. + nixDarwinCommonModules = attrValues self.darwinModules ++ [ + # Main `nix-darwin` config + ./darwin + # `home-manager` module + home-manager.darwinModules.home-manager + ( + { config, lib, pkgs, ... }: + let + inherit (config.users) primaryUser; + in + { + nixpkgs = nixpkgsConfig; + # Hack to support legacy worklows that use `` etc. + nix.nixPath = { nixpkgs = "$HOME/dotfiles.nix/nixpkgs.nix"; }; + # `home-manager` config + users.users.${primaryUser}.home = "/Users/${primaryUser}"; + home-manager.useGlobalPkgs = true; + home-manager.users.${primaryUser} = homeManagerCommonConfig; + # Add a registry entry for this flake + nix.registry.my.flake = self; + } + ) + ]; + in + { + # `nix-darwin` configs + darwinConfigurations = rec { + # Mininal configurations to bootstrap systems + bootstrap-x86 = makeOverridable darwinSystem { + system = "x86_64-darwin"; + modules = [ ./darwin/bootstrap.nix { nixpkgs = nixpkgsConfig; } ]; + }; + bootstrap-arm = bootstrap-x86.override { system = "aarch64-darwin"; }; + + # M1 MBP + matbook = darwinSystem { + system = "aarch64-darwin"; + modules = nixDarwinCommonModules ++ [ + { + users.primaryUser = "mat"; + networking.computerName = "matbook pro m1"; + networking.hostName = "matbook"; + networking.knownNetworkServices = [ + "Wi-Fi" + ]; + } + ]; + }; + + # Config with small modifications needed/desired for CI with GitHub workflow + githubCI = darwinSystem { + system = "x86_64-darwin"; + modules = nixDarwinCommonModules ++ [ + ({ lib, ... }: { + users.primaryUser = "runner"; + homebrew.enable = lib.mkForce false; + }) + ]; + }; + + # Build and activate with `nix build .#cloudVM.activationPackage; ./result/activate` + cloudVM = home-manager.lib.homeManagerConfiguration { + system = "x86_64-linux"; + stateVersion = homeManagerStateVersion; + homeDirectory = "/home/mat"; + username = "mat"; + configuration = { + imports = [ homeManagerCommonConfig ]; + nixpkgs = nixpkgsConfig; + }; + }; + + # attrValues self.darwinModules ++ [ + # # Main `nix-darwin` config + # ./configuration.nix + # # `home-manager` module + # home-manager.darwinModules.home-manager + # { + # nixpkgs = nixpkgsConfig; + # # `home-manager` config + # home-manager.useGlobalPkgs = true; + # home-manager.useUserPackages = true; + # home-manager.users.mat = import ./home.nix; + # } + # ]; + # }; + }; + + # Overlays --------------------------------------------------------------- {{{ + + overlays = { + # nixpkgs overlays + pkgs-stable = final: prev: { + pkgs-stable = import inputs.nixpkgs { + inherit (prev.stdenv) system; + inherit (nixpkgsConfig) config; + }; + }; + + pkgs-unstable = final: prev: { + pkgs-unstable = import inputs.nixpkgs-unstable { + inherit (prev.stdenv) system; + inherit (nixpkgsConfig) config; + }; + }; + + colors = import ./overlays/colors.nix; + + # Overlay useful on Macs with Apple Silicon + apple-silicon = final: prev: optionalAttrs (prev.stdenv.system == "aarch64-darwin") { + # Add access to x86 packages system is running Apple Silicon + pkgs-x86 = import inputs.nixpkgs-unstable { + system = "x86_64-darwin"; + inherit (nixpkgsConfig) config; + }; + }; + }; + + # `nix-darwin` modules (some are pending upstream acceptance) + darwinModules = { + programs-nix-index = import ./modules/darwin/programs/nix-index.nix; + security-pam = import ./modules/darwin/security/pam.nix; + users = import ./modules/darwin/users.nix; + }; + + # home manager configurations + homeManagerModules = { + # configs-git-aliases = import ./home/configs/git-aliases.nix; + # configs-gh-aliases = import ./home/configs/gh-aliases.nix; + configs-starship-symbols = import ./home/configs/starship-symbols.nix; + programs-neovim-extras = import ./modules/home/programs/neovim/extras.nix; + programs-kitty-extras = import ./modules/home/programs/kitty/extras.nix; + }; + + } // flake-utils.lib.eachDefaultSystem (system: { + legacyPackages = import inputs.nixpkgs-unstable { + inherit system; + inherit (nixpkgsConfig) config; + overlays = with self.overlays; [ + pkgs-unstable + pkgs-stable + colors + apple-silicon + ]; + }; + }); +} \ No newline at end of file diff --git a/home/configs/starship-symbols.nix b/home/configs/starship-symbols.nix new file mode 100644 index 0000000..96c96f9 --- /dev/null +++ b/home/configs/starship-symbols.nix @@ -0,0 +1,66 @@ +{ lib, ... }: +let inherit (lib) mkDefault; in +{ + programs.starship.settings = { + aws.symbol = mkDefault " "; + battery.full_symbol = mkDefault ""; + battery.charging_symbol = mkDefault ""; + battery.discharging_symbol = mkDefault ""; + battery.unknown_symbol = mkDefault ""; + battery.empty_symbol = mkDefault ""; + cmake.symbol = mkDefault "△ "; + conda.symbol = mkDefault " "; + crystal.symbol = mkDefault " "; + dart.symbol = mkDefault " "; + directory.read_only = mkDefault " "; + docker_context.symbol = mkDefault " "; + dotnet.symbol = mkDefault " "; + elixir.symbol = mkDefault " "; + elm.symbol = mkDefault " "; + erlang.symbol = mkDefault " "; + gcloud.symbol = mkDefault " "; + git_branch.symbol = mkDefault " "; + git_commit.tag_symbol = mkDefault " "; + git_status.format = mkDefault "([$all_status$ahead_behind]($style) )"; + git_status.conflicted = mkDefault " "; + git_status.ahead = mkDefault " "; + git_status.behind = mkDefault " "; + git_status.diverged = mkDefault " "; + git_status.untracked = mkDefault " "; + git_status.stashed = mkDefault " "; + git_status.modified = mkDefault " "; + git_status.staged = mkDefault " "; + git_status.renamed = mkDefault " "; + git_status.deleted = mkDefault " "; + golang.symbol = mkDefault " "; + helm.symbol = mkDefault "⎈ "; + hg_branch.symbol = mkDefault " "; + java.symbol = mkDefault " "; + julia.symbol = mkDefault " "; + kotlin.symbol = mkDefault " "; + kubernetes.symbol = mkDefault "☸ "; + lua.symbol = mkDefault " "; + memory_usage.symbol = mkDefault " "; + nim.symbol = mkDefault " "; + nix_shell.symbol = mkDefault " "; + nodejs.symbol = mkDefault " "; + openstack.symbol = mkDefault " "; + package.symbol = mkDefault " "; + perl.symbol = mkDefault " "; + php.symbol = mkDefault " "; + purescript.symbol = mkDefault "<≡> "; + python.symbol = mkDefault " "; + ruby.symbol = mkDefault " "; + rust.symbol = mkDefault " "; + shlvl.symbol = mkDefault " "; + status.symbol = mkDefault " "; + status.not_executable_symbol = mkDefault " "; + status.not_found_symbol = mkDefault " "; + status.sigint_symbol = mkDefault " "; + status.signal_symbol = mkDefault " "; + swift.symbol = mkDefault " "; + terraform.symbol = mkDefault "𝗧 "; + vagrant.symbol = mkDefault "𝗩 "; + zig.symbol = mkDefault " "; + }; +} \ No newline at end of file diff --git a/home/default.nix b/home/default.nix new file mode 100644 index 0000000..94a5950 --- /dev/null +++ b/home/default.nix @@ -0,0 +1,132 @@ +{ config, pkgs, lib, ... }: + +{ + # Import config broken out into files + imports = [ + ./git.nix + ./kitty.nix + ./neovim.nix + ./shells.nix + ]; + + home.enableNixpkgsReleaseCheck = true; + + # Packages with configuration --------------------------------------------------------------- {{{ + + programs = { + # fancy shell history + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.atuin.enable + atuin = { + enable = true; + settings = {}; + }; + # a nicer cat + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.bat.enable + bat = { + enable = true; + config = { + style = "plain"; + }; + }; + # Direnv, load and unload environment variables depending on the current directory. + # https://direnv.net + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.direnv.enable + direnv = { + enable = true; + nix-direnv.enable = true; + }; + # Firefox + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.firefox.enable + # firefox = { + # enable = true; + # package = pkgs.firefox; + # }; + # Htop + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.htop.enable + htop = { + enable = true; + settings = { + show_program_path = true; + }; + }; + # See `./shells.nix` for more on how this is used. + fish = { + functions = { + set-bat-colors = { + body = ''set -xg BAT_THEME "Solarized ($term_background)"''; + onVariable = "term_background"; + }; + }; + interactiveShellInit = '' + # Init atuin + atuin init fish | source + bind -M insert -k up _atuin_search + bind -M insert \eOA _atuin_search + bind -M insert \e\[A _atuin_search + # Set `bat` colors based on value of `$term_backdround` when shell starts up. + set-bat-colors + ''; + }; + }; + # }}} + + # Other packages ----------------------------------------------------------------------------- {{{ + + home.packages = with pkgs; [ + # Some basics + abduco # lightweight session management + bottom # fancy version of `top` with ASCII graphs + coreutils + curl + du-dust # fancy version of `du` + exa # fancy version of `ls` + fd # fancy version of `find` + htop # fancy version of `top` + hyperfine # benchmarking tool + mosh # wrapper for `ssh` that better and not dropping connections + procs # fancy version of `ps` + ripgrep # better version of `grep` + tealdeer # rust implementation of `tldr` + thefuck + unrar # extract RAR archives + wget + xz # extract XZ archives + + # Dev stuff + cloc # source code line counter + jq + + # Useful nix related tools + cachix # adding/managing alternative binary caches hosted by Cachix + comma # run software from without installing it + niv # easy dependency management for nix projects + nixfmt + nix-prefetch-git + # nodePackages.node2nix + + ] ++ lib.optionals stdenv.isDarwin [ + cocoapods + m-cli # useful macOS CLI commands + # prefmanager # tool for working with macOS defaults + ]; + # }}} + + # Misc configuration files --------------------------------------------------------------------{{{ + + # https://docs.haskellstack.org/en/stable/yaml_configuration/#non-project-specific-config + # home.file.".stack/config.yaml".text = lib.generators.toYAML {} { + # templates = { + # scm-init = "git"; + # params = { + # author-name = config.programs.git.userName; + # author-email = config.programs.git.userEmail; + # github-username = "malob"; + # }; + # }; + # nix.enable = true; + # }; + + # Stop `parallel` from displaying citation warning + # home.file.".parallel/will-cite".text = ""; + # }}} +} \ No newline at end of file diff --git a/home/git.nix b/home/git.nix new file mode 100644 index 0000000..3457668 --- /dev/null +++ b/home/git.nix @@ -0,0 +1,31 @@ +{ pkgs, lib, ... }: + +{ + # Git + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.git.enable + # Aliases config imported in flake. + programs.git.enable = true; + + programs.git.extraConfig = { + core.editor = "${pkgs.neovim-remote}/bin/nvr --remote-wait-silent -cc split"; + diff.colorMoved = "default"; + pull.rebase = true; + }; + + programs.git.ignores = [ + ".DS_Store" + ]; + + programs.git.userEmail = "mat@mat.services"; + programs.git.userName = "mat ess"; + + # Enhanced diffs + programs.git.delta.enable = true; + + + # GitHub CLI + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.gh.enable + # Aliases config imported in flake. + programs.gh.enable = true; + programs.gh.settings.git_protocol = "ssh"; +} \ No newline at end of file diff --git a/home/kitty.nix b/home/kitty.nix new file mode 100644 index 0000000..42a88bb --- /dev/null +++ b/home/kitty.nix @@ -0,0 +1,122 @@ +{ config, lib, pkgs, ... }: +# Let-In --------------------------------------------------------------------------------------- {{{ +let + inherit (lib) mkIf; + backgroundDependantColors = colors: with colors; { + background = "#${base}"; + foreground = "#${main}"; + + # Cursor + cursor = "#${blue}"; + cursor_text_color = "#${base}"; + + # Selection + selection_background = "#${muted}"; + selection_foreground = "#${base}"; + + # Tab bar + tab_bar_background = "#${basehl}"; + inactive_tab_background = "#${strong}"; + }; +in + # }}} +{ + # Kitty terminal + # https://sw.kovidgoyal.net/kitty/conf.html + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.kitty.enable + programs.kitty.enable = true; + + # General config ----------------------------------------------------------------------------- {{{ + + programs.kitty.settings = { + # # https://fsd.it/shop/fonts/pragmatapro/ + # font_family = "PragmataPro Mono Liga"; + font_family = "FiraCode Nerd Font"; + font_size = "14.0"; + adjust_line_height = "120%"; + disable_ligatures = "cursor"; # disable ligatures when cursor is on them + + # Window layout + hide_window_decorations = "titlebar-only"; + window_padding_width = "10"; + + # Tab bar + tab_bar_edge = "top"; + tab_bar_style = "powerline"; + tab_title_template = "Tab {index}: {title}"; + active_tab_font_style = "bold"; + inactive_tab_font_style = "normal"; + tab_activity_symbol = ""; + + # Shell integration manually enabled for fish + shell_integration = "disabled"; + }; + + # Change the style of italic font variants + # programs.kitty.extraConfig = '' + # font_features PragmataProMonoLiga-Italic +ss06 + # font_features PragmataProMonoLiga-BoldItalic +ss07 + # ''; + + programs.kitty.extras.useSymbolsFromNerdFont = "FiraCode Nerd Font"; + # }}} + + # Colors config ------------------------------------------------------------------------------ {{{ + programs.kitty.extras.colors = with pkgs.lib.colors; { + enable = true; + + # Colors that aren't dependent on background + common = with pkgs.lib.colors.solarized.colors; { + # black + color0 = "#${darkBasehl}"; + color8 = "#${darkBase}"; + # red + color1 = "#${red}"; + color9 = "#${orange}"; + # green + color2 = "#${green}"; + color10 = "#${darkestTone}"; + # yellow + color3 = "#${yellow}"; + color11 = "#${darkTone}"; + # blue + color4 = "#${blue}"; + color12 = "#${lightTone}"; + # magenta + color5 = "#${magenta}"; + color13 = "#${violet}"; + # cyan + color6 = "#${cyan}"; + color14 = "#${lightestTone}"; + # white + color7 = "#${lightBasehl}"; + color15 = "#${lightBase}"; + # url underline color to fit colors + url_color = "#${blue}"; + # tab bar + active_tab_foreground = "#${lightBase}"; + active_tab_background = "#${green}"; + inactive_tab_foreground = "#${lightBase}"; + }; + + # Background dependent colors + dark = backgroundDependantColors solarized.dark; + light = backgroundDependantColors solarized.light; + }; + + programs.fish.functions.set-term-colors = { + body = "term-background $term_background"; + onVariable = "term_background"; + }; + programs.fish.interactiveShellInit = '' + # Set term colors based on value of `$term_background` when shell starts up. + set-term-colors + # Manually enable shell integration + if set -q KITTY_INSTALLATION_DIR + set --global KITTY_SHELL_INTEGRATION enabled + source "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish" + set --prepend fish_complete_path "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_completions.d" + end + ''; + # }}} +} \ No newline at end of file diff --git a/home/neovim.nix b/home/neovim.nix new file mode 100644 index 0000000..934a074 --- /dev/null +++ b/home/neovim.nix @@ -0,0 +1,92 @@ +{ config, pkgs, lib, ... }: + +let + inherit (lib) getName mkIf optional; + # inherit (config.lib.file) mkOutOfStoreSymlink; + nixConfigDir = "${config.home.homeDirectory}/dotfiles.nix"; + + nvr = "${pkgs.neovim-remote}/bin/nvr"; + + pluginWithDeps = plugin: deps: plugin.overrideAttrs (_: { dependencies = deps; }); + + nonVSCodePlugin = plugin: { + plugin = plugin; + optional = true; + config = ''if !exists('g:vscode') | packadd ${plugin.pname} | endif''; + }; +in + +{ + # Neovim + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.neovim.enable + programs.neovim = { + enable = true; + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + }; + + # Config and plugins ------------------------------------------------------------------------- {{{ + + # Minimal init.vim config to load Lua config. Nix and Home Manager don't currently support + # `init.lua`. + # xdg.configFile."nvim/lua".source = mkOutOfStoreSymlink "${nixConfigDir}/configs/nvim/lua"; + # xdg.configFile."nvim/colors".source = mkOutOfStoreSymlink "${nixConfigDir}/configs/nvim/colors"; + # programs.neovim.extraConfig = "lua require('init')"; + + programs.neovim.plugins = with pkgs.vimPlugins; [ + tabular + vim-commentary + vim-surround + ] ++ map (p: { plugin = p; optional = true; }) [ + which-key-nvim + zoomwintab-vim + ] ++ map nonVSCodePlugin [ + direnv-vim + vim-fugitive + ]; + # }}} + + # Shell related ------------------------------------------------------------------------------ {{{ + + # From personal addon module `./modules/programs/neovim/extras.nix` + programs.neovim.extras.termBufferAutoChangeDir = true; + programs.neovim.extras.nvrAliases.enable = true; + + programs.fish.functions.set-nvim-background = mkIf config.programs.neovim.enable { + # See `./shells.nix` for more on how this is used. + body = '' + # Set `background` of all running Neovim instances base on `$term_background`. + for server in (${nvr} --serverlist) + ${nvr} -s --nostart --servername $server -c "set background=$term_background" & + end + ''; + onVariable = "term_background"; + }; + + programs.fish.interactiveShellInit = mkIf config.programs.neovim.enable '' + # Run Neovim related functions on init for their effects, and to register them so they are + # triggered when the relevant event happens or variable changes. + set-nvim-background + ''; + # }}} + + # Required packages -------------------------------------------------------------------------- {{{ + + programs.neovim.extraPackages = with pkgs; [ + neovim-remote + gcc # needed for nvim-treesitter + tree-sitter # needed for nvim-treesitter + + # Language servers + # See `../configs/nvim/lua/init.lua` for configuration. + # ccls + nodePackages.bash-language-server + # nodePackages.typescript-language-server + nodePackages.vim-language-server + nodePackages.vscode-langservers-extracted + nodePackages.yaml-language-server + rnix-lsp + ] ++ optional (pkgs.stdenv.system != "x86_64-darwin") sumneko-lua-language-server; + # }}} +} \ No newline at end of file diff --git a/home/shells.nix b/home/shells.nix new file mode 100644 index 0000000..0ec6fb8 --- /dev/null +++ b/home/shells.nix @@ -0,0 +1,210 @@ +{ config, pkgs, lib, ... }: + +{ + # Fish Shell + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.fish.enable + programs.fish.enable = true; + + # Add Fish plugins + home.packages = with pkgs.fishPlugins; [ done ]; + + programs.fish.plugins = [ + { + name = "fisher"; + src = pkgs.fetchFromGitHub { + owner = "jorgebucaran"; + repo = "fisher"; + rev = "93dafd242b52a0dc6bea54130d0ea041830c7fd6"; + sha256 = "0qbqlydh7b928473f7c4gy68sr1wnwyhcvvqzcik1vx5hdbka7ad"; + }; + } + ]; + + home.file = { + ".config/fish/fish_plugins".text = '' + jorgebucaran/fisher + jorgebucaran/autopair.fish + jorgebucaran/replay.fish + jorgebucaran/getopts.fish + americanhanko/fish-spin + joseluisq/gitnow + fishpkg/fish-humanize-duration + oh-my-fish/plugin-bang-bang + matthewess/fish-autovenv + joehillen/to-fish + jethrokuan/z + decors/fish-colored-man + haslersn/fish-nix-completions + Gazorby/fish-abbreviation-tips + ''; + }; + + # Fish functions ----------------------------------------------------------------------------- {{{ + + programs.fish.functions = { + # User functions + mkdcd = { + argumentNames = [ "target" ]; + body = '' + mkdir $target + cd $target + ''; + }; + unz = { + argumentNames = [ "target" ]; + body = '' + # strip extensions + string match \*.zip $target; and set target (string split -r -m1 . $target)[1] + unzip -d $target $target + ''; + }; + + # Helpers + # Toggles `$term_background` between "light" and "dark". Other Fish functions trigger when this + # variable changes. We use a universal variable so that all instances of Fish have the same + # value for the variable. + toggle-background.body = '' + if test "$term_background" = light + set -U term_background dark + else + set -U term_background light + end + ''; + + # Set `$term_background` based on whether macOS is light or dark mode. Other Fish functions + # trigger when this variable changes. We use a universal variable so that all instances of Fish + # have the same value for the variable. + set-background-to-macOS.body = '' + # Returns 'Dark' if in dark mode fails otherwise. + if defaults read -g AppleInterfaceStyle &>/dev/null + set -U term_background dark + else + set -U term_background light + end + ''; + + # Sets Fish Shell to light or dark colorscheme based on `$term_background`. + set-shell-colors = { + body = '' + # Use correct theme for `btm` + if test "$term_background" = light + alias btm "btm --color default-light" + else + alias btm "btm --color default" + end + # Set LS_COLORS + set -xg LS_COLORS (${pkgs.vivid}/bin/vivid generate solarized-$term_background) + # Set color variables + if test "$term_background" = light + set emphasized_text brgreen # base01 + set normal_text bryellow # base00 + set secondary_text brcyan # base1 + set background_light white # base2 + set background brwhite # base3 + else + set emphasized_text brcyan # base1 + set normal_text brblue # base0 + set secondary_text brgreen # base01 + set background_light black # base02 + set background brblack # base03 + end + # Set Fish colors that change when background changes + set -g fish_color_command $emphasized_text --bold # color of commands + set -g fish_color_param $normal_text # color of regular command parameters + set -g fish_color_comment $secondary_text # color of comments + set -g fish_color_autosuggestion $secondary_text # color of autosuggestions + set -g fish_pager_color_prefix $emphasized_text --bold # color of the pager prefix string + set -g fish_pager_color_description $selection_text # color of the completion description + set -g fish_pager_color_selected_prefix $background + set -g fish_pager_color_selected_completion $background + set -g fish_pager_color_selected_description $background + ''; + onVariable = "term_background"; + }; + }; + # }}} + + # Fish configuration ------------------------------------------------------------------------- {{{ + + # Aliases + programs.fish.shellAliases = + let + nixConfigDir = "${config.home.homeDirectory}/dotfiles.nix"; + in with pkgs; { + # My additions + code = "codium"; + # OG + # Nix related + drb = "darwin-rebuild build --flake ${nixConfigDir}/"; + drs = "darwin-rebuild switch --flake ${nixConfigDir}/"; + drc = "codium ${nixConfigDir}"; + flakeup = "nix flake update --recreate-lock-file ${nixConfigDir}/"; + nb = "nix build"; + nd = "nix develop"; + nf = "nix flake"; + nr = "nix run"; + ns = "nix search"; + + # Other + ".." = "cd .."; + ":q" = "exit"; + cat = "${bat}/bin/bat"; + du = "${du-dust}/bin/dust"; + g = "${gitAndTools.git}/bin/git"; + la = "ll -a"; + ll = "ls -l --time-style long-iso --icons"; + ls = "${exa}/bin/exa"; + ps = "${procs}/bin/procs"; + tb = "toggle-background"; + }; + + # Configuration that should be above `loginShellInit` and `interactiveShellInit`. + programs.fish.shellInit = '' + set -U fish_term24bit 1 + ${lib.optionalString pkgs.stdenv.isDarwin "set-background-to-macOS"} + ''; + + programs.fish.interactiveShellInit = '' + set -g fish_greeting "ヽ(´ᗜ`)ノ welcome ヽ(´ᗜ`)ノ" + fish_vi_key_bindings + set VIRTUAL_ENV_DISABLE_PROMPT true + bind -M insert ! __history_previous_command + bind -M insert '$' __history_previous_command_arguments + ${pkgs.thefuck}/bin/thefuck --alias | source + # Run function to set colors that are dependant on `$term_background` and to register them so + # they are triggerd when the relevent event happens or variable changes. + set-shell-colors + # Set Fish colors that aren't dependant the `$term_background`. + set -g fish_color_quote cyan # color of commands + set -g fish_color_redirection brmagenta # color of IO redirections + set -g fish_color_end blue # color of process separators like ';' and '&' + set -g fish_color_error red # color of potential errors + set -g fish_color_match --reverse # color of highlighted matching parenthesis + set -g fish_color_search_match --background=yellow + set -g fish_color_selection --reverse # color of selected text (vi mode) + set -g fish_color_operator green # color of parameter expansion operators like '*' and '~' + set -g fish_color_escape red # color of character escapes like '\n' and and '\x70' + set -g fish_color_cancel red # color of the '^C' indicator on a canceled command + ''; + # }}} + + # Starship Prompt + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.starship.enable + programs.starship.enable = true; + + # Starship settings -------------------------------------------------------------------------- {{{ + + programs.starship.settings = { + # See docs here: https://starship.rs/config/ + # Symbols config configured in Flake. + + battery.display.threshold = 25; # display battery information if charge is <= 25% + directory.fish_style_pwd_dir_length = 1; # turn on fish directory truncation + directory.truncation_length = 2; # number of directories not to truncate + gcloud.disabled = true; # annoying to always have on + hostname.style = "bold green"; # don't like the default + memory_usage.disabled = true; # because it includes cached memory it's reported as full a lot + username.style_user = "bold blue"; # don't like the default + }; + # }}} +} diff --git a/install.sh b/install.sh deleted file mode 100755 index bbca43e..0000000 --- a/install.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -machine=$1 - -if [[ -z "$machine" ]]; then - machine=$(hostname) -fi - -if [[ ! -d "machines/$machine" ]]; then - echo "$machine is not a known machine" - exit -else - echo "Linking ./machines/$machine/configuration.nix to /etc/nixos/configuration.nix" -fi - -sudo ln -sf $PWD/machines/$machine/configuration.nix /etc/nixos/configuration.nix diff --git a/assets/arc-dark-red.rasi b/legacy/assets/arc-dark-red.rasi similarity index 100% rename from assets/arc-dark-red.rasi rename to legacy/assets/arc-dark-red.rasi diff --git a/assets/background-image b/legacy/assets/background-image similarity index 100% rename from assets/background-image rename to legacy/assets/background-image diff --git a/assets/colortest.fish b/legacy/assets/colortest.fish similarity index 100% rename from assets/colortest.fish rename to legacy/assets/colortest.fish diff --git a/assets/i3status.toml b/legacy/assets/i3status.toml similarity index 100% rename from assets/i3status.toml rename to legacy/assets/i3status.toml diff --git a/assets/init.vim b/legacy/assets/init.vim similarity index 100% rename from assets/init.vim rename to legacy/assets/init.vim diff --git a/assets/kitty-theme.conf b/legacy/assets/kitty-theme.conf similarity index 100% rename from assets/kitty-theme.conf rename to legacy/assets/kitty-theme.conf diff --git a/assets/lockscreen-image b/legacy/assets/lockscreen-image similarity index 100% rename from assets/lockscreen-image rename to legacy/assets/lockscreen-image diff --git a/assets/pijul.fish b/legacy/assets/pijul.fish similarity index 100% rename from assets/pijul.fish rename to legacy/assets/pijul.fish diff --git a/assets/sidetab.rasi b/legacy/assets/sidetab.rasi similarity index 100% rename from assets/sidetab.rasi rename to legacy/assets/sidetab.rasi diff --git a/assets/slate.rasi b/legacy/assets/slate.rasi similarity index 100% rename from assets/slate.rasi rename to legacy/assets/slate.rasi diff --git a/assets/systemctl.fish b/legacy/assets/systemctl.fish similarity index 100% rename from assets/systemctl.fish rename to legacy/assets/systemctl.fish diff --git a/cachix/fenix.nix b/legacy/cachix/fenix.nix similarity index 100% rename from cachix/fenix.nix rename to legacy/cachix/fenix.nix diff --git a/cachix/nix-community.nix b/legacy/cachix/nix-community.nix similarity index 100% rename from cachix/nix-community.nix rename to legacy/cachix/nix-community.nix diff --git a/hm-configs/dunst.nix b/legacy/hm-configs/dunst.nix similarity index 100% rename from hm-configs/dunst.nix rename to legacy/hm-configs/dunst.nix diff --git a/hm-configs/files-all.nix b/legacy/hm-configs/files-all.nix similarity index 100% rename from hm-configs/files-all.nix rename to legacy/hm-configs/files-all.nix diff --git a/hm-configs/files.nix b/legacy/hm-configs/files.nix similarity index 100% rename from hm-configs/files.nix rename to legacy/hm-configs/files.nix diff --git a/hm-configs/fish.nix b/legacy/hm-configs/fish.nix similarity index 100% rename from hm-configs/fish.nix rename to legacy/hm-configs/fish.nix diff --git a/hm-configs/i3.nix b/legacy/hm-configs/i3.nix similarity index 100% rename from hm-configs/i3.nix rename to legacy/hm-configs/i3.nix diff --git a/hm-configs/neovim.nix b/legacy/hm-configs/neovim.nix similarity index 100% rename from hm-configs/neovim.nix rename to legacy/hm-configs/neovim.nix diff --git a/hm-configs/vscode.nix b/legacy/hm-configs/vscode.nix similarity index 100% rename from hm-configs/vscode.nix rename to legacy/hm-configs/vscode.nix diff --git a/machines/nixpad/configuration.nix b/legacy/machines/nixpad/configuration.nix similarity index 100% rename from machines/nixpad/configuration.nix rename to legacy/machines/nixpad/configuration.nix diff --git a/profiles/caches.nix b/legacy/profiles/caches.nix similarity index 100% rename from profiles/caches.nix rename to legacy/profiles/caches.nix diff --git a/profiles/common.nix b/legacy/profiles/common.nix similarity index 100% rename from profiles/common.nix rename to legacy/profiles/common.nix diff --git a/profiles/fonts.nix b/legacy/profiles/fonts.nix similarity index 100% rename from profiles/fonts.nix rename to legacy/profiles/fonts.nix diff --git a/profiles/graphical.nix b/legacy/profiles/graphical.nix similarity index 100% rename from profiles/graphical.nix rename to legacy/profiles/graphical.nix diff --git a/profiles/laptop.nix b/legacy/profiles/laptop.nix similarity index 100% rename from profiles/laptop.nix rename to legacy/profiles/laptop.nix diff --git a/profiles/local.nix b/legacy/profiles/local.nix similarity index 100% rename from profiles/local.nix rename to legacy/profiles/local.nix diff --git a/profiles/quicksudo.nix b/legacy/profiles/quicksudo.nix similarity index 100% rename from profiles/quicksudo.nix rename to legacy/profiles/quicksudo.nix diff --git a/services/l10n.nix b/legacy/services/l10n.nix similarity index 100% rename from services/l10n.nix rename to legacy/services/l10n.nix diff --git a/services/pubkey.nix b/legacy/services/pubkey.nix similarity index 100% rename from services/pubkey.nix rename to legacy/services/pubkey.nix diff --git a/services/ssh.nix b/legacy/services/ssh.nix similarity index 100% rename from services/ssh.nix rename to legacy/services/ssh.nix diff --git a/services/vpn.nix b/legacy/services/vpn.nix similarity index 100% rename from services/vpn.nix rename to legacy/services/vpn.nix diff --git a/users/mat-hm-laptop.nix b/legacy/users/mat-hm-laptop.nix similarity index 100% rename from users/mat-hm-laptop.nix rename to legacy/users/mat-hm-laptop.nix diff --git a/users/mat-hm.nix b/legacy/users/mat-hm.nix similarity index 100% rename from users/mat-hm.nix rename to legacy/users/mat-hm.nix diff --git a/users/mat.nix b/legacy/users/mat.nix similarity index 100% rename from users/mat.nix rename to legacy/users/mat.nix diff --git a/modules/darwin/programs/nix-index.nix b/modules/darwin/programs/nix-index.nix new file mode 100644 index 0000000..be63661 --- /dev/null +++ b/modules/darwin/programs/nix-index.nix @@ -0,0 +1,17 @@ +# Additional configuration for `nix-index` to enable `command-not-found` functionality with Fish. +{ config, lib, pkgs, ... }: + +{ + config = lib.mkIf config.programs.nix-index.enable { + programs.fish.interactiveShellInit = '' + function __fish_command_not_found_handler --on-event="fish_command_not_found" + ${if config.programs.fish.useBabelfish then '' + command_not_found_handle $argv + '' else '' + ${pkgs.bashInteractive}/bin/bash -c \ + "source ${config.progams.nix-index.package}/etc/profile.d/command-not-found.sh; command_not_found_handle $argv" + ''} + end + ''; + }; +} \ No newline at end of file diff --git a/modules/darwin/security/pam.nix b/modules/darwin/security/pam.nix new file mode 100644 index 0000000..bc4895c --- /dev/null +++ b/modules/darwin/security/pam.nix @@ -0,0 +1,59 @@ +# Upstream PR: https://github.com/LnL7/nix-darwin/pull/228 +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.security.pam; + + # Implementation Notes + # + # We don't use `environment.etc` because this would require that the user manually delete + # `/etc/pam.d/sudo` which seems unwise given that applying the nix-darwin configuration requires + # sudo. We also can't use `system.patchs` since it only runs once, and so won't patch in the + # changes again after OS updates (which remove modifications to this file). + # + # As such, we resort to line addition/deletion in place using `sed`. We add a comment to the + # added line that includes the name of the option, to make it easier to identify the line that + # should be deleted when the option is disabled. + mkSudoTouchIdAuthScript = isEnabled: + let + file = "/etc/pam.d/sudo"; + option = "security.pam.enableSudoTouchIdAuth"; + in '' + ${if isEnabled then '' + # Enable sudo Touch ID authentication, if not already enabled + if ! grep 'pam_tid.so' ${file} > /dev/null; then + sed -i "" '2i\ + auth sufficient pam_tid.so # nix-darwin: ${option} + ' ${file} + fi + '' else '' + # Disable sudo Touch ID authentication, if added by nix-darwin + if grep '${option}' ${file} > /dev/null; then + sed -i "" '/${option}/d' ${file} + fi + ''} + ''; +in + +{ + options = { + security.pam.enableSudoTouchIdAuth = mkEnableOption '' + Enable sudo authentication with Touch ID + When enabled, this option adds the following line to /etc/pam.d/sudo: + auth sufficient pam_tid.so + (Note that macOS resets this file when doing a system update. As such, sudo + authentication with Touch ID won't work after a system update until the nix-darwin + configuration is reapplied.) + ''; + }; + + config = { + system.activationScripts.extraActivation.text = '' + # PAM settings + echo >&2 "setting up pam..." + ${mkSudoTouchIdAuthScript cfg.enableSudoTouchIdAuth} + ''; + }; +} \ No newline at end of file diff --git a/modules/darwin/users.nix b/modules/darwin/users.nix new file mode 100644 index 0000000..496770e --- /dev/null +++ b/modules/darwin/users.nix @@ -0,0 +1,14 @@ +{ lib, ... }: + +let + inherit (lib) mkOption types; +in + +{ + options = { + users.primaryUser = mkOption { + type = with types; nullOr string; + default = null; + }; + }; +} \ No newline at end of file diff --git a/modules/home/programs/kitty/extras.nix b/modules/home/programs/kitty/extras.nix new file mode 100644 index 0000000..bba7212 --- /dev/null +++ b/modules/home/programs/kitty/extras.nix @@ -0,0 +1,131 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.kitty.extras; + + # Create a Kitty config string from a Nix set + setToKittyConfig = with generators; toKeyValue { mkKeyValue = mkKeyValueDefault {} " "; }; + + # Write a Nix set representing a kitty config into the Nix store + writeKittyConfig = fileName: config: pkgs.writeTextDir "${fileName}" (setToKittyConfig config); + + # Path in Nix store containing light and dark kitty color configs + kitty-colors = pkgs.symlinkJoin { + name = "kitty-colors"; + paths = [ + (writeKittyConfig "dark-colors.conf" cfg.colors.dark) + (writeKittyConfig "light-colors.conf" cfg.colors.light) + ]; + }; + + # Shell scripts for changing Kitty colors + term-background = pkgs.writeShellScriptBin "term-background" '' + # Accepts arguments "light" or "dark". If shell is running in a Kitty window set the colors. + if [ -n "$KITTY_WINDOW_ID" ]; then + kitty @ --to $KITTY_LISTEN_ON set-colors --all --configured \ + ${kitty-colors}/"$1"-colors.conf & + fi + ''; + term-light = pkgs.writeShellScriptBin "term-light" '' + ${term-background}/bin/term-background light + ''; + term-dark = pkgs.writeShellScriptBin "term-dark" '' + ${term-background}/bin/term-background dark + ''; + +in { + + options.programs.kitty.extras = { + colors = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + When enable, commands term-dark and term-light will + toggle between your dark and a light colors. + term-background which accepts one argument (the value of which should + be dark or light) is also avaible. + (Note that the Kitty setting allow_remote_control = true is set to + enable this functionality.) + ''; + }; + + dark = mkOption { + type = with types; attrsOf str; + default = {}; + description = '' + Kitty color settings for dark background colorscheme. + ''; + }; + + light = mkOption { + type = with types; attrsOf str; + default = {}; + description = '' + Kitty color settings for light background colorscheme. + ''; + }; + + common = mkOption { + type = with types; attrsOf str; + default = {}; + description = '' + Kitty color settings that the light and dark background colorschemes share. + ''; + }; + + default = mkOption { + type = types.enum [ "dark" "light" ]; + default = "dark"; + description = '' + The colorscheme Kitty opens with. + ''; + }; + }; + + useSymbolsFromNerdFont = mkOption { + type = types.str; + default = ""; + example = "JetBrainsMono Nerd Font"; + description = '' + NerdFont patched fonts frequently suffer from rendering issues in terminals. To mitigate + this, we can use a non-NerdFont with Kitty and use the symbol_map setting + to tell Kitty to only use a NerdFont for NerdFont symbols. + Set this option the name of an installed NerdFont (the same name you'd use in the + font_family setting), to enable this feature. + ''; + }; + + }; + + config = mkIf config.programs.kitty.enable { + + home.packages = mkIf cfg.colors.enable [ + term-light + term-dark + term-background + ]; + + programs.kitty.settings = optionalAttrs cfg.colors.enable ( + + cfg.colors.common // cfg.colors.${cfg.colors.default} // { + allow_remote_control = "yes"; + listen_on = "unix:/tmp/mykitty"; + } + + ) // optionalAttrs (cfg.useSymbolsFromNerdFont != "") { + + # https://github.com/ryanoasis/nerd-fonts/wiki/Glyph-Sets-and-Code-Points + symbol_map = "U+E5FA-U+E62B,U+E700-U+E7C5,U+F000-U+F2E0,U+E200-U+E2A9,U+F500-U+FD46,U+E300-U+E3EB,U+F400-U+F4A8,U+2665,U+26a1,U+F27C,U+E0A3,U+E0B4-U+E0C8,U+E0CA,U+E0CC-U+E0D2,U+E0D4,U+23FB-U+23FE,U+2B58,U+F300-U+F313,U+E000-U+E00D ${cfg.useSymbolsFromNerdFont}"; + + }; + + xdg.configFile."kitty/macos-launch-services-cmdline" = + mkIf (pkgs.stdenv.isDarwin && cfg.colors.enable) { text = "--listen-on unix:/tmp/mykitty"; }; + + }; + +} \ No newline at end of file diff --git a/modules/home/programs/neovim/extras.nix b/modules/home/programs/neovim/extras.nix new file mode 100644 index 0000000..9689b2f --- /dev/null +++ b/modules/home/programs/neovim/extras.nix @@ -0,0 +1,167 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.neovim.extras; + nvr = "${pkgs.neovim-remote}/bin/nvr"; + + shellConfig = with cfg.nvrAliases; '' + # START programs.neovim.extras config ---------------------------------------------------------- + '' + optionalString cfg.termBufferAutoChangeDir '' + # If shell is running in a Neovim terminal buffer, set the PWD of the buffer to `$PWD`. + if test -n "$NVIM_LISTEN_ADDRESS"; nvim-sync-term-buffer-pwd; end + '' + optionalString cfg.nvrAliases.enable '' + # Neovim Remote aliases + if test -n "$NVIM_LISTEN_ADDRESS" + alias ${edit} "${nvr}" + alias ${split} "${nvr} -o" + alias ${vsplit} "${nvr} -O" + alias ${tabedit} "${nvr} --remote-tab" + alias ${nvim} "command nvim" + alias nvim "echo 'This shell is running in a Neovim termainal buffer. Use \'${nvim}\' to a nested instance of Neovim, otherwise use ${edit}, ${split}, ${vsplit}, or ${tabedit} to open files in the this Neovim instance.'" + else + alias ${edit} "nvim" + end + '' + '' + # END programs.neovim.extras config ------------------------------------------------------------ + ''; +in +{ + options.programs.neovim.extras = { + termBufferAutoChangeDir = mkOption { + type = types.bool; + default = false; + description = '' + When enabled, the pwd of terminal buffers in Neovim are automatically + updated to match $PWD of the shell running inside them. + Note that you cannot use this option if you are using + , use + and instead. + (Currently only works with Fish shell.) + ''; + }; + + nvrAliases = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + When enabled, shell aliases for helpful Neovim Remote commands are created if the shell is + running inside a Neovim terminal buffer. Additionally, running nvim + won't open a nested Neovim instance but instead print a message listing the available + nvr aliases, as well as the command to run if you actually want to open + a nested Neovim instance. + Note that you cannot use this option if you are using + , use + and + instead. + (Currently only works with Fish shell.) + ''; + }; + + edit = mkOption { + type = types.str; + default = "n"; + description = '' + Equivalent to Neovim's :edit command, i.e., running + n [file] will open the file in the current window. + When not in Neovim this also acts as an alias for nvim. + (Alias for nvr.) + ''; + }; + + split = mkOption { + type = types.str; + default = "ns"; + description = '' + Equivalent to Neovim's :split/command> command. + (Alias for nvr -o.) + ''; + }; + + vsplit = mkOption { + type = types.str; + default = "nv"; + description = '' + Equivalent to Neovim's :vsplit/command> command. + (Alias for nvr -O.) + ''; + }; + + tabedit = mkOption { + type = types.str; + default = "nt"; + description = '' + Equivalent to Neovim's :tabedit command. + (Alias for nvr --remote-tab.) + ''; + }; + + nvim = mkOption { + type = types.str; + default = "neovim"; + description = '' + Opens a nested Neovim instance. + ''; + }; + }; + + luaPackages = mkOption { + type = with types; listOf package; + default = []; + example = [ pkgs.luajitPackages.busted pkgs.luajitPackages.luafilesystem ]; + description = '' + Lua packages to make available in Neovim Lua environment. + Note that you cannot use this option if you are using + , use + and instead. + ''; + }; + }; + + config = mkIf config.programs.neovim.enable { + programs.fish.functions.nvim-sync-term-buffer-pwd = mkIf cfg.termBufferAutoChangeDir { + body = '' + if test -n "$NVIM_LISTEN_ADDRESS" + ${nvr} -c "let g:term_buffer_pwds.$fish_pid = '$PWD' | call Set_term_buffer_pwd() " + end + ''; + onVariable = "PWD"; + }; + + programs.neovim.extraConfig = mkIf cfg.termBufferAutoChangeDir '' + " START programs.neovim.extras.termBufferAutoChangeDir config -------------------------------- + " Dictionary used to track the PWD of terminal buffers. Keys should be PIDs and values are is + " PWD of the shell with that PID. These values are updated from the shell using `nvr`. + let g:term_buffer_pwds = {} + " Function to call to update the PWD of the current terminal buffer. + function Set_term_buffer_pwd() abort + if &buftype == 'terminal' && exists('g:term_buffer_pwds[b:terminal_job_pid]') + execute 'lchd ' . g:term_buffer_pwds[b:terminal_job_pid] + endif + endfunction + " Sometimes the PWD the shell in a terminal buffer will change when in another buffer, so + " when entering a terminal buffer we update try to update it's PWD. + augroup NvimTermPwd + au! + au BufEnter * if &buftype == 'terminal' | call Set_term_buffer_pwd() | endif + augroup END + " END programs.neovim.extras.termBufferAutoChangeDir config ---------------------------------- + ''; + + programs.fish.interactiveShellInit = mkIf + (cfg.termBufferAutoChangeDir || cfg.nvrAliases.enable) shellConfig; + + programs.neovim.plugins = lib.singleton ( + pkgs.vimUtils.buildVimPluginFrom2Nix { + name = "lua-env"; + src = pkgs.linkFarm "neovim-lua-env" ( + lib.forEach cfg.luaPackages ( + p: { name = "lua"; path = "${p}/lib/lua/${p.lua.luaversion}"; } + ) + ); + } + ); + }; +} \ No newline at end of file diff --git a/nixpkgs.nix b/nixpkgs.nix new file mode 100644 index 0000000..6595c88 --- /dev/null +++ b/nixpkgs.nix @@ -0,0 +1,7 @@ +{ + system ? builtins.currentSystem, + config ? {}, + overlays ? [], + ... +}@args: + import (import ./default.nix).inputs.nixpkgs-unstable args \ No newline at end of file diff --git a/overlays/colors.nix b/overlays/colors.nix new file mode 100644 index 0000000..a31210a --- /dev/null +++ b/overlays/colors.nix @@ -0,0 +1,72 @@ +# Colors from: https://ethanschoonover.com/solarized +# Used in Kitty terminal config: `./kitty-configs.nix` + +# SOLARIZED HEX 16/8 TERMCOL XTERM/HEX L*A*B RGB HSB +# --------- ------- ---- ------- ----------- ---------- ----------- ----------- +# base03 #002b36 8/4 brblack 234 #1c1c1c 15 -12 -12 0 43 54 193 100 21 +# base02 #073642 0/4 black 235 #262626 20 -12 -12 7 54 66 192 90 26 +# base01 #586e75 10/7 brgreen 240 #585858 45 -07 -07 88 110 117 194 25 46 +# base00 #657b83 11/7 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51 +# base0 #839496 12/6 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59 +# base1 #93a1a1 14/4 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63 +# base2 #eee8d5 7/7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93 +# base3 #fdf6e3 15/7 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99 +# yellow #b58900 3/3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71 +# orange #cb4b16 9/3 brred 166 #d75f00 50 50 55 203 75 22 18 89 80 +# red #dc322f 1/1 red 160 #d70000 50 65 45 220 50 47 1 79 86 +# magenta #d33682 5/5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83 +# violet #6c71c4 13/5 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77 +# blue #268bd2 4/4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82 +# cyan #2aa198 6/6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63 +# green #859900 2/2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60 + +final: prev: { + lib = prev.lib // { + colors = { + solarized = rec { + colors = { + darkBase = "002b36"; # base03 + darkBasehl = "073642"; # base02 + darkestTone = "586e75"; # base01 + darkTone = "657b83"; # base00 + lightTone = "839496"; # base0 + lightestTone = "93a1a1"; # base1 + lightBasehl = "eee8d5"; # base2 + lightBase = "fdf6e3"; # base3 + yellow = "b58900"; + orange = "cb4b16"; + red = "dc322f"; + magenta = "d33682"; + violet = "6c71c4"; + blue = "268bd2"; + cyan = "2aa198"; + green = "859900"; + }; + + light = with colors; { + base = lightBase; + basehl = lightBasehl; + invbase = darkBase; + invbasehl = darkBasehl; + main = darkTone; + faded = lightTone; + muted = lightestTone; + strong = darkestTone; + inherit (colors) yellow orange red megenta violet blue cyan green; + }; + + dark = with colors; { + base = darkBase; + basehl = darkBasehl; + invbase = lightBase; + invbasehl = lightBasehl; + main = lightTone; + faded = darkTone; + muted = darkestTone; + strong = lightestTone; + inherit (colors) yellow orange red megenta violet blue cyan green; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/profiles/server.nix b/profiles/server.nix deleted file mode 100644 index e1c7ab0..0000000 --- a/profiles/server.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ config, pkgs, ... }: - -{ - - imports = [ ./common.nix ./local.nix ]; - -}