treewide: Refactor in order to clean up flake.nix
This commit is contained in:
parent
068e6d5d77
commit
e8b16459d9
|
@ -1,9 +1,13 @@
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
|
modulesPath,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
imports = [
|
imports = [
|
||||||
|
"${modulesPath}/profiles/headless.nix"
|
||||||
|
(import ../modules)
|
||||||
|
|
||||||
./services/gitea.nix
|
./services/gitea.nix
|
||||||
./services/nextcloud.nix
|
./services/nextcloud.nix
|
||||||
./services/webserver.nix
|
./services/webserver.nix
|
||||||
|
@ -12,6 +16,14 @@
|
||||||
./sops.nix
|
./sops.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
(final: prev: {
|
||||||
|
local = import ../pkgs {
|
||||||
|
pkgs = prev;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
nix = {
|
nix = {
|
||||||
package = pkgs.nixFlakes;
|
package = pkgs.nixFlakes;
|
||||||
extraOptions = ''
|
extraOptions = ''
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
{
|
{
|
||||||
|
imports = [
|
||||||
|
./hardware-configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
# Required for the lish console
|
# Required for the lish console
|
||||||
boot.kernelParams = ["console=ttyS0,19200n8"];
|
boot.kernelParams = ["console=ttyS0,19200n8"];
|
||||||
|
|
17
configuration/hardware-specific/vm.nix
Normal file
17
configuration/hardware-specific/vm.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{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";
|
||||||
|
|
||||||
|
# Use the staging secrets
|
||||||
|
sops.defaultSopsFile = lib.mkOverride 99 ../../keys/staging.yaml;
|
||||||
|
|
||||||
|
# # Set up VM settings to match real VPS
|
||||||
|
# virtualisation.memorySize = 3941;
|
||||||
|
# virtualisation.cores = 2;
|
||||||
|
}
|
17
flake.lock
17
flake.lock
|
@ -190,22 +190,6 @@
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixos-hardware": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1665321371,
|
|
||||||
"narHash": "sha256-0SO6MTW0bX6lxZmz1AZW/Xmk+hnTd7/hp1vF7Tp7jg0=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixos-hardware",
|
|
||||||
"rev": "236ba4df714131059945d7754c0aa3fbe9d2f74c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "master",
|
|
||||||
"repo": "nixos-hardware",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1665466769,
|
"lastModified": 1665466769,
|
||||||
|
@ -299,7 +283,6 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixos-hardware": "nixos-hardware",
|
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"sops-nix": "sops-nix",
|
"sops-nix": "sops-nix",
|
||||||
"tlaternet-webserver": "tlaternet-webserver"
|
"tlaternet-webserver": "tlaternet-webserver"
|
||||||
|
|
113
flake.nix
113
flake.nix
|
@ -3,12 +3,10 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
|
||||||
nixos-hardware.url = "github:nixos/nixos-hardware/master";
|
|
||||||
sops-nix = {
|
sops-nix = {
|
||||||
url = "github:Mic92/sops-nix";
|
url = "github:Mic92/sops-nix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
tlaternet-webserver = {
|
tlaternet-webserver = {
|
||||||
url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git";
|
url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
@ -18,111 +16,90 @@
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
nixos-hardware,
|
|
||||||
sops-nix,
|
sops-nix,
|
||||||
tlaternet-webserver,
|
tlaternet-webserver,
|
||||||
}: let
|
}: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
|
||||||
overlays = [
|
|
||||||
(final: prev: {
|
|
||||||
local = import ./pkgs {
|
|
||||||
pkgs = prev;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
pkgs = import nixpkgs {inherit system overlays;};
|
|
||||||
sops-pkgs = sops-nix.packages.${system};
|
|
||||||
in {
|
in {
|
||||||
nixosConfigurations = {
|
##################
|
||||||
|
# Configurations #
|
||||||
|
##################
|
||||||
|
nixosConfigurations = let
|
||||||
|
# Modules that should be generic to all systems
|
||||||
|
genericModule = {...}: {
|
||||||
|
imports = [
|
||||||
|
# Inject flake dependencies
|
||||||
|
sops-nix.nixosModules.sops
|
||||||
|
tlaternet-webserver.nixosModules.default
|
||||||
|
|
||||||
|
# Import actual configuration
|
||||||
|
(import ./configuration)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
# The actual system definition
|
||||||
tlaternet = nixpkgs.lib.nixosSystem {
|
tlaternet = nixpkgs.lib.nixosSystem {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
|
||||||
modules = [
|
modules = [
|
||||||
({modulesPath, ...}: {
|
genericModule
|
||||||
imports = [(modulesPath + "/profiles/headless.nix")];
|
(import ./configuration/hardware-specific/linode)
|
||||||
nixpkgs.overlays = overlays;
|
|
||||||
})
|
|
||||||
(import ./modules)
|
|
||||||
|
|
||||||
(import ./configuration)
|
|
||||||
(import ./configuration/linode.nix)
|
|
||||||
(import ./configuration/hardware-configuration.nix)
|
|
||||||
sops-nix.nixosModules.sops
|
|
||||||
tlaternet-webserver.nixosModules.default
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# A qemu VM to test the above with
|
||||||
vm = nixpkgs.lib.nixosSystem {
|
vm = nixpkgs.lib.nixosSystem {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
|
||||||
modules = [
|
modules = [
|
||||||
({modulesPath, ...}: {
|
genericModule
|
||||||
imports = [(modulesPath + "/profiles/headless.nix")];
|
(import ./configuration/hardware-specific/vm.nix)
|
||||||
nixpkgs.overlays = overlays;
|
|
||||||
})
|
|
||||||
(import ./modules)
|
|
||||||
|
|
||||||
(import ./configuration)
|
|
||||||
sops-nix.nixosModules.sops
|
|
||||||
tlaternet-webserver.nixosModules.default
|
|
||||||
({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";
|
|
||||||
|
|
||||||
# Use the staging secrets
|
|
||||||
sops.defaultSopsFile = lib.mkOverride 99 ./keys/staging.yaml;
|
|
||||||
|
|
||||||
# # Set up VM settings to match real VPS
|
|
||||||
# virtualisation.memorySize = 3941;
|
|
||||||
# virtualisation.cores = 2;
|
|
||||||
})
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Helper functions #
|
||||||
|
####################
|
||||||
|
lib = import ./lib {lib = nixpkgs.lib;};
|
||||||
|
|
||||||
|
####################
|
||||||
|
# VM launch script #
|
||||||
|
####################
|
||||||
apps.${system}.default = let
|
apps.${system}.default = let
|
||||||
inherit (self.nixosConfigurations.vm.config.system.build) vm;
|
inherit (self.nixosConfigurations.vm.config.system.build) vm;
|
||||||
inherit (nixpkgs.legacyPackages.${system}) writeShellScript;
|
inherit (nixpkgs.legacyPackages.${system}) writeShellScript;
|
||||||
inherit (nixpkgs.lib.attrsets) mapAttrsToList;
|
qemuNetOpts = self.lib.makeQemuNetOpts {
|
||||||
inherit (nixpkgs.lib.strings) concatStringsSep;
|
|
||||||
ports = {
|
|
||||||
"2222" = "2222";
|
"2222" = "2222";
|
||||||
"3080" = "80";
|
"3080" = "80";
|
||||||
"3443" = "443";
|
"3443" = "443";
|
||||||
"2221" = "2221";
|
|
||||||
"21025" = "21025"; # Starbound
|
"21025" = "21025"; # Starbound
|
||||||
};
|
};
|
||||||
QEMU_NET_OPTS =
|
|
||||||
concatStringsSep ","
|
|
||||||
(mapAttrsToList
|
|
||||||
(host: vm: "hostfwd=::${host}-:${vm}")
|
|
||||||
ports);
|
|
||||||
in {
|
in {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = builtins.toString (writeShellScript "run-vm" ''
|
program = builtins.toString (writeShellScript "run-vm" ''
|
||||||
export QEMU_OPTS="-m 3941 -smp 2 -curses"
|
export QEMU_OPTS="-m 3941 -smp 2 -curses"
|
||||||
export QEMU_NET_OPTS="${QEMU_NET_OPTS}"
|
export QEMU_NET_OPTS="${qemuNetOpts}"
|
||||||
"${vm}/bin/run-tlaternet-vm"
|
"${vm}/bin/run-tlaternet-vm"
|
||||||
'');
|
'');
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
###########################
|
||||||
|
# Development environment #
|
||||||
|
###########################
|
||||||
|
devShells.${system}.default = let
|
||||||
|
inherit (sops-nix.packages.${system}) sops-import-keys-hook sops-init-gpg-key;
|
||||||
|
deploy-rs-bin = deploy-rs.packages.${system}.default;
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in
|
||||||
|
nixpkgs.legacyPackages.${system}.mkShell {
|
||||||
sopsPGPKeyDirs = ["./keys/hosts/" "./keys/users/"];
|
sopsPGPKeyDirs = ["./keys/hosts/" "./keys/users/"];
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
sops-pkgs.sops-import-keys-hook
|
sops-import-keys-hook
|
||||||
];
|
];
|
||||||
buildInputs = with pkgs; [
|
packages = with pkgs; [
|
||||||
nixfmt
|
nixfmt
|
||||||
git-lfs
|
git-lfs
|
||||||
sops-pkgs.sops-init-gpg-key
|
sops-init-gpg-key
|
||||||
|
deploy-rs-bin
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
10
lib/default.nix
Normal file
10
lib/default.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{lib}: let
|
||||||
|
inherit (lib.attrsets) mapAttrsToList;
|
||||||
|
inherit (lib.strings) concatStringsSep;
|
||||||
|
in {
|
||||||
|
makeQemuNetOpts = portMapping:
|
||||||
|
concatStringsSep ","
|
||||||
|
(mapAttrsToList
|
||||||
|
(host: vm: "hostfwd=::${host}-:${vm}")
|
||||||
|
portMapping);
|
||||||
|
}
|
Loading…
Reference in a new issue