Added music specialization + formatter + archiver

This commit is contained in:
Samy Avrillon 2025-09-23 20:26:09 +02:00
parent f50bb2e8c3
commit 2abe84b8c2
9 changed files with 537 additions and 374 deletions

44
flake.lock generated
View File

@ -39,6 +39,26 @@
"type": "github"
}
},
"musnix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1756852730,
"narHash": "sha256-qPere4RBHoZxiEGl8zXU8gjroZg4gkYGEwaAbKmL4vE=",
"owner": "musnix",
"repo": "musnix",
"rev": "7ccc92050e43dc92309396c6f2fe1f542214a242",
"type": "github"
},
"original": {
"owner": "musnix",
"repo": "musnix",
"type": "github"
}
},
"nix-vscode-extensions": {
"inputs": {
"flake-utils": "flake-utils",
@ -79,8 +99,10 @@
"root": {
"inputs": {
"home-manager": "home-manager",
"musnix": "musnix",
"nix-vscode-extensions": "nix-vscode-extensions",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
@ -97,6 +119,26 @@
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1758206697,
"narHash": "sha256-/DbPkh6PZOgfueCbs3uzlk4ASU2nPPsiVWhpMCNkAd0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "128222dc911b8e2e18939537bed1762b7f3a04aa",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",

View File

@ -9,6 +9,12 @@
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
nix-vscode-extensions.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
musnix.url = "github:musnix/musnix";
musnix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
@ -19,7 +25,11 @@
mkNixosSystems = lib.mapAttrs (
name: modules:
lib.nixosSystem {
modules = modules ++ [
modules = [
inputs.musnix.nixosModules.musnix
]
++ modules
++ [
{
imports = [ (import "${inputs.home-manager}/nixos") ];
networking.hostName = name;
@ -31,7 +41,20 @@
);
in
{
formatter.x86_64-linux = inputs.nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
formatter.x86_64-linux =
inputs.treefmt-nix.lib.mkWrapper (import inputs.nixpkgs { system = "x86_64-linux"; })
{
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
black.enable = true;
};
settings.formatter.black.options = [
"--line-length"
"79"
];
};
nixosConfigurations = mkNixosSystems {
polysaa = [

View File

@ -91,5 +91,11 @@
settings.General.Experimental = true;
};
# Creates a specialisation for rt kernel
specialisation.zik.configuration = {
musnix.enable = true;
users.users.mysaa.extraGroups = [ "audio" ];
};
system.stateVersion = "25.05";
}

View File

@ -63,6 +63,8 @@
nano
wget
git
tree
ripgrep
];
# Some programs need SUID wrappers, can be configured further or are

View File

@ -1,28 +1,40 @@
{config, pkgs, lib, ...}:
{
config,
pkgs,
lib,
...
}:
let
filterToString = (m: f:
if builtins.isString f
then "(${m},contains,${f})"
else if builtins.isList f
then "OR "+(lib.strings.concatStringsSep " OR " (builtins.map (filterToString m) f))
else builtins.throw "Wrong filter content"
filterToString = (
m: f:
if builtins.isString f then
"(${m},contains,${f})"
else if builtins.isList f then
"OR " + (lib.strings.concatStringsSep " OR " (builtins.map (filterToString m) f))
else
builtins.throw "Wrong filter content"
);
convertFilters = (filz: builtins.map (fil: {
convertFilters = (
filz:
builtins.map (fil: {
enabled = true;
type = "17";
name = "Moving emails to folder " + fil.folder;
action = "Move to folder";
actionValue = "imap://mysaa%40hadoly.fr@imap.hadoly.fr/" + (fil.folderEscaped or fil.folder);
condition = filterToString (fil.matching or "all addresses") fil.email;
}) filz);
restFilter = (out: {
}) filz
);
restFilter = (
out: {
enabled = true;
type = "17";
name = "Moving other emails to " + out;
action = "Move to folder";
actionValue = "imap://mysaa%40hadoly.fr@imap.hadoly.fr/INBOX/" + out;
condition = "ALL";
});
}
);
rules = [
{
folder = "Assos/AliENS";
@ -257,7 +269,8 @@
];
}
];
in {
in
{
home-manager.users.mysaa.accounts.email.accounts = {
personal.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "s@nc") ];
ens.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "ENS-Lyon") ];

View File

@ -0,0 +1,80 @@
import mailbox
import sys
from imap_tools import A, MailBox
from datetime import date
import os
MDloc = "/home/mysaa/Globox"
MD = mailbox.Maildir(MDloc)
# firstDate = '"1-Sept-2025"'
firstDate = date(day=1, month=9, year=2025)
def parseFolder(folderString):
if folderString[0] == 34: # Double quote
folderString = folderString[1:-1]
folderz = (
folderString.replace(b"&", b"+")
.replace(b",", b"/")
.decode("utf-7")
.split(".")
)
return folderz
def sbdify(name):
if name == "INBOX":
return "Inbox.sbd" # I have no idea why thunderbird uncapitalizes this
return name + ".sbd"
password = sys.argv[1].strip()
with MailBox("imap.hadoly.fr", 993).login("mysaa@hadoly.fr", password) as M:
folders = []
folderzz = []
folderToFolderz = dict()
for f in M.folder.list():
folders.append(f)
print(f)
mdfolders = {"": MD}
folders = sorted(folders, key=lambda f: f.name.count(f.delim))
for f in folders:
print("Checking folder", f)
ff = f.name.split(f.delim)
folderPath = os.path.join(MDloc, *[sbdify(s) for s in ff[:-1]], ff[-1])
if os.path.exists(folderPath):
print("Already exists")
else:
print("Creating the folder", folderPath)
os.makedirs(folderPath)
os.mkdir(os.path.join(folderPath, "tmp"))
os.mkdir(os.path.join(folderPath, "cur"))
mdf = mailbox.Maildir(folderPath, create=True)
mdfolders[f.name] = mdf
print("Now filling the emails")
for f in folders:
mdfolder = mdfolders[f.name]
M.folder.set(f.name)
uids = M.uids(
A(date_lt=firstDate, seen=True, flagged=False, draft=False)
)
print(
"Moving",
len(uids),
"from folder",
f.name,
"out of",
len(M.uids(A(all=True))),
)
for u in uids:
msg = next(M.fetch(A(uid=u)))
msg = mailbox.MaildirMessage(msg.obj.as_bytes())
msg.set_subdir("cur")
msg.set_flags("S")
mdfolder.add(msg)
# Then remove the message
M.delete(u)

View File

@ -5,7 +5,7 @@
...
}:
let
clean-nixos-git-check-script = pkgs.writeScript "clean-nixos-git-check" ''
clean-nixos-git-check-script = pkgs.writers.writeBash "clean-nixos-git-check" ''
if [ -z "$(${pkgs.git}/bin/git -C /etc/nixos status -u --porcelain)" ]
then
echo "/etc/nixos is clean !"
@ -98,7 +98,7 @@
};
Service = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/bash ${clean-nixos-git-check-script}";
ExecStart = "${clean-nixos-git-check-script}";
};
};
timers.check-nixos-git-clean = {
@ -117,6 +117,4 @@
};
};
}

View File

@ -4,9 +4,14 @@
pkgs,
...
}:
let globox-id = "b446944a47d39ae969ebe27f81cf2d8963df7a04dd40e31e61c7c2ecc1ac7437";
let
globox-id = "b446944a47d39ae969ebe27f81cf2d8963df7a04dd40e31e61c7c2ecc1ac7437";
archiver = pkgs.writers.writePython3 "mail-archiver" {
libraries = with pkgs.python3Packages; [ imap-tools ];
} (builtins.readFile ./archiver.py);
in {
in
{
home-manager.users.mysaa.accounts.email.accounts = {
"hadoly".thunderbird.enable = true;
"personal".thunderbird.enable = true;
@ -40,8 +45,7 @@
"ecloud"
"google"
];
settings =
{
settings = {
"mail.account.account_${globox-id}.server" = "server_${globox-id}";
"mail.server.server_${globox-id}.directory" = "/home/mysaa/Globox";
#user_pref("mail.server.server1.directory-rel", "[ProfD]../../../Globox");
@ -84,35 +88,30 @@
# };
# })
# ];
/*security.pam.services.dovecot2 = {};
services.dovecot2 = {
enable = true;
enablePAM = false;
extraConfig = ''
protocols = imap
auth_mechanisms = plain login
service imap-login {
inet_listener imap {
port = 10143
address = 127.0.0.1
}
inet_listener imaps {
port = 10993
address = 127.0.0.1
}
}
log_path = /home/mysaa/.local/dovecot.log
passdb {
driver = passwd-file
args = /etc/dovecot-passwd
}
userdb {
driver = passwd
}
mail_location = maildir:/home/mysaa/Globox/:LAYOUT=fs
'';
home-manager.users.mysaa.systemd.user = {
services.mail-archiver = {
Unit = {
Description = "Archives emails from Hadoly account to Globox";
};
environment.etc.dovecot-passwd.text = ''
mysaa:{plain}aaaaa
*/
Service = {
Type = "oneshot";
ExecStart = "${archiver} $(cat /run/secrets/pass/hadoly_password)";
};
};
timers.mail-archiver = {
Unit = {
Description = "Weekly archiving of emails";
};
Timer = {
OnCalendar = "Tue *-*-* 13:00:00";
Persistent = "true";
Unit = "mail-archiver.service";
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
}