From 91dbef3d59ccdad84bbc455b3cbe326195eb2685 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Thu, 21 Apr 2022 04:49:44 +0000 Subject: [PATCH] Split up base and add xonsh Add Xonsh configurations from dotfiles Split up the base configuration into more manageable sizes --- flake.nix | 2 +- home/xonsh.nix | 7 -- profiles/{base.nix => base/default.nix} | 90 ++--------------- profiles/base/nix.nix | 19 ++++ profiles/base/programs.nix | 22 ++++ profiles/base/syncthing.nix | 46 +++++++++ profiles/base/xonsh.nix | 127 ++++++++++++++++++++++++ 7 files changed, 225 insertions(+), 88 deletions(-) delete mode 100644 home/xonsh.nix rename profiles/{base.nix => base/default.nix} (63%) create mode 100644 profiles/base/nix.nix create mode 100644 profiles/base/programs.nix create mode 100644 profiles/base/syncthing.nix create mode 100644 profiles/base/xonsh.nix diff --git a/flake.nix b/flake.nix index 8bd1166..8cad3c7 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ mods = hostname: [ inputs.agenix.nixosModule ./modules - ./profiles/base.nix + ./profiles/base ./hosts/${hostname} inputs.home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; diff --git a/home/xonsh.nix b/home/xonsh.nix deleted file mode 100644 index 9425c5b..0000000 --- a/home/xonsh.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ ... }: - -{ - home.files.".xonshrc" = '' - -''; -} diff --git a/profiles/base.nix b/profiles/base/default.nix similarity index 63% rename from profiles/base.nix rename to profiles/base/default.nix index a918a69..644d95f 100755 --- a/profiles/base.nix +++ b/profiles/base/default.nix @@ -1,32 +1,21 @@ { config, pkgs, agenix, ... }: -let - syncs = [ - "nas" - "dns" - "linode" - ]; -in { - # Enable flakes - nix = { - package = pkgs.nixFlakes; + imports = [ + ./nix.nix + ./programs.nix + ./syncthing.nix + ./xonsh.nix + ]; - # 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; + # Enable the OpenSSH daemon for remote control + services.openssh.enable = true; + #services.openssh.permitRootLogin = "yes"; + # Define a user account. Don't forget to set a password with ‘passwd’. users.users.greg = { isNormalUser = true; @@ -39,65 +28,6 @@ in ]; }; - # Enable the OpenSSH daemon for remote control - services.openssh.enable = true; - #services.openssh.permitRootLogin = "yes"; - - services.syncthing = { - enable = true; - user = "greg"; - group = "users"; - dataDir = "/home/greg/sync"; - devices = { - nas = { - addresses = [ - "tcp://nas.thehellings.lan:22000" - "tcp://chronicles.greg-hellings.gmail.com.beta.tailscale.net:22000" - ]; - id = "74JUTZG-77EPGO3-FEYCL2P-CHDWP5G-6EXWZVB-XTAH6O5-TUXCVY2-QNRHSQ4"; - }; - dns = { - addresses = [ - "tcp://dns.thehellings.lan:22000" - "tcp://2maccabees.greg-hellings.gmail.com.beta.tailscale.net:22000" - ]; - id = "C4XJCH7-3ZNW6XZ-R5DB2EU-OEGVVT2-WPHQAG7-UDWER36-6NO5KZR-4MN5VAK"; - }; - linode = { - addresses = [ - "tcp://linode.thehellings.com:22000" - ]; - id = "3PHWAI5-ILAWGGD-S5FC5QM-M2WQ2FX-PZ3IXQF-QVRKANG-WXAACJC-2MZN3Q5"; - }; - }; - folders = { - "mkrvy-tc6x9" = { - enable = true; - path = "/home/greg/drive"; - devices = syncs; - }; - }; - }; - - # 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 - pwgen - tmux - transcrypt - 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"; console = { diff --git a/profiles/base/nix.nix b/profiles/base/nix.nix new file mode 100644 index 0000000..0b23255 --- /dev/null +++ b/profiles/base/nix.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: + +{ + # 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; +} diff --git a/profiles/base/programs.nix b/profiles/base/programs.nix new file mode 100644 index 0000000..ce02325 --- /dev/null +++ b/profiles/base/programs.nix @@ -0,0 +1,22 @@ +{ pkgs, agenix, ... }: + +{ + # 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 + pwgen + tmux + transcrypt + 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 + ]; +} diff --git a/profiles/base/syncthing.nix b/profiles/base/syncthing.nix new file mode 100644 index 0000000..5058476 --- /dev/null +++ b/profiles/base/syncthing.nix @@ -0,0 +1,46 @@ +{ ... }: + +let + syncs = [ + "nas" + "dns" + "linode" + ]; +in +{ + services.syncthing = { + enable = true; + user = "greg"; + group = "users"; + dataDir = "/home/greg/sync"; + devices = { + nas = { + addresses = [ + "tcp://nas.thehellings.lan:22000" + "tcp://chronicles.greg-hellings.gmail.com.beta.tailscale.net:22000" + ]; + id = "74JUTZG-77EPGO3-FEYCL2P-CHDWP5G-6EXWZVB-XTAH6O5-TUXCVY2-QNRHSQ4"; + }; + dns = { + addresses = [ + "tcp://dns.thehellings.lan:22000" + "tcp://2maccabees.greg-hellings.gmail.com.beta.tailscale.net:22000" + ]; + id = "C4XJCH7-3ZNW6XZ-R5DB2EU-OEGVVT2-WPHQAG7-UDWER36-6NO5KZR-4MN5VAK"; + }; + linode = { + addresses = [ + "tcp://linode.thehellings.com:22000" + ]; + id = "3PHWAI5-ILAWGGD-S5FC5QM-M2WQ2FX-PZ3IXQF-QVRKANG-WXAACJC-2MZN3Q5"; + }; + }; + folders = { + "mkrvy-tc6x9" = { + enable = true; + path = "/home/greg/drive"; + devices = syncs; + }; + }; + }; +} diff --git a/profiles/base/xonsh.nix b/profiles/base/xonsh.nix new file mode 100644 index 0000000..b49ebc8 --- /dev/null +++ b/profiles/base/xonsh.nix @@ -0,0 +1,127 @@ +{ pkgs, ... }: + +{ + programs.xonsh = { + enable = true; + config = '' +# set -e == $RAISE_SUBPROC_ERROR = True +# set -x == trace on; $XONSH_TRACE_SUBPROC = True +# $? == _.rtn + +import os + +$TIMEFORMAT = '%3Uu %3Ss %3lR %P%%' +$CLICOLOR = 1 +$LSCOLORS = 'ExGxBxDxCxEgEdxbxgxcxd' +$EDITOR = '${pkgs.vim}/vim' +$PKG_CONFIG_PATH = '/usr/local/lib/pkgconfig' +# Tells vox where to find virtualenvs +$VIRTUALENV_HOME = $HOME + '/venv/' +$PROMPT = '{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {short_cwd}{branch_color}{curr_branch: {}}{RESET} {BOLD_BLUE}{prompt_end}{RESET} ' + + +$SWORD_PATH = $HOME + '/.sword' +$OS_CLOUD = 'default' + + +$GOPATH = '~/.go' +$JAVA_HOME = '/etc/alternatives/java_sdk' +$MAVEN_OPTS = ' -Dmaven.wagon.http.ssl.insecure=true' + + +# Coloured man page support +# using 'less' env vars (format is '\E[;m') +$LESS_TERMCAP_mb = "\033[01;31m" # begin blinking +$LESS_TERMCAP_md = "\033[01;31m" # begin bold +$LESS_TERMCAP_me = "\033[0m" # end mode +$LESS_TERMCAP_so = "\033[01;44;36m" # begin standout-mode (bottom of screen) +$LESS_TERMCAP_se = "\033[0m" # end standout-mode +$LESS_TERMCAP_us = "\033[00;36m" # begin underline +$LESS_TERMCAP_ue = "\033[0m" # end underline + + +#################################### +# +# Alias Time +# +#################################### +aliases['ll'] = 'ls -l' + +aliases['vup'] = 'vagrant up --provision --provider libvirt' +aliases['vos'] = 'vagrant up --provision --provider openstack' +aliases['vssh'] = 'vagrant ssh' +aliases['vhalt'] = 'vagrant halt' +aliases['vprov'] = 'vagrant provision' +aliases['vdown'] = 'vagrant destroy' + +aliases['ac'] = 'vox activate' +aliases['d'] = 'vox deactivate' + +aliases['devroles'] = 'cd ~/src/ansible_collections/devroles' +aliases['molcol'] = 'molecule -c ../../tests/molecule.yml' + +aliases['packaging'] = 'cd ~/src/packaging' + +def _yaml2json(args, stdin=None, stdout=None): + import sys, yaml, json + from yaml import CLoader + json.dump(yaml.load(stdin, Loader=CLoader), stdout, indent=4) + +def _py2env(args): + vox new @(args[0]) -p /usr/bin/python2 + +def _py3env(args): + vox new @(args[0]) + +def _rundock(args): + if os.path.exists('/usr/bin/podman'): + e = 'podman' + else: + e = 'docker' + @(e) exec -ti @(args[0]) /bin/bash + +def _pip_extras(args): + import importlib_metadata + print(importlib_metadata.metadata(args[0]).get_all('Provides-Extra')) + +# Container stuff +def _newdock(args): + if os.path.exists('/usr/bin/podman'): + e = 'podman' + else: + e = 'docker' + @(e) run -P --privileged=true -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v @(os.getcwd()):/dmnt -v /etc/pki:/etc/pki:ro -d --name @(args[1]) @(args[0]) /sbin/init + rundock @(args[1]) + +def _unknown_host(args): + sed -i -e @(args[0])d ~/.ssh/known_hosts + +aliases['yaml2json'] = _yaml2json +aliases['py2env'] = _py2env +aliases['py3env'] = _py3env +aliases['rundock'] = _rundock +aliases['newdock'] = _newdock +aliases['unknown_host'] = _unknown_host +aliases['pip_extras'] = _pip_extras +### +# +# Other random nice-to-have things +# +### + +# Does virtualenv support +xontrib load vox +# Faster coreutils +xontrib load coreutils + +# Allows identifying JSON as if it was Python by adding some new builtins to the language +import builtins +builtins.true = True +builtins.false = False +builtins.null = None + +# Open a new terminal tab (Gnome Terminal) in the same CWD +$PROMPT = '{vte_new_tab_cwd}' + $PROMPT +''; + }; +}