code-remote

This commit is contained in:
Peder Bergebakken Sundt 2023-03-19 04:24:33 +01:00
parent 18488deb72
commit a44486650a
1 changed files with 53 additions and 49 deletions

View File

@ -1,25 +1,29 @@
{ config, pkgs, lib, inputs, ... }: { config, pkgs, lib, inputs, ... }:
# TODO: # TODO:
# * [x] generate a ssh key if not existing # * [x] ~~generate a ssh key if not existing~~
# * [ ] automatically pull the repo on boot, do i need keys for that? # * [ ] prompt to make a token using 'gh'?
# * [ ] possibly store some key using nix-sops
# * [ ] automatically pull the repo on first boot
# * [ ] customize the shit out of vscode # * [ ] customize the shit out of vscode
# * [ ] don't ignore PDFs # * [ ] don't ignore PDFs
# * [ ] fix the taskrunner
# * [ ] fix the markdown preview not opening when prompted
# * [ ] run the whole thing in a xvfb? should enable drawio and curv # * [ ] run the whole thing in a xvfb? should enable drawio and curv
# * [ ] 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
let let
domain = "${config.networking.hostName}.${config.networking.domain}";
mkDomain = subname: "${subname}.${domain}";
hostName = config.networking.hostName; hostName = config.networking.hostName;
subdomain = "code-server.${config.networking.fqdn}";
container-name = "code-server-pandoc-papers"; container-name = "code-server-pandoc-papers";
container = config.containers.${container-name}.config; container = config.containers.${container-name}.config;
in { in {
networking.nat = { networking.nat.enable = true;
enable = true; networking.nat.internalInterfaces = ["ve-+"];
internalInterfaces = ["ve-+"]; networking.nat.externalInterface = "eno1"; # TODO: can i make this automatic?
externalInterface = "eno1"; # TODO: can i make this automatic? #networking.nat.enableIPv6 = true;
#enableIPv6 = true;
};
#imports = [ #imports = [
# "/home/pbsds/repos/nixpkgs-trees/containers-mkdir/nixos/modules/virtualisation/nixos-containers.nix" # "/home/pbsds/repos/nixpkgs-trees/containers-mkdir/nixos/modules/virtualisation/nixos-containers.nix"
@ -37,30 +41,21 @@ in {
hostAddress = "10.240.100.2"; hostAddress = "10.240.100.2";
localAddress = "10.240.100.3"; localAddress = "10.240.100.3";
#forwardPorts = [
# {
# #hostAddress = "127.0.0.1"; # does not exist
# hostPort = 53754;
# containerPort = 53754;
# protocol = "tcp";
# }
#];
#bindMounts."/home" = {
# hostPath = "/var/lib/code-server";
# isReadOnly = false;
#};
config = { config, pkgs, lib, ... }: { config = { config, pkgs, lib, ... }: {
system.stateVersion = "22.11"; system.stateVersion = "22.11";
#imports = [ <home-manager/nixos> ]; imports = [ inputs.home-manager.nixosModule ];
#home-manager.useGlobalPkgs = true; # brrr home-manager.useGlobalPkgs = true; # brrr
#home-manager.useUserPackages = true; # requiredm installs user packages to /etc instead of ~/.nix-profile 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-manager.users.${config.services.code-server.user} = { pkgs, config, ... }: {
# programs.git.enable = true; home.stateVersion = "22.11";
# programs.git.userName = "Noximilien code-server"; programs.git.enable = true;
# programs.git.userEmail = "theotheo@ntnu.no"; programs.git.userName = "code-server";
#}; programs.git.userEmail = "pbsds@hotmail.com";
#programs.vscode.extensions
#programs.vscode.bindings
#programs.vscode.userSettings
};
systemd.services.initial-setup = { systemd.services.initial-setup = {
enable = true; enable = true;
@ -86,10 +81,16 @@ in {
test -d "$HOME/repo" || ( test -d "$HOME/repo" || (
set -x set -x
cp -a ${inputs.pbsds-papers.outPath} "$HOME/repo" cp -a ${inputs.pbsds-papers.outPath} "$HOME/repo"
chmod -R a+w "$HOME/repo" chmod -R +w "$HOME/repo"
)
test -e "$HOME/repo/neural-intersection-fields/.vscode" || (
cd "$HOME/repo/neural-intersection-fields" cd "$HOME/repo/neural-intersection-fields"
ln -s ../.vscode . ln -s ../.vscode .
) )
if test -d "$HOME/repo/.git"; then
( cd $HOME/repo; git pull --rebase --autostash ) # TODO: somehow rollback if failed
fi
''; '';
}; };
@ -114,11 +115,11 @@ in {
passthru.executableName = "code-server"; passthru.executableName = "code-server";
passthru.longName = "Visual Studio Code Server"; passthru.longName = "Visual Studio Code Server";
}); });
#vscodeExtensions = with (import <nixos-unstable> {}).vscode-extensions; [ #vscodeExtensions = with pkgs.unstable.vscode-extensions; [
vscodeExtensions = with pkgs.vscode-extensions; [ vscodeExtensions = with pkgs.vscode-extensions; [
shd101wyy.markdown-preview-enhanced shd101wyy.markdown-preview-enhanced
sanaajani.taskrunnercode sanaajani.taskrunnercode # doesn't work?
tomoki1207.pdf tomoki1207.pdf # no firefox?
] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [ ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
{ {
name = "new-railscasts"; name = "new-railscasts";
@ -164,25 +165,28 @@ in {
} }
]; ];
}; };
extraPackages = let extraPackages = (with pkgs; [
shellnix = import "${inputs.pbsds-papers}/shell.nix" { inherit pkgs; }; git gh hub
in (with pkgs; [ imagemagick ]) # for some reason it isn't passed from shell.nix micro
++ shellnix.buildInputs ]) ++ (let
++ shellnix.nativeBuildInputs shell = import "${inputs.pbsds-papers}/shell.nix" { inherit pkgs; };
++ shellnix.propagatedBuildInputs in
++ shellnix.propagatedNativeBuildInputs; (with pkgs; [ imagemagick librsvg ]) # for some reason it isn't picked up from from shell.nix?
++ shell.buildInputs
++ shell.nativeBuildInputs
++ shell.propagatedBuildInputs
++ shell.propagatedNativeBuildInputs
);
}; };
networking.firewall = { networking.firewall.enable = true;
enable = true; networking.firewall.allowedTCPPorts = [
allowedTCPPorts = [ config.services.code-server.port
config.services.code-server.port ];
];
};
}; };
}; };
services.nginx.virtualHosts.${mkDomain "code-server"} = { services.nginx.virtualHosts.${subdomain} = {
forceSSL = true; # addSSL = true; forceSSL = true; # addSSL = true;
enableACME = true; #useACMEHost = acmeDomain; enableACME = true; #useACMEHost = acmeDomain;
locations."/" = { locations."/" = {