diff --git a/.gitattributes b/.gitattributes index 6d34fee..3ab6513 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ #pattern filter=crypt diff=crypt **/*.crypt filter=crypt diff=crypt home/ssh/id_rsa* filter=crypt diff=crypt +modules/ssh/id_* filter=crypt diff=crypt diff --git a/.gitignore b/.gitignore index c70dc2d..0d96e93 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ host +result diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..f860526 --- /dev/null +++ b/configuration.nix @@ -0,0 +1,120 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ./modules/automatic/nix.nix + ]; + + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + boot.loader.efi.efiSysMountPoint = "/boot/efi"; + + networking.hostName = "lappy"; # Define your hostname. + # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Enable networking + networking.networkmanager.enable = true; + + # Set your time zone. + time.timeZone = "America/Chicago"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.utf8"; + + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the GNOME Desktop Environment. + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + + # Configure keymap in X11 + services.xserver = { + layout = "us"; + xkbVariant = ""; + }; + + # Enable CUPS to print documents. + services.printing.enable = true; + + # Enable sound with pipewire. + sound.enable = true; + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + # If you want to use JACK applications, uncomment this + #jack.enable = true; + + # use the example session manager (no others are packaged yet so this is enabled by default, + # no need to redefine it in your config for now) + #media-session.enable = true; + }; + + # Enable touchpad support (enabled default in most desktopManager). + # services.xserver.libinput.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.greg = { + isNormalUser = true; + description = "Greg Hellings"; + extraGroups = [ "networkmanager" "wheel" ]; + packages = with pkgs; [ + firefox + # thunderbird + ]; + }; + + # Allow unfree packages + nixpkgs.config.allowUnfree = true; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + git + vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. + wget + ]; + + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + # services.openssh.enable = true; + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + # networking.firewall.enable = false; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "22.05"; # Did you read the comment? + +} diff --git a/flake.lock b/flake.lock index c5464f9..cd348f3 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1648942457, - "narHash": "sha256-i29Z1t3sVfCNfpp+KAfeExvpqHQSbLO1KWylTtfradU=", + "lastModified": 1652712410, + "narHash": "sha256-hMJ2TqLt0DleEnQFGUHK9sV2aAzJPU8pZeiZoqRozbE=", "owner": "ryantm", "repo": "agenix", - "rev": "0d5e59ed645e4c7b60174bc6f6aac6a203dc0b01", + "rev": "7e5e58b98c3dcbf497543ff6f22591552ebfe65b", "type": "github" }, "original": { @@ -46,16 +46,16 @@ ] }, "locked": { - "lastModified": 1649887911, - "narHash": "sha256-Af0Ppb1RZ7HWuxUvF0/O7h3cy8tqU2eKFyVwyA1ZD+w=", + "lastModified": 1656169755, + "narHash": "sha256-Nlnm4jeQWEGjYrE6hxi/7HYHjBSZ/E0RtjCYifnNsWk=", "owner": "nix-community", "repo": "home-manager", - "rev": "7244c6715cb8f741f3b3e1220a9279e97b2ed8f5", + "rev": "4a3d01fb53f52ac83194081272795aa4612c2381", "type": "github" }, "original": { "owner": "nix-community", - "ref": "release-21.11", + "ref": "release-22.05", "repo": "home-manager", "type": "github" } @@ -78,26 +78,59 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1650244918, - "narHash": "sha256-DsS5nxjTpnoUC4pNXJI1rit7TnDTij8vQDa5PtcDCD0=", + "lastModified": 1659342832, + "narHash": "sha256-ePnxG4hacRd6oZMk+YeCSYMNUnHCe+qPLI0/+VaTu48=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7b38b03d76ab71bdc8dc325e3f6338d984cc35ca", + "rev": "e43cf1748462c81202a32b26294e9f8eefcc3462", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-21.11", + "ref": "nixos-22.05", "repo": "nixpkgs", "type": "github" } }, + "nixunstable": { + "locked": { + "lastModified": 1659219666, + "narHash": "sha256-pzYr5fokQPHv7CmUXioOhhzDy/XyWOIXP4LZvv/T7Mk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7b9be38c7250b22d829ab6effdee90d5e40c6e5c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nurpkgs": { + "locked": { + "lastModified": 1659423577, + "narHash": "sha256-i2wSHqFqu4xpBJU/o9SRpQblAHknnEtyeN6Kuq/c1JA=", + "owner": "nix-community", + "repo": "NUR", + "rev": "0bdb7691364dc93c8f04016c0ed395b675bdc50c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NUR", + "type": "github" + } + }, "root": { "inputs": { "agenix": "agenix", "darwin": "darwin", "home-manager": "home-manager", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "nixunstable": "nixunstable", + "nurpkgs": "nurpkgs" } } }, diff --git a/flake.nix b/flake.nix index 8bd302a..e4da5fb 100644 --- a/flake.nix +++ b/flake.nix @@ -5,34 +5,40 @@ description = "Greg's machines!"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; + nixunstable.url = "github:nixos/nixpkgs/nixos-unstable"; agenix.url = "github:ryantm/agenix"; home-manager = { - url = "github:nix-community/home-manager/release-21.11"; + url = "github:nix-community/home-manager/release-22.05"; inputs.nixpkgs.follows = "nixpkgs"; }; darwin = { url = "github:lnl7/nix-darwin/master"; inputs.nixpkgs.follows = "nixpkgs"; }; + nurpkgs.url = "github:nix-community/NUR"; }; - outputs = inputs: + outputs = {nixpkgs, nixunstable, agenix, home-manager, nurpkgs, self}@inputs: let + local_overlay = import ./overlays; + mods = hostname: [ - inputs.agenix.nixosModule + { nixpkgs.overlays = [ nurpkgs.overlay local_overlay ]; } + agenix.nixosModule ./modules - ./profiles/linux ./hosts/${hostname} - inputs.home-manager.nixosModules.home-manager { + 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"; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit nixunstable; + }; } ]; - machine = system: name: inputs.nixpkgs.lib.nixosSystem { - system = system; + machine = system: name: nixpkgs.lib.nixosSystem { + inherit system; specialArgs = inputs; modules = mods name; }; @@ -43,12 +49,28 @@ ./hosts/${hostname} ]; + unstableMachine = system: name: inputs.nixunstable.lib.nixosSystem { + system = system; + modules = mods name; + specialArgs = { + nixpkgs = inputs.nixunstable; + nixunstable = inputs.nixunstable; + agenix = inputs.agenix; + home-manager = inputs.home-manager; + nur = inputs.nur; + }; + }; + in { nixosConfigurations = { - "2maccabees" = machine "aarch64-linux" "2maccabees"; + "2maccabees" = unstableMachine "aarch64-linux" "2maccabees"; "linode" = machine "x86_64-linux" "linode"; + "jude" = machine "x86_64-linux" "jude"; + + "lappy" = machine "x86_64-linux" "lappy"; + "iso" = machine "x86_64-linux" "iso"; }; @@ -62,5 +84,14 @@ defaultPackage."x86_64-linux" = inputs.self.nixosConfigurations.iso.config.system.build.isoImage; defaultPackage."x86_64-darwin" = inputs.self.darwinConfigurations.C02G48H8MD6R.system; + + homeConfigurations = ( + import ./home { + inherit nixpkgs nixunstable agenix home-manager nurpkgs; + } + ); + + overlay = local_overlay; + modules = import ./modules; }; } diff --git a/hardware-configuration.nix b/hardware-configuration.nix new file mode 100644 index 0000000..19de254 --- /dev/null +++ b/hardware-configuration.nix @@ -0,0 +1,39 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" "rtsx_usb_sdmmc" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/63bcc80e-0501-4aef-bb58-30bb83881055"; + fsType = "ext4"; + }; + + fileSystems."/boot/efi" = + { device = "/dev/disk/by-uuid/C617-B2B1"; + fsType = "vfat"; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/bc4f24a3-5969-4bcb-95f4-f80109e36ebb"; } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp7s0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp6s0.useDHCP = lib.mkDefault true; + + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/home/ansible.nix b/home/ansible.nix new file mode 100644 index 0000000..f4df8b6 --- /dev/null +++ b/home/ansible.nix @@ -0,0 +1,28 @@ +{ ... }: + +{ + home.file.".ansible.cfg".text = '' +[defaults] +forks=10 +host_key_checking=False +# Also available: profile_roles +callback_enabled=timer,profile_tasks +stdout_callback=yaml +nocows=1 +cow_selection=tux +collections_path=~/src + +[ssh_connection] +pipelining=True +ssh_args = -o ControlMaster=auto -o ControlPersist=600s -o IdentitiesOnly=yes -o GSSAPIAuthentication=no -o StrictHostKeyChecking=no +control_path=%(directory)s/%%h-%%r +control_path_dir=/tmp + +[callback_profile_tasks] +sort_order=descending + +[galaxy] +role_skeleton_ignore = ^.git$,^.*/.git_keep$,\..*.swp +role_skeleton = ~/src/ansible_collections/meta_ansible_templates/role +''; +} diff --git a/home/default.nix b/home/default.nix new file mode 100644 index 0000000..ec0ed68 --- /dev/null +++ b/home/default.nix @@ -0,0 +1,35 @@ +{ nixpkgs, nurpkgs, home-manager, username ? builtins.getEnv "USER", ... }: + +let + homeDirectory = if username == "root" then "/root" else "/home/${username}"; + configDir = "${homeDirectory}/.config"; + + pkgs = import nixpkgs { + config.allowUnfree = true; + config.xdg.configHome = configDir; + overlays = [ + nurpkgs.overlay + (import ../overlays) + ]; + }; + + nur = import nurpkgs { + inherit pkgs; + nur = pkgs; + }; + + mkhome = system: gui: + home-manager.lib.homeManagerConfiguration rec { + inherit pkgs system username homeDirectory; + stateVersion = "22.05"; + configuration = import ./home.nix username { + inherit nur pkgs gui; + inherit (pkgs) config lib stdenv; + }; + }; +in { + "aarch64-gui" = mkhome "aarch64-linux" true; + "aarch64-nogui" = mkhome "aarch64-linux" false; + "x86_64-gui" = mkhome "x86_64-linux" true; + "x86_64-nogui" = mkhome "x86_64-linux" false; +} diff --git a/home/direnv.nix b/home/direnv.nix new file mode 100644 index 0000000..b6d26ad --- /dev/null +++ b/home/direnv.nix @@ -0,0 +1,12 @@ +{ pkgs, ... }: + +{ + programs.direnv = { + enable = true; + nix-direnv.enable = true; + }; + + home.packages = [ + pkgs.xonsh-direnv + ]; +} diff --git a/home/gui/chat.nix b/home/gui/chat.nix new file mode 100644 index 0000000..ffc9f8b --- /dev/null +++ b/home/gui/chat.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +{ + home.packages = with pkgs; [ + element-desktop + nheko + ]; +} diff --git a/home/gui/default.nix b/home/gui/default.nix new file mode 100644 index 0000000..8ce60ed --- /dev/null +++ b/home/gui/default.nix @@ -0,0 +1,18 @@ +{ pkgs, ... }: + +{ + imports = [ + ./chat.nix + ./firefox.nix + ./terminal.nix + ]; + + home.packages = with pkgs; [ + bitwarden + gnucash + handbrake + onlyoffice-bin + synology-drive-client + vlc + ]; +} diff --git a/home/gui/firefox.nix b/home/gui/firefox.nix new file mode 100644 index 0000000..d1b97c7 --- /dev/null +++ b/home/gui/firefox.nix @@ -0,0 +1,41 @@ +{ 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; + package = pkgs.firefox-wayland.override { + cfg = { + enableGnomeExtensions = true; + }; + }; + extensions = with pkgs.nur.repos.rycee.firefox-addons; [ + bitwarden + octotree + refined-github + tree-style-tab + 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..b9e007d 100644 --- a/home/home.nix +++ b/home/home.nix @@ -1,13 +1,28 @@ -name: { pkgs, lib, ...}: +name: { pkgs, lib, gui, ...}: -{ +let + guiImports = if gui then + [ ./gui ] else []; + +in { imports = [ + ./modules + ./ansible.nix ./bash.nix + ./direnv.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}"; + + home.stateVersion = "22.05"; + home.packages = with pkgs; [ + cdrtools + ffmpeg + hms + libtheora + x265 + ]; } 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/ssh.nix b/home/ssh.nix index 879df1f..56d239a 100644 --- a/home/ssh.nix +++ b/home/ssh.nix @@ -35,6 +35,11 @@ "src.fedoraproject.org pkgs.fedoraproject.org" = { user = "greghellings"; }; + + "127.*".extraOptions = { + PubkeyAcceptedAlgorithms = "+ssh-rsa"; + HostkeyAlgorithms = "+ssh-rsa"; + }; }; }; diff --git a/home/vim.nix b/home/vim.nix index 4ea06f9..45e1781 100644 --- a/home/vim.nix +++ b/home/vim.nix @@ -15,14 +15,16 @@ in programs.vim = { enable = true; plugins = with pkgs.vimPlugins; [ + ansible-vim bufexplorer ctrlp + direnv-vim nerdtree vim-gitgutter vim-flake8 vim-fugitive vim-indent-guides - #vim-stabs + vim-packer gruvbox syntastic ]; @@ -72,12 +74,13 @@ set wildignore+=*.swp,*.pyc,*.class,.tox let g:ctrlp_working_path_mode = 'arc' 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' ], - \}, - \'fallback': 'find . -type f | grep -v -e "\.tox/" -e "\.git/"' -\} +let g:ctrlp_show_hidden = 1 +"let g:ctrlp_user_command = { +" \'types': { +" \1: ['.git', '${pkgs.git}/bin/git ls-files --cached --exclude-standard --others' ], +" \}, +" \'fallback': '${pkgs.findutils}/bin/find . -type f | ${pkgs.gnugrep}/bin/grep -v -e "\.tox/" -e "\.git/"' +"\} " let g:ctrpl_match_func = { 'match': 'pymatcher#PyMatch' } " Settings for NerdTree @@ -88,6 +91,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..aafa96a --- /dev/null +++ b/home/xonsh.nix @@ -0,0 +1,123 @@ +{ pkgs, config, lib, ... }: + +{ + 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"; + dirflake = "nix flake new -t github:nix-community/nix-direnv"; + tsup = "sudo tailscale up"; + tspub = "sudo tailscale up --exit-node=linode"; + tshome = "sudo tailscale up --exit-node=2maccabees"; + tsclear = "sudo tailscale up --exit-node=''"; + rebuild = "sudo nixos-rebuild switch"; + }; + + configHeader = '' +# set -e == $RAISE_SUBPROC_ERROR = True +# set -x == trace on; $XONSH_TRACE_SUBPROC = True +# $? == _.rtn + +import os + +xontrib load direnv +''; + +#$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/2maccabees/dnsmasq.nix b/hosts/2maccabees/dnsmasq.nix index 000d958..ed96138 100644 --- a/hosts/2maccabees/dnsmasq.nix +++ b/hosts/2maccabees/dnsmasq.nix @@ -2,14 +2,22 @@ let extraHosts = builtins.concatStringsSep "\n" [ + # Local hosts "10.42.0.1 switch" "10.42.1.1 router" - "10.42.1.2 dns smart" - "100.99.244.92 dns.me.ts" + "10.42.1.2 2maccabees 2maccabees.thehellings.lan dns dns.thehellings.lan smart smart.thehellings.lan" "10.42.1.3 printer" "10.42.1.4 chronicles nas" - "100.119.228.115 nas.me.ts" "10.42.1.12 tv" + + # Tailscale hosts + "100.90.74.19 jude.me.ts" + "100.99.244.92 dns.me.ts 2maccabees.me.ts smart.me.ts" + "100.119.228.115 chronicles.me.ts nas.me.ts" + "100.115.57.8 linode.me.ts" + + # Dev hosts + "10.42.101.1 icdm.lan wiki.icdm.lan *.icdm.lan" ]; extraConfig = builtins.concatStringsSep "\n" [ diff --git a/hosts/2maccabees/home-assistant.nix b/hosts/2maccabees/home-assistant.nix index ac77178..6db8bf3 100755 --- a/hosts/2maccabees/home-assistant.nix +++ b/hosts/2maccabees/home-assistant.nix @@ -7,19 +7,44 @@ in { virtualisation.podman.enable = true; + services.home-assistant = { + enable = true; + configDir = "/var/lib/hass"; + package = (pkgs.home-assistant.override { + extraComponents = [ + "accuweather" + "cast" + "eufy" + "lovelace" + "tplink" + "wiz" + "zwave_js" + ]; + }).overrideAttrs (oldAttrs: { + doInstallCheck = false; + }); + + config = { + default_config = {}; + esphome = {}; # Get these things loaded, even if not configured + met = {}; + tts = [ { platform = "google_translate"; } ]; + http = { + use_x_forwarded_for = true; + trusted_proxies = [ "127.0.0.1" "::1" ]; + server_host = "127.0.0.1"; + }; + "automation ui" = "!include automations.yaml"; + "script ui" = "!include scripts.yaml"; + "scene ui" = "!include scenes.yaml"; + }; + }; + # Although NixOS has a package for Home Assistant, it is not kept as up to date as the container and the upstream # is very vocal about only supporting their own container or the HAOS deployments. So we deploy the container here # and avoid any potential messes from that virtualisation.oci-containers = { backend = "podman"; - containers."home-assistant" = { - image = "ghcr.io/home-assistant/home-assistant:stable"; - ports = [ "127.0.0.1:8123:8123" ]; - volumes = [ "/var/lib/hass:/config" ]; - extraOptions = [ - "--device" "/dev/ttyAMA0" - ]; - }; # I have ZWave devices. The easiest way to connect to them is the zwavejs2mqtt service running, so we spin up # its container and map the ZWave device into it @@ -36,13 +61,6 @@ in # Both of the above container need storage for their configuration and devices, but it is not created correctly by # the container. So we add the creation of /var/lib/{zwave,hass} to the systemd Unit files systemd.services = { - "podman-home-assistant" = { - serviceConfig = { - StateDirectory = "hass"; - StateDirectoryMode = pkgs.lib.mkForce "0777"; - }; - }; - "podman-zwave".serviceConfig = { StateDirectory = "zwave"; StateDirectoryMode = pkgs.lib.mkForce "0777"; @@ -50,74 +68,12 @@ in }; - # Podman 3.4, which is in NixOS 21.11 does not support creating multiple network interfaces during launch. Starting in Podman - # 4.0 (NixOS 22.05) that will be possible. For now, adding this sidecar service that executes after every time the Home Assistant - # container is started will do the necessary Podman commands to attach the container to the interface for VLAN 66. Once we - # upgrade to NixOS 22.05 this service can go away and we can explicitly add two "--network" options to the Home Assistant container - systemd.services."home-assistant-network-attach" = { - requires = service_list; - path = [ pkgs.podman pkgs.coreutils ]; - script = "sleep 10 && podman network connect podman66 home-assistant"; - wantedBy = service_list; - serviceConfig = { - Type = "oneshot"; - }; - }; - - # This ensures that Podman has a separate network configured to attach to my IOT VLAN so that Home Assistant is able to communicate - # with my devices as well as with the rest of the LAN. - systemd.services.podman66 = { - wantedBy = service_list; - before = service_list; - path = [ pkgs.podman ]; - script = "podman network create -d macvlan -o parent=vlan66 --subnet 192.168.66.0/24 --ip-range 192.168.66.192/26 --gateway 192.168.66.1 podman66 || true"; - serviceConfig = { - Type = "oneshot"; - }; - }; - - # I do not want to have to remember the port number for Home Assistant's UI, so we use Nginx to proxy communication from - # smart.thehellings.lan to the Home Assistant UI - # After the first activation of this container, before you can access the Home Assistant UI, you need to ensure that the - # Home Assistant's configuration at /var/lib/hass/configuration.yaml includes the following option. Update the IP address - # if you have changed the value of your default podman network. - # ```yaml - # http: - # use_x_forwarded_for: true - # trusted_proxies: - # - "10.88.0.1" - # ``` - # Home assistant will not accept connections from the proxy if these values are not set. If you are adding those values - # manually after initial creation of the containers, then you will need to issue `systemctl restart podman-home-assistant.service` - # for Home Assistant to pick up the new values. After that, proxy connections should work well. If you are sitting behind - # multiple layers of proxies, then add more of them in the list. The list also accepts subnet notation in case you have - # multiple potentially incoming connections. So you could do "10.88.0.1/24", according to the docs. However, that has not - # worked in my testing, as Home Assistant throws an error on start up saying that value is invalid greg.proxies."smart.thehellings.lan".target = "http://127.0.0.1:8123"; # Ensure that both ports are up and running. We keep 8123 directly open because we are on the LAN and sometimes want to connect # directly for troubleshooting Nginx configuration networking.firewall = { enable = true; - allowedTCPPorts = [ 80 8123 ]; - }; - - # No data is secure unless it is backed up! So we back up the data on this node to our NAS using Syncthing, from there we will - # handle things like off site - services.syncthing = { - enable = true; - folders = { - "asdf-fdsa" = { - enable = true; - path = "/var/lib/hass"; - devices = [ "nas" ]; - }; - - "zwave-live" = { - enable = true; - path = "/var/lib/zwave"; - devices = [ "nas" ]; - }; - }; + allowedTCPPorts = [ 80 8091 8123 ]; }; } diff --git a/hosts/2maccabees/networking.nix b/hosts/2maccabees/networking.nix index 3217e34..5825944 100644 --- a/hosts/2maccabees/networking.nix +++ b/hosts/2maccabees/networking.nix @@ -20,11 +20,6 @@ address = "192.168.66.2"; prefixLength = 24; } ]; - - vlan67.ipv4.addresses = [ { - address = "192.168.67.2"; - prefixLength = 24; - } ]; }; vlans = { @@ -32,10 +27,6 @@ id = 66; interface = "eth0"; }; - vlan67 = { - id = 67; - interface = "eth0"; - }; }; }; diff --git a/hosts/iso/default.nix b/hosts/iso/default.nix index 23333be..18535c8 100644 --- a/hosts/iso/default.nix +++ b/hosts/iso/default.nix @@ -2,7 +2,7 @@ { imports = [ - "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-base.nix" + "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-graphical-calamares-gnome.nix" ]; networking.networkmanager.enable = lib.mkForce false; diff --git a/hosts/jude/boot.nix b/hosts/jude/boot.nix new file mode 100644 index 0000000..f01208d --- /dev/null +++ b/hosts/jude/boot.nix @@ -0,0 +1,15 @@ +{ ... }: + +{ + # Use the systemd-boot EFI boot loader. + #boot.loader.systemd-boot.enable = true; + boot.loader.grub.device = "/dev/nvme0n1"; + boot.loader.grub.useOSProber = true; + boot.loader.grub.extraEntries = '' + menuentry "Windows" { + chainloader (hd0,2)+1 + } + ''; + boot.loader.efi.canTouchEfiVariables = true; + networking.interfaces.enp4s0.useDHCP = true; +} diff --git a/hosts/jude/default.nix b/hosts/jude/default.nix new file mode 100644 index 0000000..3d80293 --- /dev/null +++ b/hosts/jude/default.nix @@ -0,0 +1,15 @@ +{ ... }: + +{ + imports = [ + ./boot.nix + ./hardware-configuration.nix + ./podman.nix + ./printing.nix + ./virt.nix + ]; + programs.steam.enable = true; + networking.hostName = "jude"; + greg.tailscale.enable = true; + greg.gnome.enable= true; +} diff --git a/hosts/jude/hardware-configuration.nix b/hosts/jude/hardware-configuration.nix new file mode 100644 index 0000000..8dbc6be --- /dev/null +++ b/hosts/jude/hardware-configuration.nix @@ -0,0 +1,24 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/27ae91ed-32e9-411e-8227-0d99e360fbbf"; + fsType = "btrfs"; + }; + + swapDevices = [ ]; + + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/jude/podman.nix b/hosts/jude/podman.nix new file mode 100644 index 0000000..837ebf4 --- /dev/null +++ b/hosts/jude/podman.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + virtualisation.podman = { + enable = true; + dockerCompat = true; + }; +} diff --git a/hosts/jude/printing.nix b/hosts/jude/printing.nix new file mode 100644 index 0000000..07d237f --- /dev/null +++ b/hosts/jude/printing.nix @@ -0,0 +1,12 @@ +{ pkgs, ... }: + +{ + # ipp://printer.thehellings.lan:631/ - generic postscript printer + services.printing = { + enable = true; + drivers = with pkgs; [ + gutenprint + gutenprintBin + ]; + }; +} diff --git a/hosts/jude/virt.nix b/hosts/jude/virt.nix new file mode 100644 index 0000000..accf728 --- /dev/null +++ b/hosts/jude/virt.nix @@ -0,0 +1,31 @@ +{ pkgs, ... }: + +{ + environment.systemPackages = with pkgs; [ + ansible + libguestfs + packer + virt-manager + vagrant + ]; + + # Give my user access to the libvirtd process + users.users.greg.extraGroups = [ "libvirtd" ]; + + virtualisation = { + libvirtd = { + enable = true; + onBoot = "ignore"; # Do not auto-restart VMs on boot, unless they are marked autostart + }; + + waydroid = { + enable = true; + }; + + virtualbox.host.enable = true; + }; + + users.extraGroups.vboxusers.members = [ "greg" ]; + + boot.extraModprobeConfig = "options kvm_amd nested=1"; +} diff --git a/hosts/lappy/default.nix b/hosts/lappy/default.nix new file mode 100644 index 0000000..fb9dd7e --- /dev/null +++ b/hosts/lappy/default.nix @@ -0,0 +1,15 @@ +{ ... }: + +{ + imports = [ + ./hardware-configuration.nix + ]; + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + boot.loader.efi.efiSysMountPoint = "/boot/efi"; + # Graphics, please + greg.gnome.enable = true; + # Set host name + networking.hostName = "lappy"; +} diff --git a/hosts/lappy/hardware-configuration.nix b/hosts/lappy/hardware-configuration.nix new file mode 100644 index 0000000..19de254 --- /dev/null +++ b/hosts/lappy/hardware-configuration.nix @@ -0,0 +1,39 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" "rtsx_usb_sdmmc" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/63bcc80e-0501-4aef-bb58-30bb83881055"; + fsType = "ext4"; + }; + + fileSystems."/boot/efi" = + { device = "/dev/disk/by-uuid/C617-B2B1"; + fsType = "vfat"; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/bc4f24a3-5969-4bcb-95f4-f80109e36ebb"; } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp7s0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp6s0.useDHCP = lib.mkDefault true; + + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/linode/default.nix b/hosts/linode/default.nix index 2ab58f5..ae0a13c 100644 --- a/hosts/linode/default.nix +++ b/hosts/linode/default.nix @@ -10,6 +10,7 @@ ]; greg.home = false; greg.linode.enable = true; + greg.tailscale.enable = true; networking.hostName = "linode"; networking.domain = "thehellings.com"; } diff --git a/hosts/linode/nextcloud.nix b/hosts/linode/nextcloud.nix index b4c7265..9a87315 100644 --- a/hosts/linode/nextcloud.nix +++ b/hosts/linode/nextcloud.nix @@ -25,13 +25,9 @@ enableACME = true; }; - services.syncthing.folders."nextcloud-backup" = { - path = "${config.services.nextcloud.datadir}"; - enable = true; - devices = [ "nas" ]; + greg.backup.jobs.nextcloud = { + src = "/var/lib/nextcloud"; + dest = "nextcloud-backup"; + user = "nextcloud"; }; - - services.cron.systemCronJobs = [ - "59 2 * * * root chmod -R a+r ${config.services.syncthing.folders.nextcloud-backup.path} && find ${config.services.syncthing.folders.nextcloud-backup.path} -type d -exec chmod a+x '{}' \\;" - ]; } diff --git a/hosts/linode/nginx.nix b/hosts/linode/nginx.nix index 9f17309..dc7c4de 100644 --- a/hosts/linode/nginx.nix +++ b/hosts/linode/nginx.nix @@ -5,7 +5,7 @@ in { security.acme = { acceptTerms = true; - email = "greg.hellings@gmail.com"; + defaults.email = "greg.hellings@gmail.com"; }; services.nginx = { @@ -30,5 +30,6 @@ in greg.proxies."thehellings.com" = { target = "http://${homepage}/"; ssl = true; + genAliases = false; }; } diff --git a/hosts/linode/postgres.nix b/hosts/linode/postgres.nix index 9191feb..fd2da32 100644 --- a/hosts/linode/postgres.nix +++ b/hosts/linode/postgres.nix @@ -27,25 +27,31 @@ root root postgres ''; }; - services.postgresqlBackup.enable = true; + services.postgresqlBackup = { + enable = true; + databases = [ + "nextcloud" + "synapse" + ]; + }; services.logrotate = { enable = true; - paths = { - postgres = { + settings = { + postgresBackup = { enable = true; - path = "${config.services.postgresqlBackup.location}/*.gz"; + files = "${config.services.postgresqlBackup.location}/*.gz"; + }; + postgresLog = { + enable = true; + files = "/var/lib/postgresql/*/log/*.log"; }; }; }; - services.syncthing.folders."postgres-backups" = { - path = "${config.services.postgresqlBackup.location}"; - enable = true; - devices = [ "nas" ]; + greg.backup.jobs.postgresql = { + src = "/var/backup/postgresql"; + dest = "linode-postgres"; + user = "postgres"; }; - - services.cron.systemCronJobs = [ - "59 2 * * * root chmod -R a+r ${config.services.postgresqlBackup.location} && find ${config.services.postgresqlBackup.location} -type d -exec chmod a+x '{}' \\;" - ]; } diff --git a/hosts/linode/synapse.nix b/hosts/linode/synapse.nix index 2d296e5..02bb222 100644 --- a/hosts/linode/synapse.nix +++ b/hosts/linode/synapse.nix @@ -74,26 +74,30 @@ return 200 '${builtins.toJSON client}'; services.matrix-synapse = { enable = true; - database_name = "synapse"; - database_user = "matrix-synapse"; # Identify ourselves as the root of our own domain - server_name = "thehellings.com"; - #registration_shared_secret = "B9EoPr2WV9hzwc7uL2Sx1JmvCeKDEOGCpB0uginQcQtEH4wzRtkSIdo7lltrjSQa"; - # Bind a single listener to localhost only, disable SSL/TLS, and put - # it behind an nginx proxy - listeners = [ { - port = 8448; - bind_address = "127.0.0.1"; - type = "http"; # Offload SSL/TLS to Nginx - tls = false; - resources = [ { - names = [ "client" "federation" ]; - compress = false; # Offload compressiong to Nginx + settings = { + database.args = { + user = "matrix-synapse"; + database = "synapse"; + }; + server_name = "thehellings.com"; + #registration_shared_secret = "B9EoPr2WV9hzwc7uL2Sx1JmvCeKDEOGCpB0uginQcQtEH4wzRtkSIdo7lltrjSQa"; + # Bind a single listener to localhost only, disable SSL/TLS, and put + # it behind an nginx proxy + listeners = [ { + port = 8448; + bind_addresses = ["127.0.0.1"]; + type = "http"; # Offload SSL/TLS to Nginx + tls = false; + resources = [ { + names = [ "client" "federation" ]; + compress = false; # Offload compressiong to Nginx + } ]; } ]; - } ]; - app_service_config_files = [ - "/etc/${fbRegistrationFile}" - ]; + app_service_config_files = [ + "/etc/${fbRegistrationFile}" + ]; + }; }; # Open networking ports for the server diff --git a/modules/automatic.nix b/modules/automatic.nix new file mode 100644 index 0000000..b8f2f38 --- /dev/null +++ b/modules/automatic.nix @@ -0,0 +1,12 @@ +{ ... }: + +{ + imports = [ + ./automatic/nix.nix + ./automatic/programs.nix + ./automatic/syncthing.nix + ./automatic/users.nix + ]; + # I am a fan of network manager, myself + networking.networkmanager.enable = true; +} diff --git a/modules/automatic/nix.nix b/modules/automatic/nix.nix new file mode 100644 index 0000000..2c97556 --- /dev/null +++ b/modules/automatic/nix.nix @@ -0,0 +1,21 @@ +{ 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) } + +# Used by direnv +keep-outputs = true +keep-derivations = true +''; + }; + nixpkgs.config.allowUnfree = true; + system.stateVersion = "22.05"; +} diff --git a/modules/automatic/programs.nix b/modules/automatic/programs.nix new file mode 100644 index 0000000..f2f273a --- /dev/null +++ b/modules/automatic/programs.nix @@ -0,0 +1,30 @@ +{ pkgs, agenix, ... }: + +let + myPackages = pypackages: with pypackages; [ + pkgs.xonsh-direnv + ]; + + myPython = pkgs.python3.withPackages myPackages; +in { + # Base packages that need to be in all my hosts + environment.systemPackages = with pkgs; [ + agenix.defaultPackage."${system}" + bitwarden-cli + diffutils + git + gnupatch + findutils + hms # My own home manager switcher + home-manager + htop + myPython + pwgen + tmux + transcrypt + unzip + vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. + wget + yamllint # Used in vim + ]; +} diff --git a/modules/automatic/syncthing.nix b/modules/automatic/syncthing.nix new file mode 100644 index 0000000..1bd8471 --- /dev/null +++ b/modules/automatic/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 = "ROZPUG5-G4IAXYA-JNRQXRD-5PFU2BQ-WVJTOGZ-DFMGJ5E-Q4IGXCJ-JHSNDQ6"; + }; + }; + folders = { + "mkrvy-tc6x9" = { + path = "/home/greg/drive"; + enable = true; + devices = syncs; + }; + }; + }; +} diff --git a/modules/automatic/users.nix b/modules/automatic/users.nix new file mode 100644 index 0000000..86ef2b9 --- /dev/null +++ b/modules/automatic/users.nix @@ -0,0 +1,43 @@ +{ config, pkgs, agenix, ... }: + +{ +<<<<<<<< HEAD:profiles/linux/default.nix + imports = [ + ../shared + ./programs.nix + ./syncthing.nix + ./xonsh.nix + ]; + + + # Use hardlinking instead of copying when possible + nix.autoOptimiseStore = true; + + # I am a fan of network manager, myself + networking.networkmanager.enable = true; + +======== +>>>>>>>> origin/main:modules/automatic/users.nix + # 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; + createHome = true; + extraGroups = [ "wheel" "networkmanager" ]; # Enable ‘sudo’ for the user. + shell = pkgs.xonsh; + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAEAQDLQRq55JKqLifX+31kEXyuoB8gfM+5thAlgR7XLPvvdu6g2a5cCWyozQ1I2oGbPRfJtzcJ5ifM7Ii2PuqAj3MdYFLHBEDOhIpBBWme9Ts2YB9HJ4NorBvB4zEfJd0Q7k2MmylyeBOwdwGz3bVqPRDcJbxWFMDHqr33FEs6SXdfyAQ5SvhWGARI84qz8zUUdOp6M4e3aIGO3cx1gA+YzYQ4FbUtL8+m1NFO8VoNFMZBMf5q0iF/SgEu5bmGWUCePia6DvfeBFQ2/y4Y7WmOj980WE+JmFTkIvmGruMYeGI8FuDQ2JIIIcehddy9bQbPF4VlGnTFsHqJYVRUUWc+vH1cPNMn01oB8s27ogf9e1lyhIN+cZOgp/jDt4eXcO4Wr04uwj7CI6m+d8iMQOa5Jv0hmNgqqiwOMVBlKeo0FCxlovzwvn/Lia9WZ74JqM6JwLCD8SZ0oFgiSIHOTHrQhr7iaCmj7X/0ey7VR8FnCrpeAJpG+ELTfWGshF1d9QR2zW7u4EsXTDLiuOmdJ+/KxwMvjMcWdlg2+Qch6SwulTQRxWaED2IWJo+YiAql8eaiVXu/eZJGLoiskGFZnONoLrzIT4pSjakPlrSpn/M/GkP1pDpaMkr24OhJsGpJNEU3F1ZcOMqy2iJzIxlPmU8Xg0I/OrnbJplpaXeRCqnmouJUJhWkaPzawaVyW7dtvprLWcpQtUgTRet18WLyOrLKlq1jwvNRMTPKUJ2IFJMpk2pNEP6bdiUxyMa4vrRIEU2p1zsYSUJpCRLtccZ/i/+yAqwnTA2L5TdAORi9nD2uCdM/Ljz52V3A14QapS6oqcoWx2soWKgnsbVXoG8DxmUTpll77Ze9t7Y5216SMInWuOu0vstP8ZcgFmWsiBgIYIuLA58abWHMxgD251phYidua6R3Gtkf8J/kYqTR1P6eJF1bt5efEg7FD2aL1QQZsYJo3CRNz7yVe1XqMdPbfe2mFXQVF9TDX5x6r9Ir3d0KiEmTlBdByz8nSyPJ8IQxC58NT4LNVQs3p2XH2Zcf6B4JOBSmV4NNBnLseFobsxniWjkWwZigED/D2iu3OXuuhmskCbw0hKy2rBcKffaSNMioVqYIiYNfKlMlSvAacQKqc/1HCpqgX8PwAcSgNSLy4K7/gIrTHmjY+g+CH7onzatWzkLo+0vsZRa/D/qwhhK2CU2FeU07mhnWxWuzqpJuqVaAwDTaEforK7nQUtAOFAZZP6qGhIoqsynYt4THb+QORb3QYfaP0PVgQwXfVU5Q8eUQFZ8A+siPtOASFjDumsIbseB5VzkF+UhvdseJwkX2+4pVFu8eHFDyvArYsHeGK6fBcQGJFQc2jSs6doIP9HD9IO2R ghelling@unknown38BAF87CD102" + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDv26EhyBZS9E5bcuZDHHkh/oeyINHXlsD3OEL1UjZekIsiHoMv2QHYq99cYO/CsTVGcZj4ZTOKxrQQ069Cm1II76nXJP9mb3+jip5QAE/zYSWfxi3SgQum95qmkQsx9mxeKFi4NfUU9qN9vpmJkn0hrvYWg8vU98bcYmkx4RtGW6EgZJed3347EtHshTqq3UfAbj3ErSQdCbEqgNOjokzGWmcx16HyyO5HoQj2FP7PGQmArzMz0V76BRsnpg97CoPKkoWoGk+P13BCWWXR9GCa2PbJ9uprzPa6Ib4+i9RJPdeSkUiLlFi6rBTHaZUT9WUIEaqNSq3bbu1bIqMXkifPeDw7m+TMfOBT8MUBciJaPlPTgXuz3T4kCHBI041hIt+/VqryGtxnT45IavyUaN3JWYntDbpG3eEW4N9IB2oGWuC/XuTJrsUaNpLPpApUKuozxhsFELBRepU+j+Wn4kgJJl8hy0n+WL63ZUee+/F23C7UNXoOc/wU3KbpxO6ipsTSkTzhZpQF2LOuA3JUs5t9ZaiCJ2P9r8axHiphCRcIYSbcCo3pZupf1eTDSXm+x9/UB2sfzErNEH4SdakoSdAi8jG8WhPVOs3BrIXjVBjvyBLeOH86EzBGR/Ba8X6MWoEW9Oau1C3P/z65VH8RHpvPvp6axlMynyVI1ygt5uheuQ== gregory.hellings@C02G48H8MD6R" + ]; + }; + + i18n.defaultLocale = "en_US.UTF-8"; + + console = { + font = "Lat2-Terminus16"; + keyMap = "us"; + }; +} diff --git a/modules/backup.nix b/modules/backup.nix new file mode 100644 index 0000000..f3df0e1 --- /dev/null +++ b/modules/backup.nix @@ -0,0 +1,107 @@ +{ lib, config, pkgs, ... }: + +let + cfg = config.greg.backup; + backup_key = "backup_keys/id_ed25519"; + + makeJob = name: job: { + paths = job.src; + encryption.mode = "none"; + environment.BORG_RSH = "ssh -i /etc/${backup_key} -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'"; + repo = "ssh://backup@nas.me.ts//volume1/NetBackup/${job.dest}"; + compression = "auto,zstd"; + startAt = "daily"; + + user = job.user; + group = job.group; + preHook = job.pre; + postHook = job.post; + }; + + cronJob = name: job: + let + binName = "backup-${name}"; + script = pkgs.writeShellScriptBin binName '' +exec 1> >(systemd-cat -t $(basename $0)) 2>&1 +set -ex +${job.pre} +${pkgs.rsync}/bin/rsync -avz --delete -e "${pkgs.openssh}/bin/ssh -i /etc/${backup_key} -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'" ${job.src}/* backup@nas.me.ts:/volume1/NetBackup/${job.dest}/ +${job.post} +''; + in { + inherit script; + cron = "0 1 * * * ${job.user} ${script}/bin/${binName}"; + }; + +in with lib; { + options = { + greg.backup = { + key = mkOption { + type = types.path; + description = "SSH key to use"; + default = ./ssh/id_ed25519; + }; + + jobs = mkOption { + default = {}; + + type = with types; attrsOf (submodule ( + { name, config, options, ... }: + { + options = { + src = mkOption { + type = types.str; + description = "Local path (string form) to backup from"; + }; + + dest = mkOption { + type = types.str; + }; + + user = mkOption { + type = types.str; + default = "root"; + description = "User to run backup as"; + }; + + pre = mkOption { + type = types.str; + default = ""; + description = "Commands to run before backup"; + }; + + post = mkOption { + type = types.str; + default = ""; + description = "Commands to run after backup"; + }; + }; + } + )); + }; + }; + }; + + config = let + jobs = attrValues ( mapAttrs cronJob cfg.jobs ); + in mkIf ( ( attrValues cfg.jobs ) != [] ) + { + #services.borgbackup = { + # jobs = mapAttrs makeJob cfg.jobs; + #}; + services.cron = { + enable = true; + systemCronJobs = map (e: e.cron) jobs; + }; + + environment.etc = mkIf ( cfg.key != null ) { + "${backup_key}" = { + user = "nobody"; + mode = "0777"; + source = cfg.key; + }; + }; + + environment.systemPackages = map (e: e.script) jobs; + }; +} diff --git a/modules/default.nix b/modules/default.nix index cddba76..b766d39 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -2,9 +2,14 @@ { imports = [ + ./automatic.nix + ./backup.nix ./home.nix + ./gnome.nix ./linode.nix ./proxy.nix ./rpi4.nix + ./tailscale.nix + ./xprograms.nix ]; } diff --git a/modules/gnome.nix b/modules/gnome.nix new file mode 100644 index 0000000..b168e8e --- /dev/null +++ b/modules/gnome.nix @@ -0,0 +1,57 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.greg.gnome; + +in with lib; { + options = { + greg.gnome.enable = mkEnableOption "Enable my default Gnome3 setup"; + }; + + config = mkIf cfg.enable { + greg.xprograms.enable = true; + + # Sets up a basic Gnome installation + services = { + xserver = { + enable = true; + displayManager.gdm.enable = true; + desktopManager.gnome.enable = true; + layout = "us"; + # Trackpad support + libinput.enable = true; + }; + + udev.packages = with pkgs; [ + gnome3.gnome-settings-daemon + ]; + + pipewire.enable = true; + + # Enablement for Firefox + gnome = { + chrome-gnome-shell.enable = true; + sushi.enable = true; + gnome-online-accounts.enable = true; + }; + }; + + programs.dconf.enable = true; + programs.sway.enable = true; # Gives us 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 + gnome3.gnome-tweaks + gnome3.dconf-editor + gnomeExtensions.appindicator + gnomeExtensions.clipboard-indicator + gnomeExtensions.dash-to-dock + ]; + }; +} diff --git a/modules/proxy.nix b/modules/proxy.nix index c13247f..e108242 100644 --- a/modules/proxy.nix +++ b/modules/proxy.nix @@ -3,6 +3,8 @@ let cfg = config.greg.proxies; + alias = name: with builtins; head (split "\\." name); + makeHost = name: dest: { forceSSL = dest.ssl; enableACME = dest.ssl; @@ -14,6 +16,7 @@ proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; ''; }; + serverAliases = lib.mkIf dest.genAliases [ "${alias name}" ]; }; in with lib; { @@ -37,6 +40,12 @@ in with lib; { { name, config, options, ... }: { options = { + genAliases = mkOption { + type = types.bool; + description = "Whether to auto-generate short alias name"; + default = true; + }; + target = mkOption { type = types.str; description = ''The destination that is being proxied.''; diff --git a/modules/ssh/id_ed25519 b/modules/ssh/id_ed25519 new file mode 100644 index 0000000..cd9f979 --- /dev/null +++ b/modules/ssh/id_ed25519 @@ -0,0 +1,9 @@ +U2FsdGVkX1+8TBMzBYN9YHgBu1txsCXL0bCxLaGsDMoAaMdkBEdFI1owuEIpM5/E +wJICFzAcEmdFMpX0ZZn4c/jIA7K3Q+p1uxaj+7zcdmzRs08ZxU64yG7LTM47cffJ +W2L1OOFvJPICOs5WmwC/R+4FG6LBIa09W58Xn3OkUEFTe2L2iK73J0ecXuWYjEhN +2y9UvtXr1dHJdXSVY0i7DoPb22JUGuWRRWnT1ThW83xDMs6d83PLD26/BIS/HJiJ +24d0HXuO3nXkkdPX6ocRJmAM0PeMtW+uPG4/HjS6xWaJThBljfvC0I1NRWK7SYR8 ++Ret+OXlYhQmSN0M8cGixQKxlrn4iUpawpRnTsug3aSe0Nx30eTw/aRt6WkyeWLS +g/aEnOiaIFSyg780nq5AENQW9/XgvWAb/i9k4AKwKBdyeaAveA/37xoM/6rWToXu +Cql9d4sAF9mEZjSIjXulMQakZHep59MiNclK1WJQQHjQh1DabXS6CEjVD+jJOG9R +cpTkdJ1/Q711jJR7hZK7SNNoo8EH3Vpl5czpJjp+zJE= diff --git a/modules/ssh/id_ed25519.pub b/modules/ssh/id_ed25519.pub new file mode 100644 index 0000000..491f4e5 --- /dev/null +++ b/modules/ssh/id_ed25519.pub @@ -0,0 +1,3 @@ +U2FsdGVkX199UgWOiZI4QFCTOsVVEQatJHJFBVDmavrKzuGL+2RX1Fsi1uEafGpz +Fa6UGCWVrUvaT69yxpt3PBtSjkFiZtR9g1A0LzWT3XaUB41/0DJIzAsbK62Ya9UT +A+xICWdf2WVk6n0xeNIvPQ== diff --git a/modules/tailscale.nix b/modules/tailscale.nix new file mode 100644 index 0000000..54e34b1 --- /dev/null +++ b/modules/tailscale.nix @@ -0,0 +1,14 @@ +{ lib, config, ... }: + +let + cfg = config.greg.tailscale; +in { + options = { + greg.tailscale.enable = lib.mkEnableOption "Enable Tailscale"; + }; + + config = lib.mkIf cfg.enable { + services.tailscale.enable = true; + networking.firewall.checkReversePath = "loose"; + }; +} 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/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..e228946 --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,15 @@ +self: super: +{ + xonsh-direnv = super.callPackage ./xonsh-direnv.nix { + buildPythonPackage = self.python3.pkgs.buildPythonPackage; + fetchPypi = self.python.pkgs.fetchPypi; + }; + + xonsh = super.xonsh.overridePythonAttrs (old: rec{ + propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.xonsh-direnv ]; + }); + + hms = super.callPackage ./hms.nix { + pkgs = self.pkgs; + }; +} diff --git a/overlays/defeault.nix b/overlays/defeault.nix deleted file mode 100644 index f71814b..0000000 --- a/overlays/defeault.nix +++ /dev/null @@ -1,6 +0,0 @@ -self: super: -{ - git = super.git.override { - meta.priority = 4; - }; -} diff --git a/overlays/hms.nix b/overlays/hms.nix new file mode 100644 index 0000000..b3cefb1 --- /dev/null +++ b/overlays/hms.nix @@ -0,0 +1,20 @@ +{ pkgs, ... }: + +pkgs.writeShellScriptBin "hms" '' +set -eo pipefail +# Build different targets with GUI or not +if [ -z "$DISPLAY" ]; then + target="nogui" +else + target="gui" +fi + +# Build and switch +echo "Building $(uname -m)-$target" +dest=$(mktemp -d) +pushd "$dest" > /dev/null +nix build --impure /etc/nixos#homeConfigurations.$(uname -m)-$target.activationPackage +./result/activate +popd > /dev/null +rm -r "$dest" +'' diff --git a/overlays/xonsh-direnv.nix b/overlays/xonsh-direnv.nix new file mode 100644 index 0000000..07d57a5 --- /dev/null +++ b/overlays/xonsh-direnv.nix @@ -0,0 +1,20 @@ +{ lib, buildPythonPackage, fetchPypi, pkgs}: + +buildPythonPackage rec { + pname = "xonsh-direnv"; + version = "1.6.1"; + + src = fetchPypi { + inherit pname version; + sha256 = "Nt8Da1EtMVWZ9mbBDjys7HDutLYifwoQ1HVmI5CN2Ww="; + }; + + meta = with lib; { + description = "Direnv support for Xonsh"; + homepage = "https://github.com/74th/xonsh-direnv/"; + license = licenses.mit; + maintainers = []; + }; + + doCheck = false; +} diff --git a/profiles/gnome.nix b/profiles/gnome.nix deleted file mode 100644 index d2fc077..0000000 --- a/profiles/gnome.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ config, pkgs, ... }: - -{ - # Sets up a basic Gnome installation - services.xserver = { - enable = true; - displayManager = { - gdm.enable = true; - gnome.enable = true; - }; - layout = "us"; - # Trackpad support - libinput.enable = true; - }; - - programs.dconf.enable = true; - - # Enable some Gnome plugins that I like - environment.systemPackages = with pkgs; [ - gnome3.adwaita-icon-theme - gnomeExtensions.appindicator - ]; - - services.udev.packages = with pkgs; [ - gnome3.gnome-settings-daemon - ]; -} diff --git a/profiles/linux/default.nix b/profiles/linux/default.nix old mode 100755 new mode 100644 index a8feb7b..86ef2b9 --- a/profiles/linux/default.nix +++ b/profiles/linux/default.nix @@ -1,6 +1,7 @@ { config, pkgs, agenix, ... }: { +<<<<<<<< HEAD:profiles/linux/default.nix imports = [ ../shared ./programs.nix @@ -15,6 +16,8 @@ # I am a fan of network manager, myself networking.networkmanager.enable = true; +======== +>>>>>>>> origin/main:modules/automatic/users.nix # Enable the OpenSSH daemon for remote control services.openssh.enable = true; #services.openssh.permitRootLogin = "yes"; @@ -37,8 +40,4 @@ font = "Lat2-Terminus16"; keyMap = "us"; }; - - # 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"; } diff --git a/profiles/linux/programs.nix b/profiles/linux/programs.nix index ce02325..f2f273a 100644 --- a/profiles/linux/programs.nix +++ b/profiles/linux/programs.nix @@ -1,22 +1,30 @@ { pkgs, agenix, ... }: -{ +let + myPackages = pypackages: with pypackages; [ + pkgs.xonsh-direnv + ]; + + myPython = pkgs.python3.withPackages myPackages; +in { # Base packages that need to be in all my hosts environment.systemPackages = with pkgs; [ agenix.defaultPackage."${system}" + bitwarden-cli diffutils git gnupatch findutils + hms # My own home manager switcher home-manager htop - python3 + myPython pwgen tmux transcrypt + unzip 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/linux/syncthing.nix b/profiles/linux/syncthing.nix index 5058476..1bd8471 100644 --- a/profiles/linux/syncthing.nix +++ b/profiles/linux/syncthing.nix @@ -32,13 +32,13 @@ in addresses = [ "tcp://linode.thehellings.com:22000" ]; - id = "3PHWAI5-ILAWGGD-S5FC5QM-M2WQ2FX-PZ3IXQF-QVRKANG-WXAACJC-2MZN3Q5"; + id = "ROZPUG5-G4IAXYA-JNRQXRD-5PFU2BQ-WVJTOGZ-DFMGJ5E-Q4IGXCJ-JHSNDQ6"; }; }; folders = { "mkrvy-tc6x9" = { - enable = true; path = "/home/greg/drive"; + enable = true; devices = syncs; }; }; diff --git a/profiles/shared/nix.nix b/profiles/shared/nix.nix index 1c9dc17..2c97556 100644 --- a/profiles/shared/nix.nix +++ b/profiles/shared/nix.nix @@ -10,7 +10,12 @@ experimental-features = nix-command flakes min-free = ${toString (1024 * 1024 * 1024) } max-free = ${toString (5 * 1024 * 1024 * 1024) } + +# Used by direnv +keep-outputs = true +keep-derivations = true ''; }; nixpkgs.config.allowUnfree = true; + system.stateVersion = "22.05"; }