tlaternet-server/flake.nix
Tristan Daniël Maat 2a7f905bc2
WIP: Add hydra
2021-05-17 00:15:07 +01:00

126 lines
3.9 KiB
Nix

{
description = "tlater.net host configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-20.09";
nixos-hardware.url = "github:nixos/nixos-hardware/master";
flake-utils.url = "github:numtide/flake-utils";
tlaternet-webserver = {
url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
tlaternet-templates = {
url = "git+https://gitea.tlater.net/tlaternet/tlaternet-templates.git";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, nixpkgs, nixos-hardware, flake-utils, tlaternet-webserver
, tlaternet-templates, ... }@inputs:
let
overlays = [
(final: prev: {
tlaternet-webserver =
tlaternet-webserver.legacyPackages.${prev.system}.packages;
tlaternet-templates =
tlaternet-templates.legacyPackages.${prev.system}.packages;
local = import ./pkgs {
pkgs = prev;
local-lib = self.lib.${prev.system};
};
})
];
in {
nixosConfigurations = {
tlaternet = let system = "x86_64-linux";
in nixpkgs.lib.nixosSystem {
inherit system;
modules = [
({ modulesPath, ... }: {
imports = [ (modulesPath + "/profiles/headless.nix") ];
nixpkgs.overlays = overlays;
})
(import ./modules)
(import ./configuration)
(import ./configuration/linode.nix)
(import ./configuration/hardware-configuration.nix)
];
};
vm = let system = "x86_64-linux";
in nixpkgs.lib.nixosSystem {
inherit system;
modules = [
({ modulesPath, ... }: {
imports = [ (modulesPath + "/profiles/headless.nix") ];
nixpkgs.overlays = overlays;
})
(import ./modules)
(import ./configuration)
({ config, lib, ... }: {
users.users.tlater.password = "insecure";
# Disable graphical tty so -curses works
boot.kernelParams = [ "nomodeset" ];
# Sets the base domain for nginx to localhost so that we
# can easily test locally with the VM.
services.nginx.domain = lib.mkOverride 99 "localhost";
# Hydra uses X-Forwarded-Port to figure out how to
# include links to static files, but because we redirect
# 443 -> 3443 in the vm we need to explicitly set this
# (nginx can't see qemu's port redirection).
services.nginx.virtualHosts =
let domain = config.services.nginx.domain;
in {
"hydra.${domain}".locations."/".extraConfig = ''
proxy_set_header X-Forwarded-Port 3443;
'';
};
# # Set up VM settings to match real VPS
# virtualisation.memorySize = 3941;
# virtualisation.cores = 2;
})
];
};
};
} // flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system overlays; };
in {
devShell = with pkgs;
mkShell {
buildInputs = [ nixfmt git-lfs ];
shellHook = ''
export QEMU_OPTS="-m 3941 -smp 2 -curses"
export QEMU_NET_OPTS="hostfwd=::3022-:2222,hostfwd=::3080-:80,hostfwd=::3443-:443,hostfwd=::3021-:2221,hostfwd=::25565-:25565"
# Work around sudo requiring a full terminal
export NIX_SSHOPTS="-t"
'';
};
packages = import ./pkgs {
inherit pkgs;
local-lib = self.lib.${system};
};
lib = import ./lib {
inherit pkgs inputs;
lib = nixpkgs.lib;
};
});
}