1

restructure

This commit is contained in:
2022-08-08 17:42:01 +02:00
parent 5d69b16661
commit b0e740eb4a
9 changed files with 6 additions and 6 deletions

View File

@ -1,99 +0,0 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.modules.audio;
in {
imports = [ ];
options.modules.audio = {
enable = mkOption {
type = types.bool;
default = false;
description = "Configure for realtime audio and enable a bunch of music production tools";
};
carla.enable = mkOption {
type = types.bool;
default = false;
description = "Enable Carla + guitar-specific stuff";
};
yabridge = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable yabridge + yabridgectl";
};
autoSync = mkOption {
type = types.bool;
default = false;
description = "Sync yabridge plugins on nixos-rebuild";
};
};
bitwig = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable Bitwig Studio digital audio workstation";
};
};
extraPackages = mkOption {
type = types.listOf types.package;
default = [ ];
description = "Extra packages to install";
};
};
config = mkIf cfg.enable {
# Use builtins.concatLists instead of mkMerge as this is more safe as the type is specified,
# also mkMerge doesn't work in every case as it yields a set
home.packages = with pkgs; builtins.concatLists [
# lib.optional is preferred over mkIf or if...then...else by nix coding standards
# lib.optional wraps its argument in a list, lib.optionals doesn't
# This means that lib.optional can be used for single packages/arguments
# and lib.optionals has to be used when the argument is itself a list
# I use lib.optionals everywhere as I think this is more clear
(optionals cfg.carla.enable [ carla ])
(optionals cfg.yabridge.enable [ yabridge yabridgectl ])
(optionals cfg.bitwig.enable [ bitwig-studio ])
cfg.extraPackages
];
# NOTE: This desktop entry is created in /etc/profiles/per-user/christoph/share/applications
# This location is part of XDG_DATA_DIRS
xdg.desktopEntries.guitar = mkIf cfg.carla.enable {
name = "Guitar Amp (Carla)";
genericName = "Guitar Amp Simulation";
icon = "carla";
exec = "env PIPEWIRE_LATENCY=256/48000 gamemoderun carla ${config.home.homeDirectory}/.config/carla/GuitarDefault.carxp";
terminal = false;
categories = [ "Music" "Audio" ];
};
home.activation = mkMerge [
(mkIf cfg.carla.enable {
# The module includes the default carla project with ArchetypePetrucci + ArchetypeGojira
# TODO: I don't know if I should keep this
linkCarlaConfig = hm.dag.entryAfter [ "writeBoundary" ] ''
if [ ! -L "${config.home.homeDirectory}/.config/carla" ]; then
ln -sf ${config.home.homeDirectory}/NixFlake/config/carla ${config.home.homeDirectory}/.config/carla
fi
'';
})
(mkIf cfg.yabridge.autoSync {
syncYabridge = hm.dag.entryAfter [ "writeBoundary" ] ''
yabridgectl sync
'';
})
];
};
}

View File

@ -1,133 +0,0 @@
# https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules
# This is a function with arguments
{ config, lib, pkgs, ... }:
# We add stuff from lib to our namespace (mkOption...)
with lib;
let
# This is the current state of the option that this module defines
# We use it to determine if the config should be changed below
cfg = config.modules.emacs;
in {
imports = [ ];
# Options is a vector of options this module defines
# This module defines only the "emacs" option and suboptions "enable" and "doom"
options.modules.emacs = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable the GNU Emacs editor";
};
doom = {
enable = mkOption {
type = types.bool;
default = false;
description = "Use the Doom Emacs framework";
};
autoSync = mkOption {
type = types.bool;
default = false;
description = "Sync Doom Emacs on nixos-rebuild";
};
autoUpgrade = mkOption {
type = types.bool;
default = false;
description = "Automatically upgrade Doom Emacs on nixos-rebuild";
};
};
};
# Config is the merged set of all module configurations
# Here we define what happens to the config if the module is active (but only if the module is active)
# Since this module is for HomeManager, config is not the system config
# Attribute sets like config can be defined multiple times (every module defines a different config), on
# building the config they are merged
# Because config depends on itself recursively (through cfg) we use mkIf instead of the normal if...then...else,
# as it delays the evaluation (the if is moved inside the assignments inside the set)
# mkIf can only be used in the config section (like mkMerge, mkForce and co)
config = mkIf cfg.enable {
# What home packages should be enabled
home.packages = with pkgs; [
((emacsPackagesFor emacsPgtkNativeComp).emacsWithPackages
(epkgs: [ epkgs.vterm ]))
# binutils # conflicts with gcc
zstd
(ripgrep.override { withPCRE2 = true; })
fd
# libgccjit
sqlite
inkscape
graphviz
gnuplot
pandoc
nixfmt
shellcheck
maim
# TODO: Use LaTeX module instead
texlive.combined.scheme-medium
emacs-all-the-icons-fonts
bashInteractive # For keychain
# Treemacs needs python + syntax coloring in org/latex needs pygments
(python310.withPackages (ppkgs:
[
ppkgs.pygments
])) # withPackages expects a function that gets all the packages as argument and returns a list with the packages we want
];
home.sessionPath = mkIf cfg.doom.enable [ "${config.home.homeDirectory}/.emacs.d/bin" ];
# Note: Don't do it this way as the config becomes immutable
# We tell HomeManager where the config files belong
# home.file.".config/doom" = {
# # With onChange you even could rebuild doom emacs when rebuilding HomeManager but I don't want this to become too slow
# recursive = true; # is a directory
# source = ../../config/doom;
# };
home.activation = mkMerge [
# The parantheses around mkIf are needed for precedence in this case
(mkIf cfg.doom.enable {
# If doom is enabled we want to clone the framework
# The activation script is being run when home-manager rebuilds
# Because we write to the filesystem, this script has to be run after HomeManager's writeBoundary
installDoomEmacs = hm.dag.entryAfter [ "writeBoundary" ] ''
if [ ! -d "${config.home.homeDirectory}/.emacs.d" ]; then
git clone --depth=1 --single-branch "https://github.com/doomemacs/doomemacs" "${config.home.homeDirectory}/.emacs.d"
fi
'';
# With this approach we keep the config mutable as it is not copied and linked from store
linkDoomConfig = hm.dag.entryAfter [ "writeBoundary" "installDoomEmacs" ] ''
if [ ! -L "${config.home.homeDirectory}/.config/doom" ]; then
ln -sf ${config.home.homeDirectory}/NixFlake/config/doom ${config.home.homeDirectory}/.config/doom
fi
'';
})
(mkIf (cfg.doom.enable && cfg.doom.autoSync) {
syncDoomEmacs = hm.dag.entryAfter [ "writeBoundary" "linkDoomConfig" ] ''
${config.home.homeDirectory}/.emacs.d/bin/doom sync
'';
})
(mkIf (cfg.doom.enable && cfg.doom.autoUpgrade) {
upgradeDoomEmacs = hm.dag.entryAfter [ "writeBoundary" "linkDoomConfig" ] ''
${config.home.homeDirectory}/.emacs.d/bin/doom upgrade -!
'';
})
];
};
}

View File

@ -1,144 +0,0 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.modules.flatpak;
in {
imports = [ ];
options.modules.flatpak = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable flatpak support";
};
fontFix = mkOption {
type = types.bool;
default = false;
description = "Link fonts to ~/.local/share/fonts so flatpak apps can find them";
};
iconFix = mkOption {
type = types.bool;
default = false;
description = "Link icons to ~/.local/share/icons so flatpak apps can find them";
};
autoUpdate = mkOption {
type = types.bool;
default = false;
description = "Update flatpak apps on nixos-rebuild";
};
autoPrune = mkOption {
type = types.bool;
default = false;
description = "Remove unused packages on nixos-rebuild";
};
discord.enable = mkOption {
type = types.bool;
default = false;
description = "Enable Discord";
};
spotify.enable = mkOption {
type = types.bool;
default = false;
description = "Enable Spotify";
};
flatseal.enable = mkOption {
type = types.bool;
default = false;
description = "Enable Flatseal";
};
};
config = mkIf cfg.enable {
# NOTE: Is already set by flatpak.enable in configuration.nix
# xdg.systemDirs.data = [
# "/var/lib/flatpak/exports/share"
# "${home.homeDirectory}/.local/share/flatpak/exports/share"
# ];
home.activation = mkMerge [
(mkIf cfg.fontFix {
# We link like this to be able to address the absolute location, also the fonts won't get copied to store
# NOTE: This path contains all the fonts because fonts.fontDir.enable is true
linkFontDir = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
if [ ! -L "${config.home.homeDirectory}/.local/share/fonts" ]; then
ln -sf /run/current-system/sw/share/X11/fonts ${config.home.homeDirectory}/.local/share/fonts
fi
'';
})
(mkIf cfg.iconFix {
# Fixes missing icons + cursor
# NOTE: This path works because we have homeManager.useUserPackages = true (everything is stored in /etc/profiles/)
linkIconDir = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
if [ ! -L "${config.home.homeDirectory}/.local/share/icons" ]; then
ln -sf /etc/profiles/per-user/christoph/share/icons ${config.home.homeDirectory}/.local/share/icons
fi
'';
})
# TODO: I should find a smarter way than this to make it easy to add flatpak options
{
# TODO: Enable this block only if any flatpak is enabled
# TODO: Only install new flatpaks, check with flatpak list | grep <name> | wc -l
installFlatpaks = let
to_install = builtins.concatLists [
(optionals cfg.discord.enable [ "com.discordapp.Discord" ])
(optionals cfg.spotify.enable [ "com.spotify.Client" ])
(optionals cfg.flatseal.enable [ "com.github.tchx84.Flatseal" ])
];
to_install_str = builtins.concatStringsSep " " to_install;
in
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
sudo flatpak install -y ${to_install_str} || echo "Nothing to be installed"
'';
}
{
# TODO: Enable this block only if any flatpak is disabled
# TODO: Only remove flatpaks that are installed, check with flatpak list | grep <name> | wc -l
removeFlatpaks = let
to_remove = builtins.concatLists [
(optionals (!cfg.discord.enable) [ "com.discordapp.Discord" ])
(optionals (!cfg.spotify.enable) [ "com.spotify.Client" ])
(optionals (!cfg.flatseal.enable) [ "com.github.tchx84.Flatseal" ])
];
to_remove_str = builtins.concatStringsSep " " to_remove;
in
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
sudo flatpak uninstall -y ${to_remove_str} || echo "Nothing to be removed"
'';
}
(mkIf cfg.autoUpdate {
updateFlatpak = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
sudo flatpak update -y
'';
})
(mkIf cfg.autoPrune {
pruneFlatpak = lib.hm.dag.entryAfter [ "writeBoundary" "removeFlatpak" ] ''
sudo flatpak uninstall --unused -y
'';
})
];
# TODO: Add option for extra overrides and concatenate this string together
# Allow access to linked fonts/icons
home.file.".local/share/flatpak/overrides/global".text = ''
[Context]
filesystems=/run/current-system/sw/share/X11/fonts:ro;/run/current-system/sw/share/icons:ro;/nix/store:ro
'';
};
}

View File

@ -1,14 +0,0 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.modules.gaming;
flatpak = config.modules.flatpak;
in {
imports = [ ];
options.modules.gaming = {};
config = mkIf cfg.enable {};
}