2019-10-24 02:20:38 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# name of the program
|
|
|
|
# -------------------
|
|
|
|
program = "slack";
|
|
|
|
|
|
|
|
tarBin = "${pkgs.gnutar}/bin/tar";
|
|
|
|
|
|
|
|
# command that will be jailed
|
|
|
|
# ---------------------------
|
|
|
|
command = "${pkgs.slack}/bin/slack";
|
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
desktopFile =
|
|
|
|
let
|
|
|
|
name = program;
|
|
|
|
comment = "Chat Programm";
|
|
|
|
in
|
|
|
|
pkgs.writeTextFile {
|
|
|
|
name = "${name}.desktop";
|
|
|
|
destination = "/share/applications/${name}.desktop";
|
|
|
|
text = ''
|
|
|
|
[Desktop Entry]
|
|
|
|
Categories=Application;Utility;
|
|
|
|
Comment=${comment}
|
|
|
|
Encoding=UTF-8
|
|
|
|
Exec=${bin}/bin/${name}
|
|
|
|
Icon=gnome-lockscreen
|
|
|
|
Name=${name}
|
|
|
|
Terminal=false
|
|
|
|
Type=Application
|
|
|
|
'';
|
|
|
|
};
|
2019-10-24 02:20:38 +02:00
|
|
|
|
|
|
|
# the script
|
|
|
|
# ----------
|
2021-11-01 09:20:42 +01:00
|
|
|
bin =
|
|
|
|
let
|
|
|
|
backupFile = "${cfg.homeBackup}.tar.lzma";
|
|
|
|
rolloutFile = "${cfg.home}.tar.lzma";
|
|
|
|
lockFile = "${cfg.home}-lock";
|
|
|
|
in
|
|
|
|
pkgs.writeShellScriptBin "${program}" ''
|
|
|
|
# set -x
|
|
|
|
if [[ ! -e ${lockFile} ]]
|
2019-12-20 05:54:26 +01:00
|
|
|
then
|
2021-11-01 09:20:42 +01:00
|
|
|
# rollout backup
|
|
|
|
if [[ -e ${backupFile} ]]
|
|
|
|
then
|
|
|
|
cp ${backupFile} ${rolloutFile}
|
|
|
|
sudo -u ${program} ${tarBin} xf ${rolloutFile} --directory ${cfg.home}
|
|
|
|
rm ${rolloutFile}
|
|
|
|
touch ${lockFile}
|
|
|
|
fi
|
2019-12-20 05:54:26 +01:00
|
|
|
fi
|
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
sudo -u ${program} ${command}
|
|
|
|
'';
|
2019-12-20 05:54:26 +01:00
|
|
|
|
|
|
|
backupScript = pkgs.writeShellScriptBin "${program}-backup" ''
|
|
|
|
sudo -u ${program} \
|
|
|
|
${tarBin} \
|
|
|
|
--exclude=.cache \
|
|
|
|
--exclude=".config/**/*Cache*" \
|
|
|
|
--exclude-cache-all \
|
|
|
|
--exclude=Downloads \
|
|
|
|
--create \
|
|
|
|
--verbos \
|
|
|
|
--lzma \
|
|
|
|
--file ${cfg.home}.tar.lzma \
|
|
|
|
--directory ${cfg.home} \
|
|
|
|
.
|
|
|
|
|
|
|
|
cp ${cfg.home}.tar.lzma ${cfg.homeBackup}.tar.lzma
|
|
|
|
'';
|
2019-10-24 02:20:38 +02:00
|
|
|
|
|
|
|
cfg = config.programs.custom.slack;
|
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
in
|
|
|
|
{
|
2019-10-24 02:20:38 +02:00
|
|
|
|
|
|
|
options.programs.custom.slack = {
|
|
|
|
enable = mkEnableOption "install slack";
|
|
|
|
|
|
|
|
homeBackup = mkOption {
|
2019-12-20 05:54:26 +01:00
|
|
|
type = with types; nullOr string;
|
2019-10-24 02:20:38 +02:00
|
|
|
description = ''
|
|
|
|
folder where to backup
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# todo : make sure the folder /home/sudoers belongs to mainUser
|
|
|
|
home = mkOption {
|
2019-12-20 05:54:26 +01:00
|
|
|
type = with types; string;
|
2019-10-24 02:20:38 +02:00
|
|
|
default = "/home/sudoers/slack";
|
|
|
|
description = ''
|
|
|
|
home folder of this
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-12-20 05:54:26 +01:00
|
|
|
security.sudo.extraConfig = ''
|
|
|
|
${config.users.users.mainUser.name} ALL=(${program}) NOPASSWD: ALL
|
|
|
|
'';
|
2019-10-24 02:20:38 +02:00
|
|
|
|
|
|
|
# create users
|
|
|
|
users.users."${program}" = {
|
2019-12-20 05:54:26 +01:00
|
|
|
home = cfg.home;
|
|
|
|
createHome = true;
|
|
|
|
# initialPassword = "${program}";
|
|
|
|
shell = pkgs.bashInteractive;
|
|
|
|
isNormalUser = true;
|
|
|
|
group = "users";
|
|
|
|
# enable video usage
|
|
|
|
extraGroups = [ "video" "audio" ];
|
2019-10-24 02:20:38 +02:00
|
|
|
};
|
|
|
|
|
2019-12-20 05:54:26 +01:00
|
|
|
environment.systemPackages = [ bin backupScript desktopFile ];
|
2019-10-24 02:20:38 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|