From 13be0b0895f290689fe13f922640e5dba97f018d Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Mon, 18 Apr 2022 11:38:06 -0500 Subject: [PATCH] Convert to flakes Convert the install to flakes Move home-manager into core repository --- flake.lock | 22 +++++++ flake.nix | 10 +++ home/bash.nix | 95 +++++++++++++++++++++++++++ home/git.nix | 25 +++++++ home/home.nix | 12 ++++ home/vim.nix | 164 ++++++++++++++++++++++++++++++++++++++++++++++ home/xonsh.nix | 7 ++ profiles/base.nix | 29 +++++--- 8 files changed, 356 insertions(+), 8 deletions(-) create mode 100644 home/bash.nix create mode 100644 home/git.nix create mode 100644 home/home.nix create mode 100644 home/vim.nix create mode 100644 home/xonsh.nix diff --git a/flake.lock b/flake.lock index a898f60..44530e7 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,27 @@ "type": "github" } }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1649887911, + "narHash": "sha256-Af0Ppb1RZ7HWuxUvF0/O7h3cy8tqU2eKFyVwyA1ZD+w=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "7244c6715cb8f741f3b3e1220a9279e97b2ed8f5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-21.11", + "repo": "home-manager", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1638587357, @@ -53,6 +74,7 @@ "root": { "inputs": { "agenix": "agenix", + "home-manager": "home-manager", "nixpkgs": "nixpkgs_2" } } diff --git a/flake.nix b/flake.nix index 61f04b9..5533eaa 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,10 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; agenix.url = "github:ryantm/agenix"; + home-manager = { + url = "github:nix-community/home-manager/release-21.11"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs: @@ -15,7 +19,13 @@ inputs.agenix.nixosModule ./profiles/base.nix ./hosts/${hostname} + inputs.home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.users.greg = import ./home/home.nix "greg"; + home-manager.users.root = import ./home/home.nix "root"; + } ]; + in { nixosConfigurations = { "2maccabees" = inputs.nixpkgs.lib.nixosSystem { diff --git a/home/bash.nix b/home/bash.nix new file mode 100644 index 0000000..abc5098 --- /dev/null +++ b/home/bash.nix @@ -0,0 +1,95 @@ +{ pkgs, ... }: + +{ + programs.bash = { + enable = true; + shellAliases = { + acp = "rsync --progress -ah"; + agbuild = "ansible-galaxy collection build"; + apub = "ansible-galaxy collection publish --api-key \${GALAXY_API_KEY}"; + calc = "bc"; + d = "deactivate"; + devroles = "cd ~/src/ansible_collections/devroles"; + gohome = "ssh greg@dns.greg-hellings.gmail.com.beta.tailscale.net -D localhost:10080"; + ll = "ls -l"; + molcol = "molecule -c ../../tests/molecule.yml"; + packaging = "cd ~/src/packaging"; + vdown = "vagrant destroy"; + vhalt = "vagrant halt"; + vos = "vagrant up --provision --provider openstack"; + vprov = "vagrant provision"; + vssh = "vagrant ssh"; + vup = "vagrant up --provision --provider libvirt"; + yaml2js = "python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)"; + }; + sessionVariables = { + ANSIBLE_COLLECTIONS_PATH="\${HOME}/src/"; + CLICOLOR = "1"; + EDITOR = "${pkgs.vim}/bin/vim"; + GALAXY_API_KEY = "11498be21eb34b5776af72bcec59ddfdafcf27e5"; + GIT_SSL_NO_VERIFY = "True"; + LSCOLORS = "ExGxBxDxCxEgEdxbxgxcxd"; + MAVEN_OPTS = " -Dmaven.wagon.http.ssl.insecure=true "; + OS_CLOUD = "default"; + SWORD_PATH = "\${HOME}/.sword"; + TIMEFORMAT = "%3Uu %3Ss %3lR %P%%"; + VAGRANT_CLOUD_TOKEN = "zCQN8OBMy6Kl2g.atlasv1.JHsu0HsHMDdqCWqyUjJuCKDH0DyDzOHhbDBCrphUyjOP8OoM9i39SYmtk3Q4DKxfZXE"; + }; + profileExtra = '' +if [ -e /etc/profile ]; then + . /etc/profile +fi +''; + bashrcExtra = '' +function swordtag { + if [ x"$1" == "x" ]; then + echo "Please provide tag version" + return + fi + svn cp http://crosswire.org/svn/sword/branches/sword-1-8-x/ http://crosswire.org/svn/sword/tags/sword-$1/ +} + +function newdock { + if [ x"$1" == "x" -o x"$2" == "x" ]; then + echo "expected arguments [name] [source]" + return + fi + podman run -P --privileged=true -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v "$(pwd):/dmnt" -t -i --name="$1" "$2" /bin/bash +} + +function rundock { + podman start -a -i "$1" +} + +function ac { + source ~/venv/''${1}/bin/activate +} + +function py2env { + /usr/bin/virtualenv -p /usr/bin/python2 "''${HOME}/venv/''${1}" + "''${HOME}/venv/''${1}/bin/pip" install -U pip +} + +function py3env { + VENV_NAME="''${1}" + #PYVERSION="$(python3 -c "import sys;print(sys.version[:sys.version.find('.',2)])")" + #SITE_PACKAGES_PATH="/usr/lib64/python''${PYVERSION}/site-packages/" + #VENV_SITE_PACKAGES="''${HOME}/venv/''${VENV_NAME}/lib64/python''${PYVERSION}/site-packages/" + # Create the virtualenv and update pip to latest + /usr/bin/python3 -m venv --clear "''${HOME}/venv/''${VENV_NAME}" --system-site-packages + "''${HOME}/venv/''${1}/bin/python3" -m pip install -U pip + # Link SELinux into the environment if necessary + #if [ -d "''${SITE_PACKAGES_PATH}" ]; then + # ln -s "''${SITE_PACKAGES_PATH}/selinux" "''${VENV_SITE_PACKAGES}" + # ln -s ''${SITE_PACKAGES_PATH}/_selinux*.so "''${VENV_SITE_PACKAGES}" + #else + # echo "ERROR: LibSELinux not found for Python ''${PYVERSION}. Install system package to enable." + #fi +} + +function unknown_host { + sed -i -e ''${1}d ~/.ssh/known_hosts +} +''; + }; +} diff --git a/home/git.nix b/home/git.nix new file mode 100644 index 0000000..aedd549 --- /dev/null +++ b/home/git.nix @@ -0,0 +1,25 @@ +{ ... }: + +{ + programs.git = { + enable = true; + userName = "Greg Hellings"; + userEmail = "greg.hellings@gmail.com"; + aliases = { + st = "status"; + ci = "commit"; + co = "checkout"; + }; + ignores = [ + ".*.swp" ".*.swo" ".*.swn" # vim + ".idea" # IntelliJ + ".DS_Store" # Macs + "Thumbs.db" # Windows + ".tox" # Tox temp directory + ]; + extraConfig = { + push.default = "upstream"; + pull.rebase = "false"; + }; + }; +} diff --git a/home/home.nix b/home/home.nix new file mode 100644 index 0000000..8395b83 --- /dev/null +++ b/home/home.nix @@ -0,0 +1,12 @@ +name: pkgs: + +{ + imports = [ + ./bash.nix + ./git.nix + ./vim.nix + ]; + + home.username = name; + home.homeDirectory = if name == "root" then "/root" else "/home/${name}"; +} diff --git a/home/vim.nix b/home/vim.nix new file mode 100644 index 0000000..01dd602 --- /dev/null +++ b/home/vim.nix @@ -0,0 +1,164 @@ +{ pkgs, ... }: + +let + vim-stabs = pkgs.vimUtils.buildVimPlugin { + name = "vim-stabs"; + src = pkgs.fetchFromGitHub { + owner = "Thyrum"; + repo = "vim-stabs"; + rev = "4654d4e000680e1f608b40f155af08873446ed63"; + sha256 = "0hi1c5zv38hwxbyrf11fz97r728jgbppz4is7fwzwhfrzhwbw0ga"; + }; + }; +in +{ + programs.vim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + bufexplorer + ctrlp + nerdtree + vim-gitgutter + vim-flake8 + vim-fugitive + vim-indent-guides + #vim-stabs + gruvbox + syntastic + ]; + settings = { + background = "dark"; + copyindent = true; + expandtab = false; + hidden = true; + ignorecase = true; + mouse = "a"; + number = true; + relativenumber = true; + shiftwidth = 4; + smartcase = true; + tabstop = 4; + }; + extraConfig = '' +set nocompatible +syntax enable +set preserveindent +set softtabstop=0 +set nowrap +set showcmd +set cursorline +set lazyredraw +set showmatch +set hlsearch +" Shows non-printing characters +set listchars=tab:→\ ,extends:→,precedes:←,trail:·,eol:¬ +set list + +" Highlights bad whitespace +autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red +autocmd BufWinEnter * match ExtraWhitespace /\s\+$/ +autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@ \be +map :NERDTreeToggle +map :CtrlP +" Allows navigating splits +map j +map k +map h +map l + +colorscheme gruvbox + +" ============================================================================ +" User functions to just make life easier +" ============================================================================ +" Toggle absolute line numbers when we don't have focus, and hybrid when +" we do have it +augroup numbertoggle + autocmd! + autocmd BufEnter,FocusGained,InsertLeave * set relativenumber + autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber +augroup END +" syntax highlighting for Vagrantfiles +augroup vagrant + au! + au BufRead,BufNewFile Vagrantfile set filetype=ruby +augroup END +" Creates the directory for a file if it doesn't already exist. +function! s:MkNonExDir(file, buf) + if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/' + let dir=fnamemodify(a:file, ':h') + if !isdirectory(dir) + call mkdir(dir, 'p') + endif + endif +endfunction +augroup BWCCreateDir + autocmd! + autocmd BufWritePre * :call s:MkNonExDir(expand(''), +expand('')) +augroup END + +" Return indent (all whitespace at start of a line), converted from +" tabs to spaces if what = 1, or from spaces to tabs otherwise. +" When converting to tabs, result has no redundant spaces. +function! Indenting(indent, what, cols) + let spccol = repeat(' ', a:cols) + let result = substitute(a:indent, spccol, '\t', 'g') + let result = substitute(result, ' \+\ze\t', ''', 'g') + if a:what == 1 + let result = substitute(result, '\t', spccol, 'g') + endif + return result +endfunction + +" Convert whitespace used for indenting (before first non-whitespace). +" what = 0 (convert spaces to tabs), or 1 (convert tabs to spaces). +" cols = string with number of columns per tab, or empty to use 'tabstop'. +" The cursor position is restored, but the cursor will be in a different +" column when the number of characters in the indent of the line is changed. +function! IndentConvert(line1, line2, what, cols) + let savepos = getpos('.') + let cols = empty(a:cols) ? &tabstop : a:cols + execute a:line1 . ',' . a:line2 . 's/^\s\+/\=Indenting(submatch(0), a:what, cols)/e' + call histdel('search', -1) + call setpos('.', savepos) +endfunction +command! -nargs=? -range=% Space2Tab call IndentConvert(,,0,) +command! -nargs=? -range=% Tab2Space call IndentConvert(,,1,) +command! -nargs=? -range=% RetabIndent call IndentConvert(,,&et,) +''; + }; +} diff --git a/home/xonsh.nix b/home/xonsh.nix new file mode 100644 index 0000000..9425c5b --- /dev/null +++ b/home/xonsh.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + home.files.".xonshrc" = '' + +''; +} diff --git a/profiles/base.nix b/profiles/base.nix index 9872ae4..3168521 100755 --- a/profiles/base.nix +++ b/profiles/base.nix @@ -8,6 +8,22 @@ let ]; in { + # Enable flakes + nix = { + package = pkgs.nixFlakes; + + # Keep freespace available, at a minimum, and enable Flakes + extraOptions = '' + experimental-features = nix-command flakes + min-free = ${toString (1024 * 1024 * 1024) } + max-free = ${toString (5 * 1024 * 1024 * 1024) } + ''; + + # Use hardlinking instead of copying when possible + autoOptimiseStore = true; + }; + nixpkgs.config.allowUnfree = true; + # I am a fan of network manager, myself networking.networkmanager.enable = true; @@ -74,7 +90,10 @@ in # Base packages that need to be in all my hosts environment.systemPackages = with pkgs; [ agenix.defaultPackage."${system}" + diffutils git + gnupatch + findutils home-manager htop python3 @@ -82,6 +101,8 @@ in tmux vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. wget + xonsh + yamllint # Used in vim ]; i18n.defaultLocale = "en_US.UTF-8"; @@ -91,14 +112,6 @@ in keyMap = "us"; }; - # Keep freespace available, at a minimum - nix.extraOptions = '' - min-free = ${toString (1024 * 1024 * 1024) } - max-free = ${toString (5 * 1024 * 1024 * 1024) } - ''; - # Use hardlinking instead of copying when possible - nix.autoOptimiseStore = true; - # The set of default values, which allow syou to keep system defaults set # to a predictable value as you upgrade the system system.stateVersion = "21.11";