moved all of my config into this nix flake
This commit is contained in:
53
mods/battery_monitor.nix
Normal file
53
mods/battery_monitor.nix
Normal file
@@ -0,0 +1,53 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
# Regularly check the battery status and send a notification when it discharges
|
||||
# below certain thresholds.
|
||||
# Implemented by calling the `acpi` program regularly. This is the simpler and
|
||||
# safer approach because the battery might not send discharging events.
|
||||
|
||||
let conf = config.modules.battery_monitor;
|
||||
|
||||
in {
|
||||
options.modules.battery_monitor = with lib; {
|
||||
enable = mkEnableOption "battery_monitor";
|
||||
};
|
||||
|
||||
config = lib.mkIf conf.enable {
|
||||
# Regularly check battery status
|
||||
systemd.user.services.battery_monitor = {
|
||||
wants = [ "display-manager.service" ];
|
||||
wantedBy = [ "graphical-session.target" ];
|
||||
script = ''
|
||||
count_10=0
|
||||
prev_val=100
|
||||
check () { [[ $1 -ge $val ]] && [[ $1 -lt $prev_val ]]; }
|
||||
notify () {
|
||||
${pkgs.libnotify}/bin/notify-send -a Battery "$@" \
|
||||
-h "int:value:$val" "Discharging" "$val%, $remaining"
|
||||
}
|
||||
while true; do
|
||||
IFS=: read _ bat0 < <(${pkgs.acpi}/bin/acpi -b)
|
||||
IFS=\ , read status val remaining <<<"$bat0"
|
||||
val=''${val%\%}
|
||||
if [[ $status = Discharging ]]; then
|
||||
echo "$val%, $remaining"
|
||||
|
||||
if check 20; then notify
|
||||
elif check 15 || [[ $val -le 7 ]]; then notify -u critical
|
||||
elif [[ $val -le 4 ]]
|
||||
then
|
||||
${pkgs.notify}/bin/notify-send -a Hibernate soon...
|
||||
sleep 10
|
||||
${pkgs.notify}/bin/notify-send -a Hibernate NOW
|
||||
sudo systemctl hibernate
|
||||
fi
|
||||
fi
|
||||
prev_val=$val
|
||||
# Sleep longer when battery is high to save CPU
|
||||
if [[ $val -gt 30 ]]; then sleep 10m; elif [[ $val -ge 20 ]]; then sleep 5m; else sleep 1m; fi
|
||||
done
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
11
mods/my-nixpkgs-overlay.nix
Normal file
11
mods/my-nixpkgs-overlay.nix
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
{ pkgs, confDir, inputs, ... }:
|
||||
{
|
||||
nixpkgs.overlays = [
|
||||
{
|
||||
localPacketTracer8 = (pkgs.callPackage ../../prebuilt/packetTracer/default.nix {confDir = confDir;});
|
||||
xdg-desktop-portal-termfilechooser = (pkgs.callPackage ../../mods/xdg-desktop-portal-termfilechooser/default.nix {});
|
||||
firefox = inputs.firefox.packages.${pkgs.system}.firefox-nightly-bin;
|
||||
}
|
||||
];
|
||||
}
|
||||
86
mods/xdg-desktop-portal-termfilechooser/default.nix
Normal file
86
mods/xdg-desktop-portal-termfilechooser/default.nix
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
{ lib
|
||||
, stdenv
|
||||
, fetchFromGitHub
|
||||
, meson
|
||||
, pkgconfig
|
||||
, inih
|
||||
, systemd
|
||||
, scdoc
|
||||
, ninja
|
||||
, pkgs
|
||||
, alacritty
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "xdg-desktop-portal-termfilechooser";
|
||||
version = "0.0.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "GermainZ";
|
||||
repo = "xdg-desktop-portal-termfilechooser";
|
||||
rev = "71dc7ab06751e51de392b9a7af2b50018e40e062";
|
||||
hash = "sha256-645hoLhQNncqfLKcYCgWLbSrTRUNELh6EAdgUVq3ypM=";
|
||||
};
|
||||
|
||||
#doCheck = true;
|
||||
#doUnpack = true;
|
||||
|
||||
#passthru.tests.version =
|
||||
#testVersion { package = hello; };
|
||||
|
||||
nativeBuildInputs = [
|
||||
meson
|
||||
pkgconfig
|
||||
inih
|
||||
systemd
|
||||
scdoc
|
||||
ninja
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
systemd
|
||||
];
|
||||
|
||||
patches = [
|
||||
./xdg-desktop-portal-termfilechooser-add-x11.patch
|
||||
./test.patch
|
||||
./test2.patch
|
||||
./meson-build.patch
|
||||
./lf-wrapper.patch
|
||||
|
||||
];
|
||||
|
||||
mesonFlags = [
|
||||
"-Dsd-bus-provider=libsystemd"
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
ninja install
|
||||
'';
|
||||
|
||||
postConfigure = ''
|
||||
substituteInPlace ../src/core/config.c --replace '#define FILECHOOSER_DEFAULT_CMD "/usr/share/xdg-desktop-portal-termfilechooser/ranger-wrapper.sh"' '#define FILECHOOSER_DEFAULT_CMD "${placeholder "out"}/share/xdg-desktop-portal-termfilechooser/lf-wrapper.sh"'
|
||||
|
||||
ls ../contrib
|
||||
substituteInPlace ../contrib/lf-wrapper.sh --replace '#CCCMMMDDD' '${alacritty}/bin/alacritty'
|
||||
|
||||
echo "###### start"
|
||||
cat ../src/core/config.c
|
||||
echo "###### end"
|
||||
|
||||
'';
|
||||
#exit 1
|
||||
#substituteInPlace ../src/core/config.c --replace '#define FILECHOOSER_DEFAULT_DIR "/tmp"' '#define FILECHOOSER_DEFAULT_DIR "${placeholder "out"}/share/xdg-desktop-portal/portals/termfilechooser.portal"'
|
||||
|
||||
meta = with lib; {
|
||||
description = "A xdg portal, that let's you use your favourite terminal file chooser to choose files acroos all applications";
|
||||
longDescription = "A long description";
|
||||
homepage = "https://github.com/GermainZ/xdg-desktop-portal-termfilechooser";
|
||||
license = licenses.mit;
|
||||
maintainers = [ maintainers.eelco ];
|
||||
platforms = platforms.all;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
78
mods/xdg-desktop-portal-termfilechooser/flake.nix
Normal file
78
mods/xdg-desktop-portal-termfilechooser/flake.nix
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
description = "xdg-desktop-portal-termfilechooser";
|
||||
|
||||
#inputs = {
|
||||
#nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
|
||||
#};
|
||||
|
||||
outputs = { self, nixpkgs }: {
|
||||
packages.x86_64-linux.default = with nixpkgs.x86_64.pkgs; pkgs.mkDerivation rec {
|
||||
pname = "xdg-desktop-portal-termfilechooser";
|
||||
version = "0.0.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "GermainZ";
|
||||
repo = "xdg-desktop-portal-termfilechooser";
|
||||
rev = "71dc7ab06751e51de392b9a7af2b50018e40e062";
|
||||
hash = "sha256-645hoLhQNncqfLKcYCgWLbSrTRUNELh6EAdgUVq3ypM=";
|
||||
};
|
||||
|
||||
#doCheck = true;
|
||||
#doUnpack = true;
|
||||
|
||||
#passthru.tests.version =
|
||||
#testVersion { package = hello; };
|
||||
|
||||
nativeBuildInputs = [
|
||||
meson
|
||||
pkgconfig
|
||||
inih
|
||||
systemd
|
||||
scdoc
|
||||
ninja
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
systemd
|
||||
];
|
||||
|
||||
patches = [
|
||||
./xdg-desktop-portal-termfilechooser-add-x11.patch
|
||||
./test.patch
|
||||
./test2.patch
|
||||
./meson-build.patch
|
||||
./lf-wrapper.patch
|
||||
];
|
||||
|
||||
mesonFlags = [
|
||||
"-Dsd-bus-provider=libsystemd"
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
ninja install
|
||||
'';
|
||||
|
||||
postConfigure = ''
|
||||
substituteInPlace ../src/core/config.c --replace '#define FILECHOOSER_DEFAULT_CMD "/usr/share/xdg-desktop-portal-termfilechooser/ranger-wrapper.sh"' '#define FILECHOOSER_DEFAULT_CMD "${placeholder "out"}/share/xdg-desktop-portal-termfilechooser/lf-wrapper.sh"'
|
||||
|
||||
ls ../contrib
|
||||
substituteInPlace ../contrib/lf-wrapper.sh --replace '#CCCMMMDDD' '${alacritty}/bin/alacritty'
|
||||
|
||||
echo "###### start"
|
||||
cat ../src/core/config.c
|
||||
echo "###### end"
|
||||
|
||||
'';
|
||||
#exit 1
|
||||
#substituteInPlace ../src/core/config.c --replace '#define FILECHOOSER_DEFAULT_DIR "/tmp"' '#define FILECHOOSER_DEFAULT_DIR "${placeholder "out"}/share/xdg-desktop-portal/portals/termfilechooser.portal"'
|
||||
|
||||
meta = with lib; {
|
||||
description = "A xdg portal, that let's you use your favourite terminal file chooser to choose files acroos all applications";
|
||||
longDescription = "A long description";
|
||||
homepage = "https://github.com/GermainZ/xdg-desktop-portal-termfilechooser";
|
||||
license = licenses.mit;
|
||||
maintainers = [ maintainers.eelco ];
|
||||
platforms = platforms.all;
|
||||
};
|
||||
};
|
||||
}
|
||||
42
mods/xdg-desktop-portal-termfilechooser/lf-wrapper.patch
Normal file
42
mods/xdg-desktop-portal-termfilechooser/lf-wrapper.patch
Normal file
@@ -0,0 +1,42 @@
|
||||
diff --git a/contrib/lf-wrapper.sh b/contrib/lf-wrapper.sh
|
||||
new file mode 100755
|
||||
index 0000000..9b9a20d
|
||||
--- /dev/null
|
||||
+++ b/contrib/lf-wrapper.sh
|
||||
@@ -0,0 +1,36 @@
|
||||
+#!/bin/sh
|
||||
+# This wrapper script is invoked by xdg-desktop-portal-termfilechooser.
|
||||
+#
|
||||
+# Inputs:
|
||||
+# 1. "1" if multiple files can be chosen, "0" otherwise.
|
||||
+# 2. "1" if a directory should be chosen, "0" otherwise.
|
||||
+# 3. "0" if opening files was requested, "1" if writing to a file was
|
||||
+# requested. For example, when uploading files in Firefox, this will be "0".
|
||||
+# When saving a web page in Firefox, this will be "1".
|
||||
+# 4. If writing to a file, this is recommended path provided by the caller. For
|
||||
+# example, when saving a web page in Firefox, this will be the recommended
|
||||
+# path Firefox provided, such as "~/Downloads/webpage_title.html".
|
||||
+# Note that if the path already exists, we keep appending "_" to it until we
|
||||
+# get a path that does not exist.
|
||||
+# 5. The output path, to which results should be written.
|
||||
+#
|
||||
+# Output:
|
||||
+# The script should print the selected paths to the output path (argument #5),
|
||||
+# one path per line.
|
||||
+# If nothing is printed, then the operation is assumed to have been canceled.
|
||||
+
|
||||
+multiple="$1"
|
||||
+directory="$2"
|
||||
+save="$3"
|
||||
+path="$4"
|
||||
+out="$5"
|
||||
+
|
||||
+echo teeeeeeeeeeeeeeeeeeeeeeeeeeest
|
||||
+read
|
||||
+
|
||||
+#mdolphin
|
||||
+#alacritty
|
||||
+#CCCMMMDDD
|
||||
+
|
||||
+
|
||||
+exit
|
||||
16
mods/xdg-desktop-portal-termfilechooser/meson-build.patch
Normal file
16
mods/xdg-desktop-portal-termfilechooser/meson-build.patch
Normal file
@@ -0,0 +1,16 @@
|
||||
diff --git a/meson.build b/meson.build
|
||||
index 8225b6f..f416565 100644
|
||||
--- a/meson.build
|
||||
+++ b/meson.build
|
||||
@@ -109,6 +109,11 @@ install_data(
|
||||
install_dir: join_paths(get_option('datadir'), 'xdg-desktop-portal-termfilechooser'),
|
||||
)
|
||||
|
||||
+install_data(
|
||||
+ 'contrib/lf-wrapper.sh',
|
||||
+ install_dir: join_paths(get_option('datadir'), 'xdg-desktop-portal-termfilechooser'),
|
||||
+)
|
||||
+
|
||||
scdoc = dependency('scdoc', required: get_option('man-pages'), version: '>= 1.9.7')
|
||||
if scdoc.found()
|
||||
man_pages = ['xdg-desktop-portal-termfilechooser.5.scd']
|
||||
14
mods/xdg-desktop-portal-termfilechooser/test.patch
Normal file
14
mods/xdg-desktop-portal-termfilechooser/test.patch
Normal file
@@ -0,0 +1,14 @@
|
||||
diff --git a/contrib/ranger-wrapper.sh b/contrib/ranger-wrapper.sh
|
||||
index 88bc697..b5d3fe0 100755
|
||||
--- a/contrib/ranger-wrapper.sh
|
||||
+++ b/contrib/ranger-wrapper.sh
|
||||
@@ -25,6 +25,9 @@ save="$3"
|
||||
path="$4"
|
||||
out="$5"
|
||||
|
||||
+echo hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
|
||||
+read
|
||||
+
|
||||
cmd="/usr/bin/ranger"
|
||||
termcmd="${TERMCMD:-/usr/bin/kitty}"
|
||||
|
||||
21
mods/xdg-desktop-portal-termfilechooser/test2.patch
Normal file
21
mods/xdg-desktop-portal-termfilechooser/test2.patch
Normal file
@@ -0,0 +1,21 @@
|
||||
diff --git a/src/filechooser/filechooser.c b/src/filechooser/filechooser.c
|
||||
index 6cecec6..bd9ba7f 100644
|
||||
--- a/src/filechooser/filechooser.c
|
||||
+++ b/src/filechooser/filechooser.c
|
||||
@@ -19,6 +19,7 @@ static const char interface_name[] = "org.freedesktop.impl.portal.FileChooser";
|
||||
static int exec_filechooser(void *data, bool writing, bool multiple, bool directory, char *path, char ***selected_files, size_t *num_selected_files) {
|
||||
struct xdpw_state *state = data;
|
||||
char *cmd_script = state->config->filechooser_conf.cmd;
|
||||
+ logprint(ERROR, "hiiiiiiiiiiiiiii ... cmd_script: %s", cmd_script);
|
||||
if (!cmd_script) {
|
||||
logprint(ERROR, "cmd not specified");
|
||||
return -1;
|
||||
@@ -33,7 +34,7 @@ static int exec_filechooser(void *data, bool writing, bool multiple, bool direct
|
||||
snprintf(cmd, str_size, "%s %d %d %d \"%s\" \"%s\"", cmd_script, multiple, directory, writing, path, PATH_PORTAL);
|
||||
|
||||
remove(PATH_PORTAL);
|
||||
- logprint(TRACE, "executing command: %s", cmd);
|
||||
+ logprint(ERROR, "executing command: %s", cmd);
|
||||
int ret = system(cmd);
|
||||
if (ret) {
|
||||
logprint(ERROR, "could not execute %s: %d", cmd, errno);
|
||||
@@ -0,0 +1,10 @@
|
||||
diff --git a/termfilechooser.portal b/termfilechooser.portal
|
||||
index f072ba0..65f21d8 100644
|
||||
--- a/termfilechooser.portal
|
||||
+++ b/termfilechooser.portal
|
||||
@@ -1,4 +1,4 @@
|
||||
[portal]
|
||||
DBusName=org.freedesktop.impl.portal.desktop.termfilechooser
|
||||
Interfaces=org.freedesktop.impl.portal.FileChooser;
|
||||
-UseIn=i3;wlroots;sway;Wayfire;river;mate;lxde;openbox;unity;pantheon
|
||||
+UseIn=i3;wlroots;sway;Wayfire;river;mate;lxde;openbox;unity;pantheon;x11
|
||||
Reference in New Issue
Block a user