flake.nix: Clean up and refactor

This commit is contained in:
Tristan Daniël Maat 2022-10-12 01:17:49 +01:00
parent 7095ab2631
commit e512e73b5e
Signed by: tlater
GPG key ID: 49670FD774E43268
2 changed files with 107 additions and 114 deletions

View file

@ -2,11 +2,26 @@
"nodes": { "nodes": {
"flake-utils": { "flake-utils": {
"locked": { "locked": {
"lastModified": 1649676176, "lastModified": 1659877975,
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -70,7 +85,6 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"sops-nix": "sops-nix", "sops-nix": "sops-nix",
@ -125,9 +139,7 @@
}, },
"tlaternet-templates": { "tlaternet-templates": {
"inputs": { "inputs": {
"flake-utils": [ "flake-utils": "flake-utils",
"flake-utils"
],
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
@ -148,9 +160,7 @@
}, },
"tlaternet-webserver": { "tlaternet-webserver": {
"inputs": { "inputs": {
"flake-utils": [ "flake-utils": "flake-utils_2",
"flake-utils"
],
"naersk": "naersk", "naersk": "naersk",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"

191
flake.nix
View file

@ -4,7 +4,6 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
nixos-hardware.url = "github:nixos/nixos-hardware/master"; nixos-hardware.url = "github:nixos/nixos-hardware/master";
flake-utils.url = "github:numtide/flake-utils";
sops-nix = { sops-nix = {
url = "github:Mic92/sops-nix"; url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -12,17 +11,11 @@
tlaternet-webserver = { tlaternet-webserver = {
url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git"; url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git";
inputs = { inputs.nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
}; };
tlaternet-templates = { tlaternet-templates = {
url = "git+https://gitea.tlater.net/tlaternet/tlaternet-templates.git"; url = "git+https://gitea.tlater.net/tlaternet/tlaternet-templates.git";
inputs = { inputs.nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
}; };
}; };
@ -30,12 +23,12 @@
self, self,
nixpkgs, nixpkgs,
nixos-hardware, nixos-hardware,
flake-utils,
sops-nix, sops-nix,
tlaternet-webserver, tlaternet-webserver,
tlaternet-templates, tlaternet-templates,
... }: let
} @ inputs: let system = "x86_64-linux";
overlays = [ overlays = [
(final: prev: { (final: prev: {
tlaternet-webserver = tlaternet-webserver =
@ -47,102 +40,92 @@
}; };
}) })
]; ];
in
{
nixosConfigurations = {
tlaternet = let
system = "x86_64-linux";
in
nixpkgs.lib.nixosSystem {
inherit system;
modules = [ pkgs = import nixpkgs {inherit system overlays;};
({modulesPath, ...}: { sops-pkgs = sops-nix.packages.${system};
imports = [(modulesPath + "/profiles/headless.nix")]; in {
nixpkgs.overlays = overlays; nixosConfigurations = {
}) tlaternet = nixpkgs.lib.nixosSystem {
(import ./modules) inherit system;
(import ./configuration) modules = [
(import ./configuration/linode.nix) ({modulesPath, ...}: {
(import ./configuration/hardware-configuration.nix) imports = [(modulesPath + "/profiles/headless.nix")];
sops-nix.nixosModules.sops nixpkgs.overlays = overlays;
]; })
}; (import ./modules)
vm = let (import ./configuration)
system = "x86_64-linux"; (import ./configuration/linode.nix)
in (import ./configuration/hardware-configuration.nix)
nixpkgs.lib.nixosSystem { sops-nix.nixosModules.sops
inherit system;
modules = [
({modulesPath, ...}: {
imports = [(modulesPath + "/profiles/headless.nix")];
nixpkgs.overlays = overlays;
})
(import ./modules)
(import ./configuration)
sops-nix.nixosModules.sops
({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";
# # 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;};
sops-pkgs = sops-nix.packages.${system};
in {
devShell = pkgs.mkShell {
sopsPGPKeyDirs = ["./keys/hosts/" "./keys/users/"];
nativeBuildInputs = with sops-pkgs; [
sops-import-keys-hook
]; ];
buildInputs = with pkgs;
with sops-pkgs; [
nixfmt
git-lfs
sops-init-gpg-key
];
shellHook = let
inherit (pkgs.lib.attrsets) mapAttrsToList;
inherit (pkgs.lib.strings) concatStringsSep;
ports = {
"3022" = "2222";
"3080" = "80";
"3443" = "443";
"3021" = "2221";
"25565" = "25565";
"21025" = "21025"; # Starbound
};
QEMU_NET_OPTS =
concatStringsSep ","
(mapAttrsToList
(host: vm: "hostfwd=::${host}-:${vm}")
ports);
in ''
export QEMU_OPTS="-m 3941 -smp 2 -curses"
export QEMU_NET_OPTS="${QEMU_NET_OPTS}"
# Work around sudo requiring a full terminal
export NIX_SSHOPTS="-t"
'';
}; };
packages = import ./pkgs {inherit pkgs;}; vm = nixpkgs.lib.nixosSystem {
}); inherit system;
modules = [
({modulesPath, ...}: {
imports = [(modulesPath + "/profiles/headless.nix")];
nixpkgs.overlays = overlays;
})
(import ./modules)
(import ./configuration)
sops-nix.nixosModules.sops
({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";
# # Set up VM settings to match real VPS
# virtualisation.memorySize = 3941;
# virtualisation.cores = 2;
})
];
};
};
devShells.${system}.default = pkgs.mkShell {
sopsPGPKeyDirs = ["./keys/hosts/" "./keys/users/"];
nativeBuildInputs = [
sops-pkgs.sops-import-keys-hook
];
buildInputs = with pkgs; [
nixfmt
git-lfs
sops-pkgs.sops-init-gpg-key
];
shellHook = let
inherit (pkgs.lib.attrsets) mapAttrsToList;
inherit (pkgs.lib.strings) concatStringsSep;
ports = {
"2222" = "2222";
"3080" = "80";
"3443" = "443";
"2221" = "2221";
"21025" = "21025"; # Starbound
};
QEMU_NET_OPTS =
concatStringsSep ","
(mapAttrsToList
(host: vm: "hostfwd=::${host}-:${vm}")
ports);
in ''
export QEMU_OPTS="-m 3941 -smp 2 -curses"
export QEMU_NET_OPTS="${QEMU_NET_OPTS}"
# Work around sudo requiring a full terminal when deploying to
# a remote host
export NIX_SSHOPTS="-t"
'';
};
};
} }