1

update modules and use modules mylib

This commit is contained in:
2022-08-08 21:19:13 +02:00
parent d68ef47405
commit 135ae485a6
6 changed files with 71 additions and 139 deletions

View File

@ -34,7 +34,6 @@ rec {
modules.flatpak = {
enable = true;
# TODO: Make these active by default and remove the links if disabled
fontFix = true;
iconFix = true;
autoUpdate = true;

View File

@ -1,19 +1,27 @@
{ inputs, pkgs, lib, ... }:
let
in {
mkBoolOpt = { def, desc ? "" }:
{
rec {
mkBoolOpt = def: desc:
lib.mkOption {
type = lib.types.bool;
default = def;
description = desc;
};
linkMutable = { src, dest, after }:
lib.hm.dag.entryAfter [ "writeBoundary" ] ++ after ''
mkElse = pred: do:
(lib.mkIf (!pred) do);
mkLink = src: dest:
''
if [ ! -L "${dest}" ]; then
ln -sf ${src} ${dest}
fi
'';
mkUnlink = dest:
''
if [ -L "${dest}" ]; then
rm ${dest}
fi
'';
}

View File

@ -1,6 +1,7 @@
{ config, lib, pkgs, ... }:
{ config, lib, mylib, pkgs, ... }:
with lib;
with mylib.modules;
let
cfg = config.modules.audio;
@ -8,38 +9,13 @@ 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";
};
enable = mkBoolOpt false "Configure for realtime audio and enable a bunch of music production tools";
carla.enable = mkBoolOpt false "Enable Carla + guitar-specific stuff";
bitwig.enable = mkBoolOpt false "Enable Bitwig Studio digital audio workstation";
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";
};
enable = mkBoolOpt false "Enable yabridge + yabridgectl";
autoSync = mkBoolOpt false "Sync yabridge plugins on nixos-rebuild";
};
extraPackages = mkOption {
@ -78,15 +54,14 @@ in {
};
home.activation = mkMerge [
# The module includes the default carla project with ArchetypePetrucci + ArchetypeGojira
(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
'';
linkCarlaConfig = hm.dag.entryAfter [ "writeBoundary" ]
(mkLink "${config.home.homeDirectory}/NixFlake/config/carla" "${config.home.homeDirectory}/.config/carla");
})
(mkElse cfg.carla.enable {
unlinkCarlaConfig = hm.dag.entryAfter [ "writeBoundary" ]
(mkUnlink "${config.home.homeDirectory}/.config/carla");
})
(mkIf cfg.yabridge.autoSync {

View File

@ -1,10 +1,11 @@
# https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules
# This is a function with arguments
{ config, lib, pkgs, ... }:
{ config, lib, mylib, pkgs, ... }:
# We add stuff from lib to our namespace (mkOption...)
with lib;
with mylib.modules;
let
# This is the current state of the option that this module defines
@ -16,30 +17,12 @@ in {
# 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";
};
enable = mkBoolOpt false "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";
};
enable = mkBoolOpt false "Use the Doom Emacs framework";
autoSync = mkBoolOpt false "Sync Doom Emacs on nixos-rebuild";
autoUpgrade = mkBoolOpt false "Upgrade Doom Emacs on nixos-rebuild";
};
};
@ -108,22 +91,21 @@ in {
'';
# 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
'';
linkDoomConfig = hm.dag.entryAfter [ "writeBoundary" "installDoomEmacs" ]
(mkLink "${config.home.homeDirectory}/NixFlake/config/doom" "${config.home.homeDirectory}/.config/doom");
})
(mkElse cfg.doom.enable {
unlinkDoomConfig = hm.dag.entryAfter [ "writeBoundary" "installDoomEmacs" ]
(mkUnlink "${config.home.homeDirectory}/.config/doom");
})
(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,6 +1,7 @@
{ config, lib, pkgs, ... }:
{ config, lib, mylib, pkgs, ... }:
with lib;
with mylib.modules;
let
cfg = config.modules.flatpak;
@ -8,53 +9,17 @@ in {
imports = [ ];
options.modules.flatpak = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable flatpak support";
};
enable = mkBoolOpt false "Enable flatpak support";
fontFix = mkBoolOpt false "Link fonts to ~/.local/share/fonts so flatpak apps can find them";
iconFix = mkBoolOpt false "Link icons to ~/.local/share/icons so flatpak apps can find them";
autoUpdate = mkBoolOpt false "Update flatpak apps on nixos-rebuild";
autoPrune = mkBoolOpt false "Remove unused packages on nixos-rebuild";
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";
};
# TODO: Add library function to make this easier
# The flatpak name should be included and a list of all enabled apps should be available
discord.enable = mkBoolOpt false "Enable Discord";
spotify.enable = mkBoolOpt false "Enable Spotify";
flatseal.enable = mkBoolOpt false "Enable Flatseal";
};
config = mkIf cfg.enable {
@ -66,24 +31,26 @@ in {
# ];
home.activation = mkMerge [
# 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
(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
'';
linkFontDir = lib.hm.dag.entryAfter [ "writeBoundary" ]
(mkLink "/run/current-system/sw/share/X11/fonts" "${config.home.homeDirectory}/.local/share/fonts");
})
(mkElse cfg.fontFix {
unlinkFontDir = lib.hm.dag.entryAfter [ "writeBoundary" ]
(mkUnlink "${config.home.homeDirectory}/.local/share/fonts");
})
# Fixes missing icons + cursor
# NOTE: This path works because we have homeManager.useUserPackages = true (everything is stored in /etc/profiles/)
(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
'';
linkIconDir = lib.hm.dag.entryAfter [ "writeBoundary" ]
(mkLink "/etc/profiles/per-user/christoph/share/icons" "${config.home.homeDirectory}/.local/share/icons");
})
(mkElse cfg.iconFix {
unlinkIconDir = lib.hm.dag.entryAfter [ "writeBoundary" ]
(mkUnlink "${config.home.homeDirectory}/.local/share/icons");
})
# TODO: I should find a smarter way than this to make it easy to add flatpak options

View File

@ -1,6 +1,7 @@
{ config, lib, pkgs, ... }:
{ config, lib, mylib, pkgs, ... }:
with lib;
with mylib.modules;
let
cfg = config.modules.gaming;