config/profiles/code-remote/default.nix

224 lines
8.3 KiB
Nix
Raw Normal View History

2023-03-09 21:13:18 +01:00
{ config, pkgs, lib, inputs, ... }:
2022-10-17 22:40:48 +02:00
2023-02-24 21:36:30 +01:00
# TODO:
2023-03-19 04:24:33 +01:00
# * [x] ~~generate a ssh key if not existing~~
# * [ ] prompt to make a token using 'gh'?
# * [ ] possibly store some key using nix-sops
# * [ ] automatically pull the repo on first boot
2023-02-24 21:36:30 +01:00
# * [ ] customize the shit out of vscode
2023-03-09 21:13:18 +01:00
# * [ ] don't ignore PDFs
2023-03-19 04:24:33 +01:00
# * [ ] fix the taskrunner
# * [ ] fix the markdown preview not opening when prompted
2023-03-09 21:13:18 +01:00
# * [ ] run the whole thing in a xvfb? should enable drawio and curv
2023-03-19 04:24:33 +01:00
# * [ ] switch to openvscode-server? https://sourcegraph.com/github.com/bendlas/nixos-config/-/blob/code-server.container.nix?L39%3A26=
# https://github.com/coder/code-server/discussions/4267
2023-02-24 21:36:30 +01:00
2022-10-17 22:40:48 +02:00
let
2023-03-09 21:13:18 +01:00
hostName = config.networking.hostName;
2023-03-19 04:24:33 +01:00
subdomain = "code-server.${config.networking.fqdn}";
2023-03-09 21:13:18 +01:00
container-name = "code-server-pandoc-papers";
container = config.containers.${container-name}.config;
2022-10-17 22:40:48 +02:00
in {
2023-03-19 04:24:33 +01:00
networking.nat.enable = true;
networking.nat.internalInterfaces = ["ve-+"];
networking.nat.externalInterface = "eno1"; # TODO: can i make this automatic?
#networking.nat.enableIPv6 = true;
2022-10-17 22:40:48 +02:00
#imports = [
# "/home/pbsds/repos/nixpkgs-trees/containers-mkdir/nixos/modules/virtualisation/nixos-containers.nix"
#];
#disabledModules = [
# "virtualisation/nixos-containers.nix"
#];
2023-02-24 21:36:30 +01:00
# data can be destroyed with `nixos-container destroy code-server-pandoc`
containers.${container-name} = {
2022-10-17 22:40:48 +02:00
autoStart = true;
# container has no network access
privateNetwork = true;
2023-03-09 21:13:18 +01:00
hostAddress = "10.240.100.2";
2022-10-17 22:40:48 +02:00
localAddress = "10.240.100.3";
2023-03-19 18:42:21 +01:00
#nixpkgs = inputs.unstable;
config = let host-cfg = config; in { config, pkgs, lib, ... }: {
nixpkgs.overlays = host-cfg.nixpkgs.overlays;
2023-03-09 21:13:18 +01:00
system.stateVersion = "22.11";
2023-06-11 10:12:42 +02:00
nixpkgs.config.permittedInsecurePackages = [
"nodejs-16.20.0" # TODO: remove
];
2022-10-17 22:40:48 +02:00
2023-03-19 04:24:33 +01:00
imports = [ inputs.home-manager.nixosModule ];
home-manager.useGlobalPkgs = true; # brrr
home-manager.useUserPackages = true; # required, installs user packages to /etc instead of ~/.nix-profile
home-manager.users.${config.services.code-server.user} = { pkgs, config, ... }: {
home.stateVersion = "22.11";
programs.git.enable = true;
programs.git.userName = "code-server";
programs.git.userEmail = "pbsds@hotmail.com";
#programs.vscode.extensions
#programs.vscode.bindings
#programs.vscode.userSettings
};
2022-10-17 22:40:48 +02:00
2023-02-24 21:36:30 +01:00
systemd.services.initial-setup = {
2023-03-09 21:13:18 +01:00
enable = true;
wantedBy = [ "code-server.service" ];
before = [ "code-server.service" ];
2023-02-24 21:36:30 +01:00
# TODO: run as the correct user
serviceConfig.User = config.services.code-server.user;
serviceConfig.Group = config.services.code-server.group;
2023-03-09 21:13:18 +01:00
2023-02-24 21:36:30 +01:00
# TODO: make the ssh key comment automatic
script = ''
2023-03-09 21:13:18 +01:00
test -s "$HOME/.ssh/id_ed25519.pub" || {
test -d "$HOME/.ssh" || mkdir -p "$HOME/.ssh"
echo "" | ${pkgs.openssh}/bin/ssh-keygen -t ed25519 -a 100 -C "code-server@code-server-pandoc-${hostName}" -f "$HOME/.ssh/id_ed25519"
2023-02-24 21:36:30 +01:00
echo
}
2023-03-09 21:13:18 +01:00
echo "My pubkey is:"
cat "$HOME/.ssh/id_ed25519.pub"
2023-02-24 21:36:30 +01:00
#${pkgs.curl}/bin/curl "https://github.com/pbsds.keys" | grep "$(cat $HOME/.ssh/id_ed25519.pub | cut -d" " -f-2)"
2023-03-09 21:13:18 +01:00
test -d "$HOME/repo" || (
set -x
cp -a ${inputs.pbsds-papers.outPath} "$HOME/repo"
2023-03-19 04:24:33 +01:00
chmod -R +w "$HOME/repo"
)
test -e "$HOME/repo/neural-intersection-fields/.vscode" || (
2023-03-09 21:13:18 +01:00
cd "$HOME/repo/neural-intersection-fields"
ln -s ../.vscode .
)
2023-03-19 04:24:33 +01:00
if test -d "$HOME/repo/.git"; then
( cd $HOME/repo; git pull --rebase --autostash ) # TODO: somehow rollback if failed
fi
2023-02-24 21:36:30 +01:00
'';
};
2022-10-17 22:40:48 +02:00
services.code-server = {
enable = true;
host = "0.0.0.0"; # container
port = 53754;
2023-03-09 21:13:18 +01:00
#user = "code-server";
2023-02-24 21:36:30 +01:00
#group = "code.server";
2023-03-09 21:13:18 +01:00
2023-02-24 21:36:30 +01:00
# a nice tool if you don't care about security: https://argon2.online/
hashedPassword = "$argon2i$v=19$m=16,t=2,p=1$MHh5UGNtU1lWR1UySnhIZw$ITg8U7Gq2CXByuOOnrKVUg"; # hunter2
2023-03-09 21:13:18 +01:00
extraArguments = [
"${config.users.users.${config.services.code-server.user}.home}/repo/neural-intersection-fields"
];
2022-10-17 22:40:48 +02:00
package = pkgs.vscode-with-extensions.override {
2023-03-19 18:42:21 +01:00
#vscode = pkgs.code-server.overrideAttrs (old: {
vscode = pkgs.unstable.code-server.overrideAttrs (old: {
2023-02-24 21:36:30 +01:00
# vscode-with-extensions compatibility
# https://github.com/NixOS/nixpkgs/pull/192889
2022-10-17 22:40:48 +02:00
passthru.executableName = "code-server";
passthru.longName = "Visual Studio Code Server";
});
2023-03-19 04:24:33 +01:00
#vscodeExtensions = with pkgs.unstable.vscode-extensions; [
2023-02-24 21:36:30 +01:00
vscodeExtensions = with pkgs.vscode-extensions; [
2023-03-19 18:42:21 +01:00
#shd101wyy.markdown-preview-enhanced
2023-03-19 04:24:33 +01:00
sanaajani.taskrunnercode # doesn't work?
tomoki1207.pdf # no firefox?
2022-10-17 22:40:48 +02:00
] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
2023-03-19 18:42:21 +01:00
{
name = "markdown-preview-enhanced";
publisher = "shd101wyy";
#version = "0.6.7";
#sha256 = "5tgxpjkpbgv8HcfLBbDcOOEd8swinK5iHtnO34892ik=";
version = "0.6.8";
sha256 = "9NRaHgtyiZJ0ic6h1B01MWzYhDABAl3Jm2IUPogYWr0=";
}
/* === */
2022-10-17 22:40:48 +02:00
{
name = "new-railscasts";
publisher = "carakan";
version = "1.0.68";
sha256 = "sha256-uZCAurvZu7QHjTR6ukmYbsI58GpfTo3shdoX/MH2ElA=";
}
{
name = "theme-railscasts";
publisher = "PaulOlteanu";
version = "4.0.1";
sha256 = "sha256-67RNcMr+hvzn2FvapkHLd8OdEBAz8w4cwsGlu0tbCNY=";
}
{
name = "trailscasts";
publisher = "mksafi";
version = "1.2.3";
sha256 = "sha256-mZ9I1BYf8x3lpl5/2sojk+5GMfhDqRBzs6nFkumlPKg=";
}
{
name = "vscode-theme-railscasts-plus";
publisher = "marlosirapuan";
version = "0.0.6";
sha256 = "sha256-8GyyxDeehFo/lGSmA6dfXZ3DMZ/B632ax+9q3+irjws=";
}
{
name = "theme-railscast-next";
publisher = "edus44";
version = "0.0.2";
sha256 = "sha256-RYk6X4iKoEQlKSVhydnwWQJqt884+HC9DZN2aqIbfNI=";
}
{ # best, but no markdown
name = "railscasts";
publisher = "mrded";
version = "0.0.4";
sha256 = "sha256-vjfoeRW+rmYlzSuEbYJqg41r03zSfbfuNCfAhHYyjDc=";
}
{
name = "beardedtheme";
publisher = "BeardedBear";
version = "7.4.0";
sha256 = "sha256-8FY9my7v7bcfD0LH5AVNGI2dF1qMLnVp2LR/CiP01NQ=";
}
];
};
2023-03-19 04:24:33 +01:00
extraPackages = (with pkgs; [
git gh hub
micro
]) ++ (let
2023-06-11 09:36:00 +02:00
#shell = import "${inputs.pbsds-papers}/shell.nix" { inherit pkgs; };
shell = inputs.pbsds-papers.devShells.${pkgs.system}.default;
2023-03-19 04:24:33 +01:00
in
(with pkgs; [ imagemagick librsvg ]) # for some reason it isn't picked up from from shell.nix?
++ shell.buildInputs
++ shell.nativeBuildInputs
++ shell.propagatedBuildInputs
++ shell.propagatedNativeBuildInputs
);
2022-10-17 22:40:48 +02:00
};
2023-03-19 04:24:33 +01:00
networking.firewall.enable = true;
networking.firewall.allowedTCPPorts = [
config.services.code-server.port
];
2022-10-17 22:40:48 +02:00
};
};
2023-03-19 04:24:33 +01:00
services.nginx.virtualHosts.${subdomain} = {
2022-10-17 22:40:48 +02:00
forceSSL = true; # addSSL = true;
enableACME = true; #useACMEHost = acmeDomain;
locations."/" = {
2023-03-09 21:13:18 +01:00
#proxyPass = "http://127.0.0.1:${toString container.services.code-server.port}";
#proxyPass = "http://10.240.100.3:${toString container.services.code-server.port}";
proxyPass = "http://${config.containers.${container-name}.localAddress}:${toString container.services.code-server.port}";
2022-10-17 22:40:48 +02:00
proxyWebsockets = true;
2023-06-11 09:36:00 +02:00
# https://github.com/coder/code-server/issues/4443
extraConfig = ''
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
'';
2022-10-17 22:40:48 +02:00
};
};
}