refactor: pull out systems

This commit is contained in:
2025-07-17 15:21:06 +00:00
parent 20dcbdfdc4
commit 23d9db27e6
6 changed files with 128 additions and 99 deletions

View File

@@ -18,7 +18,8 @@
}@inputs: let }@inputs: let
flake = ./.; flake = ./.;
nixpkgs = nixpkgs-25-05; nixpkgs = nixpkgs-25-05;
self-lib = import ./lib { inherit flake self inputs; }; overlays = [ self.overlays.default ];
self-lib = import ./lib { inherit flake self inputs nixpkgs; };
buildPostgresqlExtension = buildPostgresqlExtension =
pkgs: pkgs.callPackage (import (builtins.path { pkgs: pkgs.callPackage (import (builtins.path {
@@ -369,98 +370,15 @@
}); });
}; };
nixosConfigurations = { nixosConfigurations = {
"devvm|manual|${system}" = import "./nixos/system/devvm|manual" { inherit flake self inputs; }; "devvm-manual|${system}" = import ./nixos/system/devvm-manual/default.nix { inherit flake self inputs system; };
"hemar-test|${system}" = nixpkgs.lib.nixosSystem { "devvm-hemar|${system}" = import ./nixos/system/devvm-hemar/default.nix { inherit flake self inputs system; };
inherit system;
modules = [
({modulesPath, pkgs, lib, ...}: {
imports = [
self.nixosModules.hectic
(modulesPath + "/profiles/qemu-guest.nix")
];
hectic = {
archetype.dev.enable = true;
hardware.hetzner-cloud.enable = true;
};
users.users.root.openssh.authorizedKeys.keys = [
''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICrbBG+U07f7OKvOxYIGYCaNvyozzxQF+I9Fb5TYZErK yukkop vm-postgres''
];
services.postgresql =
let
package = pkgs.postgresql_15;
in {
enable = true;
package = package;
settings =
{
port = 64317;
listen_addresses = lib.mkForce "*";
shared_preload_libraries = "";
};
extensions = [ package.pkgs.hemar ];
authentication = builtins.concatStringsSep "\n" [
"local all all trust"
"host sameuser all 127.0.0.1/32 scram-sha-256"
"host sameuser all ::1/128 scram-sha-256"
];
initialScript = pkgs.writeText "init-sql-script" ''
SET log_min_messages TO DEBUG1;
SET client_min_messages TO DEBUG1;
ALTER DATABASE postgres SET log_min_messages TO DEBUG1;
ALTER DATABASE postgres SET client_min_messages TO DEBUG1;
CREATE EXTENSION "hemar";
\i ${./package/c/hemar/test}/mod.sql
'';
};
environment.systemPackags = with pkgs; [
gdb
hectic.nvim-pager
(writeScriptBin "check" ''
journalctl -u postgresql.service | grep postgresql-post-start | sed 's|psql:/nix/store/[^:]*:[0-9]*: ||' | sed 's|^[^:]*:[^:]*:[^:]*: ||' | grep -v '^\[.*\]' | ${hectic.prettify-log}/bin/prettify-log --color-output
'')
];
programs.zsh.shellAliases = self.lib.sharedShellAliasesForDevVm // {
conn = "sudo su postgres -c 'psql -p 64317'";
};
virtualisation = {
vmVariant = {
systemd.services.fix-root-perms = {
description = "Fix root directory permissions";
after = [ "local-fs.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.coreutils}/bin/chmod 755 /";
};
};
virtualisation = {
diskSize = 1024*6;
diskImage = null;
forwardPorts = [ ];
};
};
};
networking.firewall = {
enable = true;
allowedTCPPorts = [
80
];
};
})
];
pkgs = import nixpkgs {inherit system; overlays = [ self.overlays.default ];};
};
}; };
}) // }) //
{ {
legacyPackages = self.lib.forAllSystems (system: import nixpkgs {
inherit system overlays;
});
lib = self-lib; lib = self-lib;
overlays.default = import ./overlay { inherit flake self inputs nixpkgs; }; overlays.default = import ./overlay { inherit flake self inputs nixpkgs; };
nixosModules = import ./nixos/module { inherit flake self inputs nixpkgs; }; nixosModules = import ./nixos/module { inherit flake self inputs nixpkgs; };

View File

@@ -1,5 +1,4 @@
{ flake, inputs, self }: let { flake, inputs, self, nixpkgs }: let
nixpkgs = inputs.nixpkgs-25-05;
lib = nixpkgs.lib; lib = nixpkgs.lib;
recursiveUpdate = nixpkgs.lib.recursiveUpdate; recursiveUpdate = nixpkgs.lib.recursiveUpdate;
@@ -12,7 +11,7 @@
"aarch64-darwin" "aarch64-darwin"
]; ];
forSpecSystemsWithPkgs = supportedSystems: pkgOverlays: f: forSystemsWithPkgs = supportedSystems: pkgOverlays: f:
builtins.foldl' ( builtins.foldl' (
acc: system: let acc: system: let
pkgs = import nixpkgs { pkgs = import nixpkgs {
@@ -28,7 +27,7 @@
) {} ) {}
supportedSystems; supportedSystems;
forAllSystemsWithPkgs = pkgOverlays: f: forSpecSystemsWithPkgs commonSystems pkgOverlays f; forAllSystemsWithPkgs = pkgOverlays: f: forSystemsWithPkgs commonSystems pkgOverlays f;
parseEnv = import ./parse-env.nix; parseEnv = import ./parse-env.nix;
@@ -44,7 +43,10 @@
else {}; else {};
in { in {
# -- For all systems -- # -- For all systems --
inherit dotEnv minorEnvironment parseEnv forAllSystemsWithPkgs forSpecSystemsWithPkgs commonSystems; inherit dotEnv minorEnvironment parseEnv forAllSystemsWithPkgs forSystemsWithPkgs commonSystems;
forSystems = systems: nixpkgs.lib.genAttrs systems;
forAllSystems = nixpkgs.lib.genAttrs commonSystems;
shellModules.logs = '' shellModules.logs = ''
RED='\033[0;31m' RED='\033[0;31m'
@@ -144,6 +146,8 @@ in {
paths; paths;
in in
listToAttrs attrList; listToAttrs attrList;
nixpkgs-lib = nixpkgs.lib;
} // rec { } // rec {
/* Supplied a directory, reads it's recursive structure into NixOS modules, so /* Supplied a directory, reads it's recursive structure into NixOS modules, so
that provided a `./module` dir with `module/foo/bar.nix` in it it outputs that provided a `./module` dir with `module/foo/bar.nix` in it it outputs

View File

@@ -5,13 +5,11 @@
system, system,
... ...
}: let }: let
inherit (self.legacyPackages."${system}") pkgs;
# Use folder name as name of this system # Use folder name as name of this system
name = builtins.baseNameOf ./.; name = builtins.baseNameOf ./.;
in pkgs.lib.nixosSystem { in self.lib.nixpkgs-lib.nixosSystem {
inherit pkgs; inherit (self.legacyPackages."${system}") pkgs;
modules = [ modules = [
{ networking.hostName = name; } { networking.hostName = name; }
(import ./${name}.nix { inherit flake self inputs; }) (import ./${name}.nix { inherit flake self inputs; })

View File

@@ -0,0 +1,91 @@
{
inputs,
flake,
self
}: {
modulesPath,
pkgs,
lib,
...
}: {
imports = [
self.nixosModules.hectic
(modulesPath + "/profiles/qemu-guest.nix")
];
hectic = {
archetype.dev.enable = true;
hardware.hetzner-cloud.enable = true;
};
users.users.root.openssh.authorizedKeys.keys = [
''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICrbBG+U07f7OKvOxYIGYCaNvyozzxQF+I9Fb5TYZErK yukkop vm-postgres''
];
services.postgresql =
let
package = pkgs.postgresql_15;
in {
enable = true;
package = package;
settings =
{
port = 64317;
listen_addresses = lib.mkForce "*";
shared_preload_libraries = "";
};
extensions = [ package.pkgs.hemar ];
authentication = builtins.concatStringsSep "\n" [
"local all all trust"
"host sameuser all 127.0.0.1/32 scram-sha-256"
"host sameuser all ::1/128 scram-sha-256"
];
initialScript = pkgs.writeText "init-sql-script" ''
SET log_min_messages TO DEBUG1;
SET client_min_messages TO DEBUG1;
ALTER DATABASE postgres SET log_min_messages TO DEBUG1;
ALTER DATABASE postgres SET client_min_messages TO DEBUG1;
CREATE EXTENSION "hemar";
\i ${flake}/package/c/hemar/test/mod.sql
'';
};
environment.systemPackages = with pkgs; [
gdb
hectic.nvim-pager
(writeScriptBin "check" ''
journalctl -u postgresql.service | grep postgresql-post-start | sed 's|psql:/nix/store/[^:]*:[0-9]*: ||' | sed 's|^[^:]*:[^:]*:[^:]*: ||' | grep -v '^\[.*\]' | ${hectic.prettify-log}/bin/prettify-log --color-output
'')
];
programs.zsh.shellAliases = self.lib.sharedShellAliasesForDevVm // {
conn = "sudo su postgres -c 'psql -p 64317'";
};
virtualisation = {
vmVariant = {
systemd.services.fix-root-perms = {
description = "Fix root directory permissions";
after = [ "local-fs.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.coreutils}/bin/chmod 755 /";
};
};
virtualisation = {
diskSize = 1024*6;
diskImage = null;
forwardPorts = [ ];
};
};
};
networking.firewall = {
enable = true;
allowedTCPPorts = [
80
];
};
}

View File

@@ -0,0 +1,17 @@
{
flake,
self,
inputs,
system,
...
}: let
# Use folder name as name of this system
name = builtins.baseNameOf ./.;
in self.lib.nixpkgs-lib.nixosSystem {
inherit (self.legacyPackages."${system}") pkgs;
modules = [
{ networking.hostName = name; }
(import ./${name}.nix { inherit flake self inputs; })
];
}

View File

@@ -7,6 +7,7 @@
pkgs, pkgs,
modulesPath, modulesPath,
config, config,
...
}: }:
{ {
imports = [ imports = [