113 Commits

Author SHA1 Message Date
7ae0649456 nixpkgs shortcut registries 2022-11-03 11:26:31 -04:00
660ea997df fix standalone home-manager on macos 2022-11-03 11:25:58 -04:00
15f4116178 fixes for kitty on macos 2022-11-03 11:25:36 -04:00
9386008fa2 fix: identity file wrong path on macos 2022-11-03 11:24:03 -04:00
920ec8b43e add terminfo to openssh devices 2022-11-03 08:51:51 -04:00
6241b8e624 fix neovim tree-sitter bug
requires installing tree-sitter and nodejs to environment :(
2022-11-03 08:30:28 -04:00
7741394306 add back removed applications 2022-11-02 22:15:29 -04:00
07fec71ba4 put hashed pass in a separate file 2022-11-02 21:47:11 -04:00
41d289c5db refactor colors and options
preparing for light mode, even though specializations aren't working
2022-11-02 21:29:14 -04:00
b2850e8b79 improve visuals of volume notification 2022-10-31 23:54:29 -04:00
afd44279d2 tweaks to aerc, replace delete with move to trash 2022-10-31 23:43:14 -04:00
d73ccab008 replace pulseaudio with pipewire
closes #8
2022-10-31 23:40:53 -04:00
969e89cda3 set kitty to default in i3 2022-10-31 20:47:42 -04:00
38695b29bd use shift+enter for completion in terminal 2022-10-31 20:47:33 -04:00
40424a0102 temp: disable visidata bc of python errors 2022-10-31 14:46:04 -04:00
d7b711ff02 replace alacritty with kitty on macos 2022-10-31 14:45:51 -04:00
7bd2125438 fix: actually use exa for ls 2022-10-30 20:43:49 -04:00
0448037a6b set kitty tab style to slant 2022-10-30 20:43:34 -04:00
7075371b11 remove warning about dirty git tree 2022-10-30 20:42:32 -04:00
22885f1b27 temp: try to show users in lightdm greeter
still isn't working unfortunately
2022-10-30 20:16:37 -04:00
52edaa7d9c prevent ctrl-q from quitting firefox
will this affect macos?
2022-10-30 20:16:01 -04:00
c74d003a57 change alacritty scrollback keybind to match kitty
add fonts for kitty
2022-10-30 20:15:32 -04:00
2d10939285 clean up flake inputs and allow standalone home-manager
closes #11
2022-10-30 20:14:41 -04:00
b15cd8c0b6 add basic kitty config
closes #7
2022-10-30 20:13:32 -04:00
dfd903d3c9 add aerc and fix nvim 0.8 2022-10-30 13:57:14 -04:00
2af30faf7c update system and fix nvim 2022-10-29 14:42:37 -04:00
b718a01dc4 i think i fixed picom screen tearing 2022-10-29 08:57:14 -04:00
e16674c817 tweaks for i3 and common 2022-10-28 23:58:33 -04:00
bf09e166a9 fix: grub wrong monitor 2022-10-28 23:58:25 -04:00
3dcafb8c25 package ocr script with dependencies 2022-10-25 20:22:17 -04:00
be581dba1f fix: jellyfin dir permissions for nextcloud 2022-10-23 04:16:42 +00:00
941fa359d9 add windows app plaintext list 2022-10-22 15:10:30 +00:00
f6096e3472 replace vimwiki with mkdnflow 2022-10-22 14:29:50 +00:00
cd204f5ac3 move apps declaration to apps directory 2022-10-18 12:31:42 +00:00
4c685eb8dd ignore non-age files in private dir 2022-10-18 12:25:06 +00:00
2694e3288c move generators to hosts directory 2022-10-18 12:21:22 +00:00
af31c65788 fix: generator module references 2022-10-18 12:17:58 +00:00
ef6c920c48 move calibre-web patch to patches directory
still requires overlay because there is no package option
2022-10-18 03:19:23 +00:00
d97e3fda07 gitea litestream permissions fixes 2022-10-16 20:39:04 +00:00
982566a92e add gitea service 2022-10-16 20:34:28 +00:00
27e2a42e46 fix: typo in copy 2022-10-16 20:21:25 +00:00
41d8e30990 vaultwarden automated backups 2022-10-16 19:06:56 +00:00
6f67e31723 working vaultwarden
haven't tested websockets
2022-10-16 18:10:11 +00:00
7bca2775d1 don't start stop-minecraft timer on rebuild 2022-10-16 14:44:42 +00:00
89a95445e1 remove age and loadkey module 2022-10-16 14:25:47 +00:00
084e832039 wsl fixes 2022-10-16 14:21:38 +00:00
e1e27ca065 backup calibre data 2022-10-16 03:47:21 +00:00
6e26b64f43 backups requires secrets 2022-10-16 03:19:41 +00:00
0f112ea16b reencrypt secrets and fix nextcloud backups 2022-10-16 03:18:58 +00:00
69a54b99c8 new secrets management system 2022-10-16 01:32:39 +00:00
e2c351098b move cloudflare to separate file 2022-10-15 19:00:37 +00:00
5410afb45b switch to /var/lib for calibre-web 2022-10-15 15:29:21 +00:00
bc83c818db honeypot for banning port scanners 2022-10-15 12:16:05 +00:00
8cce61f4a8 change metrics server hostname 2022-10-14 13:08:13 +00:00
595eac9367 switch from netdata to grafana 2022-10-14 04:01:41 +00:00
a17a048d9d set credentials oneshots to stop after launch 2022-10-14 01:35:14 +00:00
c2d0037bab autostart and stop minecraft server 2022-10-14 01:34:35 +00:00
e2af159c26 lockdown caddy and ssh connections 2022-10-13 23:40:30 +00:00
01e71e5810 add minecraft server 2022-10-10 23:09:32 +00:00
c4c75cd587 switch to netdata cloud
fix performance issues with caddy mostly
2022-10-10 19:22:39 +00:00
a5e186ee87 netdata metrics with basic auth
seems to have performance problems with caddy
2022-10-10 18:11:08 +00:00
170f8c67de enable transmission web allowlist 2022-10-10 03:25:28 +00:00
b0aa82e7d0 refactor wireguard and add port forwarding 2022-10-10 03:13:16 +00:00
7aacfe7887 fix issues reaching transmission web 2022-10-09 20:41:04 +00:00
d8b5d74dcb transmission reaches internet through vpn 2022-10-09 18:32:43 +00:00
129e4bba4b wireguard working but not transmission 2022-10-09 14:12:31 +00:00
e309889b0b replace activationscripts with systemd 2022-10-09 03:51:25 +00:00
5872abcc33 move calibre perms out of activations 2022-10-08 15:57:52 +00:00
bfa9e8fc4e remember to require age for mail 2022-10-08 15:52:43 +00:00
8dba2ef88b litestream backups for nextcloud 2022-10-08 15:52:19 +00:00
e89db82e7f make whois core utility 2022-10-07 03:31:14 +00:00
4044721606 add vaultwarden, not activated 2022-10-07 00:44:06 +00:00
0637cc693b fix: patch calibre-web cloudflare login issues 2022-10-05 03:59:13 +00:00
a9ae0c8858 add activationscript for jellyfin directory 2022-10-04 22:59:28 +00:00
da01f3be9b add cloudflare IPs as nextcloud trusted proxies 2022-10-04 22:43:04 +00:00
a7117fe4e9 fix: max upload size for nextcloud 2022-10-04 12:29:29 +00:00
c2b570b2af don't use s3 as primary nextcloud storage 2022-10-04 03:06:55 +00:00
84ecbf9974 grant nextcloud access to jellyfin 2022-10-04 00:45:05 +00:00
f38f782b63 add helper statements for loadkeys app 2022-10-03 12:32:09 +00:00
31f3cfe77c fix firewall issues with oracle 2022-10-03 12:19:29 +00:00
a0089e28ae move mailpass to private section 2022-10-03 12:12:50 +00:00
92223a49cd separate age ssh key setup from nextcloud 2022-10-03 04:05:07 +00:00
2434376963 working nextcloud configuration 2022-10-02 20:54:26 +00:00
f196f546b8 add jellyfin, switch caddy to one listener 2022-10-02 17:40:10 +00:00
b4ba0706c0 move caddy config into separate file 2022-10-02 15:24:25 +00:00
90bc2ecd49 add iptables settings for oracle reboot 2022-10-02 15:09:54 +00:00
19de583433 setup caddy and calibre-web 2022-10-02 14:48:51 +00:00
8a97d9b2da calibre needs to use path it can read 2022-10-02 02:47:10 +00:00
015c393274 docs: deprecated nixFlakes package 2022-10-01 21:42:33 +00:00
db0645075f setup calibre server 2022-10-01 21:39:36 +00:00
034ff33e70 add more description for mkpasswd salt 2022-10-01 18:28:32 +00:00
cd53060f02 switch to ssh for dotfiles repo 2022-10-01 18:28:03 +00:00
f20b4ee31a add ssh host to starship 2022-10-01 18:24:06 +00:00
381e06519b add oracle hardware config 2022-10-01 16:29:16 +00:00
3ec1ef4394 add server bootloader 2022-10-01 16:24:44 +00:00
d303924f02 try adding oracle server config 2022-10-01 16:21:34 +00:00
485e8223cf Merge branch 'aws-nix-build' 2022-10-01 15:26:01 +00:00
657bec0929 browse active directory on macos 2022-09-30 11:09:58 -04:00
4e23d677e8 auto-formatting changes 2022-09-30 10:11:55 -04:00
5ce4ebf522 fix: hostname for macos 2022-09-28 15:33:49 -04:00
e6b7938218 update lockfile and fix some darwin configs 2022-09-27 21:30:27 -04:00
1addb7ec21 manage touchid sudo with nix-darwin 2022-09-25 14:47:04 +00:00
ba14638a8a navigate git hunks in neovim 2022-09-25 14:46:50 +00:00
ddd517e0dd update installer with gum, add more charm stuff 2022-09-25 04:19:46 +00:00
0ac3aec208 dynamic rebuild-nixos based on current hostname 2022-09-24 16:53:16 +00:00
ae90b1041d add charm packages, fix neovim tree height 2022-09-24 14:26:02 +00:00
9b0dcaba9f docs: update wsl instructions for fonts and term 2022-09-24 01:55:11 +00:00
0bf5fd5862 update docs for non-nix users 2022-09-23 14:35:14 -04:00
7a9f7dd760 add more general utilities 2022-09-21 16:58:04 -04:00
f834cc20f4 aws generator gh workflow and terraform upload 2022-09-21 03:49:04 +00:00
720a3cc409 additional options needed to build aws image 2022-09-20 12:50:04 +00:00
9e3345ff9b add sshd for aws generators 2022-09-20 11:50:45 +00:00
50a538c78e start generator work 2022-09-20 04:01:45 +00:00
105 changed files with 2842 additions and 640 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@
**/.direnv/**
result
.luarc.json
private/**
!private/**.age
!private/**.sha512

View File

@ -1,6 +1,17 @@
This repository contains configuration files for my NixOS, macOS, and WSL
hosts.
They are organized and managed by [Nix](https://nixos.org), so some of the
configuration may be difficult to translate to a non-Nix system.
However, some of the configurations are easier to lift directly:
- [Neovim](https://github.com/nmasur/dotfiles/tree/master/modules/neovim/lua)
- [Fish functions](https://github.com/nmasur/dotfiles/tree/master/modules/shell/fish/functions)
- [More fish aliases](https://github.com/nmasur/dotfiles/blob/master/modules/shell/fish/default.nix)
- [Git aliases](https://github.com/nmasur/dotfiles/blob/master/modules/shell/git.nix)
- [Hammerspoon](https://github.com/nmasur/dotfiles/tree/master/modules/darwin/hammerspoon)
---
# Installation
@ -14,7 +25,7 @@ installer disk:
```bash
lsblk # Choose the disk you want to wipe
nix-shell -p nixFlakes
nix-shell -p nixVersions.stable
nix run github:nmasur/dotfiles#installer -- nvme0n1 desktop
```
@ -24,7 +35,7 @@ If you're already running NixOS, you can switch to this configuration with the
following command:
```bash
nix-shell -p nixFlakes
nix-shell -p nixVersions.stable
sudo nixos-rebuild switch --flake github:nmasur/dotfiles#desktop
```
@ -35,10 +46,16 @@ WSL](https://xeiaso.net/blog/nix-flakes-4-wsl-2022-05-01), you can switch to
the WSL configuration:
```
nix-shell -p nixFlakes
nix-shell -p nixVersions.stable
sudo nixos-rebuild switch --flake github:nmasur/dotfiles#wsl
```
You should also download the
[FiraCode](https://github.com/ryanoasis/nerd-fonts/releases/download/v2.2.2/FiraCode.zip)
font and install it on Windows. Install [Alacritty](https://alacritty.org/) and
move the `windows/alacritty.yml` file to
`C:\Users\<user>\AppData\Roaming\alacritty`.
## macOS
To get started on a bare macOS installation, first install Nix:

23
apps/default.nix Normal file
View File

@ -0,0 +1,23 @@
{ pkgs, ... }: rec {
default = readme;
# Format and install from nothing
installer = import ./installer.nix { inherit pkgs; };
# Display the readme for this repository
readme = import ./readme.nix { inherit pkgs; };
# Load the SSH key for this machine
loadkey = import ./loadkey.nix { inherit pkgs; };
# Encrypt secret for all machines
encrypt-secret = import ./encrypt-secret.nix { inherit pkgs; };
# Re-encrypt secrets for all machines
reencrypt-secrets = import ./reencrypt-secrets.nix { inherit pkgs; };
# Connect machine metrics to Netdata Cloud
netdata = import ./netdata-cloud.nix { inherit pkgs; };
}

19
apps/encrypt-secret.nix Normal file
View File

@ -0,0 +1,19 @@
{ pkgs, ... }: {
# nix run github:nmasur/dotfiles#encrypt-secret > private/mysecret.age
type = "app";
program = builtins.toString (pkgs.writeShellScript "encrypt-secret" ''
printf "\nEnter the secret data to encrypt for all hosts...\n\n" 1>&2
read -p "Secret: " secret
printf "\nEncrypting...\n\n" 1>&2
tmpfile=$(mktemp)
echo "''${secret}" > ''${tmpfile}
${pkgs.age}/bin/age --encrypt --armor --recipients-file ${
builtins.toString ../hosts/public-keys
} $tmpfile
rm $tmpfile
'');
}

View File

@ -13,10 +13,12 @@
PARTITION_PREFIX=""
if [ -z "$DISK" ] || [ -z "$FLAKE" ]; then
echo "Missing required parameter."
echo "Usage: installer -- <disk> <host>"
echo "Example: installer -- nvme0n1 desktop"
echo "Flake example: nix run github:nmasur/dotfiles#installer -- nvme0n1 desktop"
${pkgs.gum}/bin/gum style --width 50 --margin "1 2" --padding "2 4" \
--foreground "#fb4934" \
"Missing required parameter." \
"Usage: installer -- <disk> <host>" \
"Example: installer -- nvme0n1 desktop" \
"Flake example: nix run github:nmasur/dotfiles#installer -- nvme0n1 desktop"
echo "(exiting)"
exit 1
fi
@ -25,10 +27,14 @@
PARTITION_PREFIX="p"
esac
parted /dev/''${DISK} -- mklabel gpt
parted /dev/''${DISK} -- mkpart primary 512MiB 100%
parted /dev/''${DISK} -- mkpart ESP fat32 1MiB 512MiB
parted /dev/''${DISK} -- set 3 esp on
${pkgs.gum}/bin/gum confirm \
"This will ERASE ALL DATA on the disk /dev/''${DISK}. Are you sure you want to continue?" \
--default=false
${pkgs.parted}/bin/parted /dev/''${DISK} -- mklabel gpt
${pkgs.parted}/bin/parted /dev/''${DISK} -- mkpart primary 512MiB 100%
${pkgs.parted}/bin/parted /dev/''${DISK} -- mkpart ESP fat32 1MiB 512MiB
${pkgs.parted}/bin/parted /dev/''${DISK} -- set 3 esp on
mkfs.ext4 -L nixos /dev/''${DISK}''${PARTITION_PREFIX}1
mkfs.fat -F 32 -n boot /dev/''${DISK}''${PARTITION_PREFIX}2
@ -36,7 +42,7 @@
mkdir --parents /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
nixos-install --flake github:nmasur/dotfiles#''${FLAKE}
${pkgs.nixos-install-tools}/bin/nixos-install --flake github:nmasur/dotfiles#''${FLAKE}
'');
}

12
apps/loadkey.nix Normal file
View File

@ -0,0 +1,12 @@
{ pkgs, ... }: {
type = "app";
program = builtins.toString (pkgs.writeShellScript "loadkey" ''
printf "\nEnter the seed phrase for your SSH key...\n"
printf "\nThen press ^D when complete.\n\n"
${pkgs.melt}/bin/melt restore ~/.ssh/id_ed25519
printf "\n\nContinuing activation.\n\n"
'');
}

19
apps/netdata-cloud.nix Normal file
View File

@ -0,0 +1,19 @@
{ pkgs, ... }: {
type = "app";
program = builtins.toString (pkgs.writeShellScript "netdata-cloud" ''
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
mkdir --parents --mode 0750 /var/lib/netdata/cloud.d
printf "\nEnter the claim token for netdata cloud...\n\n"
read -p "Token: " token
echo "''${token}" > /var/lib/netdata/cloud.d/token
chown -R netdata:netdata /var/lib/netdata
${pkgs.netdata}/bin/netdata-claim.sh -id=$(uuidgen)
printf "\n\nNow restart netdata service.\n\n"
'');
}

View File

@ -0,0 +1,27 @@
{ pkgs, ... }: {
# nix run github:nmasur/dotfiles#reencrypt-secrets ./private
type = "app";
program = builtins.toString (pkgs.writeShellScript "reencrypt-secrets" ''
if [ $# -eq 0 ]; then
echo "Must provide directory to reencrypt."
exit 1
fi
encrypted=$1
for encryptedfile in ''${1}/*; do
tmpfile=$(mktemp)
echo "Decrypting ''${encryptedfile}..."
${pkgs.age}/bin/age --decrypt \
--identity ~/.ssh/id_ed25519 $encryptedfile > $tmpfile
echo "Encrypting ''${encryptedfile}..."
${pkgs.age}/bin/age --encrypt --armor --recipients-file ${
builtins.toString ../hosts/public-keys
} $tmpfile > $encryptedfile
rm $tmpfile
done
echo "Finished."
'');
}

67
flake.lock generated
View File

@ -7,11 +7,11 @@
]
},
"locked": {
"lastModified": 1662478528,
"narHash": "sha256-Myjd0HPL5lXri3NXOcJ6gP7IKod2eMweQBKM4uxgEGw=",
"lastModified": 1666776005,
"narHash": "sha256-HwSMF19PpczfqNHKcFsA6cF4PVbG00uUSdbq6q3jB5o=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "3b69bf3cc26ae19de847bfe54d6ab22d7381a90a",
"rev": "f6648ca0698d1611d7eadfa72b122252b833f86c",
"type": "github"
},
"original": {
@ -60,11 +60,11 @@
"utils": "utils"
},
"locked": {
"lastModified": 1663328500,
"narHash": "sha256-7n+J/exp8ky4dmk02y5a9R7CGmJvHpzrHMzfEkMtSWA=",
"lastModified": 1666903647,
"narHash": "sha256-sFI1Gh9DTGzHnBINondupUGYbe+T0wZcpcZjkW0qffM=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "5427f3d1f0ea4357cd4af0bffee7248d640c6ffc",
"rev": "213a06295dff96668a1d673b9fd1c03ce1de6745",
"type": "github"
},
"original": {
@ -74,13 +74,49 @@
"type": "github"
}
},
"nixlib": {
"locked": {
"lastModified": 1636849918,
"narHash": "sha256-nzUK6dPcTmNVrgTAC1EOybSMsrcx+QrVPyqRdyKLkjA=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "28a5b0557f14124608db68d3ee1f77e9329e9dd5",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixos-generators": {
"inputs": {
"nixlib": "nixlib",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1666812839,
"narHash": "sha256-0nBDgjPU+iDsvz89W+cDEyhnFGSwCJmwDl/gMGqYiU0=",
"owner": "nix-community",
"repo": "nixos-generators",
"rev": "41f3518bc194389df22a3d198215eae75e6b5ab9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixos-generators",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1663357389,
"narHash": "sha256-oYA2nVRSi6yhCBqS5Vz465Hw+3BQOVFEhfbfy//3vTs=",
"lastModified": 1666959691,
"narHash": "sha256-TRpWA3t8ata79HOGtFd5dDCl1kJQmIE16PDF53/Hcxo=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "da6a05816e7fa5226c3f61e285ef8d9dfc868f3c",
"rev": "448a599c49978c2794401bfc3a2e1fba1a8663be",
"type": "github"
},
"original": {
@ -107,11 +143,11 @@
},
"nur": {
"locked": {
"lastModified": 1663440270,
"narHash": "sha256-RkBoLyxamsBqRn9lB9RbFSDg7KHiGgHBsrpffEVXWCQ=",
"lastModified": 1667025500,
"narHash": "sha256-88akaieCIrqta3Uyha7Zv3FJWzKJebb2BrOdZba1zdI=",
"owner": "nix-community",
"repo": "nur",
"rev": "7511d58da488c67887745f40fd4846aa8c876d25",
"rev": "21dd192519af12a01f1348bbfa86cde47f7aa392",
"type": "github"
},
"original": {
@ -124,6 +160,7 @@
"inputs": {
"darwin": "darwin",
"home-manager": "home-manager",
"nixos-generators": "nixos-generators",
"nixpkgs": "nixpkgs",
"nur": "nur",
"wallpapers": "wallpapers",
@ -168,11 +205,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1661772734,
"narHash": "sha256-DkvAaLDg9D6O0i2MzUknaf/U078K4KWAZaJQmNC/tL8=",
"lastModified": 1666720338,
"narHash": "sha256-7V91ZtTz7zDXb6hivktQ9RlBglP+WEkYFSciPJHwMJw=",
"owner": "nix-community",
"repo": "NixOS-WSL",
"rev": "c1b0259313f661cf74051c916cf3bb4f061ce11f",
"rev": "7bfb8f5aa91fee30a189eae32cda8ddc465076df",
"type": "github"
},
"original": {

View File

@ -32,9 +32,15 @@
flake = false;
};
# Used to generate NixOS images for other platforms
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, darwin, wsl, home-manager, nur, wallpapers }:
};
outputs = { self, nixpkgs, ... }@inputs:
let
@ -45,7 +51,7 @@
gitName = fullName;
gitEmail = "7386960+nmasur@users.noreply.github.com";
mailServer = "noahmasur.com";
dotfilesRepo = "https://github.com/nmasur/dotfiles";
dotfilesRepo = "git@github.com:nmasur/dotfiles";
};
# System types to support.
@ -55,33 +61,38 @@
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in {
in rec {
nixosConfigurations = {
desktop = import ./hosts/desktop {
inherit nixpkgs home-manager nur globals wallpapers;
};
wsl = import ./hosts/wsl { inherit nixpkgs wsl home-manager globals; };
desktop = import ./hosts/desktop { inherit inputs globals; };
wsl = import ./hosts/wsl { inherit inputs globals; };
oracle = import ./hosts/oracle { inherit inputs globals; };
};
darwinConfigurations = {
macbook = import ./hosts/macbook {
inherit nixpkgs darwin home-manager nur globals;
macbook = import ./hosts/macbook { inherit inputs globals; };
};
# For quickly applying local settings with:
# home-manager switch --flake .#desktop
homeConfigurations = {
desktop =
nixosConfigurations.desktop.config.home-manager.users.${globals.user}.home;
macbook =
darwinConfigurations.macbook.config.home-manager.users."Noah.Masur".home;
};
# Package servers into images with a generator
packages.x86_64-linux = with inputs; {
aws = import ./hosts/aws {
inherit inputs globals;
system = "x86_64-linux";
};
};
apps = forAllSystems (system:
let pkgs = import nixpkgs { inherit system; };
in rec {
default = readme;
# Format and install from nothing
installer = import ./apps/installer.nix { inherit pkgs; };
# Display the readme for this repository
readme = import ./apps/readme.nix { inherit pkgs; };
});
in import ./apps { inherit pkgs; });
devShells = forAllSystems (system:
let pkgs = import nixpkgs { inherit system; };
@ -101,6 +112,7 @@
vault
awscli2
google-cloud-sdk
ansible
kubectl
kubernetes-helm
kustomize

32
hosts/aws/default.nix Normal file
View File

@ -0,0 +1,32 @@
{ inputs, globals, ... }:
with inputs;
nixos-generators.nixosGenerate {
inherit system;
format = "amazon";
modules = [
home-manager.nixosModules.home-manager
{
user = globals.user;
fullName = globals.fullName;
dotfilesRepo = globals.dotfilesRepo;
gitName = globals.gitName;
gitEmail = globals.gitEmail;
networking.hostName = "sheep";
gui.enable = false;
colorscheme = (import ../modules/colorscheme/gruvbox);
passwordHash = null;
publicKey =
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+AbmjGEwITk5CK9y7+Rg27Fokgj9QEjgc9wST6MA3s";
# AWS settings require this
permitRootLogin = "prohibit-password";
}
../../hosts/common.nix
../../modules/nixos
../../modules/services/sshd.nix
] ++ [
# Required to fix diskSize errors during build
({ ... }: { amazonImage.sizeMB = 16 * 1024; })
];
}

80
hosts/aws/main.tf Normal file
View File

@ -0,0 +1,80 @@
locals {
image_file = one(fileset(path.root, "result/nixos-amazon-image-*.vhd"))
}
# Upload to S3
resource "aws_s3_object" "image" {
bucket = "your_bucket_name"
key = basename(local.image_file)
source = local.image_file
etag = filemd5(local.image_file)
}
# Setup IAM access for the VM Importer
data "aws_iam_policy_document" "vmimport_trust_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["vmie.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "vmimport" {
statement {
actions = [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
]
resources = [
"arn:aws:s3:::${aws_s3_object.image.bucket}",
"arn:aws:s3:::${aws_s3_object.image.bucket}/*",
]
}
statement {
actions = [
"ec2:ModifySnapshotAttribute",
"ec2:CopySnapshot",
"ec2:RegisterImage",
"ec2:Describe*",
]
resources = ["*"]
}
}
resource "aws_iam_role" "vmimport" {
name = "vmimport"
assume_role_policy = data.aws_iam_policy_document.vmimport_trust_policy.json
inline_policy {
name = "vmimport"
policy = data.aws_iam_policy_document.vmimport.json
}
}
# Import to EBS
resource "aws_ebs_snapshot_import" "image" {
disk_container {
format = "VHD"
user_bucket {
s3_bucket = aws_s3_object.image.bucket
s3_key = aws_s3_object.image.key
}
}
role_name = aws_iam_role.vmimport.name
}
# Convert to AMI
resource "aws_ami" "image" {
description = "Created with NixOS."
name = replace(basename(local.image_file), "/\\.vhd$/", "")
virtualization_type = "hvm"
ebs_block_device {
device_name = "/dev/xvda"
snapshot_id = aws_ebs_snapshot_import.image.id
volume_size = 8
}
}

260
hosts/aws/workflow.yml Normal file
View File

@ -0,0 +1,260 @@
name: 'Terraform'
env:
AWS_ACCOUNT_NUMBER: ''
AWS_PLAN_ROLE_NAME: github_actions_plan
AWS_APPLY_ROLE_NAME: github_actions_admin
# Always required. Used for authenticating to AWS, but can also act as your
# default region if you don't want to specify in the provider configuration.
AWS_REGION: us-east-1
# You must change these to fit your project.
TF_VAR_project: change-me
TF_VAR_label: change-me
TF_VAR_owner: Your Name Here
# If storing Terraform in a subdirectory, specify it here.
TERRAFORM_DIRECTORY: .
# Pinned versions of tools to use.
# Check for new releases:
# - https://github.com/hashicorp/terraform/releases
# - https://github.com/fugue/regula/releases
# - https://github.com/terraform-linters/tflint/releases
TERRAFORM_VERSION: 1.2.6
REGULA_VERSION: 2.9.0
TFLINT_VERSION: 0.39.1
# Terraform configuration options
TERRAFORM_PARALLELISM: 10
# These variables are passed to Terraform based on GitHub information.
TF_VAR_repo: ${{ github.repository }}
# This workflow is triggered in the following ways.
on:
# Any push or merge to these branches.
push:
branches:
- dev
- prod
# Any pull request targeting these branches (plan only).
pull_request:
branches:
- dev
- prod
# Any manual trigger on these branches.
workflow_dispatch:
branches:
- dev
- prod
# -------------------------------------------------------------------
# The rest of this workflow can operate without adjustments. Edit the
# below content at your own risk!
# -------------------------------------------------------------------
# Used to connect to AWS IAM
permissions:
id-token: write
contents: read
pull-requests: write
# Only run one workflow at a time for each Terraform state. This prevents
# lockfile conflicts, especially during PR vs push.
concurrency: terraform-${{ github.base_ref || github.ref }}
jobs:
terraform:
name: 'Terraform'
# Change this if you need to run your deployment on-prem.
runs-on: ubuntu-latest
steps:
# Downloads the current repo code to the runner.
- name: Checkout Repo Code
uses: actions/checkout@v2
# Install Nix
- name: Install Nix
uses: cachix/install-nix-action@v17
# Build the image
- name: Build Image
run: nix build .#aws
# Login to AWS
- name: AWS Assume Role
uses: aws-actions/configure-aws-credentials@v1.6.1
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
# Exports all GitHub Secrets as environment variables prefixed by
# "TF_VAR_", which exposes them to Terraform. The name of each GitHub
# Secret must match its Terraform variable name exactly.
- name: Export Secrets to Terraform Variables
env:
ALL_SECRETS: ${{ toJson(secrets) }}
run: |
echo "$ALL_SECRETS" \
| jq "to_entries | .[] | \"TF_VAR_\" + ( .key | ascii_downcase ) + \"=\" + .value" \
| tr -d \" >> $GITHUB_ENV
# Installs the Terraform binary and some other accessory functions.
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
# Checks whether Terraform is formatted properly. If this fails, you
# should install the pre-commit hook.
- name: Check Formatting
run: |
terraform fmt -no-color -check -diff -recursive
# Downloads a Terraform code lint test.
- uses: terraform-linters/setup-tflint@v1
name: Setup TFLint
with:
tflint_version: v${{ env.TFLINT_VERSION }}
# Sets up linting with this codebase.
- name: Init TFLint
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: tflint --init
# Lints the current code.
- name: Run TFLint
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: |
tflint -f compact
find ./modules/* -type d -maxdepth 0 | xargs -I __ tflint -f compact --disable-rule=terraform_required_providers --disable-rule=terraform_required_version __
# Connects to remote state backend and download providers.
- name: Terraform Init
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: |
terraform init \
-backend-config="role_arn=${{ env.AWS_STATE_ROLE_ARN }}" \
-backend-config="region=us-east-1" \
-backend-config="workspace_key_prefix=accounts/${{ env.AWS_ACCOUNT_NUMBER }}/${{ github.repository }}" \
-backend-config="key=state.tfstate" \
-backend-config="dynamodb_table=global-tf-state-lock"
# Set the Terraform Workspace to the current branch name.
- name: Set Terraform Workspace
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
shell: bash
run: |
export WORKSPACE=${{ github.base_ref || github.ref_name }}
terraform workspace select ${WORKSPACE} || terraform workspace new $WORKSPACE
echo "TF_WORKSPACE=$(echo ${WORKSPACE} | sed 's/\//_/g')" >> $GITHUB_ENV
# Checks differences between current code and infrastructure state.
- name: Terraform Plan
id: plan
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: |
terraform plan \
-input=false \
-no-color \
-out=tfplan \
-parallelism=${TERRAFORM_PARALLELISM} \
-var-file=variables-${TF_WORKSPACE}.tfvars
# Gets the results of the plan for pull requests.
- name: Terraform Show Plan
id: show
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: terraform show -no-color tfplan
# Adds the results of the plan to the pull request.
- name: Comment Plan
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
STDOUT: "```terraform\n${{ steps.show.outputs.stdout }}```"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
})
// 2. Prepare format of the comment
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
# Downloads Regula and checks whether the plan meets compliance requirements.
- name: Regula Compliance Check
shell: bash
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: |
REGULA_URL="https://github.com/fugue/regula/releases/download/v${REGULA_VERSION}/regula_${REGULA_VERSION}_Linux_x86_64.tar.gz"
curl -sL "$REGULA_URL" -o regula.tar.gz
tar xzf regula.tar.gz
terraform show -json tfplan | ./regula run
# Deploys infrastructure or changes to infrastructure.
- name: Terraform Apply
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
working-directory: ${{ env.TERRAFORM_DIRECTORY }}
run: |
terraform apply \
-auto-approve \
-input=false \
-parallelism=${TERRAFORM_PARALLELISM} \
tfplan

View File

@ -3,9 +3,9 @@
imports =
[ ../modules/shell ../modules/neovim ../modules/repositories/dotfiles.nix ];
options = with lib; {
user = mkOption {
type = types.str;
options = rec {
user = lib.mkOption {
type = lib.types.str;
description = "Primary user of the system";
};
fullName = lib.mkOption {
@ -21,35 +21,54 @@
if pkgs.stdenv.isDarwin then "$HOME/Downloads" else "$HOME/downloads";
};
};
identityFile = lib.mkOption {
type = lib.types.str;
description = "Path to existing private key file.";
default = "/etc/ssh/ssh_host_ed25519_key";
};
gui = {
enable = mkEnableOption {
description = "Enable graphics";
enable = lib.mkEnableOption {
description = "Enable graphics.";
default = false;
};
};
colorscheme = mkOption {
type = types.attrs;
description = "Base16 color scheme";
theme = {
colors = lib.mkOption {
type = lib.types.attrs;
description = "Base16 color scheme.";
default = (import ../modules/colorscheme/gruvbox).dark;
};
homePath = mkOption {
type = types.path;
dark = lib.mkOption {
type = lib.types.bool;
description = "Enable dark mode.";
default = true;
};
};
# colorscheme = lib.mkOption {
# type = types.attrs;
# description = "Base16 color scheme";
# };
homePath = lib.mkOption {
type = lib.types.path;
description = "Path of user's home directory.";
default = builtins.toPath (if pkgs.stdenv.isDarwin then
"/Users/${config.user}"
else
"/home/${config.user}");
};
dotfilesPath = mkOption {
type = types.path;
dotfilesPath = lib.mkOption {
type = lib.types.path;
description = "Path of dotfiles repository.";
default = config.homePath + "/dev/personal/dotfiles";
};
dotfilesRepo = mkOption {
type = types.str;
dotfilesRepo = lib.mkOption {
type = lib.types.str;
description = "Link to dotfiles repository.";
};
unfreePackages = mkOption {
type = types.listOf types.str;
unfreePackages = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "List of unfree packages to allow.";
default = [ ];
};
@ -59,7 +78,10 @@
in {
# Enable features in Nix commands
nix.extraOptions = "experimental-features = nix-command flakes";
nix.extraOptions = ''
experimental-features = nix-command flakes
warn-dirty = false
'';
# Basic common system packages for all devices
environment.systemPackages = with pkgs; [ git vim wget curl ];

View File

@ -1,4 +1,6 @@
{ nixpkgs, home-manager, nur, globals, wallpapers, ... }:
{ inputs, globals, ... }:
with inputs;
# System configuration for my desktop
nixpkgs.lib.nixosSystem {
@ -12,18 +14,15 @@ nixpkgs.lib.nixosSystem {
nixpkgs.overlays = [ nur.overlay ];
# Set registry to flake packages, used for nix X commands
nix.registry.nixpkgs.flake = nixpkgs;
gaming.steam = true;
gaming.leagueoflegends = true;
gaming.legendary = true;
gui = {
enable = true;
compositor.enable = true;
wallpaper = "${wallpapers}/gruvbox/road.jpg";
gtk.theme = { name = "Adwaita-dark"; };
identityFile = "/home/${globals.user}/.ssh/id_ed25519";
gui.enable = true;
theme = {
colors = (import ../../modules/colorscheme/gruvbox).dark;
dark = true;
};
colorscheme = (import ../../modules/colorscheme/gruvbox);
passwordHash =
"$6$PZYiMGmJIIHAepTM$Wx5EqTQ5GApzXx58nvi8azh16pdxrN6Qrv1wunDlzveOgawitWzcIxuj76X9V868fsPi/NOIEO8yVXqwzS9UF.";
wallpaper = "${wallpapers}/gruvbox/road.jpg";
gtk.theme.name = nixpkgs.lib.mkDefault "Adwaita-dark";
passwordHash = nixpkgs.lib.fileContents ../../private/password.sha512;
}
./hardware-configuration.nix
@ -31,14 +30,19 @@ nixpkgs.lib.nixosSystem {
../../modules/hardware
../../modules/nixos
../../modules/graphical
../../modules/gaming
../../modules/applications
../../modules/mail/himalaya.nix
../../modules/applications/media.nix
../../modules/applications/firefox.nix
../../modules/applications/kitty.nix
../../modules/applications/1password.nix
../../modules/applications/discord.nix
../../modules/applications/nautilus.nix
../../modules/applications/obsidian.nix
../../modules/mail/default.nix
../../modules/gaming/steam.nix
../../modules/gaming/legendary.nix
../../modules/repositories/notes.nix
../../modules/services/keybase.nix
../../modules/services/gnupg.nix
../../modules/services/mullvad.nix
../../modules/programming/nix.nix
../../modules/programming/haskell.nix
];
}

View File

@ -1,4 +1,6 @@
{ nixpkgs, darwin, home-manager, nur, globals, ... }:
{ inputs, globals, ... }:
with inputs;
# System configuration for my work MacBook
darwin.lib.darwinSystem {
@ -12,18 +14,21 @@ darwin.lib.darwinSystem {
})
home-manager.darwinModules.home-manager
{
identityFile = "/Users/Noah.Masur/.ssh/id_ed25519";
gui.enable = true;
colorscheme = (import ../../modules/colorscheme/gruvbox);
mailUser = globals.user;
networking.hostName = "noah-masur-mac";
nixpkgs.overlays = [ nur.overlay ];
# Set registry to flake packages, used for nix X commands
nix.registry.nixpkgs.flake = nixpkgs;
}
../common.nix
../../modules/darwin
../../modules/mail
../../modules/applications/alacritty.nix
../../modules/applications/kitty.nix
../../modules/applications/discord.nix
../../modules/mail/himalaya.nix
../../modules/repositories/notes.nix
../../modules/programming/nix.nix
../../modules/programming/terraform.nix

90
hosts/oracle/default.nix Normal file
View File

@ -0,0 +1,90 @@
{ inputs, globals, ... }:
with inputs;
# System configuration for an Oracle free server
# How to install:
# https://blog.korfuri.fr/posts/2022/08/nixos-on-an-oracle-free-tier-ampere-machine/
nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
specialArgs = { };
modules = [
(removeAttrs globals [ "mailServer" ])
home-manager.nixosModules.home-manager
{
gui.enable = false;
colorscheme = (import ../../modules/colorscheme/gruvbox);
# FQDNs for various services
networking.hostName = "oracle";
bookServer = "books.masu.rs";
streamServer = "stream.masu.rs";
nextcloudServer = "cloud.masu.rs";
transmissionServer = "download.masu.rs";
metricsServer = "metrics.masu.rs";
vaultwardenServer = "vault.masu.rs";
giteaServer = "git.masu.rs";
# Disable passwords, only use SSH key
publicKey =
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+AbmjGEwITk5CK9y7+Rg27Fokgj9QEjgc9wST6MA3s";
# Nextcloud backup config
backupS3 = {
endpoint = "s3.us-west-002.backblazeb2.com";
bucket = "noahmasur-backup";
accessKeyId = "0026b0e73b2e2c80000000005";
};
# Grant access to Jellyfin directories from Nextcloud
users.users.nextcloud.extraGroups = [ "jellyfin" ];
# Wireguard config for Transmission
networking.wireguard.interfaces.wg0 = {
# The local IPs for this machine within the Wireguard network
# Any inbound traffic bound for these IPs should be kept on localhost
ips = [ "10.66.13.200/32" "fc00:bbbb:bbbb:bb01::3:dc7/128" ];
peers = [{
# Identity of Wireguard target peer (VPN)
publicKey = "bOOP5lIjqCdDx5t+mP/kEcSbHS4cZqE0rMlBI178lyY=";
# The public internet address of the target peer
endpoint = "86.106.143.132:51820";
# Which outgoing IP ranges should be sent through Wireguard
allowedIPs = [ "0.0.0.0/0" "::0/0" ];
# Send heartbeat signal within the network
persistentKeepalive = 25;
}];
};
# VPN port forwarding
services.transmission.settings.peer-port = 57599;
# Grant access to Transmission directories from Jellyfin
users.users.jellyfin.extraGroups = [ "transmission" ];
}
./hardware-configuration.nix
../common.nix
../../modules/nixos
../../modules/hardware/server.nix
../../modules/services/sshd.nix
../../modules/services/calibre.nix
../../modules/services/jellyfin.nix
../../modules/services/nextcloud.nix
../../modules/services/cloudflare.nix
../../modules/services/transmission.nix
../../modules/services/prometheus.nix
../../modules/services/vaultwarden.nix
../../modules/services/gitea.nix
../../modules/gaming/minecraft-server.nix
];
}

View File

@ -0,0 +1,34 @@
# 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 + "/profiles/qemu-guest.nix") ];
boot.initrd.availableKernelModules = [ "xhci_pci" "virtio_pci" "usbhid" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
fileSystems."/" = {
device = "/dev/disk/by-uuid/e1b6bd50-306d-429a-9f45-78f57bc597c3";
fsType = "ext4";
};
fileSystems."/boot" = {
device = "/dev/disk/by-uuid/D5CA-237A";
fsType = "vfat";
};
swapDevices = [ ];
# 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.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.eth0.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
}

4
hosts/public-keys Normal file
View File

@ -0,0 +1,4 @@
# Scan hosts: ssh-keyscan -t ed25519 <hostnames>
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+AbmjGEwITk5CK9y7+Rg27Fokgj9QEjgc9wST6MA3s noah
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHVknmPi7sG6ES0G0jcsvebzKGWWaMfJTYgvOue6EULI oracle.masu.rs

View File

@ -1,20 +0,0 @@
{ nixpkgs, home-manager, globals, ... }:
# System configuration for a generic server
nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { };
modules = [
globals
home-manager.nixosModules.home-manager
{
networking.hostName = "sheep";
gui.enable = false;
colorscheme = (import ../../modules/colorscheme/gruvbox);
passwordHash =
"$6$PZYiMGmJIIHAepTM$Wx5EqTQ5GApzXx58nvi8azh16pdxrN6Qrv1wunDlzveOgawitWzcIxuj76X9V868fsPi/NOIEO8yVXqwzS9UF.";
}
../common.nix
../../modules/nixos
];
}

View File

@ -1,4 +1,6 @@
{ nixpkgs, wsl, home-manager, globals, ... }:
{ inputs, globals, ... }:
with inputs;
# System configuration for WSL
nixpkgs.lib.nixosSystem {
@ -12,10 +14,10 @@ nixpkgs.lib.nixosSystem {
networking.hostName = "wsl";
# Set registry to flake packages, used for nix X commands
nix.registry.nixpkgs.flake = nixpkgs;
identityFile = "/home/${globals.user}/.ssh/id_ed25519";
gui.enable = false;
colorscheme = (import ../../modules/colorscheme/gruvbox);
passwordHash =
"$6$PZYiMGmJIIHAepTM$Wx5EqTQ5GApzXx58nvi8azh16pdxrN6Qrv1wunDlzveOgawitWzcIxuj76X9V868fsPi/NOIEO8yVXqwzS9UF.";
passwordHash = nixpkgs.lib.fileContents ../../private/password.sha512;
wsl = {
enable = true;
automountPath = "/mnt";

View File

@ -23,8 +23,8 @@
key_bindings = [
# Used for word completion in fish_user_key_bindings
{
key = "L";
mods = "Control|Shift";
key = "Return";
mods = "Shift";
chars = "\\x1F";
}
# Used for searching nixpkgs in fish_user_key_bindings
@ -34,8 +34,8 @@
chars = "\\x11F";
}
{
key = "K";
mods = "Control";
key = "H";
mods = "Control|Shift";
mode = "~Vi";
action = "ToggleViMode";
}
@ -54,32 +54,32 @@
];
colors = {
primary = {
background = config.colorscheme.base00;
foreground = config.colorscheme.base05;
background = config.theme.colors.base00;
foreground = config.theme.colors.base05;
};
cursor = {
text = "#1d2021";
cursor = config.colorscheme.base05;
cursor = config.theme.colors.base05;
};
normal = {
black = "#1d2021";
red = config.colorscheme.base08;
green = config.colorscheme.base0B;
yellow = config.colorscheme.base0A;
blue = config.colorscheme.base0D;
magenta = config.colorscheme.base0E;
cyan = config.colorscheme.base0C;
white = config.colorscheme.base05;
red = config.theme.colors.base08;
green = config.theme.colors.base0B;
yellow = config.theme.colors.base0A;
blue = config.theme.colors.base0D;
magenta = config.theme.colors.base0E;
cyan = config.theme.colors.base0C;
white = config.theme.colors.base05;
};
bright = {
black = config.colorscheme.base03;
red = config.colorscheme.base09;
green = config.colorscheme.base01;
yellow = config.colorscheme.base02;
blue = config.colorscheme.base04;
magenta = config.colorscheme.base06;
cyan = config.colorscheme.base0F;
white = config.colorscheme.base07;
black = config.theme.colors.base03;
red = config.theme.colors.base09;
green = config.theme.colors.base01;
yellow = config.theme.colors.base02;
blue = config.theme.colors.base04;
magenta = config.theme.colors.base06;
cyan = config.theme.colors.base0F;
white = config.theme.colors.base07;
};
};
draw_bold_text_with_bright_colors = false;

View File

@ -6,6 +6,7 @@
./calibre.nix
./discord.nix
./firefox.nix
./kitty.nix
./media.nix
./obsidian.nix
./qbittorrent.nix

View File

@ -33,6 +33,7 @@
settings = {
"browser.aboutConfig.showWarning" = false;
"browser.warnOnQuit" = false;
"browser.quitShortcut.disabled" = true;
"browser.theme.dark-private-windows" = true;
"browser.toolbars.bookmarks.visibility" = "newtab";
"browser.startup.page" = 3; # Restore previous session
@ -47,65 +48,65 @@
};
userChrome = ''
:root {
--focus-outline-color: ${config.colorscheme.base04} !important;
--toolbar-color: ${config.colorscheme.base07} !important;
--focus-outline-color: ${config.theme.colors.base04} !important;
--toolbar-color: ${config.theme.colors.base07} !important;
--tab-min-height: 30px !important;
}
/* Background of tab bar */
.toolbar-items {
background-color: ${config.colorscheme.base00} !important;
background-color: ${config.theme.colors.base00} !important;
}
/* Tabs themselves */
.tabbrowser-tab .tab-stack {
border-radius: 5px 5px 0 0;
overflow: hidden;
background-color: ${config.colorscheme.base00};
color: ${config.colorscheme.base06} !important;
background-color: ${config.theme.colors.base00};
color: ${config.theme.colors.base06} !important;
}
.tab-content {
border-bottom: 2px solid color-mix(in srgb, var(--identity-tab-color) 40%, transparent);
border-radius: 5px 5px 0 0;
background-color: ${config.colorscheme.base00};
color: ${config.colorscheme.base06} !important;
background-color: ${config.theme.colors.base00};
color: ${config.theme.colors.base06} !important;
}
.tab-content[selected=true] {
border-bottom: 2px solid color-mix(in srgb, var(--identity-tab-color) 25%, transparent);
background-color: ${config.colorscheme.base01} !important;
color: ${config.colorscheme.base07} !important;
background-color: ${config.theme.colors.base01} !important;
color: ${config.theme.colors.base07} !important;
}
/* Below tab bar */
#nav-bar {
background: ${config.colorscheme.base01} !important;
background: ${config.theme.colors.base01} !important;
}
/* URL bar in nav bar */
#urlbar[focused=true] {
color: ${config.colorscheme.base07} !important;
background: ${config.colorscheme.base02} !important;
caret-color: ${config.colorscheme.base05} !important;
color: ${config.theme.colors.base07} !important;
background: ${config.theme.colors.base02} !important;
caret-color: ${config.theme.colors.base05} !important;
}
#urlbar:not([focused=true]) {
color: ${config.colorscheme.base04} !important;
background: ${config.colorscheme.base02} !important;
color: ${config.theme.colors.base04} !important;
background: ${config.theme.colors.base02} !important;
}
#urlbar ::-moz-selection {
color: ${config.colorscheme.base07} !important;
background: ${config.colorscheme.base02} !important;
color: ${config.theme.colors.base07} !important;
background: ${config.theme.colors.base02} !important;
}
#urlbar-input-container {
border: 1px solid ${config.colorscheme.base01} !important;
border: 1px solid ${config.theme.colors.base01} !important;
}
#urlbar-background {
background: ${config.colorscheme.base01} !important;
background: ${config.theme.colors.base01} !important;
}
/* Text in URL bar */
#urlbar-input, #urlbar-scheme, .searchbar-textbox {
color: ${config.colorscheme.base07} !important;
color: ${config.theme.colors.base07} !important;
}
'';
userContent = ''
@-moz-document url-prefix(about:blank) {
* {
background-color:${config.colorscheme.base01} !important;
background-color:${config.theme.colors.base01} !important;
}
}
'';

View File

@ -0,0 +1,76 @@
{ config, pkgs, lib, ... }: {
config = lib.mkIf config.gui.enable {
home-manager.users.${config.user} = {
# xsession.windowManager.i3.config.terminal = "kitty";
# programs.rofi.terminal = "${pkgs.kitty}/bin/kitty";
programs.kitty = {
enable = true;
environment = { };
extraConfig = "";
font.size = 14;
keybindings = {
"shift+enter" = "send_text all \\x1F";
"super+f" = "toggle_fullscreen";
};
settings = {
# Colors (adapted from: https://github.com/kdrag0n/base16-kitty/blob/master/templates/default-256.mustache)
background = config.theme.colors.base00;
foreground = config.theme.colors.base05;
selection_background = config.theme.colors.base05;
selection_foreground = config.theme.colors.base00;
url_color = config.theme.colors.base04;
cursor = config.theme.colors.base05;
active_border_color = config.theme.colors.base03;
inactive_border_color = config.theme.colors.base01;
active_tab_background = config.theme.colors.base00;
active_tab_foreground = config.theme.colors.base05;
inactive_tab_background = config.theme.colors.base01;
inactive_tab_foreground = config.theme.colors.base04;
tab_bar_background = config.theme.colors.base01;
# normal
color0 = config.theme.colors.base00;
color1 = config.theme.colors.base08;
color2 = config.theme.colors.base0B;
color3 = config.theme.colors.base0A;
color4 = config.theme.colors.base0D;
color5 = config.theme.colors.base0E;
color6 = config.theme.colors.base0C;
color7 = config.theme.colors.base05;
# bright
color8 = config.theme.colors.base03;
color9 = config.theme.colors.base08;
color10 = config.theme.colors.base0B;
color11 = config.theme.colors.base0A;
color12 = config.theme.colors.base0D;
color13 = config.theme.colors.base0E;
color14 = config.theme.colors.base0C;
color15 = config.theme.colors.base07;
# extended base16 colors
color16 = config.theme.colors.base09;
color17 = config.theme.colors.base0F;
color18 = config.theme.colors.base01;
color19 = config.theme.colors.base02;
color20 = config.theme.colors.base04;
color21 = config.theme.colors.base06;
# Scrollback
scrolling_lines = 10000;
scrollback_pager_history_size = 10; # MB
scrollback_pager = ''
${pkgs.neovim}/bin/nvim -c 'setlocal nonumber nolist showtabline=0 foldcolumn=0|Man!' -c "autocmd VimEnter * normal G" -'';
# Window
window_padding_width = 6;
tab_bar_edge = "top";
tab_bar_style = "slant";
};
};
};
};
}

View File

@ -5,6 +5,7 @@
mpv # Video viewer
sxiv # Image viewer
mupdf # PDF viewer
zathura # PDF viewer
];
};

View File

@ -2,6 +2,7 @@
name = "gruvbox"; # Dark, Medium
author =
"Dawid Kurek (dawikur@gmail.com), morhetz (https://github.com/morhetz/gruvbox)";
dark = {
base00 = "#282828"; # ----
base01 = "#3c3836"; # ---
base02 = "#504945"; # --
@ -19,4 +20,24 @@
base0E = "#d3869b"; # purple
base0F = "#d65d0e"; # brown
neovimConfig = ./neovim.lua;
};
light = {
base00 = "#fbf1c7"; # ----
base01 = "#ebdbb2"; # ---
base02 = "#d5c4a1"; # --
base03 = "#bdae93"; # -
base04 = "#665c54"; # +
base05 = "#504945"; # ++
base06 = "#3c3836"; # +++
base07 = "#282828"; # ++++
base08 = "#9d0006"; # red
base09 = "#af3a03"; # orange
base0A = "#b57614"; # yellow
base0B = "#79740e"; # green
base0C = "#427b58"; # aqua/cyan
base0D = "#076678"; # blue
base0E = "#8f3f71"; # purple
base0F = "#d65d0e"; # brown
neovimConfig = ./neovim-light.lua;
};
}

View File

@ -6,6 +6,7 @@ M.packer = function(use)
config = function()
vim.g.gruvbox_italicize_strings = 0
vim.cmd("colorscheme gruvbox8")
vim.cmd("set background=dark")
end,
})
end

View File

@ -5,8 +5,9 @@
./fonts.nix
./hammerspoon.nix
./homebrew.nix
./kitty.nix
./networking.nix
./nixpkgs.nix
./ssl.nix
./system.nix
./tmux.nix
./user.nix

View File

@ -3,10 +3,13 @@
home-manager.users.${config.user} = {
home.packages = with pkgs;
[ (nerdfonts.override { fonts = [ "FiraCode" ]; }) ];
[ (nerdfonts.override { fonts = [ "Victor Mono" ]; }) ];
programs.alacritty.settings = {
font.normal.family = "FiraCode Nerd Font Mono";
programs.alacritty.settings = { font.normal.family = "Victor Mono"; };
programs.kitty.font = {
package = pkgs.nerdfonts;
name = "Victor Mono";
};
};

View File

@ -56,7 +56,7 @@ function obj:init()
-- Launcher shortcuts
self.launcher:bind("ctrl", "space", function() end)
self.launcher:bind("", "return", function()
self:switch("Alacritty.app")
self:switch("kitty.app")
end)
self.launcher:bind("", "C", function()
self:switch("Calendar.app")

View File

@ -9,24 +9,25 @@ WORK_RIGHT_MONITOR = "DELL U2415 (1)"
LAPTOP_MONITOR = "Built-in Retina Display"
-- Used to find out the name of the monitor in Hammerspoon
function dump(o)
if type(o) == "table" then
local s = "{ "
for k, v in pairs(o) do
if type(k) ~= "number" then
k = '"' .. k .. '"'
end
s = s .. "[" .. k .. "] = " .. dump(v) .. ","
end
return s .. "} "
else
return tostring(o)
end
end
-- local function dump(o)
-- if type(o) == "table" then
-- local s = "{ "
-- for k, v in pairs(o) do
-- if type(k) ~= "number" then
-- k = '"' .. k .. '"'
-- end
-- s = s .. "[" .. k .. "] = " .. dump(v) .. ","
-- end
-- return s .. "} "
-- else
-- return tostring(o)
-- end
-- end
-- Turn on when looking for the monitor name
-- print(dump(hs.screen.allScreens()))
function concat(...)
local function concat(...)
local res = {}
for _, tab in ipairs({ ... }) do
for _, elem in ipairs(tab) do
@ -36,12 +37,12 @@ function concat(...)
return res
end
function worklayout()
local function worklayout()
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "l", function()
local u = hs.geometry.unitrect
-- set the layout
local left = {
-- { "Alacritty", nil, WORK_LEFT_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true },
{ "kitty", nil, WORK_LEFT_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true },
}
local right = {
{ "Slack", nil, WORK_RIGHT_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true },

View File

@ -29,17 +29,19 @@
];
brews = [
"trash" # Delete files and folders to trash instead of rm
"openjdk" # Required by Apache Directory Studio
];
casks = [
"firefox" # Firefox packaging on Nix is broken for MacOS
"1password" # 1Password packaging on Nix is broken for MacOS
"firefox" # Firefox packaging on Nix is broken for macOS
"1password" # 1Password packaging on Nix is broken for macOS
"scroll-reverser" # Different scroll style for mouse vs. trackpad
"meetingbar" # Show meetings in menu bar
"gitify" # Git notifications in menu bar
"logitech-g-hub" # Mouse and keyboard management
"mimestream" # Gmail client
"obsidian" # Obsidian packaging on Nix is not available for MacOS
"obsidian" # Obsidian packaging on Nix is not available for macOS
"steam" # Not packaged for Nix
"apache-directory-studio" # Packaging on Nix is not available for macOS
];
};

16
modules/darwin/kitty.nix Normal file
View File

@ -0,0 +1,16 @@
{ config, pkgs, lib, ... }: {
# MacOS-specific settings for Kitty
home-manager.users.${config.user} = {
programs.kitty = {
darwinLaunchOptions = [ "--start-as=fullscreen" ];
font.size = lib.mkForce 20;
settings = {
shell = "${pkgs.fish}/bin/fish";
macos_traditional_fullscreen = true;
macos_quit_when_last_window_closed = true;
};
};
};
}

View File

@ -1,8 +1,9 @@
{ ... }: {
{ config, ... }: {
networking = {
computerName = "MacBook"; # Host name
hostName = "MacBook";
computerName = "${config.fullName}'\\''s Mac";
# Adjust if necessary
# hostName = "";
};
}

View File

@ -1,4 +1,4 @@
{ config, lib, ... }: {
{ config, pkgs, lib, ... }: {
home-manager.users.${config.user} = {
@ -18,6 +18,13 @@
commandline --function execute
'';
};
rebuild-home = lib.mkForce {
body = ''
git -C ${config.dotfilesPath} add --intent-to-add --all
commandline -r "${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#macbook";
commandline --function execute
'';
};
};
};

View File

@ -1,11 +0,0 @@
{ config, pkgs, ... }: {
# security.pki.certificateFiles = [
# "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
# (builtins.toString ../work/nixos-org-certs.crt)
# ];
security.pki.certificates =
[ (builtins.readFile ../work/nixos-org-certs.crt) ];
}

View File

@ -1,7 +1,11 @@
{ ... }: {
{ pkgs, ... }: {
services.nix-daemon.enable = true;
environment.shells = [ pkgs.fish ];
security.pam.enableSudoTouchIdAuth = true;
system = {
keyboard = {
@ -139,12 +143,12 @@
echo "Define dock icon function"
__dock_item() {
printf '%s%s%s%s%s' \
'<dict><key>tile-data</key><dict><key>file-data</key><dict>' \
'<key>_CFURLString</key><string>' \
printf "%s%s%s%s%s" \
"<dict><key>tile-data</key><dict><key>file-data</key><dict>" \
"<key>_CFURLString</key><string>" \
"$1" \
'</string><key>_CFURLStringType</key><integer>0</integer>' \
'</dict></dict></dict>'
"</string><key>_CFURLStringType</key><integer>0</integer>" \
"</dict></dict></dict>"
}
echo "Choose and order dock icons"
@ -161,16 +165,6 @@
"$(__dock_item /Applications/Alacritty.app)" \
"$(__dock_item /System/Applications/System\ Preferences.app)"
echo "Enable sudo Touch ID"
echo "# sudo: auth account password session" > /tmp/sudofile
echo "auth sufficient pam_smartcard.so" >> /tmp/sudofile
echo "auth sufficient pam_tid.so " >> /tmp/sudofile
echo "auth required pam_opendirectory.so" >> /tmp/sudofile
echo "account required pam_permit.so" >> /tmp/sudofile
echo "password required pam_deny.so" >> /tmp/sudofile
echo "session required pam_permit.so" >> /tmp/sudofile
sudo mv /tmp/sudofile /etc/pam.d/sudo
echo "Allow apps from anywhere"
SPCTL=$(spctl --status)
if ! [ "$SPCTL" = "assessments disabled" ]; then

View File

@ -1,8 +1,9 @@
{ config, pkgs, lib, ... }: {
users.users."${config.user}" = { # macOS user
users.users."${config.user}" = {
# macOS user
home = config.homePath;
shell = pkgs.zsh; # Default shell
shell = pkgs.fish; # Default shell
};
}

View File

@ -1,4 +1,19 @@
{ config, pkgs, lib, ... }: {
{ config, pkgs, lib, ... }:
let
# Quickly package shell scripts with their dependencies
# From https://discourse.nixos.org/t/how-to-create-a-script-with-dependencies/7970/6
mkScript = { name, file, env ? [ ] }:
pkgs.writeScriptBin name ''
for i in ${lib.concatStringsSep " " env}; do
export PATH="$i/bin:$PATH"
done
exec ${pkgs.bash}/bin/bash ${file} $@
'';
in {
home-manager.users.${config.user} = {
@ -11,12 +26,17 @@
mpd # TUI slideshows
awscli2
awslogs
kubectl
k9s
google-cloud-sdk
ansible
vault
consul
noti # Create notifications programmatically
ipcalc
(pkgs.writeScriptBin "ocr"
(builtins.readFile ../shell/bash/scripts/ocr.sh))
ipcalc # Make IP network calculations
(mkScript {
name = "ocr";
file = ../shell/bash/scripts/ocr.sh;
env = [ tesseract ];
})
];
programs.fish.shellAbbrs = {

View File

@ -1,7 +1,5 @@
{ config, ... }: {
imports = [ ./leagueoflegends.nix ./lutris.nix ./steam.nix ./legendary.nix ];
config = {
hardware.opengl = {
enable = true;

View File

@ -4,10 +4,9 @@ let home-packages = config.home-manager.users.${config.user}.home.packages;
in {
options.gaming.legendary =
lib.mkEnableOption "Legendary - Epic Games Launcher";
imports = [ ./. ];
config = lib.mkIf config.gaming.legendary {
config = {
environment.systemPackages = with pkgs; [
legendary-gl
rare # GUI for Legendary (not working)

View File

@ -0,0 +1,145 @@
{ pkgs, ... }:
let
localPort = 25564;
publicPort = 49732;
rconPort = 25575;
rconPassword = "thiscanbeanything";
in {
unfreePackages = [ "minecraft-server" ];
services.minecraft-server = {
enable = true;
eula = true;
declarative = true;
whitelist = { };
openFirewall = false;
serverProperties = {
server-port = localPort;
difficulty = "normal";
gamemode = "survival";
white-list = false;
enforce-whitelist = false;
level-name = "world";
motd = "Welcome!";
pvp = true;
player-idle-timeout = 30;
generate-structures = true;
max-players = 20;
snooper-enabled = false;
spawn-npcs = true;
spawn-animals = true;
spawn-monsters = true;
allow-nether = true;
allow-flight = false;
enable-rcon = true;
"rcon.port" = rconPort;
"rcon.password" = rconPassword;
};
};
networking.firewall.allowedTCPPorts = [ publicPort ];
## Automatically start and stop Minecraft server based on player connections
# Adapted shamelessly from:
# https://dataswamp.org/~solene/2022-08-20-on-demand-minecraft-with-systemd.html
# Prevent Minecraft from starting by default
systemd.services.minecraft-server = { wantedBy = pkgs.lib.mkForce [ ]; };
# Listen for connections on the public port, to trigger the actual
# listen-minecraft service.
systemd.sockets.listen-minecraft = {
wantedBy = [ "sockets.target" ];
requires = [ "network.target" ];
listenStreams = [ "${toString publicPort}" ];
};
# Proxy traffic to local port, and trigger hook-minecraft
systemd.services.listen-minecraft = {
path = [ pkgs.systemd ];
requires = [ "hook-minecraft.service" "listen-minecraft.socket" ];
after = [ "hook-minecraft.service" "listen-minecraft.socket" ];
serviceConfig.ExecStart =
"${pkgs.systemd.out}/lib/systemd/systemd-socket-proxyd 127.0.0.1:${
toString localPort
}";
};
# Start Minecraft if required and wait for it to be available
# Then unlock the listen-minecraft.service
systemd.services.hook-minecraft = {
path = with pkgs; [ systemd libressl busybox ];
# Start Minecraft and the auto-shutdown timer
script = ''
systemctl start minecraft-server.service
systemctl start stop-minecraft.timer
'';
# Keep checking until the service is available
postStart = ''
for i in $(seq 60); do
if ${pkgs.libressl.nc}/bin/nc -z 127.0.0.1 ${
toString localPort
} > /dev/null ; then
exit 0
fi
${pkgs.busybox.out}/bin/sleep 1
done
exit 1
'';
};
# Run a player check on a schedule for auto-shutdown
systemd.timers.stop-minecraft = {
timerConfig = {
OnCalendar = "*-*-* *:*:0/20"; # Every 20 seconds
Unit = "stop-minecraft.service";
};
};
# If no players are connected, then stop services and prepare to resume again
systemd.services.stop-minecraft = {
serviceConfig.Type = "oneshot";
script = ''
# Check when service was launched
servicestartsec=$(
date -d \
"$(systemctl show \
--property=ActiveEnterTimestamp \
minecraft-server.service \
| cut -d= -f2)" \
+%s)
# Calculate elapsed time
serviceelapsedsec=$(( $(date +%s) - servicestartsec))
# Ignore if service just started
if [ $serviceelapsedsec -lt 180 ]
then
echo "Server was just started"
exit 0
fi
PLAYERS=$(
printf "list\n" \
| ${pkgs.rcon.out}/bin/rcon -m \
-H 127.0.0.1 -p ${builtins.toString rconPort} -P ${rconPassword} \
)
if echo "$PLAYERS" | grep "are 0 of a"
then
echo "Stopping server"
systemctl stop minecraft-server.service
systemctl stop hook-minecraft.service
systemctl stop stop-minecraft.timer
fi
'';
};
}

View File

@ -1,10 +1,10 @@
{ config, pkgs, lib, ... }: {
options.gaming.steam = lib.mkEnableOption "Steam";
imports = [ ./. ];
config = lib.mkIf config.gaming.steam {
config = {
hardware.steam-hardware.enable = true;
unfreePackages = [ "steam" "steam-original" "steamcmd" ];
unfreePackages = [ "steam" "steam-original" "steamcmd" "steam-run" ];
environment.systemPackages = with pkgs; [
steam

View File

@ -1,54 +1,30 @@
{ lib, ... }: {
imports = [
./xorg.nix
./fonts.nix
./i3.nix
./polybar.nix
./picom.nix
# ./dmenu.nix
./rofi.nix
];
imports =
[ ./xorg.nix ./fonts.nix ./i3.nix ./polybar.nix ./picom.nix ./rofi.nix ];
options = with lib; {
options = {
gui = {
compositor.enable = mkEnableOption {
description = "Enable transparency, blur, shadows";
default = false;
};
launcherCommand = mkOption {
type = types.str;
launcherCommand = lib.mkOption {
type = lib.types.str;
description = "Command to use for launching";
};
systemdSearch = mkOption {
type = types.str;
systemdSearch = lib.mkOption {
type = lib.types.str;
description = "Command to use for interacting with systemd";
};
altTabCommand = mkOption {
type = types.str;
altTabCommand = lib.mkOption {
type = lib.types.str;
description = "Command to use for choosing windows";
};
toggleBarCommand = lib.mkOption {
type = lib.types.str;
description = "Command to hide and show the status bar.";
};
gtk.theme = {
name = mkOption {
type = types.str;
description = "Theme name for GTK applications";
};
package = mkOption {
type = types.str;
description = "Theme package name for GTK applications";
default = "gnome-themes-extra";
};
};
wallpaper = mkOption {
type = types.path;
wallpaper = lib.mkOption {
type = lib.types.path;
description = "Wallpaper background image file";
};
};
};

View File

@ -21,6 +21,7 @@ in {
services.polybar.config."bar/main".font-0 = "Hack Nerd Font:size=10;2";
programs.rofi.font = "Hack Nerd Font 14";
programs.alacritty.settings.font.normal.family = fontName;
programs.kitty.font.name = fontName;
};
};

View File

@ -5,15 +5,15 @@ let
lockCmd =
"${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span";
lockUpdate =
"${pkgs.betterlockscreen}/bin/betterlockscreen --update ${config.gui.wallpaper} --display 1 --span";
"${pkgs.betterlockscreen}/bin/betterlockscreen --update ${config.wallpaper} --display 1 --span";
in {
config = lib.mkIf config.services.xserver.enable {
config = {
services.xserver.windowManager = {
i3 = {
enable = true;
enable = config.services.xserver.enable;
package = pkgs.i3-gaps;
};
};
@ -25,7 +25,7 @@ in {
home-manager.users.${config.user} = {
xsession.windowManager.i3 = {
enable = true;
enable = config.services.xserver.enable;
package = pkgs.i3-gaps;
config = let
modifier = "Mod4"; # Super key
@ -43,22 +43,22 @@ in {
modifier = modifier;
assigns = {
"${ws1}" = [{ class = "Firefox"; }];
"${ws2}" = [{ class = "Alacritty"; }];
"${ws2}" = [{ class = "kitty"; }];
"${ws3}" = [{ class = "discord"; }];
"${ws4}" = [{ class = "Steam"; }];
};
bars = [{ command = "echo"; }]; # Disable i3bar
colors = let
background = config.colorscheme.base00;
inactiveBackground = config.colorscheme.base01;
border = config.colorscheme.base01;
inactiveBorder = config.colorscheme.base01;
text = config.colorscheme.base07;
inactiveText = config.colorscheme.base04;
urgentBackground = config.colorscheme.base08;
background = config.theme.colors.base00;
inactiveBackground = config.theme.colors.base01;
border = config.theme.colors.base01;
inactiveBorder = config.theme.colors.base01;
text = config.theme.colors.base07;
inactiveText = config.theme.colors.base04;
urgentBackground = config.theme.colors.base08;
indicator = "#00000000";
in {
background = config.colorscheme.base00;
background = config.theme.colors.base00;
focused = {
inherit background indicator text border;
childBorder = background;
@ -111,12 +111,12 @@ in {
# Launchers
"${modifier}+Return" =
"exec --no-startup-id alacritty; workspace ${ws2}; layout tabbed";
"exec --no-startup-id kitty; workspace ${ws2}; layout tabbed";
"${modifier}+space" =
"exec --no-startup-id ${config.gui.launcherCommand}";
"exec --no-startup-id ${config.launcherCommand}";
"${modifier}+Shift+s" =
"exec --no-startup-id ${config.gui.systemdSearch}";
"Mod1+Tab" = "exec --no-startup-id ${config.gui.altTabCommand}";
"exec --no-startup-id ${config.systemdSearch}";
"Mod1+Tab" = "exec --no-startup-id ${config.altTabCommand}";
"${modifier}+Shift+c" = "reload";
"${modifier}+Shift+r" = "restart";
"${modifier}+Shift+q" = ''
@ -125,7 +125,7 @@ in {
# Window options
"${modifier}+q" = "kill";
"${modifier}+b" = "exec ${config.gui.toggleBarCommand}";
"${modifier}+b" = "exec ${config.toggleBarCommand}";
"${modifier}+f" = "fullscreen toggle";
"${modifier}+h" = "focus left";
"${modifier}+j" = "focus down";
@ -205,12 +205,18 @@ in {
modes = { };
startup = [
{
command = "feh --bg-fill ${config.gui.wallpaper}";
command = "feh --bg-fill ${config.wallpaper}";
always = true;
notification = false;
}
{
command = "i3-msg workspace ${ws1}";
command =
"i3-msg workspace ${ws2}, move workspace to output right";
notification = false;
}
{
command =
"i3-msg workspace ${ws1}, move workspace to output left";
notification = false;
}
];
@ -238,7 +244,7 @@ in {
};
programs.fish.functions = {
update-lock-screen = {
update-lock-screen = lib.mkIf config.services.xserver.enable {
description = "Update lockscreen with wallpaper";
body = lockUpdate;
};
@ -247,17 +253,19 @@ in {
# Update lock screen cache only if cache is empty
home.activation.updateLockScreenCache =
let cacheDir = "${config.homePath}/.cache/betterlockscreen/current";
in config.home-manager.users.${config.user}.lib.dag.entryAfter
in lib.mkIf config.services.xserver.enable
(config.home-manager.users.${config.user}.lib.dag.entryAfter
[ "writeBoundary" ] ''
if [ ! -d ${cacheDir} ] || [ -z "$(ls ${cacheDir})" ]; then
$DRY_RUN_CMD ${lockUpdate}
fi
'';
'');
};
# Ref: https://github.com/betterlockscreen/betterlockscreen/blob/next/system/betterlockscreen%40.service
systemd.services.lock = {
enable = config.services.xserver.enable;
description = "Lock the screen on resume from suspend";
before = [ "sleep.target" "suspend.target" ];
serviceConfig = {

View File

@ -1,11 +1,11 @@
{ config, lib, ... }: {
config =
lib.mkIf (config.services.xserver.enable && config.gui.compositor.enable) {
config = lib.mkIf (config.services.xserver.enable) {
home-manager.users.${config.user} = {
services.picom = {
enable = true;
backend = "glx";
settings = {
blur = false;
blurExclude = [ ];

View File

@ -2,7 +2,7 @@
config = lib.mkIf config.services.xserver.enable {
gui.toggleBarCommand = "polybar-msg cmd toggle";
toggleBarCommand = "polybar-msg cmd toggle";
home-manager.users.${config.user} = {
@ -23,14 +23,14 @@
# offset-y = -5;
# offset-y = "5%";
# dpi = 96;
background = config.colorscheme.base01;
foreground = config.colorscheme.base05;
background = config.theme.colors.base01;
foreground = config.theme.colors.base05;
line-size = "3pt";
border-top-size = 0;
border-right-size = 0;
border-left-size = 0;
border-bottom-size = "4pt";
border-color = config.colorscheme.base00;
border-color = config.theme.colors.base00;
padding-left = 2;
padding-right = 2;
module-margin = 1;
@ -58,35 +58,35 @@
fuzzy-match = true;
format = "<label-state> <label-mode>";
label-focused = "%name%";
label-focused-foreground = config.colorscheme.base01;
label-focused-background = config.colorscheme.base05;
label-focused-underline = config.colorscheme.base03;
label-focused-foreground = config.theme.colors.base01;
label-focused-background = config.theme.colors.base05;
label-focused-underline = config.theme.colors.base03;
label-focused-padding = padding;
label-unfocused = "%name%";
label-unfocused-padding = padding;
label-visible = "%name%";
label-visible-underline = config.colorscheme.base01;
label-visible-underline = config.theme.colors.base01;
label-visible-padding = padding;
label-urgent = "%name%";
label-urgent-foreground = config.colorscheme.base00;
label-urgent-background = config.colorscheme.base08;
label-urgent-underline = config.colorscheme.base0F;
label-urgent-foreground = config.theme.colors.base00;
label-urgent-background = config.theme.colors.base08;
label-urgent-underline = config.theme.colors.base0F;
label-urgent-padding = padding;
};
"module/xworkspaces" = {
type = "internal/xworkspaces";
label-active = "%name%";
label-active-background = config.colorscheme.base05;
label-active-foreground = config.colorscheme.base01;
label-active-underline = config.colorscheme.base03;
label-active-background = config.theme.colors.base05;
label-active-foreground = config.theme.colors.base01;
label-active-underline = config.theme.colors.base03;
label-active-padding = 1;
label-occupied = "%name%";
label-occupied-padding = 1;
label-urgent = "%name%";
label-urgent-background = config.colorscheme.base08;
label-urgent-background = config.theme.colors.base08;
label-urgent-padding = 1;
label-empty = "%name%";
label-empty-foreground = config.colorscheme.base06;
label-empty-foreground = config.theme.colors.base06;
label-empty-padding = 1;
};
"module/xwindow" = {
@ -108,10 +108,10 @@
format-volume = "<ramp-volume> <label-volume>";
# format-volume-background = colors.background;
# label-volume-background = colors.background;
format-volume-foreground = config.colorscheme.base0B;
format-volume-foreground = config.theme.colors.base0B;
label-volume = "%percentage%%";
label-muted = " ---";
label-muted-foreground = config.colorscheme.base03;
label-muted-foreground = config.theme.colors.base03;
ramp-volume-0 = "";
ramp-volume-1 = "";
ramp-volume-2 = "";
@ -163,7 +163,7 @@
date = "%d %b %l:%M %p";
date-alt = "%Y-%m-%d %H:%M:%S";
label = "%date%";
label-foreground = config.colorscheme.base0A;
label-foreground = config.theme.colors.base0A;
# format-background = colors.background;
};
"settings" = {

View File

@ -25,19 +25,19 @@
# Inspired by https://github.com/sherubthakur/dotfiles/blob/master/users/modules/desktop-environment/rofi/launcher.rasi
"*" = {
background-color = mkLiteral config.colorscheme.base00;
foreground-color = mkLiteral config.colorscheme.base07;
text-color = mkLiteral config.colorscheme.base07;
border-color = mkLiteral config.colorscheme.base04;
background-color = mkLiteral config.theme.colors.base00;
foreground-color = mkLiteral config.theme.colors.base07;
text-color = mkLiteral config.theme.colors.base07;
border-color = mkLiteral config.theme.colors.base04;
};
# Holds the entire window
"#window" = {
transparency = "real";
background-color = mkLiteral config.colorscheme.base00;
text-color = mkLiteral config.colorscheme.base07;
background-color = mkLiteral config.theme.colors.base00;
text-color = mkLiteral config.theme.colors.base07;
border = mkLiteral "4px";
border-color = mkLiteral config.colorscheme.base04;
border-color = mkLiteral config.theme.colors.base04;
border-radius = mkLiteral "4px";
width = mkLiteral "850px";
padding = mkLiteral "15px";
@ -45,10 +45,10 @@
# Wrapper around bar and results
"#mainbox" = {
background-color = mkLiteral config.colorscheme.base00;
background-color = mkLiteral config.theme.colors.base00;
border = mkLiteral "0px";
border-radius = mkLiteral "0px";
border-color = mkLiteral config.colorscheme.base04;
border-color = mkLiteral config.theme.colors.base04;
children = map mkLiteral [ "inputbar" "listview" ];
spacing = mkLiteral "10px";
padding = mkLiteral "10px";
@ -59,7 +59,7 @@
expand = false;
str = ":";
margin = mkLiteral "0px 0.3em 0em 0em";
text-color = mkLiteral config.colorscheme.base07;
text-color = mkLiteral config.theme.colors.base07;
};
# Command prompt left of the input
@ -67,7 +67,7 @@
# Actual text box
"#entry" = {
placeholder-color = mkLiteral config.colorscheme.base03;
placeholder-color = mkLiteral config.theme.colors.base03;
expand = true;
horizontal-align = "0";
placeholder = "Launch Program";
@ -85,7 +85,7 @@
# Results
"#listview" = {
background-color = mkLiteral config.colorscheme.base00;
background-color = mkLiteral config.theme.colors.base00;
padding = mkLiteral "0px";
columns = 1;
lines = 12;
@ -104,9 +104,9 @@
"#element.selected" = {
border = mkLiteral "1px";
border-radius = mkLiteral "4px";
border-color = mkLiteral config.colorscheme.base07;
background-color = mkLiteral config.colorscheme.base04;
text-color = mkLiteral config.colorscheme.base00;
border-color = mkLiteral config.theme.colors.base07;
background-color = mkLiteral config.theme.colors.base04;
text-color = mkLiteral config.theme.colors.base00;
};
"#element-text" = {
@ -116,8 +116,8 @@
margin = mkLiteral "0px 2.5px 0px 2.5px";
};
"#element-text.selected" = {
background-color = mkLiteral config.colorscheme.base04;
text-color = mkLiteral config.colorscheme.base00;
background-color = mkLiteral config.theme.colors.base04;
text-color = mkLiteral config.theme.colors.base00;
};
# Not sure how to get icons
@ -125,11 +125,11 @@
size = mkLiteral "18px";
border = mkLiteral "0px";
padding = mkLiteral "2px 5px 2px 2px";
background-color = mkLiteral config.colorscheme.base00;
background-color = mkLiteral config.theme.colors.base00;
};
"#element-icon.selected" = {
background-color = mkLiteral config.colorscheme.base04;
text-color = mkLiteral config.colorscheme.base00;
background-color = mkLiteral config.theme.colors.base04;
text-color = mkLiteral config.theme.colors.base00;
};
};
@ -144,9 +144,9 @@
};
gui.launcherCommand = "${pkgs.rofi}/bin/rofi -show run -modi run";
gui.systemdSearch = "${pkgs.rofi-systemd}/bin/rofi-systemd";
gui.altTabCommand = "${pkgs.rofi}/bin/rofi -show window -modi window";
launcherCommand = "${pkgs.rofi}/bin/rofi -show run -modi run";
systemdSearch = "${pkgs.rofi-systemd}/bin/rofi-systemd";
altTabCommand = "${pkgs.rofi}/bin/rofi -show window -modi window";
};

View File

@ -1,15 +1,25 @@
{ config, pkgs, lib, ... }:
{ config, pkgs, lib, ... }: {
let
gtkTheme = {
name = config.gui.gtk.theme.name;
package = pkgs.${config.gui.gtk.theme.package};
options = {
gtk.theme = {
name = lib.mkOption {
type = lib.types.str;
description = "Theme name for GTK applications";
};
package = lib.mkOption {
type = lib.types.str;
description = "Theme package name for GTK applications";
default = "gnome-themes-extra";
};
};
};
in {
config = lib.mkIf config.gui.enable {
config = let
gtkTheme = {
name = config.gtk.theme.name;
package = pkgs."${config.gtk.theme.package}";
};
in lib.mkIf config.gui.enable {
# Enable the X11 windowing system.
services.xserver = {
@ -22,11 +32,16 @@ in {
displayManager = {
lightdm = {
enable = config.services.xserver.enable;
background = config.gui.wallpaper;
background = config.wallpaper;
# Make the login screen dark
greeters.gtk.theme = gtkTheme;
# Show default user
extraSeatDefaults = ''
greeter-hide-users = false
'';
};
};
@ -41,7 +56,7 @@ in {
services.dbus.packages = [ pkgs.dconf ];
programs.dconf.enable = true;
environment.sessionVariables = { GTK_THEME = config.gui.gtk.theme.name; };
environment.sessionVariables = { GTK_THEME = config.gtk.theme.name; };
home-manager.users.${config.user} = {
@ -50,7 +65,10 @@ in {
pbpaste = "xclip -selection clipboard -out";
};
gtk = let gtkExtraConfig = { gtk-application-prefer-dark-theme = true; };
gtk = let
gtkExtraConfig = {
gtk-application-prefer-dark-theme = config.theme.dark;
};
in {
enable = true;
theme = gtkTheme;

View File

@ -33,8 +33,11 @@ in {
config = lib.mkIf config.gui.enable {
sound.enable = true;
# Enable PulseAudio
hardware.pulseaudio.enable = true;
# Enable PipeWire
services.pipewire = {
enable = true;
pulse.enable = true;
};
# These aren't necessary, but helpful for the user
environment.systemPackages = with pkgs; [
@ -52,7 +55,8 @@ in {
# Make sure that Volnoti actually starts (home-manager doesn't start
# user daemon's automatically)
startup = [{
command = "systemctl --user restart volnoti";
command =
"systemctl --user restart volnoti --alpha 0.15 --radius 40 --timeout 0.2";
always = true;
notification = false;
}];

View File

@ -10,6 +10,9 @@
# Check for other OSes and make them available
useOSProber = true;
# Attempt to display GRUB on widescreen monitor
gfxmodeEfi = "1920x1080";
# Install GRUB onto the boot disk
# device = config.fileSystems."/boot".device;

View File

@ -0,0 +1,7 @@
{ config, ... }: {
# Servers need a bootloader or they won't start
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
}

187
modules/mail/aerc.nix Normal file
View File

@ -0,0 +1,187 @@
{ config, pkgs, ... }: {
config = {
home-manager.users.${config.user} = {
home.packages = with pkgs; [
w3m # Render HTML
dante # Socksify for rendering HTML
];
programs.aerc = {
enable = true;
extraBinds = {
# Binds are of the form <key sequence> = <command to run>
# To use '=' in a key sequence, substitute it with "Eq": "<Ctrl+Eq>"
# If you wish to bind #, you can wrap the key sequence in quotes: "#" = quit
global = {
"<C-p>" = ":prev-tab<Enter>";
"<C-n>" = ":next-tab <Enter>";
"<C-t>" = ":term<Enter>";
"?" = ":help keys<Enter>";
};
messages = {
q = ":quit<Enter>";
j = ":next <Enter>";
"<Down>" = ":next<Enter>";
"<C-d>" = ":next 50%<Enter>";
"<C-f>" = ":next 100%<Enter>";
"<PgDn>" = ":next 100%<Enter>";
k = ":prev <Enter>";
"<Up>" = ":prev<Enter>";
"<C-u>" = ":prev 50%<Enter>";
"<C-b>" = ":prev 100%<Enter>";
"<PgUp>" = ":prev 100%<Enter>";
g = ":select 0 <Enter>";
G = ":select -1<Enter>";
J = ":next-folder <Enter>";
K = ":prev-folder<Enter>";
H = ":collapse-folder<Enter>";
L = ":expand-folder<Enter>";
v = ":mark -t<Enter>";
V = ":mark -v<Enter>";
T = ":toggle-threads<Enter>";
"<Enter>" = ":view<Enter>";
d = ":prompt 'Really delete this message?' 'delete-message'<Enter>";
D = ":move Trash<Enter>";
A = ":archive flat<Enter>";
C = ":compose<Enter>";
rr = ":reply -a<Enter>";
rq = ":reply -aq<Enter>";
Rr = ":reply<Enter>";
Rq = ":reply -q<Enter>";
c = ":cf<space>";
"$" = ":term<space>";
"!" = ":term<space>";
"|" = ":pipe<space>";
"/" = ":search<space>";
"\\" = ":filter <space>";
n = ":next-result<Enter>";
N = ":prev-result<Enter>";
"<Esc>" = ":clear<Enter>";
};
"messages:folder=Drafts" = { "<Enter>" = ":recall<Enter>"; };
view = {
"/" = ":toggle-key-passthrough <Enter> /";
q = ":close<Enter>";
O = ":open<Enter>";
S = ":save<space>";
"|" = ":pipe<space>";
D = ":move Trash<Enter>";
A = ":archive flat<Enter>";
"<C-l>" = ":open-link <space>";
f = ":forward <Enter>";
rr = ":reply -a<Enter>";
rq = ":reply -aq<Enter>";
Rr = ":reply<Enter>";
Rq = ":reply -q<Enter>";
H = ":toggle-headers<Enter>";
"<C-k>" = ":prev-part<Enter>";
"<C-j>" = ":next-part<Enter>";
J = ":next <Enter>";
K = ":prev<Enter>";
};
"view::passthrough" = {
"$noinherit" = "true";
"$ex" = "<C-x>";
"<Esc>" = ":toggle-key-passthrough<Enter>";
};
compose = {
# Keybindings used when the embedded terminal is not selected in the compose
# view
"$noinherit" = "true";
"$ex" = "<C-x>";
"<C-k>" = ":prev-field<Enter>";
"<C-j>" = ":next-field<Enter>";
"<A-p>" = ":switch-account -p<Enter>";
"<A-n>" = ":switch-account -n<Enter>";
"<tab>" = ":next-field<Enter>";
"<C-p>" = ":prev-tab<Enter>";
"<C-n>" = ":next-tab<Enter>";
};
"compose::editor" = {
# Keybindings used when the embedded terminal is selected in the compose view
"$noinherit" = "true";
"$ex" = "<C-x>";
"<C-k>" = ":prev-field<Enter>";
"<C-j>" = ":next-field<Enter>";
"<C-p>" = ":prev-tab<Enter>";
"<C-n>" = ":next-tab<Enter>";
};
"compose::review" = {
# Keybindings used when reviewing a message to be sent
y = ":send <Enter>";
n = ":abort<Enter>";
p = ":postpone<Enter>";
q = ":choose -o d discard abort -o p postpone postpone<Enter>";
e = ":edit<Enter>";
a = ":attach<space>";
d = ":detach<space>";
};
terminal = {
"$noinherit" = "true";
"$ex" = "<C-x>";
"<C-p>" = ":prev-tab<Enter>";
"<C-n>" = ":next-tab<Enter>";
};
};
extraConfig = {
general.unsafe-accounts-conf = true;
viewer = { pager = "${pkgs.less}/bin/less -R"; };
filters = {
"text/plain" =
"${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/colorize";
"text/calendar" =
"${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/calendar";
"text/html" =
"${pkgs.aerc}/share/aerc/filters/html"; # Requires w3m, dante
# "text/html" =
# "${pkgs.aerc}/share/aerc/filters/html | ${pkgs.aerc}/share/aerc/filters/colorize";
# "text/*" =
# ''${pkgs.bat}/bin/bat -fP --file-name="$AERC_FILENAME "'';
"message/delivery-status" =
"${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/colorize";
"message/rfc822" =
"${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/colorize";
"application/x-sh" = "${pkgs.bat}/bin/bat -fP -l sh";
"application/pdf" = "${pkgs.zathura}/bin/zathura -";
};
};
};
accounts.email.accounts.home.aerc = {
enable = true;
extraAccounts = {
check-mail = "5m";
check-mail-cmd = "${pkgs.isync}/bin/mbsync -a";
};
};
programs.fish.shellAbbrs = { ae = "aerc"; };
};
};
}

83
modules/mail/default.nix Normal file
View File

@ -0,0 +1,83 @@
{ config, pkgs, lib, ... }: {
imports = [ ./himalaya.nix ./aerc.nix ];
options = {
mailUser = lib.mkOption {
type = lib.types.str;
description = "User name for the email address.";
default = config.user;
};
mailServer = lib.mkOption {
type = lib.types.str;
description = "Server name for the email address.";
};
};
config = {
home-manager.users.${config.user} = {
programs.mbsync = { enable = true; };
services.mbsync = lib.mkIf pkgs.stdenv.isLinux {
enable = true;
frequency = "*:0/5";
};
accounts.email = {
maildirBasePath = "${config.homePath}/mail";
accounts = {
home = let address = "${config.mailUser}@${config.mailServer}";
in {
userName = address;
realName = config.fullName;
primary = true;
inherit address;
aliases = map (mailUser: "${mailUser}@${config.mailServer}") [
"me"
"hey"
"admin"
];
alot = { };
flavor = "plain";
folders = { };
getmail = { };
imap = {
host = "imap.purelymail.com";
port = 993;
tls.enable = true;
};
imapnotify = {
enable = false;
boxes = [ ];
onNotify = "";
onNotifyPost = "";
};
maildir = { path = "main"; };
mbsync = {
enable = true;
create = "maildir";
expunge = "none";
remove = "none";
patterns = [ "*" ];
extraConfig.channel = {
CopyArrivalDate = "yes"; # Sync time of original message
};
};
mu.enable = false;
notmuch.enable = false;
passwordCommand =
"${pkgs.age}/bin/age --decrypt --identity ${config.identityFile} ${
builtins.toString ../../private/mailpass.age
}";
smtp = {
host = "smtp.purelymail.com";
port = 465;
tls.enable = true;
};
};
};
};
};
};
}

View File

@ -1,89 +1,19 @@
{ config, pkgs, lib, ... }: {
options = {
mailUser = lib.mkOption {
type = lib.types.str;
description = "User name for the email address.";
default = config.user;
};
mailServer = lib.mkOption {
type = lib.types.str;
description = "Server name for the email address.";
};
};
{ config, ... }: {
config = {
home-manager.users.${config.user} = {
programs.himalaya = { enable = true; };
programs.mbsync = { enable = true; };
services.mbsync = lib.mkIf pkgs.stdenv.isLinux {
enable = true;
frequency = "*:0/5";
};
accounts.email = {
maildirBasePath = "${config.homePath}/mail";
accounts = {
home = let address = "${config.mailUser}@${config.mailServer}";
in {
userName = address;
realName = config.fullName;
primary = true;
inherit address;
aliases = map (mailUser: "${mailUser}@${config.mailServer}") [
"me"
"hey"
"admin"
];
alot = { };
flavor = "plain";
folders = { };
getmail = { };
himalaya = {
accounts.email.accounts.home.himalaya = {
enable = true;
settings = {
backend = "imap";
sender = "smtp";
downloads-dir = config.userDirs.download;
smtp-insecure = true;
};
};
imap = {
host = "imap.purelymail.com";
port = 993;
tls.enable = true;
};
imapnotify = {
enable = false;
boxes = [ ];
onNotify = "";
onNotifyPost = "";
};
maildir = { path = "main"; };
mbsync = {
enable = true;
create = "maildir";
expunge = "none";
remove = "none";
patterns = [ "*" ];
extraConfig.channel = {
CopyArrivalDate = "yes"; # Sync time of original message
};
};
mu.enable = false;
notmuch.enable = false;
passwordCommand =
"${pkgs.age}/bin/age --decrypt --identity ${config.homePath}/.ssh/id_ed25519 ${
builtins.toString ./mailpass.age
}";
smtp = {
host = "smtp.purelymail.com";
port = 465;
tls.enable = true;
};
};
};
};
programs.fish.shellAbbrs = { hi = "himalaya"; };

View File

@ -1,5 +0,0 @@
age-encryption.org/v1
-> ssh-ed25519 MgHaOw 8h/ESNjn0gknNXoHM34UobHzPgmRunoP97H+KHOuGQM
qowH+6TlCRECGCscRgKx6kswY+PZezYUD6E+x9e+5pM
--- kFj1JzRdh/D13Uq9aNTzMJIFysEE+kzzthjewOIR2+o
Ȳ<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>}rC<72>z<><7A><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@ -5,6 +5,8 @@
home.packages = with pkgs; [
neovim
gcc # for tree-sitter
tree-sitter # for tree-sitter-gitignore parser
nodejs # for tree-sitter-gitignore parser
shfmt # used everywhere
shellcheck # used everywhere
];
@ -15,7 +17,12 @@
source = ./lua;
recursive = true; # Allows adding more files
};
"nvim/lua/packer/colors.lua".source = config.colorscheme.neovimConfig;
"nvim/lua/packer/colors.lua".source = config.theme.colors.neovimConfig;
"nvim/lua/background.lua".text = ''
vim.cmd("set background=${
if config.theme.dark == true then "dark" else "light"
}")
'';
};
programs.git.extraConfig.core.editor = "nvim";

View File

@ -1,3 +1,4 @@
require("packer_init")
require("settings")
require("keybinds")
require("background")

View File

@ -14,8 +14,7 @@ M.packer = function(use)
return vim.fn.executable(program) == 1
end
local capabilities =
require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
local capabilities = require("cmp_nvim_lsp").default_capabilities()
if on_path("lua-language-server") then
require("lspconfig").sumneko_lua.setup({
capabilities = capabilities,
@ -80,6 +79,7 @@ M.packer = function(use)
return vim.fn.executable(program) == 1
end
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
require("null-ls").setup({
sources = {
require("null-ls").builtins.formatting.stylua.with({
@ -133,15 +133,15 @@ M.packer = function(use)
-- require("null-ls").builtins.diagnostics.pylint,
},
-- Format on save
on_attach = function(client)
if client.resolved_capabilities.document_formatting then
local id = vim.api.nvim_create_augroup("LspFormatting", {
clear = true,
})
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = id,
pattern = "*",
callback = vim.lsp.buf.formatting_seq_sync,
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end,

View File

@ -29,7 +29,39 @@ M.packer = function(use)
})
-- Markdown renderer / wiki notes
use("vimwiki/vimwiki")
-- use("vimwiki/vimwiki")
use({
"jakewvincent/mkdnflow.nvim",
config = function()
require("mkdnflow").setup({
modules = {
bib = false,
conceal = true,
folds = false,
},
perspective = {
priority = "current",
fallback = "first",
nvim_wd_heel = false, -- Don't change working dir
},
links = {
style = "markdown",
conceal = true,
},
wrap = true,
to_do = {
symbols = { " ", "-", "x" },
},
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.o.autowriteall = true -- Save in new buffer
vim.o.wrapmargin = 79 -- Wrap text automatically
end,
})
end,
})
end
return M

View File

@ -8,49 +8,6 @@ M.packer = function(use)
require("impatient")
end,
})
-- Improve speed and filetype detection
use({
"nathom/filetype.nvim",
config = function()
-- Filetype for .env files
local envfiletype = function()
vim.bo.filetype = "text"
vim.bo.syntax = "sh"
end
-- Force filetype patterns that Vim doesn't know about
require("filetype").setup({
overrides = {
extensions = {
Brewfile = "brewfile",
muttrc = "muttrc",
tfvars = "terraform",
tf = "terraform",
},
literal = {
Caskfile = "brewfile",
[".gitignore"] = "gitignore",
config = "config",
},
complex = {
[".*git/config"] = "gitconfig",
["tmux.conf%..*link"] = "tmux",
["gitconfig%..*link"] = "gitconfig",
[".*ignore%..*link"] = "gitignore",
[".*%.toml%..*link"] = "toml",
},
function_extensions = {},
function_literal = {
[".envrc"] = envfiletype,
[".env"] = envfiletype,
[".env.dev"] = envfiletype,
[".env.prod"] = envfiletype,
[".env.example"] = envfiletype,
},
},
})
end,
})
end
return M

View File

@ -8,7 +8,7 @@ M.packer = function(use)
-- Syntax engine
use({
"nvim-treesitter/nvim-treesitter",
commit = "989c75046c46d2ed96bb65c5badd6b8f785e7f09",
commit = "9ada5f70f98d51e9e3e76018e783b39fd1cd28f7",
run = ":TSUpdate",
config = function()
require("nvim-treesitter.configs").setup({

View File

@ -16,7 +16,29 @@ M.packer = function(use)
vim.keymap.set("v", "<Leader>gd", gitsigns.diffthis)
vim.keymap.set("n", "<Leader>rgf", gitsigns.reset_buffer)
vim.keymap.set("v", "<Leader>hs", gitsigns.stage_hunk)
vim.keymap.set("v", "<Leader>hs", gitsigns.reset_hunk)
vim.keymap.set("v", "<Leader>hr", gitsigns.reset_hunk)
vim.keymap.set("v", "<Leader>hr", gitsigns.reset_hunk)
-- Navigation
vim.keymap.set("n", "]g", function()
if vim.wo.diff then
return "]g"
end
vim.schedule(function()
gitsigns.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
vim.keymap.set("n", "[g", function()
if vim.wo.diff then
return "[g"
end
vim.schedule(function()
gitsigns.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
end,
})
@ -102,7 +124,6 @@ M.packer = function(use)
},
view = {
width = 30,
height = 30,
hide_root_folder = false,
side = "left",
mappings = {

View File

@ -32,8 +32,6 @@ vim.opt.completeopt = {
"menuone",
"noselect",
}
-- Required until 0.6.0: do not source the default filetype.vim
vim.g.did_load_filetypes = 1
-- Remember last position when reopening file
vim.api.nvim_exec(
@ -77,40 +75,16 @@ vim.api.nvim_exec(
false
)
vim.api.nvim_create_autocmd("FileType", {
pattern = "*.eml",
callback = function()
vim.o.wrapmargin = 79 -- Wrap text automatically
end,
})
-- Netrw
vim.g.netrw_liststyle = 3 -- Change style to 'tree' view
vim.g.netrw_banner = 0 -- Remove useless banner
vim.g.netrw_winsize = 15 -- Explore window takes % of page
vim.g.netrw_browse_split = 4 -- Open in previous window
vim.g.netrw_altv = 1 -- Always split left
-- VimWiki
vim.g.vimwiki_list = {
{
["path"] = "$NOTES_PATH",
["syntax"] = "markdown",
["index"] = "home",
["ext"] = ".md",
},
}
vim.g.vimwiki_key_mappings = {
["all_maps"] = 1,
["mouse"] = 1,
}
vim.g.vimwiki_auto_chdir = 1 -- Set local dir to Wiki when open
vim.g.vimwiki_create_link = 0 -- Don't automatically create new links
vim.g.vimwiki_listsyms = " x" -- Set checkbox symbol progression
vim.g.vimwiki_table_mappings = 0 -- VimWiki table keybinds interfere with tab completion
vim.api.nvim_exec(
[[
au FileType markdown inoremap ;tt <Esc>:AddTag<CR>
function! PInsert(item)
let @z=a:item
norm "zpx
endfunction
command! AddTag call fzf#run({'source': 'rg "#[A-Za-z/]+[ |\$]" -o --no-filename --no-line-number | sort | uniq', 'sink': function('PInsert')})
]],
false
)

View File

@ -3,8 +3,9 @@
options = {
passwordHash = lib.mkOption {
type = lib.types.str;
type = lib.types.nullOr lib.types.str;
description = "Password created with mkpasswd -m sha-512";
# Test it by running: mkpasswd -m sha-512 --salt "PZYiMGmJIIHAepTM"
};
};

View File

@ -2,7 +2,13 @@
home-manager.users.${config.user} = {
home.packages = with pkgs; [ kubectl k9s ];
home.packages = with pkgs; [
kubectl # Basic Kubernetes queries
k9s # Terminal Kubernetes UI
kubernetes-helm # Helm CLI
fluxcd # Bootstrap clusters with Flux
kustomize # Kustomize CLI (for Flux)
];
programs.fish.shellAbbrs = {
k = "kubectl";

View File

@ -3,7 +3,7 @@
home-manager.users.${config.user} = {
home.sessionVariables = {
NOTES_PATH = "${config.homePath}/dev/personal/notes";
NOTES_PATH = "${config.homePath}/dev/personal/notes/content";
};
};

View File

@ -0,0 +1,66 @@
{ config, pkgs, lib, ... }: {
imports = [ ./secrets.nix ];
options = {
backupS3 = {
endpoint = lib.mkOption {
type = lib.types.str;
description = "S3 endpoint for backups";
};
bucket = lib.mkOption {
type = lib.types.str;
description = "S3 bucket for backups";
};
accessKeyId = lib.mkOption {
type = lib.types.str;
description = "S3 access key ID for backups";
};
};
};
config = {
users.groups.backup = { };
secrets.backup = {
source = ../../private/backup.age;
dest = "${config.secretsDirectory}/backup";
group = "backup";
permissions = "0440";
};
users.users.litestream.extraGroups = [ "backup" ];
services.litestream = {
enable = true;
environmentFile = config.secrets.backup.dest;
};
# Wait for secret to exist
systemd.services.litestream = {
after = [ "backup-secret.service" ];
requires = [ "backup-secret.service" ];
environment.AWS_ACCESS_KEY_ID = config.backupS3.accessKeyId;
};
# # Backup library to object storage
# services.restic.backups.calibre = {
# user = "calibre-web";
# repository =
# "s3://${config.backupS3.endpoint}/${config.backupS3.bucket}/calibre";
# paths = [
# "/var/books"
# "/var/lib/calibre-web/app.db"
# "/var/lib/calibre-web/gdrive.db"
# ];
# initialize = true;
# timerConfig = { OnCalendar = "00:05:00"; };
# environmentFile = backupS3File;
# };
};
}

View File

@ -0,0 +1,35 @@
{ config, pkgs, lib, ... }: {
options = {
caddyRoutes = lib.mkOption {
type = lib.types.listOf lib.types.attrs;
description = "Caddy JSON routes for http servers";
};
caddyBlocks = lib.mkOption {
type = lib.types.listOf lib.types.attrs;
description = "Caddy JSON error blocks for http servers";
default = [ ];
};
};
config = {
services.caddy = {
enable = true;
adapter = "''"; # Required to enable JSON
configFile = pkgs.writeText "Caddyfile" (builtins.toJSON {
apps.http.servers.main = {
listen = [ ":443" ];
routes = config.caddyRoutes;
errors.routes = config.caddyBlocks;
};
});
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
networking.firewall.allowedUDPPorts = [ 443 ];
};
}

View File

@ -0,0 +1,74 @@
{ config, pkgs, lib, ... }: {
imports = [ ./caddy.nix ./backups.nix ];
options = {
bookServer = lib.mkOption {
type = lib.types.str;
description = "Hostname for Calibre library";
};
};
config = {
services.calibre-web = {
enable = true;
openFirewall = true;
options = {
reverseProxyAuth.enable = false;
enableBookConversion = true;
enableBookUploading = true;
};
};
# Fix: https://github.com/janeczku/calibre-web/issues/2422
nixpkgs.overlays = [
(final: prev: {
calibre-web = prev.calibre-web.overrideAttrs (old: {
patches = (old.patches or [ ])
++ [ ../../patches/calibre-web-cloudflare.patch ];
});
})
];
caddyRoutes = [{
match = [{ host = [ config.bookServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8083"; }];
headers.request.add."X-Script-Name" = [ "/calibre-web" ];
}];
}];
# Run a backup on a schedule
systemd.timers.calibre-backup = {
timerConfig = {
OnCalendar = "*-*-* 00:00:00"; # Once per day
Unit = "calibre-backup.service";
};
wantedBy = [ "timers.target" ];
};
# Backup Calibre data to object storage
systemd.services.calibre-backup =
let libraryPath = "/var/lib/calibre-web"; # Default location
in {
description = "Backup Calibre data";
environment.AWS_ACCESS_KEY_ID = config.backupS3.accessKeyId;
serviceConfig = {
Type = "oneshot";
User = "calibre-web";
Group = "backup";
EnvironmentFile = config.secrets.backup.dest;
};
script = ''
${pkgs.awscli2}/bin/aws s3 sync \
${libraryPath}/ \
s3://${config.backupS3.bucket}/calibre/ \
--endpoint-url=https://${config.backupS3.endpoint}
'';
};
};
}

View File

@ -0,0 +1,56 @@
# This module is necessary for hosts that are serving through Cloudflare.
{ ... }:
let
cloudflareIpRanges = [
# Cloudflare IPv4: https://www.cloudflare.com/ips-v4
"173.245.48.0/20"
"103.21.244.0/22"
"103.22.200.0/22"
"103.31.4.0/22"
"141.101.64.0/18"
"108.162.192.0/18"
"190.93.240.0/20"
"188.114.96.0/20"
"197.234.240.0/22"
"198.41.128.0/17"
"162.158.0.0/15"
"104.16.0.0/13"
"104.24.0.0/14"
"172.64.0.0/13"
"131.0.72.0/22"
# Cloudflare IPv6: https://www.cloudflare.com/ips-v6
"2400:cb00::/32"
"2606:4700::/32"
"2803:f800::/32"
"2405:b500::/32"
"2405:8100::/32"
"2a06:98c0::/29"
"2c0f:f248::/32"
];
in {
imports = [ ./caddy.nix ];
config = {
# Forces Caddy to error if coming from a non-Cloudflare IP
caddyBlocks = [{
match = [{ not = [{ remote_ip.ranges = cloudflareIpRanges; }]; }];
handle = [{
handler = "static_response";
abort = true;
}];
}];
# Allows Nextcloud to trust Cloudflare IPs
services.nextcloud.config.trustedProxies = cloudflareIpRanges;
};
}

View File

@ -0,0 +1,93 @@
{ config, lib, ... }:
let giteaPath = "/var/lib/gitea"; # Default service directory
in {
imports = [ ./caddy.nix ./backups.nix ];
options = {
giteaServer = lib.mkOption {
description = "Hostname for Gitea.";
type = lib.types.str;
};
};
config = {
services.gitea = {
enable = true;
httpPort = 3001;
httpAddress = "127.0.0.1";
rootUrl = "https://${config.giteaServer}/";
database.type = "sqlite3";
settings = {
repository = {
DEFAULT_PUSH_CREATE_PRIVATE = true;
DISABLE_HTTP_GIT = false;
ACCESS_CONTROL_ALLOW_ORIGIN = config.giteaServer;
ENABLE_PUSH_CREATE_USER = true;
ENABLE_PUSH_CREATE_ORG = true;
DEFAULT_BRANCH = "main";
};
server = {
SSH_PORT = 22;
START_SSH_SERVER = false; # Use sshd instead
DISABLE_SSH = false;
# SSH_LISTEN_HOST = "0.0.0.0";
# SSH_LISTEN_PORT = 122;
};
service.DISABLE_REGISTRATION = true;
session.COOKIE_SECURE = true;
ui.SHOW_USER_EMAIL = false;
};
extraConfig = null;
};
networking.firewall.allowedTCPPorts = [ 122 ];
caddyRoutes = [{
match = [{ host = [ config.giteaServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:3001"; }];
}];
}];
## Backup config
# Open to groups, allowing for backups
systemd.services.gitea.serviceConfig.StateDirectoryMode =
lib.mkForce "0770";
systemd.tmpfiles.rules = [
"d ${giteaPath}/data 0775 gitea gitea"
"f ${giteaPath}/data/gitea.db 0660 gitea gitea"
];
# Allow litestream and gitea to share a sqlite database
users.users.litestream.extraGroups = [ "gitea" ];
users.users.gitea.extraGroups = [ "litestream" ];
# Backup sqlite database with litestream
services.litestream = {
settings = {
dbs = [{
path = "${giteaPath}/data/gitea.db";
replicas = [{
url =
"s3://${config.backupS3.bucket}.${config.backupS3.endpoint}/gitea";
}];
}];
};
};
# Don't start litestream unless gitea is up
systemd.services.litestream = {
after = [ "gitea.service" ];
requires = [ "gitea.service" ];
};
};
}

View File

@ -0,0 +1,75 @@
{ lib, pkgs, ... }:
# Currently has some issues that don't make this viable.
# Taken from:
# https://dataswamp.org/~solene/2022-09-29-iblock-implemented-in-nixos.html
# You will need to flush all rules when removing:
# https://serverfault.com/questions/200635/best-way-to-clear-all-iptables-rules
let
portsToBlock = [ 25545 25565 25570 ];
portsString =
builtins.concatStringsSep "," (builtins.map builtins.toString portsToBlock);
# Block IPs for 20 days
expire = 60 * 60 * 24 * 20;
rules = table: [
"INPUT -i eth0 -p tcp -m multiport --dports ${portsString} -m state --state NEW -m recent --set"
"INPUT -i eth0 -p tcp -m multiport --dports ${portsString} -m state --state NEW -m recent --update --seconds 10 --hitcount 1 -j SET --add-set ${table} src"
"INPUT -i eth0 -p tcp -m set --match-set ${table} src -j nixos-fw-refuse"
"INPUT -i eth0 -p udp -m set --match-set ${table} src -j nixos-fw-refuse"
];
create-rules = lib.concatStringsSep "\n"
(builtins.map (rule: "iptables -C " + rule + " || iptables -A " + rule)
(rules "blocked") ++ builtins.map
(rule: "ip6tables -C " + rule + " || ip6tables -A " + rule)
(rules "blocked6"));
delete-rules = lib.concatStringsSep "\n"
(builtins.map (rule: "iptables -C " + rule + " && iptables -D " + rule)
(rules "blocked") ++ builtins.map
(rule: "ip6tables -C " + rule + " && ip6tables -D " + rule)
(rules "blocked6"));
in {
networking.firewall = {
extraPackages = [ pkgs.ipset ];
# allowedTCPPorts = portsToBlock;
# Restore ban list when starting up
extraCommands = ''
if test -f /var/lib/ipset.conf
then
ipset restore -! < /var/lib/ipset.conf
else
ipset -exist create blocked hash:ip ${
if expire > 0 then "timeout ${toString expire}" else ""
}
ipset -exist create blocked6 hash:ip family inet6 ${
if expire > 0 then "timeout ${toString expire}" else ""
}
fi
${create-rules}
'';
# Save list when shutting down
extraStopCommands = ''
ipset -exist create blocked hash:ip ${
if expire > 0 then "timeout ${toString expire}" else ""
}
ipset -exist create blocked6 hash:ip family inet6 ${
if expire > 0 then "timeout ${toString expire}" else ""
}
ipset save > /var/lib/ipset.conf
${delete-rules}
'';
};
}

View File

@ -0,0 +1,30 @@
{ config, lib, ... }: {
options = {
streamServer = lib.mkOption {
type = lib.types.str;
description = "Hostname for Jellyfin library";
};
};
config = {
services.jellyfin.enable = true;
caddyRoutes = [{
match = [{ host = [ config.streamServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8096"; }];
}];
}];
# Create videos directory, allow anyone in Jellyfin group to manage it
systemd.tmpfiles.rules = [
"d /var/lib/jellyfin 0775 jellyfin jellyfin"
"d /var/lib/jellyfin/library 0775 jellyfin jellyfin"
];
};
}

View File

@ -0,0 +1,14 @@
{ config, pkgs, lib, ... }: {
config = {
services.netdata = {
enable = true;
# Disable local dashboard (unsecured)
config = { web.mode = "none"; };
};
};
}

View File

@ -0,0 +1,87 @@
{ config, pkgs, lib, ... }: {
imports = [ ./caddy.nix ./secrets.nix ./backups.nix ];
options = {
nextcloudServer = lib.mkOption {
type = lib.types.str;
description = "Hostname for Nextcloud";
};
};
config = {
services.nextcloud = {
enable = true;
package = pkgs.nextcloud24; # Required to specify
https = true;
hostName = "localhost";
maxUploadSize = "50G";
config = {
adminpassFile = config.secrets.nextcloud.dest;
extraTrustedDomains = [ config.nextcloudServer ];
};
};
# Don't let Nginx use main ports (using Caddy instead)
services.nginx.virtualHosts."localhost".listen = [{
addr = "127.0.0.1";
port = 8080;
}];
# Point Caddy to Nginx
caddyRoutes = [{
match = [{ host = [ config.nextcloudServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8080"; }];
}];
}];
# Create credentials file for nextcloud
secrets.nextcloud = {
source = ../../private/nextcloud.age;
dest = "${config.secretsDirectory}/nextcloud";
owner = "nextcloud";
group = "nextcloud";
permissions = "0440";
};
systemd.services.nextcloud-secret = {
requiredBy = [ "nextcloud-setup.service" ];
before = [ "nextcloud-setup.service" ];
};
## Backup config
# Open to groups, allowing for backups
systemd.services.phpfpm-nextcloud.serviceConfig.StateDirectoryMode =
lib.mkForce "0770";
# Allow litestream and nextcloud to share a sqlite database
users.users.litestream.extraGroups = [ "nextcloud" ];
users.users.nextcloud.extraGroups = [ "litestream" ];
# Backup sqlite database with litestream
services.litestream = {
settings = {
dbs = [{
path = "${config.services.nextcloud.datadir}/data/nextcloud.db";
replicas = [{
url =
"s3://${config.backupS3.bucket}.${config.backupS3.endpoint}/nextcloud";
}];
}];
};
};
# Don't start litestream unless nextcloud is up
systemd.services.litestream = {
after = [ "phpfpm-nextcloud.service" ];
requires = [ "phpfpm-nextcloud.service" ];
};
};
}

View File

@ -0,0 +1,30 @@
{ config, pkgs, lib, ... }: {
options.metricsServer = lib.mkOption {
type = lib.types.str;
description = "Hostname of the Grafana server.";
};
config = {
services.grafana.enable = true;
services.prometheus = {
enable = true;
exporters.node.enable = true;
scrapeConfigs = [{
job_name = "local";
static_configs = [{ targets = [ "127.0.0.1:9100" ]; }];
}];
};
caddyRoutes = [{
match = [{ host = [ config.metricsServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:3000"; }];
}];
}];
};
}

View File

@ -0,0 +1,91 @@
# Secrets management method taken from here:
# https://xeiaso.net/blog/nixos-encrypted-secrets-2021-01-20
# In my case, I pre-encrypt my secrets and commit them to git.
{ config, pkgs, lib, ... }: {
options = {
secretsDirectory = lib.mkOption {
type = lib.types.str;
description = "Default path to place secrets.";
default = "/var/private";
};
secrets = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
options = {
source = lib.mkOption {
type = lib.types.path;
description = "Path to encrypted secret.";
};
dest = lib.mkOption {
type = lib.types.str;
description = "Resulting path for decrypted secret.";
};
owner = lib.mkOption {
default = "root";
type = lib.types.str;
description = "User to own the secret.";
};
group = lib.mkOption {
default = "root";
type = lib.types.str;
description = "Group to own the secret.";
};
permissions = lib.mkOption {
default = "0400";
type = lib.types.str;
description = "Permissions expressed as octal.";
};
};
});
description = "Set of secrets to decrypt to disk.";
default = { };
};
};
config = {
# Create a default directory to place secrets
systemd.tmpfiles.rules = [ "d ${config.secretsDirectory} 0755 root wheel" ];
# Declare oneshot service to decrypt secret using SSH host key
# - Requires that the secret is already encrypted for the host
# - Encrypt secrets: nix run github:nmasur/dotfiles#encrypt-secret
systemd.services = lib.mapAttrs' (name: attrs: {
name = "${name}-secret";
value = {
description = "Decrypt secret for ${name}";
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script = ''
${pkgs.age}/bin/age --decrypt \
--identity ${config.identityFile} \
--output ${attrs.dest} \
${attrs.source}
chown '${attrs.owner}':'${attrs.group}' '${attrs.dest}'
chmod '${attrs.permissions}' '${attrs.dest}'
'';
};
}) config.secrets;
# Example declaration
# config.secrets.my-secret = {
# source = ../../private/my-secret.age;
# dest = "/var/lib/private/my-secret";
# owner = "my-app";
# group = "my-app";
# permissions = "0440";
# };
};
}

36
modules/services/sshd.nix Normal file
View File

@ -0,0 +1,36 @@
{ config, pkgs, lib, ... }: {
options = {
publicKey = lib.mkOption {
type = lib.types.str;
description = "Public SSH key authorized for this system.";
};
permitRootLogin = lib.mkOption {
type = lib.types.str;
description = "Root login settings.";
default = "no";
};
};
config = {
services.openssh = {
enable = true;
ports = [ 22 ];
passwordAuthentication = false;
gatewayPorts = "no";
forwardX11 = false;
allowSFTP = true;
permitRootLogin = config.permitRootLogin;
};
users.users.${config.user}.openssh.authorizedKeys.keys =
[ config.publicKey ];
# Implement a simple fail2ban service for sshd
services.sshguard.enable = true;
# Add terminfo for SSH from popular terminal emulators
environment.enableAllTerminfo = true;
};
}

View File

@ -0,0 +1,79 @@
{ config, pkgs, lib, ... }: {
imports = [ ./wireguard.nix ./secrets.nix ];
options = {
transmissionServer = lib.mkOption {
type = lib.types.str;
description = "Hostname for Transmission";
};
};
config = let
namespace = config.networking.wireguard.interfaces.wg0.interfaceNamespace;
vpnIp = lib.strings.removeSuffix "/32"
(builtins.head config.networking.wireguard.interfaces.wg0.ips);
in {
# Setup transmission
services.transmission = {
enable = true;
settings = {
port-forwarding-enabled = false;
rpc-authentication-required = true;
rpc-port = 9091;
rpc-bind-address = "0.0.0.0";
rpc-username = config.user;
rpc-host-whitelist = config.transmissionServer;
rpc-host-whitelist-enabled = true;
rpc-whitelist = "127.0.0.1,${vpnIp}";
rpc-whitelist-enabled = true;
};
credentialsFile = config.secrets.transmission.dest;
};
# Bind transmission to wireguard namespace
systemd.services.transmission = {
bindsTo = [ "netns@${namespace}.service" ];
requires = [ "network-online.target" "transmission-secret.service" ];
after = [ "wireguard-wg0.service" "transmission-secret.service" ];
unitConfig.JoinsNamespaceOf = "netns@${namespace}.service";
serviceConfig.NetworkNamespacePath = "/var/run/netns/${namespace}";
};
# Create reverse proxy for web UI
caddyRoutes = [{
match = [{ host = [ config.transmissionServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:9091"; }];
}];
}];
# Allow inbound connections to reach namespace
systemd.services.transmission-web-netns = {
description = "Forward to transmission in wireguard namespace";
requires = [ "transmission.service" ];
after = [ "transmission.service" ];
serviceConfig = {
Restart = "on-failure";
TimeoutStopSec = 300;
};
wantedBy = [ "multi-user.target" ];
script = ''
${pkgs.iproute2}/bin/ip netns exec ${namespace} ${pkgs.iproute2}/bin/ip link set dev lo up
${pkgs.socat}/bin/socat tcp-listen:9091,fork,reuseaddr exec:'${pkgs.iproute2}/bin/ip netns exec ${namespace} ${pkgs.socat}/bin/socat STDIO "tcp-connect:${vpnIp}:9091"',nofork
'';
};
# Create credentials file for transmission
secrets.transmission = {
source = ../../private/transmission.json.age;
dest = "${config.secretsDirectory}/transmission.json";
owner = "transmission";
group = "transmission";
};
};
}

View File

@ -0,0 +1,123 @@
{ config, pkgs, lib, ... }:
let vaultwardenPath = "/var/lib/bitwarden_rs"; # Default service directory
in {
imports = [ ./caddy.nix ./secrets.nix ./backups.nix ];
options = {
vaultwardenServer = lib.mkOption {
description = "Hostname for Vaultwarden.";
type = lib.types.str;
};
};
config = {
services.vaultwarden = {
enable = true;
config = {
DOMAIN = "https://${config.vaultwardenServer}";
SIGNUPS_ALLOWED = false;
SIGNUPS_VERIFY = true;
INVITATIONS_ALLOWED = true;
WEB_VAULT_ENABLED = true;
ROCKET_ADDRESS = "127.0.0.1";
ROCKET_PORT = 8222;
WEBSOCKET_ENABLED = true;
WEBSOCKET_ADDRESS = "0.0.0.0";
WEBSOCKET_PORT = 3012;
LOGIN_RATELIMIT_SECONDS = 60;
LOGIN_RATELIMIT_MAX_BURST = 10;
ADMIN_RATELIMIT_SECONDS = 300;
ADMIN_RATELIMIT_MAX_BURST = 3;
};
environmentFile = config.secrets.vaultwarden.dest;
dbBackend = "sqlite";
};
secrets.vaultwarden = {
source = ../../private/vaultwarden.age;
dest = "${config.secretsDirectory}/vaultwarden";
owner = "vaultwarden";
group = "vaultwarden";
};
networking.firewall.allowedTCPPorts = [ 3012 ];
caddyRoutes = [{
match = [{ host = [ config.vaultwardenServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8222"; }];
}];
}];
## Backup config
# Open to groups, allowing for backups
systemd.services.vaultwarden.serviceConfig.StateDirectoryMode =
lib.mkForce "0770";
systemd.tmpfiles.rules = [
"f ${vaultwardenPath}/db.sqlite3 0660 vaultwarden vaultwarden"
"f ${vaultwardenPath}/db.sqlite3-shm 0660 vaultwarden vaultwarden"
"f ${vaultwardenPath}/db.sqlite3-wal 0660 vaultwarden vaultwarden"
];
# Allow litestream and vaultwarden to share a sqlite database
users.users.litestream.extraGroups = [ "vaultwarden" ];
users.users.vaultwarden.extraGroups = [ "litestream" ];
# Backup sqlite database with litestream
services.litestream = {
settings = {
dbs = [{
path = "${vaultwardenPath}/db.sqlite3";
replicas = [{
url =
"s3://${config.backupS3.bucket}.${config.backupS3.endpoint}/vaultwarden";
}];
}];
};
};
# Don't start litestream unless vaultwarden is up
systemd.services.litestream = {
after = [ "vaultwarden.service" ];
requires = [ "vaultwarden.service" ];
};
# Run a separate file backup on a schedule
systemd.timers.vaultwarden-backup = {
timerConfig = {
OnCalendar = "*-*-* 06:00:00"; # Once per day
Unit = "vaultwarden-backup.service";
};
wantedBy = [ "timers.target" ];
};
# Backup other Vaultwarden data to object storage
systemd.services.vaultwarden-backup = {
description = "Backup Vaultwarden files";
environment.AWS_ACCESS_KEY_ID = config.backupS3.accessKeyId;
serviceConfig = {
Type = "oneshot";
User = "vaultwarden";
Group = "backup";
EnvironmentFile = config.secrets.backup.dest;
};
script = ''
${pkgs.awscli2}/bin/aws s3 sync \
${vaultwardenPath}/ \
s3://${config.backupS3.bucket}/vaultwarden/ \
--endpoint-url=https://${config.backupS3.endpoint} \
--exclude "*db.sqlite3*" \
--exclude ".db.sqlite3*"
'';
};
};
}

View File

@ -1,18 +1,44 @@
{ ... }: {
{ config, pkgs, lib, ... }: {
imports = [ ./secrets.nix ];
config = {
networking.wireguard = {
enable = true;
interfaces = {
wg0 = {
ips = [ "10.66.127.235/32" "fc00:bbbb:bbbb:bb01::3:7fea/128" ];
generatePrivateKeyFile = true;
privateKeyFile = "/private/wireguard/wg0";
peers = [{
publicKey = "cVDIYPzNChIeANp+0jE12kWM5Ga1MbmNErT1Pmaf12A=";
allowedIPs = [ "0.0.0.0/0" "::0/0" ];
endpoint = "89.46.62.197:51820";
persistentKeepalive = 25;
}];
# Establishes identity of this machine
generatePrivateKeyFile = false;
privateKeyFile = config.secrets.wireguard.dest;
# Move to network namespace for isolating programs
interfaceNamespace = "wg";
};
};
};
# Create namespace for Wireguard
# This allows us to isolate specific programs to Wireguard
systemd.services."netns@" = {
description = "%I network namespace";
before = [ "network.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.iproute2}/bin/ip netns add %I";
ExecStop = "${pkgs.iproute2}/bin/ip netns del %I";
};
};
# Create private key file for wireguard
secrets.wireguard = {
source = ../../private/wireguard.age;
dest = "${config.secretsDirectory}/wireguard";
};
};
}

View File

@ -1,5 +0,0 @@
{ config, pkgs, ... }: {
home-manager.users.${config.user}.home.packages = with pkgs; [ age ];
}

View File

@ -1,5 +1,4 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p tesseract
#!/usr/bin/env bash
# Yoinked from https://github.com/JJGO/dotfiles
# Adapted from https://github.com/sdushantha/bin
@ -9,13 +8,13 @@ TEXT_FILE="/tmp/ocr.txt"
IMAGE_FILE="/tmp/ocr.png"
function notify-send() {
osascript -e "display notification \"$2\" with title \"OCR\""
/usr/bin/osascript -e "display notification \"$2\" with title \"OCR\""
}
PATH="/usr/local/bin/:$PATH"
# Take screenshot by selecting the area
screencapture -i "$IMAGE_FILE"
/usr/sbin/screencapture -i "$IMAGE_FILE"
# Get the exit code of the previous command.
# So in this case, it is the screenshot command. If it did not exit with an
@ -44,7 +43,7 @@ fi
# Copy text to clipboard
# xclip -selection clip < "$TEXT_FILE"
pbcopy <"$TEXT_FILE"
/usr/bin/pbcopy <"$TEXT_FILE"
# Send a notification with the text that was grabbed using OCR
notify-send "ocr" "$(cat $TEXT_FILE)"

13
modules/shell/charm.nix Normal file
View File

@ -0,0 +1,13 @@
{ config, pkgs, ... }: {
home-manager.users.${config.user} = {
home.packages = with pkgs; [
glow # Markdown previews
skate # Key-value store
charm # Manage account and filesystem
];
};
}

View File

@ -1,6 +1,6 @@
{ ... }: {
imports = [
./age.nix
./charm.nix
./direnv.nix
./fish
./fzf.nix

View File

@ -7,10 +7,11 @@
home-manager.users.${config.user} = {
# Packages used in abbreviations and aliases
home.packages = with pkgs; [ curl ];
home.packages = with pkgs; [ curl exa ];
programs.fish = {
enable = true;
shellAliases = { ls = "exa"; };
functions = {
commandline-git-commits = {
description = "Insert commit into commandline";
@ -41,7 +42,6 @@
description = "Tidy up JSON using jq";
body = "pbpaste | jq '.' | pbcopy"; # Need to fix for non-macOS
};
ls = { body = "${pkgs.exa}/bin/exa $argv"; };
note = {
description = "Edit or create a note";
argumentNames = "filename";

View File

@ -14,7 +14,7 @@ bind -M insert \cp projects
bind -M default \cp projects
bind -M insert \x1F accept-autosuggestion
bind -M default \x1F accept-autosuggestion
bind -M insert \cn 'commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#"'
bind -M default \cn 'commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#"'
bind -M insert \cn 'commandline -r "nix run nixpkgs#"'
bind -M default \cn 'commandline -r "nix run nixpkgs#"'
bind -M insert \x11F nix-fzf
bind -M default \x11F nix-fzf

View File

@ -1,25 +1,27 @@
{ config, pkgs, ... }: {
{ config, pkgs, lib, ... }: {
home-manager.users.${config.user} = {
programs.fish = {
shellAbbrs = {
n = "nix";
ns = "nix-shell --run fish -p";
ns = "nix-shell -p";
nsf = "nix-shell --run fish -p";
nsr = "nix-shell-run";
nps = "nix repl '<nixpkgs>'";
nixo = "man configuration.nix";
nixh = "man home-configuration.nix";
nr = "rebuild-nixos";
nro = "rebuild-nixos offline";
hm = "rebuild-home";
};
functions = {
nix-shell-run = {
body = ''
set program $argv[1]
if test (count $argv) -ge 2
commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#$program -- $argv[2..-1]"
commandline -r "nix run nixpkgs#$program -- $argv[2..-1]"
else
commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#$program"
commandline -r "nix run nixpkgs#$program"
end
commandline -f execute
'';
@ -38,7 +40,14 @@
set option "--option substitute false"
end
git -C ${config.dotfilesPath} add --intent-to-add --all
commandline -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}"
commandline -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}#${config.networking.hostName}"
commandline --function execute
'';
};
rebuild-home = {
body = ''
git -C ${config.dotfilesPath} add --intent-to-add --all
commandline -r "${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#${config.networking.hostName}";
commandline --function execute
'';
};

View File

@ -9,6 +9,7 @@
"$git_branch"
"$git_commit"
"$git_status"
"$hostname"
"$cmd_duration"
"$character"
];
@ -47,6 +48,10 @@
deleted = "";
style = "red";
};
hostname = {
ssh_only = true;
format = "on [$hostname](bold red) ";
};
nix_shell = {
format = "[$symbol $name]($style)";
symbol = "";

View File

@ -31,6 +31,8 @@ in {
vimv-rs # Batch rename files
dig # DNS lookup
lf # File viewer
# whois # Lookup IPs
age # Encryption
];
programs.zoxide.enable = true; # Shortcut jump command

View File

@ -1,20 +0,0 @@
T2 Palo Alto CA
-----BEGIN CERTIFICATE-----
MIIDIjCCAgqgAwIBAgIJAOE7K8F61qxbMA0GCSqGSIb3DQEBCwUAMEExCzAJBgNV
BAYTAlVTMQswCQYDVQQIEwJOWTELMAkGA1UECxMCSVQxGDAWBgNVBAMTD1QyIFBh
bG8gQWx0byBDQTAeFw0xNTA3MTUyMzUzNDJaFw0yNTA3MTIyMzUzNDJaMEExCzAJ
BgNVBAYTAlVTMQswCQYDVQQIEwJOWTELMAkGA1UECxMCSVQxGDAWBgNVBAMTD1Qy
IFBhbG8gQWx0byBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANBa
nVZxAhk+spmp8JBzwtgPS+2oQ/Kpv7BRWn7Rj52oAL++a4DH2zRLb3f4mMyPpgEX
nNrvZSkonxJToEMhAed5eIKNOjcwDT8kLatfmE/LHD4xNeK0FN0p0OlTJkwLI5KZ
rne/YKqkYscYfjxyugYPb3ukjYfxeGNfeF9HGKTPAcL+fj0/fgkffJJPZ+d9+C2Z
YXXI36DoXEjHUPxOz/hKL5ohM4m86OHt6qvZaG/b43raI99ckRFTwmoF+AfdIgVa
3cuaxhnGyv+bC41LTxd1Azzys0txfxkFrt14oBUgOmPJelC26KgFoHnG8hSykNaH
Uh8S8i8jmXgEdUN+bGkCAwEAAaMdMBswDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMC
AgQwDQYJKoZIhvcNAQELBQADggEBAAqFo1P7Btgt9BZRpwmjA8ghQmQZQ9Fek1m2
aOmkPMa6OqWxXDT5VU/b02LfKb+uVLsdBC1cv7ZrRYZc7ATt8d19rohvSn7DL8GR
FEjYgj1OFvblbN8zHogDVx4gD57j9imT40vNpBcsEiRlNXDu/ExbhsDiing1tdmq
eULdQg13kdJzqVS6xJ10qddqRRUWASkq5qUwvTO2MQkCjPSGjUAHeHa9vCZRiVWQ
vWVwZ7CZ6XTzqcpfKdT/xKGHbT6xQxIhLVOvSMIhirh8OyFVzM5m+PHYN4KO6x5j
+Je/viLhvfaEVUntOkOcpQVmwOYZezQZqDDRWXo9k0vqGnZ8Gog=
-----END CERTIFICATE-----

View File

@ -0,0 +1,25 @@
diff --git a/cps/__init__.py b/cps/__init__.py
index 0b912d23..ad5d1fa9 100644
--- a/cps/__init__.py
+++ b/cps/__init__.py
@@ -83,7 +83,6 @@ app.config.update(
lm = MyLoginManager()
lm.login_view = 'web.login'
lm.anonymous_user = ub.Anonymous
-lm.session_protection = 'strong'
if wtf_present:
csrf = CSRFProtect()
diff --git a/cps/admin.py b/cps/admin.py
index 1004ee78..e295066e 100644
--- a/cps/admin.py
+++ b/cps/admin.py
@@ -98,8 +98,6 @@ def before_request():
# make remember me function work
if current_user.is_authenticated:
confirm_login()
- if not ub.check_user_session(current_user.id, flask_session.get('_id')) and 'opds' not in request.path:
- logout_user()
g.constants = constants
g.user = current_user
g.allow_registration = config.config_public_reg

10
private/backup.age Normal file
View File

@ -0,0 +1,10 @@
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IE1nSGFPdyBmVEo2
bExsZERhYi9vVXMxVThRK2w3dFR4UlZVcGlsWUFPM3pReTQwaW5ZCjQ5Z3g3amZC
bWUwWkdKTStVbFpwMmdwK3pQQU5CeE5tMVNHbXI1UkdCTFUKLT4gc3NoLWVkMjU1
MTkgWXlTVU1RIE9sTG1lOHIyVGdLNWtJRTZtdGNWWEFsTTJ5bE1HS1V2MEdKeGNN
WFMyV28KVlRHdDg5SGFadVlJempKWkp6eEp6TkhINnl0R0xDL0J0WXByclpFWE5I
VQotLS0gVVhaUDZLTy8xS3hKOVliSlpuTEY2Q2xOQUEvblBtUG9Vb0I5ZE1oOUZ1
VQr18Jwx6XDa7bwq0QWT6NdIFzqNUHWhDyUvS9twncFsr0yEAUDQd2XLtE+Vc8T9
Z7y/C8Ct5+duqd6YaeqROJz5zVj0NnI0lshirBl89PQWF9ihp4V4Hw==
-----END AGE ENCRYPTED FILE-----

10
private/mailpass.age Normal file
View File

@ -0,0 +1,10 @@
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IE1nSGFPdyBIRnEy
am1HTXptMmpSTjZQa2hQSUxNUU1rdXlod3U3bVZ0VGxQVlE2WldBClg0K3k5MDZH
NFlPdHI0VnZSZE9DTTNMeDdldUpFQ3V0V0k0RnRIZHFhdzAKLT4gc3NoLWVkMjU1
MTkgWXlTVU1RIFlxZFpqNU5kNVY2VUk0Um0zZ1d1M2FlRkYvV1BoTEFSNjZ2Vk9I
QTVHM0UKY2gvVU9wckVUNEFwdUwyVFJZUGwxOFFKYm12cUlFTEVrb3IvcXI3TnND
UQotLS0gMHdaajFjV2ozd0g5dWN5YkhiU2NBVWZVSU00aVIzY0VKYjJleVlQTUdX
QQo7rH6kOTRFP43U/qiBOCHx+hBGlaODFRS1CgzkuqfMOq8PM28RsIN+l3sbwjxE
W8chE/A0EChjIDtfYTMgsN3cYg==
-----END AGE ENCRYPTED FILE-----

10
private/nextcloud.age Normal file
View File

@ -0,0 +1,10 @@
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IE1nSGFPdyBudkxn
ZzU1YVViYUZBWVVTYm1SeHpvanQ5M0YwVGo2YldlN2RwY0tscWpBCjd0ZmtLZ2th
dEMrQk5QV0EzT0RpVkg5bGo1cHdTNzVYVkZpVzE4aHR0azgKLT4gc3NoLWVkMjU1
MTkgWXlTVU1RIFlqaEI2QUNnMjR1T0FENXJIMEJWOUFJUXZ4SlJxbUFnQktWUW9w
UFlmUUkKL1RwaWxoNFM4SkpadWtyN3JnWHdjVTYrQmo0dU9JUnp0MjN5enVsUm9o
ZwotLS0gWUd2eTR2VGkyeTZ5cHNuanMrSlZKVmc4T1ZORExmUnhDSjN0NEJkNjkz
cwriuyYCgvJe7TRi3n/JwxIRKMsoh7+xj4B5Fdxuj3BOtKVi1geSjlDHVklRwu9Y
IMCTLqQtj08JnuLfDezRGHAYCM8=
-----END AGE ENCRYPTED FILE-----

1
private/password.sha512 Normal file
View File

@ -0,0 +1 @@
$6$PZYiMGmJIIHAepTM$Wx5EqTQ5GApzXx58nvi8azh16pdxrN6Qrv1wunDlzveOgawitWzcIxuj76X9V868fsPi/NOIEO8yVXqwzS9UF.

Some files were not shown because too many files have changed in this diff Show More