Restructure the modules

While it is easier to maintain the modules by prefixing them all with
`modules`, it is not easy when used from other flakes and/or modules.
This is my attempt on making it easier with appropriate namespaces.

Update home-manager user from the restructure
This commit is contained in:
Gabriel Arazas 2022-01-09 13:38:59 +08:00
parent 4e7338686e
commit 6b481a163a
18 changed files with 94 additions and 41 deletions

View File

@ -7,7 +7,7 @@
]; ];
# My custom configuration with my custom modules starts here. # My custom configuration with my custom modules starts here.
modules = { profiles = {
agenix.enable = true; agenix.enable = true;
archiving.enable = true; archiving.enable = true;
desktop = { desktop = {
@ -24,10 +24,6 @@
virtualization.enable = true; virtualization.enable = true;
neovim.enable = true; neovim.enable = true;
}; };
themes = {
disableLimit = true;
themes.a-happy-gnome.enable = true;
};
users.users.foo-dogsquared.settings = { users.users.foo-dogsquared.settings = {
extraGroups = [ "wheel" "audio" "docker" "podman" "network-manager" ]; extraGroups = [ "wheel" "audio" "docker" "podman" "network-manager" ];
hashedPassword = hashedPassword =
@ -36,7 +32,11 @@
createHome = true; createHome = true;
home = "/home/foo-dogsquared"; home = "/home/foo-dogsquared";
}; };
};
hardware-setup.backup-archive.enable = true; hardware-setup.backup-archive.enable = true;
themes = {
disableLimit = true;
themes.a-happy-gnome.enable = true;
}; };
# Use the systemd-boot EFI boot loader. # Use the systemd-boot EFI boot loader.

View File

@ -1,9 +1,9 @@
# Enables all of my usual setup for desktop-oriented stuff. # Enables all of my usual setup for desktop-oriented stuff.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.desktop; let cfg = config.profiles.desktop;
in { in {
options.modules.desktop = { options.profiles.desktop = {
enable = lib.mkEnableOption "installations of desktop apps"; enable = lib.mkEnableOption "installations of desktop apps";
graphics.enable = graphics.enable =
lib.mkEnableOption "installations of graphics-related apps"; lib.mkEnableOption "installations of graphics-related apps";

View File

@ -2,9 +2,9 @@
# If you're looking for text editors, go to `./editors.nix`. # If you're looking for text editors, go to `./editors.nix`.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.dev; let cfg = config.profiles.dev;
in { in {
options.modules.dev = { options.profiles.dev = {
enable = enable =
lib.mkEnableOption "foo-dogsquared's user-specific development setup"; lib.mkEnableOption "foo-dogsquared's user-specific development setup";
shell.enable = shell.enable =

View File

@ -7,9 +7,9 @@
# for me is not worth to maintain. # for me is not worth to maintain.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.editors; let cfg = config.profiles.editors;
in { in {
options.modules.editors = { options.profiles.editors = {
neovim.enable = lib.mkEnableOption "foo-dogsquared's Neovim setup with Nix"; neovim.enable = lib.mkEnableOption "foo-dogsquared's Neovim setup with Nix";
emacs.enable = lib.mkEnableOption "foo-dogsquared's (Doom) Emacs setup"; emacs.enable = lib.mkEnableOption "foo-dogsquared's (Doom) Emacs setup";
}; };
@ -51,6 +51,7 @@ in {
## :lang org +roam2 ## :lang org +roam2
sqlite sqlite
anystyle-cli
]; ];
}) })
]; ];

View File

@ -1,9 +1,9 @@
# Instant setup for using internationalized languages. # Instant setup for using internationalized languages.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.i18n; let cfg = config.profiles.i18n;
in { in {
options.modules.i18n.enable = options.profiles.i18n.enable =
lib.mkEnableOption "fcitx5 as input method engine"; lib.mkEnableOption "fcitx5 as input method engine";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {

View File

@ -1,8 +1,8 @@
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.research; let cfg = config.profiles.research;
in { in {
options.modules.research.enable = options.profiles.research.enable =
lib.mkEnableOption "my usual toolbelt for research"; lib.mkEnableOption "my usual toolbelt for research";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
@ -16,5 +16,7 @@ in {
yt-dlp # The general purpose video downloader. yt-dlp # The general purpose video downloader.
zotero # It's actually good at archiving despite not being a researcher myself. zotero # It's actually good at archiving despite not being a researcher myself.
]; ];
services.syncthing.enable = true;
}; };
} }

View File

@ -0,0 +1,41 @@
{ config, options, lib, pkgs, ... }:
let
cfg = config.services.archivebox;
in {
options.services.archivebox = {
enable = lib.mkEnableOption "Archivebox service";
port = lib.mkOption {
type = lib.types.port;
description = "The port number to be used for the server at localhost.";
default = 8000;
example = 8888;
};
archivePath = lib.mkOption {
type = with lib.types; either path str;
description = "The path of the Archivebox archive.";
example = "\${config.xdg.dataHome}/archivebox";
};
};
config = lib.mkIf cfg.enable {
home.packages = [ pkgs.archivebox ];
systemd.user.services.archivebox-server = {
Unit = {
Description = "Archivebox server for ${cfg.archivePath}";
After = "network.target";
Documentation = [ "https://docs.archivebox.io/" ];
};
Install.WantedBy = [ "graphical-session.target" ];
Service = {
ExecStart = "${pkgs.archivebox}/bin/archivebox server localhost:${toString cfg.port}";
WorkingDirectory = cfg.archivePath;
Restart = "on-failure";
};
};
};
}

View File

@ -1,8 +1,8 @@
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.bleachbit; let cfg = config.services.bleachbit;
in { in {
options.modules.bleachbit = { options.services.bleachbit = {
enable = lib.mkEnableOption "automated cleanup with Bleachbit"; enable = lib.mkEnableOption "automated cleanup with Bleachbit";
startAt = lib.mkOption { startAt = lib.mkOption {
type = lib.types.str; type = lib.types.str;

View File

@ -3,14 +3,14 @@
# TODO: Make this a generic service. # TODO: Make this a generic service.
# There are multiple external storage drives now. # There are multiple external storage drives now.
let cfg = config.modules.hardware-setup.backup-archive; let cfg = config.hardware-setup.backup-archive;
in { in {
options.modules.hardware-setup.backup-archive.enable = lib.mkEnableOption options.hardware-setup.backup-archive.enable = lib.mkEnableOption
"external hard drive and automated backup service with BorgBackup"; "external hard drive and automated backup service with BorgBackup";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [{ assertions = [{
assertion = config.modules.agenix.enable; assertion = config.profiles.agenix.enable;
message = "Agenix module is not enabled."; message = "Agenix module is not enabled.";
}]; }];
@ -34,7 +34,8 @@ in {
]; ];
}; };
modules.services.borgmatic.jobs.external-storage = { # This uses the custom borgmatic NixOS service.
services.borgmatic.jobs.external-storage = {
startAt = "04/6:00:00"; startAt = "04/6:00:00";
configPath = config.age.secrets.external-backup-borgmatic-settings.path; configPath = config.age.secrets.external-backup-borgmatic-settings.path;
}; };

View File

@ -1,9 +1,9 @@
# A module that automates setting up agenix for your system. # A module that automates setting up agenix for your system.
{ inputs, lib, options, config, system, ... }: { inputs, lib, options, config, system, ... }:
let cfg = config.modules.agenix; let cfg = config.profiles.agenix;
in { in {
options.modules.agenix.enable = options.profiles.agenix.enable =
lib.mkEnableOption "agenix-related config on your system"; lib.mkEnableOption "agenix-related config on your system";
imports = [ inputs.agenix.nixosModules.age ]; imports = [ inputs.agenix.nixosModules.age ];

View File

@ -1,9 +1,9 @@
# All of your embarrassing moments, marked here forever. # All of your embarrassing moments, marked here forever.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.archiving; let cfg = config.profiles.archiving;
in { in {
options.modules.archiving.enable = options.profiles.archiving.enable =
lib.mkEnableOption "installation of various archiving tools"; lib.mkEnableOption "installation of various archiving tools";
# This is not going to set BorgBackup NixOS services for you. # This is not going to set BorgBackup NixOS services for you.

View File

@ -3,9 +3,9 @@
# That can be found in the `themes` module. # That can be found in the `themes` module.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.desktop; let cfg = config.profiles.desktop;
in { in {
options.modules.desktop = { options.profiles.desktop = {
enable = enable =
lib.mkEnableOption "all desktop-related services and default programs"; lib.mkEnableOption "all desktop-related services and default programs";
audio.enable = audio.enable =
@ -40,6 +40,7 @@ in {
(lib.mkIf cfg.audio.enable { (lib.mkIf cfg.audio.enable {
# Enable the preferred audio workflow. # Enable the preferred audio workflow.
sound.enable = false;
hardware.pulseaudio.enable = false; hardware.pulseaudio.enable = false;
security.rtkit.enable = true; security.rtkit.enable = true;
services.pipewire = { services.pipewire = {

View File

@ -1,9 +1,9 @@
# The module for anything dev-related. # The module for anything dev-related.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.dev; let cfg = config.profiles.dev;
in { in {
options.modules.dev = { options.profiles.dev = {
enable = lib.mkEnableOption enable = lib.mkEnableOption
"configurations of foo-dogsquared's barebones requirement for a development environment."; "configurations of foo-dogsquared's barebones requirement for a development environment.";
shell.enable = lib.mkEnableOption shell.enable = lib.mkEnableOption

View File

@ -7,10 +7,10 @@
{ inputs, config, options, lib, ... }: { inputs, config, options, lib, ... }:
let let
cfg = config.modules.users; cfg = config.profiles.users;
users = lib.attrNames cfg.users; users = lib.attrNames cfg.users;
homeManagerUserModules = lib.getUsers "home-manager" users; homeManagerUserModules = lib.getUsers "home-manager" users;
homeManagerModules = lib.filesToAttr ../home-manager; homeManagerModules = lib.filesToAttr ../../home-manager;
homeManagerUsers = lib.attrNames homeManagerUserModules; homeManagerUsers = lib.attrNames homeManagerUserModules;
nonexistentUsers = lib.filter (name: !lib.elem name homeManagerUsers) users; nonexistentUsers = lib.filter (name: !lib.elem name homeManagerUsers) users;
@ -33,7 +33,7 @@ let
mapUsers = f: lib.mapAttrs f cfg.users; mapUsers = f: lib.mapAttrs f cfg.users;
in { in {
options.modules.users = { options.profiles.users = {
users = lib.mkOption { users = lib.mkOption {
default = { }; default = { };
description = '' description = ''

View File

@ -2,7 +2,7 @@
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let let
cfg = config.modules.services.borgmatic; cfg = config.services.borgmatic;
jobOption = { name, config, ... }: { jobOption = { name, config, ... }: {
options = { options = {
@ -27,7 +27,7 @@ let
}; };
}; };
in { in {
options.modules.services.borgmatic = { options.services.borgmatic = {
jobs = lib.mkOption { jobs = lib.mkOption {
type = with lib.types; attrsOf (submodule jobOption); type = with lib.types; attrsOf (submodule jobOption);
description = "borgmatic jobs with each bearing a configuration file to be used."; description = "borgmatic jobs with each bearing a configuration file to be used.";

View File

@ -4,15 +4,15 @@
# See https://github.com/NixOS/nixpkgs/issues/54150 for more details. # See https://github.com/NixOS/nixpkgs/issues/54150 for more details.
let let
name = "a-happy-gnome"; name = "a-happy-gnome";
cfg = config.modules.themes.themes.a-happy-gnome;
dconf = pkgs.gnome3.dconf; dconf = pkgs.gnome3.dconf;
customDconfDb = pkgs.stdenv.mkDerivation { customDconfDb = pkgs.stdenv.mkDerivation {
name = "${name}-dconf-db"; name = "${name}-dconf-db";
buildCommand = "${dconf}/bin/dconf compile $out ${./config/dconf}"; buildCommand = "${dconf}/bin/dconf compile $out ${./config/dconf}";
}; };
cfg = config.themes.themes.a-happy-gnome;
in in
{ {
options.modules.themes.themes.a-happy-gnome.enable = lib.mkEnableOption "'A happy GNOME', foo-dogsquared's configuration of GNOME desktop environment"; options.themes.themes.a-happy-gnome.enable = lib.mkEnableOption "'A happy GNOME', foo-dogsquared's configuration of GNOME desktop environment";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.xserver.enable = true; services.xserver.enable = true;

View File

@ -3,9 +3,9 @@
# You can also show your desktop being modularized like this. # You can also show your desktop being modularized like this.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let cfg = config.modules.themes; let cfg = config.themes;
in { in {
options.modules.themes.disableLimit = lib.mkOption { options.themes.disableLimit = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''

View File

@ -26,8 +26,7 @@
}; };
# My custom modules. # My custom modules.
modules = { profiles = {
bleachbit.enable = true;
i18n.enable = true; i18n.enable = true;
dev = { dev = {
enable = true; enable = true;
@ -42,4 +41,12 @@
}; };
research.enable = true; research.enable = true;
}; };
services = {
archivebox = {
enable = true;
archivePath = "%h/library/archives";
};
bleachbit.enable = true;
};
} }