From 2abe84b8c22c346c8e53f799bbbd09b3cdaed83f Mon Sep 17 00:00:00 2001 From: Mysaa Java Date: Tue, 23 Sep 2025 20:26:09 +0200 Subject: [PATCH] Added music specialization + formatter + archiver --- flake.lock | 44 ++- flake.nix | 27 +- machines/polysaa/default.nix | 6 + profiles/basic/default.nix | 2 + profiles/basic/email-filters.nix | 531 +++++++++++++++-------------- profiles/graphical/archiver.py | 80 +++++ profiles/graphical/kde.nix | 2 +- profiles/graphical/packages.nix | 10 +- profiles/graphical/thunderbird.nix | 209 ++++++------ 9 files changed, 537 insertions(+), 374 deletions(-) create mode 100644 profiles/graphical/archiver.py diff --git a/flake.lock b/flake.lock index 311431b..833b72c 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index 13a2727..69c5d3e 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = [ diff --git a/machines/polysaa/default.nix b/machines/polysaa/default.nix index 28b2803..fc300b7 100644 --- a/machines/polysaa/default.nix +++ b/machines/polysaa/default.nix @@ -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"; } diff --git a/profiles/basic/default.nix b/profiles/basic/default.nix index 6f4859d..6e40540 100644 --- a/profiles/basic/default.nix +++ b/profiles/basic/default.nix @@ -63,6 +63,8 @@ nano wget git + tree + ripgrep ]; # Some programs need SUID wrappers, can be configured further or are diff --git a/profiles/basic/email-filters.nix b/profiles/basic/email-filters.nix index 39debee..2a92ac2 100644 --- a/profiles/basic/email-filters.nix +++ b/profiles/basic/email-filters.nix @@ -1,269 +1,282 @@ -{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" - ); - convertFilters = (filz: builtins.map (fil: { +{ + 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" + ); + convertFilters = ( + filz: + builtins.map (fil: { enabled = true; type = "17"; - name = "Moving emails to folder "+fil.folder; + name = "Moving emails to folder " + fil.folder; action = "Move to folder"; - actionValue = "imap://mysaa%40hadoly.fr@imap.hadoly.fr/"+(fil.folderEscaped or fil.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; + name = "Moving other emails to " + out; action = "Move to folder"; - actionValue = "imap://mysaa%40hadoly.fr@imap.hadoly.fr/INBOX/"+out; + actionValue = "imap://mysaa%40hadoly.fr@imap.hadoly.fr/INBOX/" + out; condition = "ALL"; - }); - rules = [ - { - folder = "Assos/AliENS"; - email = [ - "aliens.discussion@ens-lyon.fr" - "aliens.discussion@listes.ens-lyon.fr" - "azertoutes@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/AliENS/CA"; - email = [ - "aliens.ca@ens-lyon.fr" - "aliens.ca@listes.ens-lyon.fr" - "aliens.contact@ens-lyon.fr" - "aliens.contact@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/BuL/Murders"; - email = [ - "bul.murder.decouverte@ens-lyon.fr" - "bul.murder.decouverte@listes.ens-lyon.fr" - "bul.murder@ens-lyon.fr" - "bul.murder@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/Démesures"; - folderEscaped = "Assos/D&AOk-mesures"; - email = [ - "demesures@ens-lyon.fr" - "demesures@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/Diffs"; - email = [ - "fede.diffusion@ens-lyon.fr" - "fede.diffusion@listes.ens-lyon.fr" - "info.elus.etudiants@ens-lyon.fr" - "info.elus.etudiants@listes.ens-lyon.fr" - "bde.diffusion@ens-lyon.fr" - "bde.diffusion@listes.ens-lyon.fr" - "bul.diffusion@ens-lyon.fr" - "bul.diffusion@listes.ens-lyon.fr" - "enverts.diffusion@ens-lyon.fr" - "enverts.diffusion@listes.ens-lyon.fr" - "trensistor.diffusion@ens-lyon.fr" - "trensistor.diffusion@listes.ens-lyon.fr" - "aliens.diffusion@ens-lyon.fr" - "aliens.diffusion@listes.ens-lyon.fr" - "bde.foyer.diffusion@ens-lyon.fr" - "bde.foyer.diffusion@listes.ens-lyon.fr" - "bde.kfet.diffusion@ens-lyon.fr" - "bde.kfet.diffusion@listes.ens-lyon.fr" - "as-ensl@ens-lyon.fr" - "as-ensl@listes.ens-lyon.fr" - "bde.foyer@ens-lyon.fr" - "bde.foyer@listes.ens-lyon.fr" - "asset.diffusion@ens-lyon.fr" - "asset.diffusion@listes.ens-lyon.fr" - "echarde.diffusion@framalistes.org" - "echarde.membres@framalistes.org" - "enverts.enselle@ens-lyon.fr" - "enverts.enselle@listes.ens-lyon.fr" - "enverts.engraines.descartes@ens-lyon.fr" - "enverts.engraines.monod@listes.ens-lyon.fr" - "discourse+noreply@openstreetmap.fr" - "grrrndzero@grrrndzero.org" - "info@cinefac.fr" - "arcensiel.diffusion@ens-lyon.fr" - "arcensiel.diffusion@listes.ens-lyon.fr" - "bde.absurde@ens-lyon.fr" - "bde.absurde@listes.ens-lyon.fr" - "presences.diffusion@ens-lyon.fr" - "presences.diffusion@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/ENSeigner"; - email = [ - "enseigner.tuteurices@ens-lyon.fr" - "enseigner.tuteurices@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/ENvertS"; - email = [ - "enverts.bureau@ens-lyon.fr" - "enverts.bureau@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/ENvertS/Framavox"; - email = [ - "notifications@framavox.org" - ]; - } - { - folder = "Assos/Fédé"; - folderEscaped = "Assos/F&AOk-d&AOk-"; - email = [ - "fede.ca@ens-lyon.fr" - "fede.ca@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/Fédé/Art Total"; - folderEscaped = "Assos/F&AOk-d&AOk-/Art Total"; - email = [ - "fede.art-total@ens-lyon.fr" - "fede.art-total@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/Fédé/Bureau"; - folderEscaped = "Assos/F&AOk-d&AOk-/Bureau"; - email = [ - "federation@ens-lyon.fr" - "federation@listes.ens-lyon.fr" - "fede.communications@ens-lyon.fr" - ]; - } - { - folder = "Assos/Fédé/Informatique"; - folderEscaped = "Assos/F&AOk-d&AOk-/Informatique"; - email = [ - "fede.informatique@ens-lyon.fr" - "fede.informatique@listes.ens-lyon.fr" - ]; - } - - { - folder = "Assos/Fédé/Juridique"; - folderEscaped = "Assos/F&AOk-d&AOk-/Juridique"; - email = [ - "fede.juridique@ens-lyon.fr" - "fede.juridique@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/Modération"; - folderEscaped = "Assos/Mod&AOk-ration"; - email = [ - "sympa@listes.ens-lyon.fr" - "sympa-request@listes.ens-lyon.fr" - ]; - } - { - folder = "Assos/Modération"; - folderEscaped = "Assos/Mod&AOk-ration"; - email = [ - "sympa@listes.ens-lyon.fr" - ]; - matching = "\\\"reply-to\\\""; - } - { - folder = "Assos/tous-spam"; - email = [ - "tous.ens@ens-lyon.fr" - "tous.ens@listes.ens-lyon.fr" - "tous.culture@ens-lyon.fr" - "tous.culture@listes.ens-lyon.fr" - "tous.manifestations.scientifiques@ens-lyon.fr" - "tous.manifestations.scientifiques@listes.ens-lyon.fr" - "tous.etudiants@ens-lyon.fr" - "tous.etudiants@listes.ens-lyon.fr" - "tous.normaliens-eleves@ens-lyon.fr" - "tous.normaliens-eleves@listes.ens-lyon.fr" - "culture@ens-lyon.fr" - "culture@listes.ens-lyon.fr" - "information.patrimoine@ens-lyon.fr" - "information.patrimoine@listes.ens-lyon.fr" - "tous.transition.ecologique@ens-lyon.fr" - "tous.transition.ecologique@listes.ens-lyon.fr" - "manifestations.ife@ens-lyon.fr" - "manifestations.ife@listes.ens-lyon.fr" - "cercc@ens-lyon.fr" - "cercc@listes.ens-lyon.fr" - "info.syndicat.cgt@ens-lyon.fr" - "info.syndicat.cgt@listes.ens-lyon.fr" - "info.syndicat.sud@ens-lyon.fr" - "info.syndicat.sud@listes.ens-lyon.fr" - "info.syndicat.cfdt@ens-lyon.fr" - "info.syndicat.cfdt@listes.ens-lyon.fr" - "info.syndicat.snesup-fsu@ens-lyon.fr" - "info.syndicat.snesup-fsu@listes.ens-lyon.fr" - "info.syndicat.sud@ens-lyon.fr" - "info.syndicat.sud@listes.ens-lyon.fr" - "newsletter@national.lescrous.fr" - "infos@national.lescrous.fr" - ]; - } - { - folder = "Notif"; - email = [ - "nepasrepondre@credit-cooperatif.coop" - "noreply@github.com" - "no-reply@twitch.tv" - "ne_pas_repondre@sfr.fr" - "expiry@letsencrypt.org" - "info@mail.sncfconnect.com" - "service@paypal.fr" - "purchase-noreply@twitch.tv" - "no-reply@doctolib.fr" - "no-reply@canva.com" - "notifications@transifex.com" - "ne-pas-repondre@inscriptionelectorale.service-public.fr" - "noreply@steampowered.com" - "noreply@connect.sncf" - "no-reply@spotify.com" - "messagerie.leboncoin.fr" - "no.reply@leboncoin.fr" - "nepasrepondre-filesender@renater.fr" - "gitlab@aliens-lyon.fr" - "postman@ulule.com" - "no-reply@accounts.google.com" - "notifications@discord.com" - "help@acct.epicgames.com" - "no-reply+framateam@framasoft.org" - ]; - } - { - folder = "Etudes"; - email = [ - "types-announce@lists.seas.upenn.edu" - "types-announce@LISTS.SEAS.UPENN.EDU" - "categories@mq.edu.au" - "ice@framalistes.org" - "cashreadinggroup@listes.ens-lyon.fr" - ]; - } + } + ); + rules = [ + { + folder = "Assos/AliENS"; + email = [ + "aliens.discussion@ens-lyon.fr" + "aliens.discussion@listes.ens-lyon.fr" + "azertoutes@listes.ens-lyon.fr" ]; - in { - home-manager.users.mysaa.accounts.email.accounts = { - personal.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "s@nc") ]; - ens.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "ENS-Lyon") ]; - junk.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "q@nc") ]; - google.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "Google") ]; - ecloud.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "ECloud") ]; - hadoly.thunderbird.messageFilters = [ (restFilter "Hadoly") ]; - }; + } + { + folder = "Assos/AliENS/CA"; + email = [ + "aliens.ca@ens-lyon.fr" + "aliens.ca@listes.ens-lyon.fr" + "aliens.contact@ens-lyon.fr" + "aliens.contact@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/BuL/Murders"; + email = [ + "bul.murder.decouverte@ens-lyon.fr" + "bul.murder.decouverte@listes.ens-lyon.fr" + "bul.murder@ens-lyon.fr" + "bul.murder@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/Démesures"; + folderEscaped = "Assos/D&AOk-mesures"; + email = [ + "demesures@ens-lyon.fr" + "demesures@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/Diffs"; + email = [ + "fede.diffusion@ens-lyon.fr" + "fede.diffusion@listes.ens-lyon.fr" + "info.elus.etudiants@ens-lyon.fr" + "info.elus.etudiants@listes.ens-lyon.fr" + "bde.diffusion@ens-lyon.fr" + "bde.diffusion@listes.ens-lyon.fr" + "bul.diffusion@ens-lyon.fr" + "bul.diffusion@listes.ens-lyon.fr" + "enverts.diffusion@ens-lyon.fr" + "enverts.diffusion@listes.ens-lyon.fr" + "trensistor.diffusion@ens-lyon.fr" + "trensistor.diffusion@listes.ens-lyon.fr" + "aliens.diffusion@ens-lyon.fr" + "aliens.diffusion@listes.ens-lyon.fr" + "bde.foyer.diffusion@ens-lyon.fr" + "bde.foyer.diffusion@listes.ens-lyon.fr" + "bde.kfet.diffusion@ens-lyon.fr" + "bde.kfet.diffusion@listes.ens-lyon.fr" + "as-ensl@ens-lyon.fr" + "as-ensl@listes.ens-lyon.fr" + "bde.foyer@ens-lyon.fr" + "bde.foyer@listes.ens-lyon.fr" + "asset.diffusion@ens-lyon.fr" + "asset.diffusion@listes.ens-lyon.fr" + "echarde.diffusion@framalistes.org" + "echarde.membres@framalistes.org" + "enverts.enselle@ens-lyon.fr" + "enverts.enselle@listes.ens-lyon.fr" + "enverts.engraines.descartes@ens-lyon.fr" + "enverts.engraines.monod@listes.ens-lyon.fr" + "discourse+noreply@openstreetmap.fr" + "grrrndzero@grrrndzero.org" + "info@cinefac.fr" + "arcensiel.diffusion@ens-lyon.fr" + "arcensiel.diffusion@listes.ens-lyon.fr" + "bde.absurde@ens-lyon.fr" + "bde.absurde@listes.ens-lyon.fr" + "presences.diffusion@ens-lyon.fr" + "presences.diffusion@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/ENSeigner"; + email = [ + "enseigner.tuteurices@ens-lyon.fr" + "enseigner.tuteurices@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/ENvertS"; + email = [ + "enverts.bureau@ens-lyon.fr" + "enverts.bureau@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/ENvertS/Framavox"; + email = [ + "notifications@framavox.org" + ]; + } + { + folder = "Assos/Fédé"; + folderEscaped = "Assos/F&AOk-d&AOk-"; + email = [ + "fede.ca@ens-lyon.fr" + "fede.ca@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/Fédé/Art Total"; + folderEscaped = "Assos/F&AOk-d&AOk-/Art Total"; + email = [ + "fede.art-total@ens-lyon.fr" + "fede.art-total@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/Fédé/Bureau"; + folderEscaped = "Assos/F&AOk-d&AOk-/Bureau"; + email = [ + "federation@ens-lyon.fr" + "federation@listes.ens-lyon.fr" + "fede.communications@ens-lyon.fr" + ]; + } + { + folder = "Assos/Fédé/Informatique"; + folderEscaped = "Assos/F&AOk-d&AOk-/Informatique"; + email = [ + "fede.informatique@ens-lyon.fr" + "fede.informatique@listes.ens-lyon.fr" + ]; + } + + { + folder = "Assos/Fédé/Juridique"; + folderEscaped = "Assos/F&AOk-d&AOk-/Juridique"; + email = [ + "fede.juridique@ens-lyon.fr" + "fede.juridique@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/Modération"; + folderEscaped = "Assos/Mod&AOk-ration"; + email = [ + "sympa@listes.ens-lyon.fr" + "sympa-request@listes.ens-lyon.fr" + ]; + } + { + folder = "Assos/Modération"; + folderEscaped = "Assos/Mod&AOk-ration"; + email = [ + "sympa@listes.ens-lyon.fr" + ]; + matching = "\\\"reply-to\\\""; + } + { + folder = "Assos/tous-spam"; + email = [ + "tous.ens@ens-lyon.fr" + "tous.ens@listes.ens-lyon.fr" + "tous.culture@ens-lyon.fr" + "tous.culture@listes.ens-lyon.fr" + "tous.manifestations.scientifiques@ens-lyon.fr" + "tous.manifestations.scientifiques@listes.ens-lyon.fr" + "tous.etudiants@ens-lyon.fr" + "tous.etudiants@listes.ens-lyon.fr" + "tous.normaliens-eleves@ens-lyon.fr" + "tous.normaliens-eleves@listes.ens-lyon.fr" + "culture@ens-lyon.fr" + "culture@listes.ens-lyon.fr" + "information.patrimoine@ens-lyon.fr" + "information.patrimoine@listes.ens-lyon.fr" + "tous.transition.ecologique@ens-lyon.fr" + "tous.transition.ecologique@listes.ens-lyon.fr" + "manifestations.ife@ens-lyon.fr" + "manifestations.ife@listes.ens-lyon.fr" + "cercc@ens-lyon.fr" + "cercc@listes.ens-lyon.fr" + "info.syndicat.cgt@ens-lyon.fr" + "info.syndicat.cgt@listes.ens-lyon.fr" + "info.syndicat.sud@ens-lyon.fr" + "info.syndicat.sud@listes.ens-lyon.fr" + "info.syndicat.cfdt@ens-lyon.fr" + "info.syndicat.cfdt@listes.ens-lyon.fr" + "info.syndicat.snesup-fsu@ens-lyon.fr" + "info.syndicat.snesup-fsu@listes.ens-lyon.fr" + "info.syndicat.sud@ens-lyon.fr" + "info.syndicat.sud@listes.ens-lyon.fr" + "newsletter@national.lescrous.fr" + "infos@national.lescrous.fr" + ]; + } + { + folder = "Notif"; + email = [ + "nepasrepondre@credit-cooperatif.coop" + "noreply@github.com" + "no-reply@twitch.tv" + "ne_pas_repondre@sfr.fr" + "expiry@letsencrypt.org" + "info@mail.sncfconnect.com" + "service@paypal.fr" + "purchase-noreply@twitch.tv" + "no-reply@doctolib.fr" + "no-reply@canva.com" + "notifications@transifex.com" + "ne-pas-repondre@inscriptionelectorale.service-public.fr" + "noreply@steampowered.com" + "noreply@connect.sncf" + "no-reply@spotify.com" + "messagerie.leboncoin.fr" + "no.reply@leboncoin.fr" + "nepasrepondre-filesender@renater.fr" + "gitlab@aliens-lyon.fr" + "postman@ulule.com" + "no-reply@accounts.google.com" + "notifications@discord.com" + "help@acct.epicgames.com" + "no-reply+framateam@framasoft.org" + ]; + } + { + folder = "Etudes"; + email = [ + "types-announce@lists.seas.upenn.edu" + "types-announce@LISTS.SEAS.UPENN.EDU" + "categories@mq.edu.au" + "ice@framalistes.org" + "cashreadinggroup@listes.ens-lyon.fr" + ]; + } + ]; +in +{ + home-manager.users.mysaa.accounts.email.accounts = { + personal.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "s@nc") ]; + ens.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "ENS-Lyon") ]; + junk.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "q@nc") ]; + google.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "Google") ]; + ecloud.thunderbird.messageFilters = convertFilters rules ++ [ (restFilter "ECloud") ]; + hadoly.thunderbird.messageFilters = [ (restFilter "Hadoly") ]; + }; } diff --git a/profiles/graphical/archiver.py b/profiles/graphical/archiver.py new file mode 100644 index 0000000..d34c589 --- /dev/null +++ b/profiles/graphical/archiver.py @@ -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) diff --git a/profiles/graphical/kde.nix b/profiles/graphical/kde.nix index f1eaa1d..5b9c03a 100644 --- a/profiles/graphical/kde.nix +++ b/profiles/graphical/kde.nix @@ -10,7 +10,7 @@ elisa ]; - home-manager.users.mysaa.home.file.".config/kdeglobals".text = lib.generators.toINI {} { + home-manager.users.mysaa.home.file.".config/kdeglobals".text = lib.generators.toINI { } { KDE = { SingleClick = true; }; diff --git a/profiles/graphical/packages.nix b/profiles/graphical/packages.nix index ee595ae..069deca 100644 --- a/profiles/graphical/packages.nix +++ b/profiles/graphical/packages.nix @@ -4,8 +4,8 @@ pkgs, ... }: - let - clean-nixos-git-check-script = pkgs.writeScript "clean-nixos-git-check" '' +let + 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 !" @@ -15,7 +15,7 @@ exit 0 fi ''; - in +in { environment.systemPackages = with pkgs; [ @@ -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 @@ }; }; - - } diff --git a/profiles/graphical/thunderbird.nix b/profiles/graphical/thunderbird.nix index f320999..cc5aa41 100644 --- a/profiles/graphical/thunderbird.nix +++ b/profiles/graphical/thunderbird.nix @@ -4,115 +4,114 @@ 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 { - home-manager.users.mysaa.accounts.email.accounts = { - "hadoly".thunderbird.enable = true; - "personal".thunderbird.enable = true; - "ens".thunderbird.enable = true; - "junk".thunderbird.enable = true; - "google".thunderbird.enable = true; - "bernard".thunderbird.enable = true; - "dmesures".thunderbird.enable = true; - "ecloud".thunderbird.enable = true; +in +{ + home-manager.users.mysaa.accounts.email.accounts = { + "hadoly".thunderbird.enable = true; + "personal".thunderbird.enable = true; + "ens".thunderbird.enable = true; + "junk".thunderbird.enable = true; + "google".thunderbird.enable = true; + "bernard".thunderbird.enable = true; + "dmesures".thunderbird.enable = true; + "ecloud".thunderbird.enable = true; + }; + home-manager.users.mysaa.programs.thunderbird = { + enable = true; + package = pkgs.thunderbird.override { + extraPolicies.ExtensionSettings = { + "localfolder@philoux.eu" = { + install_url = "https://addons.thunderbird.net/user-media/addons/_attachments/90003/localfolders-4.2.2-tb.xpi?filehash=sha256%3A71d499b55b360769447e9f08536ee557b0419e84d5914e79c18558d86a21fbd9"; + installation_mode = "force_installed"; + }; + }; }; - home-manager.users.mysaa.programs.thunderbird = { - enable = true; - package = pkgs.thunderbird.override { - extraPolicies.ExtensionSettings = { - "localfolder@philoux.eu" = { - install_url = "https://addons.thunderbird.net/user-media/addons/_attachments/90003/localfolders-4.2.2-tb.xpi?filehash=sha256%3A71d499b55b360769447e9f08536ee557b0419e84d5914e79c18558d86a21fbd9"; - installation_mode = "force_installed"; - }; - }; - }; - profiles.default = { - isDefault = true; - accountsOrder = [ - "hadoly" - "dmesures" - "bernard" - "ens" - "account_${globox-id}" - "personal" - "junk" - "ecloud" - "google" - ]; - 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"); - "mail.server.server_${globox-id}.hostname" = "globox"; - "mail.server.server_${globox-id}.name" = "globox"; - "mail.server.server_${globox-id}.storeContractID" = "@mozilla.org/msgstore/maildirstore;1"; - "mail.server.server_${globox-id}.type" = "none"; - "mail.server.server_${globox-id}.userName" = "nobody"; + profiles.default = { + isDefault = true; + accountsOrder = [ + "hadoly" + "dmesures" + "bernard" + "ens" + "account_${globox-id}" + "personal" + "junk" + "ecloud" + "google" + ]; + 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"); + "mail.server.server_${globox-id}.hostname" = "globox"; + "mail.server.server_${globox-id}.name" = "globox"; + "mail.server.server_${globox-id}.storeContractID" = "@mozilla.org/msgstore/maildirstore;1"; + "mail.server.server_${globox-id}.type" = "none"; + "mail.server.server_${globox-id}.userName" = "nobody"; - } - // lib.attrsets.concatMapAttrs ( - _: account: - lib.optionalAttrs (account.passwordCommand != null) ( - let - id = builtins.hashString "sha256" account.name; - command = lib.concatStringsSep " " account.passwordCommand; - passwordScript = pkgs.writeShellScript "get-password.sh" '' - echo "Got command $1" >> /tmp/thunderpasswordget - ${command} | ${pkgs.netcat}/bin/nc -w 0 -U $1 - ''; - in - lib.optionalAttrs (account.smtp != null) { - "mail.smtpserver.smtp_${id}.passwordCommand" = toString passwordScript; - } - // lib.optionalAttrs (account.imap != null) { - "mail.server.server_${id}.passwordCommand" = toString passwordScript; - } - ) - ) config.home-manager.users.mysaa.accounts.email.accounts; - }; + } + // lib.attrsets.concatMapAttrs ( + _: account: + lib.optionalAttrs (account.passwordCommand != null) ( + let + id = builtins.hashString "sha256" account.name; + command = lib.concatStringsSep " " account.passwordCommand; + passwordScript = pkgs.writeShellScript "get-password.sh" '' + echo "Got command $1" >> /tmp/thunderpasswordget + ${command} | ${pkgs.netcat}/bin/nc -w 0 -U $1 + ''; + in + lib.optionalAttrs (account.smtp != null) { + "mail.smtpserver.smtp_${id}.passwordCommand" = toString passwordScript; + } + // lib.optionalAttrs (account.imap != null) { + "mail.server.server_${id}.passwordCommand" = toString passwordScript; + } + ) + ) config.home-manager.users.mysaa.accounts.email.accounts; }; + }; - # home-manager.users.mysaa.nixpkgs.overlays = [ - # (final: prev: { - # thunderbird-unwrapped = prev.thunderbird-unwrapped.overrideAttrs { - # patches = (prev.thunderbird-unwrapped.patches or [ ]) ++ [ - # ../../packages/add_passwordcommand_smtp.patch - # ../../packages/add_passwordcommand_imap.patch - # ]; - # }; - # }) - # ]; - /*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.nixpkgs.overlays = [ + # (final: prev: { + # thunderbird-unwrapped = prev.thunderbird-unwrapped.overrideAttrs { + # patches = (prev.thunderbird-unwrapped.patches or [ ]) ++ [ + # ../../packages/add_passwordcommand_smtp.patch + # ../../packages/add_passwordcommand_imap.patch + # ]; + # }; + # }) + # ]; + + home-manager.users.mysaa.systemd.user = { + services.mail-archiver = { + Unit = { + Description = "Archives emails from Hadoly account to Globox"; + }; + Service = { + Type = "oneshot"; + ExecStart = "${archiver} $(cat /run/secrets/pass/hadoly_password)"; + }; }; - environment.etc.dovecot-passwd.text = '' - mysaa:{plain}aaaaa - */ + 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" ]; + }; + }; + }; + }