From 1c19e5300d808ab50afd742826842a70366d982c Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Fri, 29 Apr 2022 10:58:31 -0500 Subject: [PATCH] Vast improvements to desktop experience --- flake.lock | 35 +++++++++- flake.nix | 6 ++ home/gui/chat.nix | 5 ++ home/gui/default.nix | 9 +++ home/gui/firefox.nix | 36 +++++++++++ home/gui/terminal.nix | 13 ++++ home/home.nix | 15 +++-- home/modules/default.nix | 7 ++ home/modules/xonsh.nix | 96 ++++++++++++++++++++++++++++ home/vim.nix | 6 +- home/xonsh.nix | 117 ++++++++++++++++++++++++++++++++++ hosts/jude/default.nix | 2 +- modules/default.nix | 1 + modules/gnome.nix | 18 +++++- modules/xprograms.nix | 16 +++++ profiles/base/default.nix | 1 - profiles/base/programs.nix | 1 - profiles/base/xonsh.nix | 127 ------------------------------------- 18 files changed, 370 insertions(+), 141 deletions(-) create mode 100644 home/gui/chat.nix create mode 100644 home/gui/default.nix create mode 100644 home/gui/firefox.nix create mode 100644 home/gui/terminal.nix create mode 100644 home/modules/default.nix create mode 100644 home/modules/xonsh.nix create mode 100644 home/xonsh.nix create mode 100644 modules/xprograms.nix delete mode 100644 profiles/base/xonsh.nix diff --git a/flake.lock b/flake.lock index 73255af..1dab8b7 100644 --- a/flake.lock +++ b/flake.lock @@ -71,11 +71,44 @@ "type": "github" } }, + "nixunstable": { + "locked": { + "lastModified": 1651007983, + "narHash": "sha256-GNay7yDPtLcRcKCNHldug85AhAvBpTtPEJWSSDYBw8U=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e10da1c7f542515b609f8dfbcf788f3d85b14936", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nur": { + "locked": { + "lastModified": 1651053120, + "narHash": "sha256-PKbB7MK6jwG4G3A/2RR0ZA8YSNanwi5R+Bvv/LwzKwo=", + "owner": "nix-community", + "repo": "NUR", + "rev": "2eb8999947487d915d6a1100d672284a1989c905", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NUR", + "type": "github" + } + }, "root": { "inputs": { "agenix": "agenix", "home-manager": "home-manager", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "nixunstable": "nixunstable", + "nur": "nur" } } }, diff --git a/flake.nix b/flake.nix index b5865b1..a37468f 100644 --- a/flake.nix +++ b/flake.nix @@ -6,16 +6,19 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; + nixunstable.url = "github:nixos/nixpkgs/nixos-unstable"; agenix.url = "github:ryantm/agenix"; home-manager = { url = "github:nix-community/home-manager/release-21.11"; inputs.nixpkgs.follows = "nixpkgs"; }; + nur.url = "github:nix-community/NUR"; }; outputs = inputs: let mods = hostname: [ + { nixpkgs.overlays = [ inputs.nur.overlay ]; } inputs.agenix.nixosModule ./modules ./profiles/base @@ -24,6 +27,9 @@ home-manager.useGlobalPkgs = true; home-manager.users.greg = import ./home/home.nix "greg"; home-manager.users.root = import ./home/home.nix "root"; + home-manager.extraSpecialArgs = { + nixunstable = inputs.nixunstable; + }; } ]; diff --git a/home/gui/chat.nix b/home/gui/chat.nix new file mode 100644 index 0000000..9f67c39 --- /dev/null +++ b/home/gui/chat.nix @@ -0,0 +1,5 @@ +{ pkgs, ... }: + +{ + home.packages = [ pkgs.element-desktop ]; +} diff --git a/home/gui/default.nix b/home/gui/default.nix new file mode 100644 index 0000000..5cffb04 --- /dev/null +++ b/home/gui/default.nix @@ -0,0 +1,9 @@ +{ ... }: + +{ + imports = [ + ./chat.nix + ./firefox.nix + ./terminal.nix + ]; +} diff --git a/home/gui/firefox.nix b/home/gui/firefox.nix new file mode 100644 index 0000000..a79cfd5 --- /dev/null +++ b/home/gui/firefox.nix @@ -0,0 +1,36 @@ +{ lib, pkgs, ... }: + +let + ffPkgs = wayland: if wayland + then [ pkgs.firefox-wayland ] + else [ pkgs.firefox ]; + + vars = { + MOZ_ENABLE_WAYLAND = "1"; + XDG_CURRENT_DESKTOP = "sway"; + }; +in with lib; +{ + programs.firefox = { + enable = true; + enableGnomeExtensions = true; + extensions = with pkgs.nur.repos.rycee.firefox-addons; [ + keepassxc-browser + octotree + refined-github + ublock-origin + ]; + profiles = { + default.settings = { + "browser.startup.page" = 3; + "browser.startup.homepage" = "https://thehellings.com"; + "doh-rollout.doorhanger-decision" = "UIDisabled"; + "doh-rollout.doneFirstRun" = true; + }; + }; + }; + + programs.bash.sessionVariables = vars; + + programs.xonsh.sessionVariables = vars; +} diff --git a/home/gui/terminal.nix b/home/gui/terminal.nix new file mode 100644 index 0000000..7d90605 --- /dev/null +++ b/home/gui/terminal.nix @@ -0,0 +1,13 @@ +{ ... }: + +{ + programs.gnome-terminal = { + enable = true; + showMenubar = true; + themeVariant = "dark"; + profile.default = { + default = true; + visibleName = "greg"; + }; + }; +} diff --git a/home/home.nix b/home/home.nix index f197fa4..197350e 100644 --- a/home/home.nix +++ b/home/home.nix @@ -1,12 +1,19 @@ -name: { pkgs, lib, ...}: +name: { pkgs, lib, nixosConfig, ...}: -{ +let + guiImports = if nixosConfig.greg.gnome.enable then + [ ./gui ] else []; + +in { imports = [ + ./modules ./bash.nix ./git.nix - ./vim.nix ./ssh.nix - ]; + ./vim.nix + ./xonsh.nix + ] ++ guiImports; + home.username = name; home.homeDirectory = if name == "root" then "/root" else "/home/${name}"; diff --git a/home/modules/default.nix b/home/modules/default.nix new file mode 100644 index 0000000..3357dd9 --- /dev/null +++ b/home/modules/default.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + imports = [ + ./xonsh.nix + ]; +} diff --git a/home/modules/xonsh.nix b/home/modules/xonsh.nix new file mode 100644 index 0000000..348612c --- /dev/null +++ b/home/modules/xonsh.nix @@ -0,0 +1,96 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.programs.xonsh; + +in with lib; { + options = { + programs.xonsh = { + enable = mkEnableOption "Enable the xonsh program"; + + sessionVariables = mkOption { + type = types.attrs; + default = {}; + example = { XONSH_TRACE_SUBPROC = true; }; + description = '' + Environment variables that will be set for the Xonsh session. + ''; + }; + + aliases = mkOption { + type = types.attrsOf types.str; + default = {}; + example = literalExpression '' + { + ll = "ls -l"; + la = "ls -a"; + } + ''; + description = '' + An attribute set that maps aliases (the top level attribute names in + this option) to command strings or directly to build outputs. + ''; + }; + + configHeader = mkOption { + type = types.lines; + default = ""; + example = literalExpression '' + import os + import sys + ''; + description = "An arbitrary string to put at the top of the config file"; + }; + + configFooter = mkOption { + type = types.lines; + default = ""; + example = literalExpression '' + def _some_method(args): + do_command() + some_other_thing() + aliases['some_method'] = _some_method + ''; + description = "An arbitrary string to put at the end of the config file"; + }; + }; + }; + + config = + let + shortAliases = concatStringsSep "\n" ( + mapAttrsToList (k: v: "aliases['${k}']='${v}'") cfg.aliases + ); + + listToPythonList = let + listInternals = args: + concatStringsSep "\n" (map (v: "'${v}'") args); + in list: "[${listInternals list}]"; + + sessionVars = concatStringsSep "\n" ( + mapAttrsToList (k: v: + if builtins.typeOf v == "string" then + "\$${k} = '${v}'" + else if builtins.typeOf v == "list" then + "\$${k} = ${listToPythonList}" + else if builtins.typeOf v == "int" then + "\$${k} = ${toString v}" + else "" + ) cfg.sessionVariables + ); + + in mkIf cfg.enable { + + home.packages = [ pkgs.xonsh ]; + + home.file.".xonshrc".text = '' +${cfg.configHeader} + +${sessionVars} + +${shortAliases} + +${cfg.configFooter} +''; + }; +} diff --git a/home/vim.nix b/home/vim.nix index 4ea06f9..eaedde5 100644 --- a/home/vim.nix +++ b/home/vim.nix @@ -22,7 +22,6 @@ in vim-flake8 vim-fugitive vim-indent-guides - #vim-stabs gruvbox syntastic ]; @@ -74,9 +73,9 @@ let g:ctrlp_switch_buffer = 0 let g:ctrlp_cmd = 'CtrlPMixed' let g:ctrlp_user_command = { \'types': { - \1: ['.git', 'git ls-files --cached --exclude-standard --others' ], + \1: ['.git', '${pkgs.git}/bin/git ls-files --cached --exclude-standard --others' ], \}, - \'fallback': 'find . -type f | grep -v -e "\.tox/" -e "\.git/"' + \'fallback': '${pkgs.findutils}/bin/find . -type f | ${pkgs.gnugrep}/bin/grep -v -e "\.tox/" -e "\.git/"' \} " let g:ctrpl_match_func = { 'match': 'pymatcher#PyMatch' } @@ -88,6 +87,7 @@ autocmd! BufWritePost .vimrc source $MYVIMRC " Tell syntastic to use yamllint let g:syntastic_yaml_checkers = ['yamllint'] let g:syntastic_yaml_yamllint_args = [] +let g:syntastic_shell = "${pkgs.bash}/bin/bash" " Shortcuts for resolving git diff conflicts let g:diffget_local_map = 'gl' let g:diffget_upstream_map = 'gu' diff --git a/home/xonsh.nix b/home/xonsh.nix new file mode 100644 index 0000000..660ffc0 --- /dev/null +++ b/home/xonsh.nix @@ -0,0 +1,117 @@ +{ pkgs, config, nixosConfig, lib, ... }: + +let + enable = nixosConfig.greg.gnome.enable; +in { + programs.xonsh = { + enable = true; + + sessionVariables = { + TIMEFORMAT = "%3Uu %3Ss %3lR %P%%"; + CLICOLOR = 1; + LSCOLORS = "ExGxBxDxCxEgEdxbxgxcxd"; + EDITOR = "${pkgs.vim}/bin/vim"; + # Tells vox where to find virtualenvs + VIRTUALENV_HOME = "${config.home.homeDirectory}/venv/"; + # vte_new_tab_cwd causes new Terminal tabs to open in the + # same CWD as the current tab + PROMPT = "{vte_new_tab_cwd}{env_name}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {short_cwd}{branch_color}{curr_branch: {}}{RESET} {BOLD_BLUE}{prompt_end}{RESET} "; + SWORD_PATH = "${config.home.homeDirectory}/.sword/"; + OS_CLOUD = "default"; + MAVEN_OPTS = " -Dmaven.wagon.http.ssl.insecure=true"; + 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 + }; + + aliases = { + ll = "ls -l"; + vup = "vagrant up --provision --provider libvirt"; + vos = "vagrant up --provision --provider openstack"; + vssh = "vagrant ssh"; + vhalt = "vagrant halt"; + vprov = "vagrant provision"; + vdown = "vagrant destroy"; + ac = "vox activate"; + d = "vox deactivate"; + devroles = "cd ~/src/ansible_collections/devroles"; + molcol = "molecule -c ../../tests/molecule.yml"; + pa = "cd ~/src/packaging"; + }; + + configHeader = '' +# set -e == $RAISE_SUBPROC_ERROR = True +# set -x == trace on; $XONSH_TRACE_SUBPROC = True +# $? == _.rtn + +import os +''; + +#$PKG_CONFIG_PATH = '/usr/local/lib/pkgconfig' +#$GOPATH = $HOME + '/.go' +#$JAVA_HOME = '/etc/alternatives/java_sdk' + configFooter = '' +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 +''; + }; +} diff --git a/hosts/jude/default.nix b/hosts/jude/default.nix index ad1dbca..8c34c55 100644 --- a/hosts/jude/default.nix +++ b/hosts/jude/default.nix @@ -6,5 +6,5 @@ ./hardware-configuration.nix ]; networking.hostName = "jude"; - greg.gnome = true; + greg.gnome.enable= true; } diff --git a/modules/default.nix b/modules/default.nix index 27807ce..8124384 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -7,5 +7,6 @@ ./linode.nix ./proxy.nix ./rpi4.nix + ./xprograms.nix ]; } diff --git a/modules/gnome.nix b/modules/gnome.nix index a3b8575..45cd953 100644 --- a/modules/gnome.nix +++ b/modules/gnome.nix @@ -5,10 +5,12 @@ let in with lib; { options = { - greg.gnome = mkEnableOption "Enable my default Gnome3 setup"; + greg.gnome.enable = mkEnableOption "Enable my default Gnome3 setup"; }; - config = mkIf cfg { + config = mkIf cfg.enable { + greg.xprograms.enable = true; + # Sets up a basic Gnome installation services.xserver = { enable = true; @@ -21,16 +23,26 @@ in with lib; { programs.dconf.enable = true; programs.sway.enable = true; # Gives us Wayland - xdg.portal.wlr.enable = true; # Allows screen sharing in Wayland + xdg.portal = { + enable = true; + gtkUsePortal = true; + wlr.enable = true; # Enables screen sharing in Wayland + }; # Enable some Gnome plugins that I like environment.systemPackages = with pkgs; [ gnome3.adwaita-icon-theme gnomeExtensions.appindicator + gnomeExtensions.dash-to-dock ]; services.udev.packages = with pkgs; [ gnome3.gnome-settings-daemon ]; + + services.pipewire.enable = true; + + # Enablement for Firefox + services.gnome.chrome-gnome-shell.enable = true; }; } diff --git a/modules/xprograms.nix b/modules/xprograms.nix new file mode 100644 index 0000000..0a31731 --- /dev/null +++ b/modules/xprograms.nix @@ -0,0 +1,16 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.greg.xprograms; + +in with lib; { + options = { + greg.xprograms.enable = mkEnableOption "Install my favorite XPrograms"; + }; + + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + keepassxc + ]; + }; +} diff --git a/profiles/base/default.nix b/profiles/base/default.nix index 644d95f..043fb38 100755 --- a/profiles/base/default.nix +++ b/profiles/base/default.nix @@ -5,7 +5,6 @@ ./nix.nix ./programs.nix ./syncthing.nix - ./xonsh.nix ]; diff --git a/profiles/base/programs.nix b/profiles/base/programs.nix index ce02325..a5aa7d5 100644 --- a/profiles/base/programs.nix +++ b/profiles/base/programs.nix @@ -16,7 +16,6 @@ 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/xonsh.nix b/profiles/base/xonsh.nix deleted file mode 100644 index 9456475..0000000 --- a/profiles/base/xonsh.nix +++ /dev/null @@ -1,127 +0,0 @@ -{ 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}/bin/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 -''; - }; -}