tlaternet-server/flake.nix

181 lines
4.7 KiB
Nix
Raw Normal View History

{
description = "tlater.net host configuration";
inputs = {
2023-12-29 15:11:46 +00:00
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
2023-02-26 05:46:11 +00:00
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
2024-03-02 01:27:24 +00:00
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs.url = "github:serokell/deploy-rs";
2022-04-23 04:06:50 +01:00
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-10-17 11:00:02 +01:00
nvfetcher = {
url = "github:berberman/nvfetcher";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-04-12 01:44:10 +01:00
tlaternet-webserver = {
url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git";
2022-10-12 01:17:49 +01:00
inputs.nixpkgs.follows = "nixpkgs";
2021-04-12 01:44:10 +01:00
};
2023-05-11 22:02:57 +01:00
foundryvtt = {
url = "github:reckenrode/nix-foundryvtt";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
sops-nix,
2022-10-17 11:00:02 +01:00
nvfetcher,
deploy-rs,
...
} @ inputs: let
2022-10-12 01:17:49 +01:00
system = "x86_64-linux";
in {
##################
# Configurations #
##################
nixosConfigurations = {
# The actual system definition
tlaternet = nixpkgs.lib.nixosSystem {
2022-10-12 01:17:49 +01:00
inherit system;
specialArgs.flake-inputs = inputs;
modules = [
./configuration
./configuration/hardware-specific/linode
];
};
2024-03-02 01:27:24 +00:00
hetzner-1 = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs.flake-inputs = inputs;
modules = [
./configuration
./configuration/hardware-specific/hetzner
];
};
2022-10-12 01:17:49 +01:00
};
2021-04-22 22:32:54 +01:00
############################
# Deployment configuration #
############################
2024-03-02 01:27:24 +00:00
deploy.nodes = {
tlaternet = {
hostname = "tlater.net";
profiles.system = {
user = "root";
path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.tlaternet;
};
2024-03-02 01:27:24 +00:00
sshUser = "tlater";
sshOpts = ["-p" "2222" "-o" "ForwardAgent=yes"];
};
2024-03-02 01:27:24 +00:00
hetzner-1 = {
hostname = "116.202.158.55";
profiles.system = {
user = "root";
path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.tlaternet;
};
sshUser = "root";
};
};
#########
# Tests #
#########
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
####################
# Helper functions #
####################
lib = import ./lib {inherit (nixpkgs) lib;};
###################
# Utility scripts #
###################
packages.${system} = let
inherit (nixpkgs.legacyPackages.${system}) writeShellScript writeShellScriptBin;
vm = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs.flake-inputs = inputs;
modules = [
./configuration
./configuration/hardware-specific/vm.nix
];
};
in {
default = vm.config.system.build.vm;
run-vm = let
2022-10-17 11:00:02 +01:00
qemuNetOpts = self.lib.makeQemuNetOpts {
"2222" = "2222";
"3080" = "80";
"3443" = "443";
2022-10-21 20:48:14 +01:00
"8448" = "8448"; # Matrix
2022-10-17 11:00:02 +01:00
"21025" = "21025"; # Starbound
};
in
writeShellScript "run-vm" ''
2022-10-17 11:00:02 +01:00
export QEMU_OPTS="-m 3941 -smp 2 -display curses"
export QEMU_NET_OPTS="${qemuNetOpts}"
"${vm.config.system.build.vm}/bin/run-tlaternet-vm"
'';
2022-10-17 11:00:02 +01:00
update-pkgs = let
nvfetcher-bin = "${nvfetcher.packages.${system}.default}/bin/nvfetcher";
in
writeShellScriptBin "update-pkgs" ''
cd "$(git rev-parse --show-toplevel)/pkgs"
${nvfetcher-bin} -o _sources_pkgs -c nvfetcher.toml
'';
2022-10-17 11:00:02 +01:00
update-nextcloud-apps = let
nvfetcher-bin = "${nvfetcher.packages.${system}.default}/bin/nvfetcher";
in
writeShellScript "update-nextcloud-apps" ''
2022-10-17 11:00:02 +01:00
cd "$(git rev-parse --show-toplevel)/pkgs"
${nvfetcher-bin} -o _sources_nextcloud -c nextcloud-apps.toml
'';
};
apps.${system} = {
default = {
type = "app";
program = builtins.toString self.packages.${system}.run-vm;
};
update-nextcloud-apps = {
type = "app";
program = builtins.toString self.packages.${system}.update-nextcloud-apps;
2022-10-17 11:00:02 +01:00
};
};
###########################
# Development environment #
###########################
2022-10-22 20:01:44 +01:00
devShells.${system}.default = nixpkgs.legacyPackages.${system}.mkShell {
sopsPGPKeyDirs = ["./keys/hosts/" "./keys/users/"];
nativeBuildInputs = [
sops-nix.packages.${system}.sops-import-keys-hook
];
2022-10-22 20:01:44 +01:00
packages = [
sops-nix.packages.${system}.sops-init-gpg-key
deploy-rs.packages.${system}.default
];
};
2022-10-12 01:17:49 +01:00
};
}