From f7703052738d98cbb82f1b07919e63b5a6e74ac4 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Fri, 7 Jul 2023 02:48:44 +0200 Subject: [PATCH] screeps and home-manager.sharedModules --- flake.nix | 19 ++--- nixos/components/gui/home-manager/default.nix | 40 ---------- nixos/components/mainUser.nix | 15 ---- nixos/components/terminal/zsh.nix | 49 +++++++++--- nixos/machines/robi/configuration.nix | 4 +- nixos/machines/robi/screeps.nix | 74 +++++++++++++++++++ 6 files changed, 120 insertions(+), 81 deletions(-) create mode 100644 nixos/machines/robi/screeps.nix diff --git a/flake.nix b/flake.nix index 6ef60ca..7b3675f 100644 --- a/flake.nix +++ b/flake.nix @@ -231,19 +231,12 @@ home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.root = { - home.stateVersion = "22.11"; - imports = [ - home-manager-utils.hmModule - ]; - }; - home-manager.users.mainUser = { - home.stateVersion = "22.11"; - imports = [ - doom-emacs-nix.hmModule - home-manager-utils.hmModule - ]; - }; + home-manager.sharedModules = [ + doom-emacs-nix.hmModule + home-manager-utils.hmModule + ]; + home-manager.users.mainUser.home.stateVersion = "22.11"; + home-manager.users.root.home.stateVersion = "22.11"; }; sopsModule = name: { lib, ... }: { diff --git a/nixos/components/gui/home-manager/default.nix b/nixos/components/gui/home-manager/default.nix index 83fb2f9..0b67dcf 100644 --- a/nixos/components/gui/home-manager/default.nix +++ b/nixos/components/gui/home-manager/default.nix @@ -18,49 +18,9 @@ with lib; home-manager.users.mainUser = { - # a better cat - programs.bat = { - enable = true; - config.theme = "gruvbox-light"; - }; - home.shellAliases.cat = "${pkgs.bat}/bin/bat"; - # notify me when a command is finished programs.noti.enable = true; - # a better ls - programs.exa = { - enable = true; - enableAliases = true; - }; - home.shellAliases.llt = "${pkgs.exa}/bin/exa -a --tree"; - - # use z instead of cd - # use zi to fuzzy search through all registered directories - programs.zoxide = { - enable = true; - enableZshIntegration = true; - }; - - # provide better `Ctrl+r` command in terminal - programs.mcfly = { - enable = true; - keyScheme = "vim"; - fuzzySearchFactor = 3; - enableZshIntegration = true; - enableBashIntegration = true; - }; - - programs.zsh = { - enable = true; - defaultKeymap = "viins"; - }; - - xdg.configFile."ncmpcpp/config".text = '' - mpd_host = "pepe.private" - mpd_port = 6600 - ''; - programs.git = { enable = true; diff --git a/nixos/components/mainUser.nix b/nixos/components/mainUser.nix index eccd90b..21b4d29 100644 --- a/nixos/components/mainUser.nix +++ b/nixos/components/mainUser.nix @@ -79,20 +79,5 @@ in }; - home-manager.users.mainUser.home.file.".mainUser" = { - enable = true; - text = builtins.toJSON ( - { - mainUser = config.users.users.mainUser.name; - normalUser = mapAttrs (_: value: value.name) - (filterAttrs (_: value: value.isNormalUser) - config.users.users); - systemUser = mapAttrs (_: value: value.name) - (filterAttrs (_: value: value.isSystemUser) - config.users.users); - } - ); - }; - }; } diff --git a/nixos/components/terminal/zsh.nix b/nixos/components/terminal/zsh.nix index 7321b97..ba02044 100644 --- a/nixos/components/terminal/zsh.nix +++ b/nixos/components/terminal/zsh.nix @@ -8,19 +8,44 @@ with lib; config = mkIf (config.components.terminal.zsh.enable) { - home-manager.users = - let - zshConfig = { - programs.zsh = { - enable = true; - defaultKeymap = "viins"; - }; - }; - in + home-manager.sharedModules = [ { - mainUser = zshConfig; - root = zshConfig; - }; + programs.zsh = { + enable = true; + defaultKeymap = "viins"; + }; + + # a better cat + programs.bat = { + enable = true; + config.theme = "gruvbox-light"; + }; + home.shellAliases.cat = "${pkgs.bat}/bin/bat"; + + # a better ls + programs.exa = { + enable = true; + enableAliases = true; + }; + home.shellAliases.llt = "${pkgs.exa}/bin/exa -a --tree"; + + # use z instead of cd + # use zi to fuzzy search through all registered directories + programs.zoxide = { + enable = true; + enableZshIntegration = true; + }; + + # provide better `Ctrl+r` command in terminal + programs.mcfly = { + enable = true; + keyScheme = "vim"; + fuzzySearchFactor = 3; + enableZshIntegration = true; + enableBashIntegration = true; + }; + } + ]; programs.zsh = { diff --git a/nixos/machines/robi/configuration.nix b/nixos/machines/robi/configuration.nix index 100b61e..7f1f421 100644 --- a/nixos/machines/robi/configuration.nix +++ b/nixos/machines/robi/configuration.nix @@ -14,6 +14,8 @@ ./hetzner.nix + # ./screeps.nix + ./borg.nix ./codimd.nix ./gitea.nix @@ -86,7 +88,7 @@ security.acme.defaults.email = "contact@ingolf-wagner.de"; sops.defaultSopsFile = ../../secrets/robi.yaml; - virtualisation.docker.enable = false; + # virtualisation.docker.enable = false; services.printing.enable = false; services.smartd.enable = true; diff --git a/nixos/machines/robi/screeps.nix b/nixos/machines/robi/screeps.nix new file mode 100644 index 0000000..7cff8d0 --- /dev/null +++ b/nixos/machines/robi/screeps.nix @@ -0,0 +1,74 @@ +{ config, lib, pkgs, ... }: +with lib; +let + debug = true; + #version = "latest"; + # version = "142c079"; # 2 years ago. + # version = "v1.14.0"; # 2 years ago. + version = "v1.13.2"; # 2 years ago. +in +{ + virtualisation.oci-containers = { + containers.screeps = { + volumes = [ + "/srv/screeps:/screeps" + (optionalString debug "/srv/screeps-tmp:/tmp") + ]; + environment.TZ = "Europe/Berlin"; + image = "screepers/screeps-launcher:${version}"; + ports = [ "21025:21025" ]; + }; + }; + + systemd.services = + let + configuration = builtins.toJSON { + steamKey = "keyFromStep3"; + version = "latest"; + mods = [ + #"screepsmod-auth" + #"screepsmod-admin-utils" + #"screepsmod-mongo" + ]; + bots = { + simplebot = "screepsbot-zeswarm"; + }; + serverConfig = { + welcomeText = "

My Cool Server

"; + constants = { + "TEST_CONSTANT" = 123; + }; + tickRate = 1000; + }; + }; + + unitConfig = { + StartLimitInterval = 200; + StartLimitBurst = 2; + }; + serviceConfig = { + Restart = mkForce (if debug then "no" else "always"); + RestartSec = 30; + ExecStartPre = [ + (toString (pkgs.writers.writeDash "create-screeps-config" '' + mkdir -p /srv/screeps/ + chown 1000:1000 -R /srv/screeps + ${optionalString debug "mkdir -p /srv/screeps-tmp"} + ${optionalString debug "chown 1000:1000 -R /srv/screeps-tmp"} + echo '${configuration}' > /srv/screeps/config.yaml + '')) + ]; + }; + in + { + podman-screeps = { inherit serviceConfig; }; + docker-screeps = { inherit serviceConfig; }; + }; + + #networking.firewall.allowedTCPPorts = [ 8123 ]; + #networking.firewall.allowedUDPPorts = [ 8123 ]; + + #networking.firewall.interfaces.wg0.allowedTCPPorts = [ 8123 ]; + #networking.firewall.interfaces.wg0.allowedUDPPorts = [ 8123 ]; + +}