Skip to content

Commit

Permalink
feat(cache): optimize inputs add atticd
Browse files Browse the repository at this point in the history
  • Loading branch information
klarkc committed Dec 19, 2023
1 parent 842c018 commit b4505b7
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 39 deletions.
115 changes: 105 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
generators.url = "github:nix-community/nixos-generators";
attic.url = "github:zhaofengli/attic";
everyday.url = "github:klarkc/nixos-everyday";
# optimizations
generators.inputs.nixpkgs.follows = "nixpkgs";
attic.inputs.nixpkgs.follows = "nixpkgs";
everyday.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, ... }@inputs:
Expand Down Expand Up @@ -44,9 +50,14 @@
runtimeInputs = with pkgs; [ qemu ];
};
};
machines = import ./machines { inherit system pkgs lib; };
machines = import ./machines {
inherit system pkgs;
flake = self;
};
in
{
inherit lib;

nixosConfigurations = {
inherit (machines.recover) recover-os;
inherit (machines.cache) cache-os;
Expand All @@ -56,19 +67,6 @@
inherit (machines.recover) recover-efi recover-vm recover-kvm;
inherit (machines.cache) cache-efi cache-vm cache-kvm;
};

devShells.${system}.default =
pkgs.mkShell
{
packages =
with machines; [
recover.recover-vm
recover.recover-kvm
cache.cache-vm
cache.cache-kvm
];

};
};

# --- Flake Local Nix Configuration ----------------------------
Expand Down
55 changes: 42 additions & 13 deletions machines/cache/default.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
{ system, lib, pkgs, ... }:
{ system, pkgs, flake, ... }:
let
inherit (lib) mkSystem mkVirtualMachine;
inherit (pkgs.lib) mkDefault;
cache-module = {
inherit (flake.inputs.everyday.nixosModules) logger;
inherit (flake.inputs.attic.nixosModules) atticd;
inherit (flake.outputs.lib) mkSystem mkVirtualMachine;
domain = "cache.klarkc.is-a.dev";
cache-module = { config, ... }: {
imports = [ logger atticd ];
networking = {
hostName = "cache-os";
networkmanager.enable = true;
};
boot = {
kernelParams = [
"copytoram"
"console=ttyS0,115200"
"console=tty1"
"boot.shell_on_fail"
];
loader = {
timeout = 15;
grub = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
};
loader.grub = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
};
};
fileSystems."/".device = mkDefault "none";

services.atticd = {
enable = true;
# echo -n 'ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64="' > /tmp/atticd.env
# openssl rand 64 | base64 -w0 >> /tmp/atticd.env
# echo -n '"' >> /tmp/atticd.env
credentialsFile = "/tmp/atticd.env";
settings = {
listen = "[::]:8080";
chunking = {
nar-size-threshold = 64 * 1024; # 64 KiB
min-size = 16 * 1024; # 16 KiB
avg-size = 64 * 1024; # 64 KiB
max-size = 256 * 1024; # 256 KiB
};
};
};
# Web server
services.nginx = {
virtualHosts.${domain} = {
forceSSL = true;
enableACME = true;
locations."/".extraConfig = ''
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
};
};
};
in
rec {
Expand Down
4 changes: 2 additions & 2 deletions machines/recover/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ system, lib, pkgs, ... }:
{ system, pkgs, flake, ... }:
let
inherit (lib) mkSystem mkVirtualMachine;
inherit (pkgs.lib) mkDefault;
inherit (flake.outputs.lib) mkSystem mkVirtualMachine;
recover-module = {
nix = {
extraOptions = ''
Expand Down

0 comments on commit b4505b7

Please sign in to comment.