about summary refs log tree commit diff
path: root/machines/srv3/configuration.nix
blob: 7e157ff63e8095c9c13c70843dd3abdf8f5683ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
{ config, lib, pkgs, ... }:
let
  crs = pkgs.callPackage ./coreruleset.nix { };
  
  www = "/srv/www";

  domain = "niedzwiedzinski.cyou";

in
  {
    imports =
      [
      ../../modules/obsidian-livesync.nix
      ./hardware-configuration.nix
      ./cgit.nix
      ./noip.nix
    ];

    services.obsidian-livesync = {
    	enable = true;
	domain = "obsidian.${domain}";
	adminsFile = "/etc/couchdb.ini";
    };

    boot.loader.grub.enable = true;
    boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only



    networking = {
      useDHCP = false;
      interfaces.enp1s0 = {
        useDHCP = true;
        ipv4.addresses = [{
          address = "192.168.1.136";
          prefixLength = 24;
        }];
      };
      hostName = "srv3";
      extraHosts = ''
      192.168.1.136 srv3.niedzwiedzinski.cyou git.niedzwiedzinski.cyou tmp.niedzwiedzinski.cyou zhr.niedzwiedzinski.cyou help.niedzwiedzinski.cyou niedzwiedzinski.cyou pics.niedzwiedzinski.cyou fresh.niedzwiedzinski.cyou obsidian.${domain}
      192.168.1.144 srv2.niedzwiedzinski.cyou
    '' + lib.readFile ( pkgs.fetchurl {
      url = "https://raw.githubusercontent.com/StevenBlack/hosts/d2be343994aacdec74865ff8d159cf6e46359adf/alternates/fakenews-gambling-porn/hosts";
      sha256 = "1la5rd0znc25q8yd1iwbx22zzqi6941vyzmgar32jx568j856s8j";
      } );
    };

    services.dnsmasq = {
      enable = true;
      settings = {
        server = [ "1.1.1.1" "8.8.8.8" ];
        #address=/.srv1.niedzwiedzinski.cyou/192.168.1.136
        address="/.srv2.niedzwiedzinski.cyou/192.168.1.144";
      };
    };

    time.timeZone = "Europe/Warsaw";
    i18n.defaultLocale = "en_US.UTF-8"; # Less confusing locale than polish one
    console.keyMap = "pl";

    nix.gc = {
      automatic = true;
      options = "--delete-older-than 30d";
    };
    nix.optimise.automatic = true;
    system.autoUpgrade = {
      enable = true;
      allowReboot = true;
    };

  environment.systemPackages = with pkgs; [
    curl wget htop git
    vim lm_sensors
  ];

  services.openssh = {
    enable = true;
    settings = {
      PasswordAuthentication = false;
      PermitRootLogin = "no";
      #AllowGroups = ["using-ssh"];
      AllowUsers = [ "pn-ssh" "pn@192.168.1.*" ];
    };
  };
  services.sshguard = {
    enable = true;
    whitelist = [
      "192.168.1.0/24"
    ];
  };

  services.freshrss = {
    enable = true;
    virtualHost = "fresh.niedzwiedzinski.cyou";
    baseUrl = "https://fresh.niedzwiedzinski.cyou";
    authType = "form";
    defaultUser = "admin";
    passwordFile = "/fresh/passwd";
  };

  services.nginx.enable = true;
  services.nginx.additionalModules = with pkgs.nginxModules; [ modsecurity ];
  services.nginx.appendHttpConfig = ''
    modsecurity on;
    # modsecurity_rules '
    #   SecRuleEngine On
    #   Include ${crs}/crs-setup.conf;
    #   Include ${crs}/rules/*.conf;
    # ';
    charset utf-8;
    source_charset utf-8;
  '';
  services.nginx.virtualHosts = {
    "srv3.niedzwiedzinski.cyou" = let
      modsec_config = builtins.toFile "modsecurity_rules.conf" ''
        SecRuleEngine On
        SecRule ARGS:testparam "@contains test" "id:1234,deny,status:403"
      '';
    in {
      enableACME = true;
      forceSSL = true;
      extraConfig = ''
        location ~ /*.md {
	  types { } default_type "text/markdown; charset=utf-8";
        }
        modsecurity_rules_file ${modsec_config};
      '';
      root = "${www}/srv3.niedzwiedzinski.cyou";
    };
    "pics.srv3.niedzwiedzinski.cyou" = {
      enableACME = true;
      forceSSL = true;
      root = "${www}/pics.niedzwiedzinski.cyou";
    };
    "pics.niedzwiedzinski.cyou" = {
      enableACME = true;
      forceSSL = true;
      root = "${www}/pics.niedzwiedzinski.cyou";
    };
    "tmp.niedzwiedzinski.cyou" = {
      enableACME = true;
      addSSL = true;
      root = "${www}/tmp.niedzwiedzinski.cyou";
      extraConfig = ''
        modsecurity_rules '
          SecRuleEngine On
          SecRule ARGS:testparam "@contains test" "id:1234,deny,status:403"
          Include ${crs}/crs-setup.conf
          Include ${crs}/all-rules.conf
        ';
      '';
    };
    "niedzwiedzinski.cyou" = {
      enableACME = true;
      forceSSL = true;
      root = "${www}/niedzwiedzinski.cyou";
    };
    "zhr.niedzwiedzinski.cyou" = {
      enableACME = true;
      forceSSL = true;
      root = "${www}/zhr.niedzwiedzinski.cyou";
      extraConfig = ''
        location /rozkazy/ {
          autoindex on;
        }
      '';
    };
    "help.niedzwiedzinski.cyou" = {
      enableACME = true;
      forceSSL = true;
      root = "${www}/niedzwiedzinski.cyou/help";
    };
   "fresh.niedzwiedzinski.cyou" = {
      enableACME = true;
      forceSSL = true;
    };
  };
  security.acme.defaults.email = "pniedzwiedzinski19@gmail.com";
  security.acme.acceptTerms = true;

  networking.firewall.enable = true;
  networking.firewall.allowedTCPPorts = [ 53 80 443 ];
  networking.firewall.allowedUDPPorts = [ 53 ];

  virtualisation.docker.enable = true;

  users = {
    groups."using-ssh" = { name = "using-ssh"; };
    users = {
      pn-ssh = {
        description = "patryk-zdalny";
        isNormalUser = true;
        extraGroups = [ "pn" "git" "using-ssh"];
        openssh.authorizedKeys.keys = [
          "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIqlCe4ovKa/Gwl5xmgu9nvVPmFXMgwdeLRYW7Gg7RWx pniedzwiedzinski19@gmail.com"
        ];
      };
      pn = {
	description = "patryk";
        isNormalUser = true;
        extraGroups = [ "wheel" "git" "using-ssh" "docker" ]; # Enable ‘sudo’ for the user.
        openssh.authorizedKeys.keys = [
          "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIqlCe4ovKa/Gwl5xmgu9nvVPmFXMgwdeLRYW7Gg7RWx pniedzwiedzinski19@gmail.com"
        ];
      };
    };
  };
}