From 17a261fc10a271cf1b86931b3373145cb623c49b Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Sun, 4 Jul 2021 21:51:48 +0100 Subject: [PATCH] Initial commit --- bootstrap.sh | 27 +++ darwin-configuration.nix | 220 ++++++++++++++++++ home.nix | 472 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 719 insertions(+) create mode 100644 bootstrap.sh create mode 100644 darwin-configuration.nix create mode 100644 home.nix diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100644 index 0000000..fead051 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +install_nix () { + echo "Installing Nix..." + curl -L https://nixos.org/nix/install | sh + echo "Nix installed." +} + +install_darwin_build () { + echo "Installing nix-darwin..." + nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer || exit 1 + ./result/bin/darwin-installer || exit 1 + rm -r ./result + echo "nix-darwin installed." +} + +nix-build --version || install_nix || exit 1 +darwin-rebuild changelog || install_darwin_build || exit 1 + +nix-channel --add https://github.com/rycee/home-manager/archive/master.tar.gz home-manager || exit 1 +nix-channel --update || exit 1 + +mkdir -p ~/.nixpkgs && cp ./darwin-configuration.nix ~/.nixpkgs/darwin-configuration.nix || exit 1 +mkdir -p ~/.config/nixpkgs && cp ./home.nix ~/.config/nixpkgs/home.nix || exit 1 + +darwin-rebuild || exit 1 +home-manager switch || exit 1 diff --git a/darwin-configuration.nix b/darwin-configuration.nix new file mode 100644 index 0000000..8087f3b --- /dev/null +++ b/darwin-configuration.nix @@ -0,0 +1,220 @@ +{ config, pkgs, lib, ... }: + +let + extensions = (with pkgs.vscode-extensions; [ + ms-vscode-remote.remote-ssh + ]) ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [ + { + name = "code-gnu-global"; + publisher = "austin"; + version = "0.2.2"; + sha256 = "1fz89m6ja25aif6wszg9h2fh5vajk6bj3lp1mh0l2b04nw2mzhd5"; + } + { + name = "Nix"; + publisher = "bbenoist"; + version = "1.0.1"; + sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b"; + } + { + name = "toml"; + publisher = "be5invis"; + version = "0.5.1"; + sha256 = "1r1y6krqw5rrdhia9xbs3bx9gibd1ky4bm709231m9zvbqqwwq2j"; + } + { + name = "haskell"; + publisher = "haskell"; + version = "1.4.0"; + sha256 = "1jk702fd0b0aqfryixpiy6sc8njzd1brd0lbkdhcifp0qlbdwki0"; + } + { + name = "Ionide-fsharp"; + publisher = "Ionide"; + version = "5.5.5"; + sha256 = "0nyi07xs7izynp2llhkqgz4i5j8gkpxy0gs934n9sm6rhs44vc66"; + } + { + name = "Ionide-Paket"; + publisher = "Ionide"; + version = "2.0.0"; + sha256 = "1455zx5p0d30b1agdi1zw22hj0d3zqqglw98ga8lj1l1d757gv6v"; + } + { + name = "latex-workshop"; + publisher = "James-Yu"; + version = "8.19.2"; + sha256 = "17jmwvj36pf207bv8nyi70vi5snskfnk7rbfcan79zl92g29id5z"; + } + { + name = "lean"; + publisher = "jroesch"; + version = "0.16.36"; + sha256 = "1ijzh82ka7k9pmzqax4ikmqv20yjmw7zi9vz2lizgsz6gdaylrj9"; + } + { + name = "language-haskell"; + publisher = "justusadam"; + version = "3.4.0"; + sha256 = "0ab7m5jzxakjxaiwmg0jcck53vnn183589bbxh3iiylkpicrv67y"; + } + { + name = "rust-analyzer"; + publisher = "matklad"; + version = "0.2.637"; + sha256 = "1bi9xklbls0jpccfg9bh3vk5s7v8f3a6f331b4hw0mpiv72ls5fr"; + } + { + name = "vscode-clang"; + publisher = "mitaki28"; + version = "0.2.4"; + sha256 = "0sys2h4jvnannlk2q02lprc2ss9nkgh0f0kwa188i7viaprpnx23"; + } + { + name = "vscode-docker"; + publisher = "ms-azuretools"; + version = "1.13.0"; + sha256 = "09iq528m3f8xa67daxyxddmg6xkzbbs2jps4hdni68j7jn0724y7"; + } + { + name = "csharp"; + publisher = "ms-dotnettools"; + version = "1.23.12"; + sha256 = "1j76399f5xhyn3qjp9gjdin7rdzn6bhig0xkswznf2yainz2x84z"; + } + { + name = "dotnet-interactive-vscode"; + publisher = "ms-dotnettools"; + version = "1.0.2309031"; + sha256 = "0vqlspq3696yyfsv17rpcbsaqs7nm7yvggv700sl1bia817cak10"; + } + { + name = "python"; + publisher = "ms-python"; + version = "2021.5.926500501"; + sha256 = "0hpb1z10ykg1sz0840qnas5ddbys9inqnjf749lvakj9spk1syk3"; + } + { + name = "vscode-pylance"; + publisher = "ms-python"; + version = "2021.6.1"; + sha256 = "1lv22z41rzbgy0b49c6avcy26747kw5533azbag4q12ylj67vn21"; + } + { + name = "jupyter"; + publisher = "ms-toolsai"; + version = "2021.7.942275039"; + sha256 = "1k60ak2scqq46gmwx3lmj82fchmvyjznra6y6p1djg2hqfkabxvx"; + } + { + name = "remote-containers"; + publisher = "ms-vscode-remote"; + version = "0.183.0"; + sha256 = "12v7037rn46svv6ff2g824hdkk7l95g4gbzrp5zdddwxs0a62jlg"; + } + { + name = "cpptools"; + publisher = "ms-vscode"; + version = "1.4.1"; + sha256 = "1728skp74b0685phjphcrrx5v7v715ms1j30xc363kvd2l9dvna8"; + } + { + name = "mono-debug"; + publisher = "ms-vscode"; + version = "0.16.2"; + sha256 = "10hixqkw5r3cg52xkbky395lv72sb9d9wrngdvmrwx62hkbk5465"; + } + { + name = "Theme-MarkdownKit"; + publisher = "ms-vscode"; + version = "0.1.4"; + sha256 = "1im78k2gaj6cri2jcvy727qdy25667v0f7vv3p3hv13apzxgzl0l"; + } + { + name = "trailing-spaces"; + publisher = "shardulm94"; + version = "0.3.1"; + sha256 = "0h30zmg5rq7cv7kjdr5yzqkkc1bs20d72yz9rjqag32gwf46s8b8"; + } + { + name = "vscode-lldb"; + publisher = "vadimcn"; + version = "1.6.4"; + sha256 = "0d2kra6rd0310qxkzn8paygirgmxd2v8yq0rbjmfnngcqccqv0pk"; + } + { + name = "vim"; + publisher = "vscodevim"; + version = "1.21.2"; + sha256 = "18bifdsm4k6rmzg5jx9kin0vlm1h9jikmka0rcyyw7zk1lxwbs9z"; + } + { + name = "debug"; + publisher = "webfreak"; + version = "0.25.1"; + sha256 = "1l01sv6kwh8dlv3kygkkd0z9m37hahflzd5bx1wwij5p61jg7np9"; + } + { + name = "markdown-all-in-one"; + publisher = "yzhang"; + version = "3.4.0"; + sha256 = "0ihfrsg2sc8d441a2lkc453zbw1jcpadmmkbkaf42x9b9cipd5qb"; + } +]; + vscode-with-extensions = pkgs.vscode-with-extensions.override { + vscodeExtensions = extensions; + }; + +in +{ + # List packages installed in system profile. To search by name, run: + # $ nix-env -qaP | grep wget + + environment.systemPackages = + [ pkgs.neovim + pkgs.alacritty + pkgs.tmux + pkgs.wget + pkgs.youtube-dl + pkgs.git + pkgs.fzf + pkgs.shellcheck + pkgs.cmake + pkgs.gcc + pkgs.gdb + pkgs.hledger + pkgs.hledger-web + pkgs.dotnet-sdk_5 + pkgs.docker + pkgs.ycmd + pkgs.keepassxc + pkgs.oh-my-zsh + pkgs.jitsi-meet + pkgs.elan + pkgs.protonmail-bridge + pkgs.handbrake + vscode-with-extensions + ]; + + nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "vscode" + "vscode-with-extensions" + "vscode-extension-ms-vscode-remote-remote-ssh" + ]; + + # Use a custom configuration.nix location. + # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix + # environment.darwinConfig = "$HOME/.config/nixpkgs/darwin/configuration.nix"; + + # Auto upgrade nix package and the daemon service. + # services.nix-daemon.enable = true; + # nix.package = pkgs.nix; + + # Create /etc/bashrc that loads the nix-darwin environment. + programs.zsh.enable = true; # default shell on catalina + # programs.fish.enable = true; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; +} diff --git a/home.nix b/home.nix new file mode 100644 index 0000000..6b5aa04 --- /dev/null +++ b/home.nix @@ -0,0 +1,472 @@ +{ config, pkgs, ... }: + +{ + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; + + # Home Manager needs a bit of information about you and the + # paths it should manage. + home.username = "Patrick"; + home.homeDirectory = "/Users/Patrick"; + + # This value determines the Home Manager release that your + # configuration is compatible with. This helps avoid breakage + # when a new Home Manager release introduces backwards + # incompatible changes. + # + # You can update Home Manager without changing this value. See + # the Home Manager release notes for a list of state version + # changes in each release. + home.stateVersion = "21.11"; + + programs.zsh = { + enable = true; + autocd = true; + dotDir = ".config/zsh"; + enableAutosuggestions = true; + enableCompletion = true; + oh-my-zsh = { + enable = true; + plugins = [ "git" "osx" "dircycle" "timer" ]; + theme = "robbyrussell"; + }; + sessionVariables = { + EDITOR = "vim"; + LC_ALL = "en_US.UTF-8"; + LC_CTYPE = "en_US.UTF-8"; + }; + shellAliases = { + view = "vim -R"; + }; + }; + + programs.fzf = { + enable = true; + enableZshIntegration = true; + }; + + programs.git = { + package = pkgs.gitAndTools.gitFull; + enable = true; + userName = "Smaug123"; + userEmail = "patrick+github@patrickstevens.co.uk"; + aliases = { + co = "checkout"; + st = "status"; + }; + extraConfig = { + push = { + default = "current"; + }; + pull = { + rebase = false; + }; + init = { + defaultBranch = "main"; + }; + advice = { + addIgnoredFile = false; + }; + }; + }; + + programs.neovim.enable = true; + programs.neovim.plugins = with pkgs.vimPlugins; [ + { plugin = rust-vim; + config = "let g:rustfmt_autosave = 1"; } + { plugin = syntastic; + config = ''let g:syntastic_rust_checkers = ['cargo'] +let g:syntastic_always_populate_loc_list = 1 +let g:syntastic_auto_loc_list = 1 +let g:syntastic_check_on_open = 1 +let g:syntastic_check_on_wq = 0''; } + + YouCompleteMe + tagbar + ]; + programs.neovim.viAlias = true; + programs.neovim.vimAlias = true; + programs.neovim.vimdiffAlias = true; + programs.neovim.withPython3 = true; + + programs.neovim.extraConfig = '' +set nu +colorscheme molokai + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Maintainer: +" Amir Salihefendic — @amix3k +" +" Awesome_version: +" Get this config, nice color schemes and lots of plugins! +" +" Install the awesome version from: +" +" https://github.com/amix/vimrc +" +" Sections: +" -> General +" -> VIM user interface +" -> Colors and Fonts +" -> Files and backups +" -> Text, tab and indent related +" -> Visual mode related +" -> Moving around, tabs and buffers +" -> Status line +" -> Editing mappings +" -> vimgrep searching and cope displaying +" -> Spell checking +" -> Misc +" -> Helper functions +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => General +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Sets how many lines of history VIM has to remember +set history=500 + +" Enable filetype plugins +filetype plugin on +filetype indent on + +" Set to auto read when a file is changed from the outside +set autoread + +" With a map leader it's possible to do extra key combinations +" like w saves the current file +let mapleader = "`" + +" :W sudo saves the file +" (useful for handling the permission-denied error) +command W w !sudo tee % > /dev/null + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => VIM user interface +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Set 7 lines to the cursor - when moving vertically using j/k +set so=7 + +" Avoid garbled characters in Chinese language windows OS +let $LANG='en' +set langmenu=en +source $VIMRUNTIME/delmenu.vim +source $VIMRUNTIME/menu.vim + +" Turn on the Wild menu +set wildmenu + +" Ignore compiled files +set wildignore=*.o,*~,*.pyc +if has("win16") || has("win32") + set wildignore+=.git\*,.hg\*,.svn\* +else + set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store +endif + +"Always show current position +set ruler + +" Height of the command bar +set cmdheight=2 + +" A buffer becomes hidden when it is abandoned +set hid + +" Ignore case when searching +set ignorecase + +" When searching try to be smart about cases +set smartcase + +" Highlight search results +set hlsearch + +" Makes search act like search in modern browsers +set incsearch + +" Don't redraw while executing macros (good performance config) +set lazyredraw + +" For regular expressions turn magic on +set magic + +" Show matching brackets when text indicator is over them +set showmatch +" How many tenths of a second to blink when matching brackets +set mat=2 + +" No annoying sound on errors +set noerrorbells +set novisualbell +set t_vb= +set tm=500 + +" Properly disable sound on errors on MacVim +if has("gui_macvim") + autocmd GUIEnter * set vb t_vb= +endif + + +" Add a bit extra margin to the left +set foldcolumn=1 + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Colors and Fonts +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Enable syntax highlighting +syntax enable + +" Enable 256 colors palette in Gnome Terminal +if $COLORTERM == 'gnome-terminal' + set t_Co=256 +endif + +set background=dark + +" Set extra options when running in GUI mode +if has("gui_running") + set guioptions-=T + set guioptions-=e + set t_Co=256 + set guitablabel=%M\ %t +endif + +" Set utf8 as standard encoding and en_US as the standard language +set encoding=utf8 + +" Use Unix as the standard file type +set ffs=unix,dos,mac + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Files, backups and undo +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Turn backup off, since most stuff is in SVN, git et.c anyway... +set nobackup +set nowb +set noswapfile + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Text, tab and indent related +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Use spaces instead of tabs +set expandtab + +" Be smart when using tabs ;) +set smarttab + +" 1 tab == 4 spaces +set shiftwidth=4 +set tabstop=4 + +" Linebreak on 500 characters +set lbr +set tw=500 + +set ai "Auto indent +set si "Smart indent +set wrap "Wrap lines + + +"""""""""""""""""""""""""""""" +" => Visual mode related +"""""""""""""""""""""""""""""" +" Visual mode pressing * or # searches for the current selection +" Super useful! From an idea by Michael Naumann +vnoremap * :call VisualSelection('''', '''')/=@/ +vnoremap # :call VisualSelection('''', '''')?=@/ + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Moving around, tabs, windows and buffers +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Map to / (search) and Ctrl- to ? (backwards search) +map / +map ? + +" Disable highlight when is pressed +map :noh + +" Smart way to move between windows +map j +map k +map h +map l + +" Close the current buffer +map bd :Bclose:tabclosegT + +" Close all the buffers +map ba :bufdo bd + +map l :bnext +map h :bprevious + +" Useful mappings for managing tabs +map tn :tabnew +map to :tabonly +map tc :tabclose +map tm :tabmove +map t :tabnext + +" Let 'tl' toggle between this and the last accessed tab +let g:lasttab = 1 +nmap tl :exe "tabn ".g:lasttab +au TabLeave * let g:lasttab = tabpagenr() + + +" Opens a new tab with the current buffer's path +" Super useful when editing files in the same directory +map te :tabedit =expand("%:p:h")/ + +" Switch CWD to the directory of the open buffer +map cd :cd %:p:h:pwd + +" Specify the behavior when switching between buffers +try + set switchbuf=useopen,usetab,newtab + set stal=2 +catch +endtry + +" Return to last edit position when opening files (You want this!) +au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + + +"""""""""""""""""""""""""""""" +" => Status line +"""""""""""""""""""""""""""""" +" Always show the status line +set laststatus=2 + + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Editing mappings +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" Move a line of text using ALT+[jk] or Command+[jk] on mac +nmap mz:m+`z +nmap mz:m-2`z +vmap :m'>+`mzgv`yo`z +vmap :m'<-2`>my` + nmap + vmap + vmap +endif + +" Delete trailing white space on save, useful for some filetypes ;) +fun! CleanExtraSpaces() + let save_cursor = getpos(".") + let old_query = getreg('/') + silent! %s/\s\+$//e + call setpos('.', save_cursor) + call setreg('/', old_query) +endfun + +if has("autocmd") + autocmd BufWritePre *.fs,*.fsi,*.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces() +endif + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Spell checking +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Pressing ,ss will toggle and untoggle spell checking +map ss :setlocal spell! + +" Shortcuts using +map sn ]s +map sp [s +map sa zg +map s? z= + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Misc +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Remove the Windows ^M - when the encodings gets messed up +noremap m mmHmt:%s///ge'tzt'm + +" Quickly open a buffer for scribble +map q :e ~/buffer + +" Quickly open a markdown buffer for scribble +map x :e ~/buffer.md + +" Toggle paste mode on and off +map pp :setlocal paste! + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Helper functions +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Returns true if paste mode is enabled +function! HasPaste() + if &paste + return 'PASTE MODE ' + endif + return '''''' +endfunction + +" Don't close window, when deleting a buffer +command! Bclose call BufcloseCloseIt() +function! BufcloseCloseIt() + let l:currentBufNum = bufnr("%") + let l:alternateBufNum = bufnr("#") + + if buflisted(l:alternateBufNum) + buffer # + else + bnext + endif + + if bufnr("%") == l:currentBufNum + new + endif + + if buflisted(l:currentBufNum) + execute("bdelete! ".l:currentBufNum) + endif +endfunction + +function! CmdLine(str) + call feedkeys(":" . a:str) +endfunction + +function! VisualSelection(direction, extra_filter) range + let l:saved_reg = @" + execute "normal! vgvy" + + let l:pattern = escape(@", "\\/.*'$^~[]") + let l:pattern = substitute(l:pattern, "\n$", "", "") + + if a:direction == 'gv' + call CmdLine("Ack '" . l:pattern . "' " ) + elseif a:direction == 'replace' + call CmdLine("%s" . '/'. l:pattern . '/') + endif + + let @/ = l:pattern + let @" = l:saved_reg +endfunction + +nnoremap c :!cargo clippy + +set statusline+=%#warningmsg# +set statusline+=%{SyntasticStatuslineFlag()} +set statusline+=%* +" Format the status line +set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c + + ''; +}