Move xdg stuff into a separate module

This commit is contained in:
Alexander Bantyev 2021-06-11 14:52:11 +03:00
parent acac53cccd
commit 6ea593aeda
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
9 changed files with 167 additions and 141 deletions

View File

@ -1,5 +1,4 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }: {
{
options.defaultApplications = lib.mkOption { options.defaultApplications = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
description = "Preferred applications"; description = "Preferred applications";
@ -11,7 +10,8 @@
desktop = "alacritty"; desktop = "alacritty";
}; };
editor = { editor = {
cmd = "${config.home-manager.users.balsoft.programs.emacs.finalPackage}/bin/emacsclient -c $@"; cmd =
"${config.home-manager.users.balsoft.programs.emacs.finalPackage}/bin/emacsclient -c $@";
desktop = "emacsclient"; desktop = "emacsclient";
}; };
browser = { browser = {
@ -53,33 +53,40 @@
VISUAL = config.defaultApplications.editor.cmd; VISUAL = config.defaultApplications.editor.cmd;
}; };
home-manager.users.balsoft.xdg.mimeApps = { home-manager.users.balsoft = {
enable = true; home.activation."mimeapps-remove" = {
defaultApplications = before = [ "checkLinkTargets" ];
with config.defaultApplications; after = [ ];
builtins.mapAttrs (name: value: data = "rm -f /home/balsoft/.config/mimeapps.list";
if value ? desktop then [ "${value.desktop}.desktop" ] else value) { };
"text/html" = browser;
"image/*" = { desktop = "org.gnome.eog"; }; xdg.mimeApps = {
"application/zip" = archive; enable = true;
"application/rar" = archive; defaultApplications = with config.defaultApplications;
"application/7z" = archive; builtins.mapAttrs (name: value:
"application/*tar" = archive; if value ? desktop then [ "${value.desktop}.desktop" ] else value) {
"x-scheme-handler/http" = browser; "text/html" = browser;
"x-scheme-handler/https" = browser; "image/*" = { desktop = "org.gnome.eog"; };
"x-scheme-handler/about" = browser; "application/zip" = archive;
"x-scheme-handler/mailto" = mail; "application/rar" = archive;
"x-scheme-handler/matrix" = matrix; "application/7z" = archive;
"application/pdf" = { desktop = "org.kde.okular"; }; "application/*tar" = archive;
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" = "x-scheme-handler/http" = browser;
text_processor; "x-scheme-handler/https" = browser;
"application/msword" = text_processor; "x-scheme-handler/about" = browser;
"application/vnd.oasis.opendocument.text" = text_processor; "x-scheme-handler/mailto" = mail;
"text/csv" = spreadsheet; "x-scheme-handler/matrix" = matrix;
"application/vnd.oasis.opendocument.spreadsheet" = spreadsheet; "application/pdf" = { desktop = "org.kde.okular"; };
"text/plain" = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" =
editor; # This actually makes Emacs an editor for everything... XDG is wierd text_processor;
}; "application/msword" = text_processor;
"application/vnd.oasis.opendocument.text" = text_processor;
"text/csv" = spreadsheet;
"application/vnd.oasis.opendocument.spreadsheet" = spreadsheet;
"text/plain" =
editor; # This actually makes Emacs an editor for everything... XDG is wierd
};
};
}; };
}; };
} }

View File

@ -2,7 +2,7 @@
let let
cfg = config.persist; cfg = config.persist;
takeAll = what: builtins.concatMap (x: x.${what}); takeAll = what: concatMap (x: x.${what});
persists = with cfg; [ state derivative cache ]; persists = with cfg; [ state derivative cache ];
@ -15,64 +15,68 @@ let
allEtcFiles = absoluteEtcFiles (takeAll "etcFiles" persists); allEtcFiles = absoluteEtcFiles (takeAll "etcFiles" persists);
allDirectories = takeAll "directories" persists; allDirectories = takeAll "directories" persists;
inherit (builtins) concatMap;
inherit (lib) mkIf;
in { in {
options = with lib; options = let
with types; inherit (lib) mkOption mkEnableOption;
let inherit (lib.types) listOf path str;
common = { common = {
directories = mkOption { directories = mkOption {
type = listOf path; type = listOf path;
default = [ ]; default = [ ];
};
etcFiles = mkOption {
type = listOf str;
default = [ ];
};
homeFiles = mkOption {
type = listOf str;
default = [ ];
};
}; };
in { etcFiles = mkOption {
persist = { type = listOf str;
default = [ ];
enable = mkEnableOption "a tmpfs root with explicit opt-in state"; };
homeFiles = mkOption {
persistRoot = mkOption { type = listOf str;
type = path; default = [ ];
default = "/persist";
};
homeDir = mkOption {
type = path;
default = "/home/balsoft";
};
# Stuff that matters
# TODO backups of this stuff
state = {
# backup = {...};
} // common;
# Stuff that can be computed from declarative+state, but is never invalidated (so shouldn't be cleaned up)
derivative = common;
# Stuff that's just there to speed up the system
# It's cleaned up regularly, to solve the cache invalidation problem once and for all
cache = {
clean = {
enable = mkEnableOption "cleaning the cache files and directories";
dates = mkOption {
type = str;
default = "weekly";
description =
"A systemd.time calendar description of when to clean the cache files";
};
};
} // common;
}; };
}; };
in {
persist = {
enable = mkEnableOption "a tmpfs root with explicit opt-in state";
persistRoot = mkOption {
type = path;
default = "/persist";
};
homeDir = mkOption {
type = path;
default = "/home/balsoft";
};
# Stuff that matters
# TODO backups of this stuff
state = {
# backup = {...};
} // common;
# Stuff that can be computed from declarative+state, but is never invalidated (so shouldn't be cleaned up)
derivative = common;
# Stuff that's just there to speed up the system
# It's cleaned up regularly, to solve the cache invalidation problem once and for all
cache = {
clean = {
enable = mkEnableOption "cleaning the cache files and directories";
dates = mkOption {
type = str;
default = "weekly";
description =
"A systemd.time calendar description of when to clean the cache files";
};
};
} // common;
};
};
imports = [ imports = [
inputs.impermanence.nixosModules.impermanence inputs.impermanence.nixosModules.impermanence
@ -94,7 +98,7 @@ in {
}) })
]; ];
config = lib.mkIf cfg.enable { config = mkIf cfg.enable {
environment.persistence.${cfg.persistRoot} = { environment.persistence.${cfg.persistRoot} = {
directories = allDirectories; directories = allDirectories;
files = allEtcFiles; files = allEtcFiles;
@ -106,10 +110,9 @@ in {
fsType = "tmpfs"; fsType = "tmpfs";
}; };
boot.initrd.postMountCommands = assert boot.initrd.postMountCommands = assert config.fileSystems
config.fileSystems ? ${cfg.persistRoot} ? ${cfg.persistRoot}
&& config.fileSystems.${cfg.persistRoot}.neededForBoot; && config.fileSystems.${cfg.persistRoot}.neededForBoot; ''
''
mkdir -p /mnt-root/nix mkdir -p /mnt-root/nix
mount --bind /mnt-root${cfg.persistRoot}/nix /mnt-root/nix mount --bind /mnt-root${cfg.persistRoot}/nix /mnt-root/nix
chmod 755 /mnt-root chmod 755 /mnt-root

View File

@ -0,0 +1,14 @@
{ config, pkgs, lib, ... }: {
home-manager.users.balsoft = {
programs.command-not-found = {
enable = true;
dbPath = ../../misc/programs.sqlite;
};
};
environment.sessionVariables = {
NIX_AUTO_RUN = "1";
};
}

View File

@ -0,0 +1,8 @@
{ config, pkgs, lib, ... }: {
home-manager.users.balsoft = {
programs.direnv.enable = true;
programs.direnv.enableNixDirenvIntegration = true;
};
persist.state.directories =
[ "/home/balsoft/.local/share/direnv" ];
}

View File

@ -13,31 +13,28 @@
gnome-online-miners.enable = true; gnome-online-miners.enable = true;
}; };
environment.sessionVariables.XDG_CURRENT_DESKTOP = "X-Generic";
persist.state.directories = map (x: "/home/balsoft/${x}") [
"Pictures"
"Documents"
"Downloads"
"Music"
"projects"
"Videos"
];
services.gvfs.enable = true; services.gvfs.enable = true;
services.geoclue2.enable = true; services.geoclue2.enable = true;
fileSystems = with config.persist;
lib.mkIf enable (builtins.listToAttrs (map (name: {
inherit name;
value.options = [ "x-gvfs-hide" ];
}) (state.directories ++ cache.directories ++ derivative.directories)));
home-manager.users.balsoft = { home-manager.users.balsoft = {
xdg.userDirs.enable = true;
home.activation.gnome = '' home.activation.gnome = ''
$DRY_RUN_CMD mkdir -p "$XDG_DATA_HOME/keyrings" $DRY_RUN_CMD mkdir -p "$XDG_DATA_HOME/keyrings"
$DRY_RUN_CMD ln -sf ${config.secrets-envsubst.gnome-keyring} "$XDG_DATA_HOME/keyrings/Default_keyring.keyring" $DRY_RUN_CMD ln -sf ${config.secrets-envsubst.gnome-keyring} "$XDG_DATA_HOME/keyrings/Default_keyring.keyring"
echo "Default_keyring" > "$XDG_DATA_HOME/keyrings/default" echo "Default_keyring" > "$XDG_DATA_HOME/keyrings/default"
$DRY_RUN_CMD mkdir -p "$XDG_CONFIG_HOME/goa-1.0" $DRY_RUN_CMD mkdir -p "$XDG_CONFIG_HOME/goa-1.0"
$DRY_RUN_CMD ln -sf ${./accounts.conf} "$XDG_CONFIG_HOME/goa-1.0/accounts.conf" $DRY_RUN_CMD ln -sf ${
./accounts.conf
} "$XDG_CONFIG_HOME/goa-1.0/accounts.conf"
$DRY_RUN_CMD mkdir -p "$XDG_CONFIG_HOME/evolution/sources" $DRY_RUN_CMD mkdir -p "$XDG_CONFIG_HOME/evolution/sources"
$DRY_RUN_CMD ln -sf ${./nextcloud.source} "$XDG_CONFIG_HOME/evolution/sources/nextcloud.source" $DRY_RUN_CMD ln -sf ${
./nextcloud.source
} "$XDG_CONFIG_HOME/evolution/sources/nextcloud.source"
''; '';
dconf.settings = { dconf.settings = {
@ -71,13 +68,9 @@
thumbnail-limit = 10; thumbnail-limit = 10;
}; };
"org/gnome/desktop/interface" = { "org/gnome/desktop/interface" = { cursor-theme = "default"; };
cursor-theme = "default";
};
"org/gnome/evince/default" = { "org/gnome/evince/default" = { inverted-colors = true; };
inverted-colors = true;
};
"org/gnome/maps" = { "org/gnome/maps" = {
night-mode = true; night-mode = true;

View File

@ -6,7 +6,6 @@ with pkgs.my-lib; {
services.udev.packages = [ pkgs.libmtp pkgs.media-player-info ]; services.udev.packages = [ pkgs.libmtp pkgs.media-player-info ];
environment.sessionVariables = { environment.sessionVariables = {
DESKTOP_SESSION = "kde";
QT_XFT = "true"; QT_XFT = "true";
QT_SELECT = "5"; QT_SELECT = "5";
KDE_SESSION_VERSION = "5"; KDE_SESSION_VERSION = "5";

View File

@ -1,49 +1,28 @@
{ pkgs, lib, config, inputs, ... }: { { pkgs, lib, config, inputs, ... }: {
systemd.coredump.enable = true;
systemd.services.systemd-timesyncd.wantedBy = [ "multi-user.target" ];
systemd.timers.systemd-timesyncd = {
timerConfig.OnCalendar = "hourly";
};
environment.sessionVariables = environment.sessionVariables =
config.home-manager.users.balsoft.home.sessionVariables // rec { config.home-manager.users.balsoft.home.sessionVariables // rec {
NIX_AUTO_RUN = "1";
LESS = "MR"; LESS = "MR";
SYSTEMD_LESS = LESS; SYSTEMD_LESS = LESS;
DE = "generic";
}; };
home-manager.users.balsoft = { home-manager.users.balsoft = {
xdg.enable = true;
home.activation."mimeapps-remove" = {
before = [ "linkGeneration" ];
after = [ ];
data = "rm -f /home/balsoft/.config/mimeapps.list";
};
news.display = "silent"; news.display = "silent";
programs.command-not-found = {
enable = true;
dbPath = ../../misc/programs.sqlite;
};
systemd.user.startServices = true;
programs.direnv.enable = true; systemd.user.startServices = true;
programs.direnv.enableNixDirenvIntegration = true;
home.stateVersion = "20.09"; home.stateVersion = "20.09";
}; };
persist.cache.directories = [ "/home/balsoft/.cache" "/var/cache" ]; persist.cache.directories = [ "/home/balsoft/.cache" "/var/cache" ];
persist.state.directories = persist.state.directories = [ "/var/lib/nixos" "/var/lib/systemd" ];
[ "/home/balsoft/.local/share/direnv" "/var/lib/nixos" "/var/lib/systemd" ];
services.avahi.enable = true;
system.stateVersion = "18.03"; system.stateVersion = "18.03";
systemd.services.systemd-timesyncd.wantedBy = [ "multi-user.target" ];
systemd.timers.systemd-timesyncd = { timerConfig.OnCalendar = "hourly"; };
services.avahi.enable = true;
} }

20
modules/workspace/xdg.nix Normal file
View File

@ -0,0 +1,20 @@
{ config, pkgs, lib, ... }: {
home-manager.users.balsoft = {
xdg.enable = true;
xdg.userDirs.enable = true;
};
environment.sessionVariables = {
XDG_CURRENT_DESKTOP = "X-Generic";
DE = "generic";
};
persist.state.directories = map (x: "/home/balsoft/${x}") [
"Pictures"
"Documents"
"Downloads"
"Music"
"projects"
"Videos"
];
}

View File

@ -6,6 +6,9 @@
secrets secrets
secrets-envsubst secrets-envsubst
autoRun
xdg
devices devices
git git
gpg gpg