flake.nix (4543B)
1 { 2 inputs = { 3 nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; 4 nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; 5 sops-nix.url = "github:Mic92/sops-nix"; 6 simple-web-app.url = "git+ssh://forgejo@git.fnarglebeast.com/silas/simple-web-app.git"; 7 daily-tracker = { 8 url = "git+ssh://forgejo@git.fnarglebeast.com/silas/daily-tracker.git"; 9 inputs.nixpkgs.follows = "nixpkgs"; 10 }; 11 mkv.url = "git+ssh://forgejo@git.fnarglebeast.com/silas/mkv.git"; 12 website = { 13 url = "git+ssh://forgejo@git.fnarglebeast.com/silas/website.git"; 14 flake = false; 15 }; 16 nixos-mailserver = { 17 url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-25.11"; 18 inputs.nixpkgs.follows = "nixpkgs"; 19 }; 20 home-manager = { 21 url = "github:nix-community/home-manager/release-25.11"; 22 inputs.nixpkgs.follows = "nixpkgs"; 23 }; 24 }; 25 outputs = 26 { 27 nixpkgs, 28 nixpkgs-unstable, 29 sops-nix, 30 simple-web-app, 31 daily-tracker, 32 mkv, 33 website, 34 nixos-mailserver, 35 home-manager, 36 ... 37 }: 38 let 39 system = "x86_64-linux"; 40 pkgs = import nixpkgs { inherit system; }; 41 pkgs-unstable = import nixpkgs-unstable { inherit system; }; 42 in 43 { 44 nixosConfigurations.poseidon = nixpkgs.lib.nixosSystem { 45 inherit system; 46 modules = [ 47 sops-nix.nixosModules.sops 48 (import ./hosts/poseidon.nix) 49 ]; 50 }; 51 nixosConfigurations.helios = nixpkgs.lib.nixosSystem { 52 inherit system; 53 modules = [ 54 sops-nix.nixosModules.sops 55 nixos-mailserver.nixosModules.mailserver 56 ( 57 inputs@{ 58 pkgs, 59 ... 60 }: 61 import ./hosts/helios.nix (inputs // { inherit simple-web-app daily-tracker mkv website; }) 62 ) 63 ]; 64 }; 65 nixosConfigurations.gaia = nixpkgs.lib.nixosSystem { 66 inherit system; 67 specialArgs = { inherit pkgs-unstable; }; 68 modules = [ 69 sops-nix.nixosModules.sops 70 ./hosts/gaia/configuration.nix 71 home-manager.nixosModules.home-manager 72 ]; 73 }; 74 devShells."${system}".default = 75 let 76 pkgs = import nixpkgs { 77 inherit system; 78 }; 79 initSql = pkgs.writeText "query-logs-init.sql" '' 80 LOAD httpfs; 81 82 CREATE MACRO urls(dir, ext, since, until) AS 83 list_transform( 84 generate_series(since::TIMESTAMP, until::TIMESTAMP, INTERVAL '1 HOUR'), 85 ts -> 'http://10.100.0.7:9090/' || dir || '/' || strftime(ts, '%Y/%m/%d/%H') || '.' || ext 86 ); 87 88 CREATE MACRO app(since, until) AS TABLE 89 SELECT 90 to_timestamp(j."__REALTIME_TIMESTAMP"::BIGINT / 1000000) as timestamp, 91 j."MESSAGE" as message, 92 j."PRIORITY" as priority, 93 j."SYSLOG_IDENTIFIER" as identifier 94 FROM read_json(urls('app', 'json.gz', since, until), format='newline_delimited', ignore_errors=true, 95 columns={__REALTIME_TIMESTAMP: 'VARCHAR', MESSAGE: 'VARCHAR', PRIORITY: 'VARCHAR', SYSLOG_IDENTIFIER: 'VARCHAR'}) j; 96 97 CREATE MACRO nginx(since, until) AS TABLE 98 SELECT 99 regexp_extract(line, '^\S+', 0) as remote_addr, 100 regexp_extract(line, '\[([^\]]+)\]', 1) as timestamp, 101 regexp_extract(line, '"(\S+) (\S+) \S+"', 1) as method, 102 regexp_extract(line, '"(\S+) (\S+) \S+"', 2) as path, 103 CAST(regexp_extract(line, '" (\d+) ', 1) AS INTEGER) as status, 104 CAST(regexp_extract(line, '" \d+ (\d+)', 1) AS INTEGER) as bytes, 105 regexp_extract(line, '"([^"]*)"[^"]*$', 1) as user_agent 106 FROM read_csv(urls('nginx', 'log.gz', since, until), header=false, columns={'line': 'VARCHAR'}, auto_detect=false, 107 delim=chr(1), quote=chr(2), escape=chr(2)) t 108 WHERE line IS NOT NULL AND length(line) > 0; 109 ''; 110 query-logs = pkgs.writeShellScriptBin "query-logs" '' 111 ${pkgs.duckdb}/bin/duckdb -init ${initSql} 112 '' 113 ; 114 in 115 pkgs.mkShell { 116 buildInputs = with pkgs; [ 117 git 118 gnumake 119 age 120 curl 121 sops 122 wireguard-tools 123 squawk 124 nixfmt-rfc-style 125 forgejo-cli 126 query-logs 127 ]; 128 }; 129 }; 130 }