WIP: feat/automated-account-deletion #174

Draft
b12f wants to merge 23 commits from feat/automated-account-deletion into main
10 changed files with 374 additions and 358 deletions
Showing only changes of commit 74f03555e5 - Show all commits

View file

@ -79,14 +79,25 @@
master = import inputs.master { inherit system; }; master = import inputs.master { inherit system; };
}; };
packages = let packages =
let
nixos-lib = import (inputs.nixpkgs + "/nixos/lib") { }; nixos-lib = import (inputs.nixpkgs + "/nixos/lib") { };
testDir = builtins.attrNames (builtins.readDir ./tests); testDir = builtins.attrNames (builtins.readDir ./tests);
testFiles = builtins.filter (n: builtins.match "^.*.nix$" n != null) testDir; testFiles = builtins.filter (n: builtins.match "^.*.nix$" n != null) testDir;
in builtins.listToAttrs (map (x: { in
builtins.listToAttrs (
map (x: {
name = "test-${lib.strings.removeSuffix ".nix" x}"; name = "test-${lib.strings.removeSuffix ".nix" x}";
value = nixos-lib.runTest (import (./tests + "/${x}") { inherit self; inherit pkgs; inherit lib; inherit config; }); value = nixos-lib.runTest (
}) testFiles); import (./tests + "/${x}") {
inherit self;
inherit pkgs;
inherit lib;
inherit config;
}
);
}) testFiles
);
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [

View file

@ -7,11 +7,16 @@
}: }:
{ {
options.pub-solar-os.backups = { options.pub-solar-os.backups = {
stores = with lib; mkOption { stores =
with lib;
mkOption {
description = '' description = ''
Periodic backups to create with Restic. Periodic backups to create with Restic.
''; '';
type = types.attrsOf (types.submodule ({ name, ... }: { type = types.attrsOf (
types.submodule (
{ name, ... }:
{
options = { options = {
passwordFile = mkOption { passwordFile = mkOption {
type = types.str; type = types.str;
@ -30,7 +35,9 @@
example = "sftp:backup@192.168.1.100:/backups/${name}"; example = "sftp:backup@192.168.1.100:/backups/${name}";
}; };
}; };
})); }
)
);
default = { }; default = { };
example = { example = {
@ -41,11 +48,16 @@
}; };
}; };
backups = with lib; mkOption { backups =
with lib;
mkOption {
description = '' description = ''
Periodic backups to create with Restic. Periodic backups to create with Restic.
''; '';
type = types.attrsOf (types.submodule ({ name, ... }: { type = types.attrsOf (
types.submodule (
{ name, ... }:
{
options = { options = {
paths = mkOption { paths = mkOption {
# This is nullable for legacy reasons only. We should consider making it a pure listOf # This is nullable for legacy reasons only. We should consider making it a pure listOf
@ -112,9 +124,7 @@
description = '' description = ''
Extra arguments passed to restic backup. Extra arguments passed to restic backup.
''; '';
example = [ example = [ "--exclude-file=/etc/nixos/restic-ignore" ];
"--exclude-file=/etc/nixos/restic-ignore"
];
}; };
extraOptions = mkOption { extraOptions = mkOption {
@ -123,9 +133,7 @@
description = '' description = ''
Extra extended options to be passed to the restic --option flag. Extra extended options to be passed to the restic --option flag.
''; '';
example = [ example = [ "sftp.command='ssh backup@192.168.1.100 -i /home/user/.ssh/id_rsa -s sftp'" ];
"sftp.command='ssh backup@192.168.1.100 -i /home/user/.ssh/id_rsa -s sftp'"
];
}; };
initialize = mkOption { initialize = mkOption {
@ -167,9 +175,7 @@
description = '' description = ''
A list of options for 'restic check'. A list of options for 'restic check'.
''; '';
example = [ example = [ "--with-cache" ];
"--with-cache"
];
}; };
dynamicFilesFrom = mkOption { dynamicFilesFrom = mkOption {
@ -211,7 +217,9 @@
''; '';
}; };
}; };
})); }
)
);
default = { }; default = { };
example = { example = {
localbackup = { localbackup = {
@ -234,20 +242,22 @@
}; };
config = { config = {
services.restic.backups = let services.restic.backups =
let
stores = config.pub-solar-os.backups.stores; stores = config.pub-solar-os.backups.stores;
backups = config.pub-solar-os.backups.backups; backups = config.pub-solar-os.backups.backups;
storeNames = builtins.attrNames stores; storeNames = builtins.attrNames stores;
backupNames = builtins.attrNames backups; backupNames = builtins.attrNames backups;
createBackups = backupName: map createBackups =
(storeName: { backupName:
map (storeName: {
name = "${backupName}-${storeName}"; name = "${backupName}-${storeName}";
value = stores."${storeName}" // backups."${backupName}"; value = stores."${storeName}" // backups."${backupName}";
}) }) storeNames;
storeNames;
in builtins.listToAttrs (lib.lists.flatten (map createBackups backupNames)); in
builtins.listToAttrs (lib.lists.flatten (map createBackups backupNames));
}; };
} }

View file

@ -6,9 +6,7 @@
... ...
}: }:
{ {
nixpkgs.config = lib.mkDefault { nixpkgs.config = lib.mkDefault { allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ ]; };
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ ];
};
nix = { nix = {
# Use default version alias for nix package # Use default version alias for nix package

View file

@ -42,9 +42,7 @@
}; };
}; };
nixpkgs.config = lib.mkDefault { nixpkgs.config = lib.mkDefault { permittedInsecurePackages = [ "keycloak-23.0.6" ]; };
permittedInsecurePackages = [ "keycloak-23.0.6" ];
};
# keycloak # keycloak
services.keycloak = { services.keycloak = {

View file

@ -4,8 +4,10 @@
lib, lib,
config, config,
... ...
}: let }:
in { let
in
{
name = "keycloak"; name = "keycloak";
hostPkgs = pkgs; hostPkgs = pkgs;
@ -42,9 +44,7 @@ in {
./support/global.nix ./support/global.nix
]; ];
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [ "f /tmp/dbf 1777 root root 10d password" ];
"f /tmp/dbf 1777 root root 10d password"
];
virtualisation.memorySize = 4096; virtualisation.memorySize = 4096;
@ -65,7 +65,9 @@ in {
enableOCR = true; enableOCR = true;
testScript = {nodes, ...}: let testScript =
{ nodes, ... }:
let
user = nodes.client.users.users.${nodes.client.pub-solar-os.authentication.username}; user = nodes.client.users.users.${nodes.client.pub-solar-os.authentication.username};
#uid = toString user.uid; #uid = toString user.uid;
bus = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u ${user.name})/bus"; bus = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u ${user.name})/bus";
@ -73,7 +75,8 @@ in {
su = command: "su - ${user.name} -c '${command}'"; su = command: "su - ${user.name} -c '${command}'";
gseval = "call --session -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval"; gseval = "call --session -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval";
wmClass = su "${gdbus} ${gseval} global.display.focus_window.wm_class"; wmClass = su "${gdbus} ${gseval} global.display.focus_window.wm_class";
in '' in
''
start_all() start_all()
nachtigall.wait_for_unit("system.slice") nachtigall.wait_for_unit("system.slice")

View file

@ -3,14 +3,11 @@
lib, lib,
config, config,
... ...
}: { }:
imports = [ {
./global.nix imports = [ ./global.nix ];
];
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [ "f /tmp/step-ca-intermediate-pw 1777 root root 10d password" ];
"f /tmp/step-ca-intermediate-pw 1777 root root 10d password"
];
networking.interfaces.eth0.ipv4.addresses = [ networking.interfaces.eth0.ipv4.addresses = [
{ {
@ -19,7 +16,8 @@
} }
]; ];
services.step-ca = let services.step-ca =
let
certificates = pkgs.stdenv.mkDerivation { certificates = pkgs.stdenv.mkDerivation {
name = "certificates"; name = "certificates";
src = ./step; src = ./step;
@ -29,7 +27,8 @@
cp -r secrets $out/ cp -r secrets $out/
''; '';
}; };
in { in
{
enable = true; enable = true;
openFirewall = true; openFirewall = true;
intermediatePasswordFile = "/tmp/step-ca-intermediate-pw"; intermediatePasswordFile = "/tmp/step-ca-intermediate-pw";

View file

@ -5,9 +5,7 @@
... ...
}: }:
{ {
imports = [ imports = [ ./global.nix ];
./global.nix
];
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true; services.xserver.displayManager.gdm.enable = true;

View file

@ -3,14 +3,13 @@
lib, lib,
config, config,
... ...
}: { }:
{
pub-solar-os.networking.domain = "test.pub.solar"; pub-solar-os.networking.domain = "test.pub.solar";
security.acme.defaults.server = "https://ca.${config.pub-solar-os.networking.domain}/acme/acme/directory"; security.acme.defaults.server = "https://ca.${config.pub-solar-os.networking.domain}/acme/acme/directory";
security.pki.certificates = [ security.pki.certificates = [ (builtins.readFile ./step/certs/root_ca.crt) ];
(builtins.readFile ./step/certs/root_ca.crt)
];
services.openssh = { services.openssh = {
enable = true; enable = true;
@ -24,10 +23,12 @@
security.pam.services.sshd.allowNullPassword = true; security.pam.services.sshd.allowNullPassword = true;
virtualisation.forwardPorts = let virtualisation.forwardPorts =
let
address = (builtins.elemAt config.networking.interfaces.eth0.ipv4.addresses 0).address; address = (builtins.elemAt config.networking.interfaces.eth0.ipv4.addresses 0).address;
lastAddressPart = builtins.elemAt (lib.strings.splitString "." address) 3; lastAddressPart = builtins.elemAt (lib.strings.splitString "." address) 3;
in [ in
[
{ {
from = "host"; from = "host";
host.port = 2000 + (lib.strings.toInt lastAddressPart); host.port = 2000 + (lib.strings.toInt lastAddressPart);

View file

@ -2,9 +2,7 @@
"federatedRoots": null, "federatedRoots": null,
"address": ":443", "address": ":443",
"insecureAddress": "", "insecureAddress": "",
"dnsNames": [ "dnsNames": ["ca.test.pub.solar"],
"ca.test.pub.solar"
],
"logger": { "logger": {
"format": "text" "format": "text"
}, },