crap ton of stuff

This commit is contained in:
randomuser 2024-01-15 03:52:45 -06:00
parent b36b585db3
commit 22d1ba38af
37 changed files with 564 additions and 129 deletions

View File

@ -7,12 +7,26 @@
../../modules/common.nix ../../modules/common.nix
../../modules/x11.nix ../../modules/x11.nix
../../modules/tlp.nix ../../modules/tlp.nix
../../modules/media.nix
../../modules/anki.nix
../../modules/power-control.nix
]; ];
environment.systemPackages = with pkgs; [
xscreensaver
];
services.getty.autologinUser = "usr";
boot.loader = {
grub.timeoutStyle = "hidden";
timeout = 0;
grub.enable = true;
grub.device = "/dev/sda";
};
hardware.pulseaudio.enable = true; hardware.pulseaudio.enable = true;
boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/sda";
networking.hostName = "x230t"; networking.hostName = "x230t";

View File

@ -16,7 +16,6 @@
st = pkgs.callPackage ./st.nix { }; st = pkgs.callPackage ./st.nix { };
rebuild = pkgs.callPackage ./rebuild.nix { }; rebuild = pkgs.callPackage ./rebuild.nix { };
utils = pkgs.callPackage ./utils.nix { }; utils = pkgs.callPackage ./utils.nix { };
xbattmon = pkgs.callPackage ./xbattmon.nix { };
}; };
in in
withSystem ( withSystem (

View File

@ -1,27 +0,0 @@
{ stdenv
, lib
, bash
, gnupg
, makeWrapper
, fetchgit
}:
stdenv.mkDerivation rec {
pname = "pash";
version = "1.00";
src = fetchgit {
url = "https://git.beepboop.systems/rndusr/pash";
sha256 = "sha256-0L3N7F4BwVdu4rR5xpUEIHcX/x64Gni8JTUki5kGH24=";
};
nativeBuildInputs = [ makeWrapper gnupg ];
installPhase = ''
mkdir -p $out/bin
cp $src/pash $out/bin/pash
wrapProgram $out/bin/pash --prefix PATH : ${lib.makeBinPath [ bash ]}
'';
phases = [ "installPhase" ];
}

View File

@ -1,2 +1,6 @@
cd ~/dot_testing cd ~/dot_testing
sudo nixos-rebuild -I nixos-config=./boxes/$(hostname).nix switch $@ if [ -f "flake.nix" ]; then
sudo nixos-rebuild --flake . switch $@
else
sudo nixos-rebuild -I nixos-config=./boxes/$(hostname).nix switch $@
fi

View File

@ -12,7 +12,7 @@
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "st"; pname = "st";
version = "69.19"; version = "1.02";
src = fetchgit { src = fetchgit {
url = "https://git.beepboop.systems/rndusr/st"; url = "https://git.beepboop.systems/rndusr/st";

View File

@ -1,5 +1,10 @@
{ stdenv { stdenv
, lib , lib
# for statusbar
, pkg-config
, libxcb
# shell scripts stuff
, makeWrapper
, sxhkd , sxhkd
, bash , bash
, feh , feh
@ -7,20 +12,23 @@
, fzy , fzy
, figlet , figlet
, curl , curl
, ytfzf
, xrandr , xrandr
, makeWrapper
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "utils"; pname = "utils";
version = "1.00"; version = "1.01";
src = ./utils; src = ./utils;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper pkg-config libxcb ];
buildInputs = [ bash feh xrandr jq curl fzy ]; buildInputs = [ libxcb bash feh xrandr jq curl fzy ytfzf ];
buildPhase = ""; buildPhase = ''
ls
make
'';
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
@ -28,10 +36,9 @@ stdenv.mkDerivation rec {
for i in $(ls $src/sh); do for i in $(ls $src/sh); do
cp $src/sh/$i $out/bin cp $src/sh/$i $out/bin
ln -sf $out/bin/tmenu_run $out/bin/regenerate ln -sf $out/bin/tmenu_run $out/bin/regenerate
wrapProgram $out/bin/$i --prefix PATH : ${lib.makeBinPath [ sxhkd bash feh xrandr jq figlet curl fzy ]} wrapProgram $out/bin/$i --prefix PATH : ${lib.makeBinPath [ sxhkd bash feh xrandr jq figlet curl fzy ytfzf ]}
done done
cp c/status/main $out/bin/statusbar
''; '';
phases = [ "buildPhase" "installPhase" ];
} }

3
builds/utils/Makefile Normal file
View File

@ -0,0 +1,3 @@
.PHONY: main
main:
make -C c/status -f Makefile

2
builds/utils/c/status/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
main
*.o

View File

@ -0,0 +1,9 @@
LDFLAGS=`pkg-config --cflags --libs xcb`
CFLAGS=-ggdb -fsanitize=address
main: battery.o bspwm.o time.o battstatus.o
clean:
rm *.o main
run:
./main

View File

@ -0,0 +1,4 @@
status
------
a simple statusbar script thing (tm)

View File

@ -0,0 +1,38 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include "battery.h"
#include "common.h"
/* config contains a path to the battery */
int mod_battery(char *config, char *name, char *pipename) {
struct message msg;
strcpy(msg.name, name);
int fd = open(pipename, O_WRONLY);
int battery;
int recvd;
chdir("/sys/class/power_supply");
chdir(config);
for(;;) {
battery = open("capacity", O_RDONLY);
recvd = read(battery, msg.content, 3);
msg.content[3] = '\0';
if (msg.content[2] == '\n') {
msg.content[2] = '\0';
}
close(battery);
write(fd, &msg, sizeof(msg));
sleep(30);
}
return 0;
}

View File

@ -0,0 +1,6 @@
#ifndef STATUS_BATTERY_H
#define STATUS_BATTERY_H
int mod_battery(char *config, char *name, char *pipename);
#endif

View File

@ -0,0 +1,48 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include "battstatus.h"
#include "common.h"
int mod_battstatus(char *config, char *name, char *pipename) {
char status;
int battery;
struct message msg;
strcpy(msg.name, name);
int fd = open(pipename, O_WRONLY);
chdir("/sys/class/power_supply");
chdir(config);
for(;;) {
battery = open("status", O_RDONLY);
read(battery, msg.content, 1);
switch(msg.content[0]) {
case 'N': /* not charging */
msg.content[0] = '-';
break;
case 'C': /* charging */
msg.content[0] = '^';
break;
case 'D': /* discharging */
msg.content[0] = 'U';
break;
case 'U': /* unknown */
msg.content[0] = '?';
break;
default: /* what's going on? */
msg.content[0] = '!';
break;
}
msg.content[1] = '\0';
close(battery);
write(fd, &msg, sizeof(msg));
sleep(30);
}
return 0;
}

View File

@ -0,0 +1,6 @@
#ifndef STATUS_BATTSTAT_H
#define STATUS_BATTSTAT_H
int mod_battstatus(char *config, char *name, char *pipename);
#endif

View File

@ -0,0 +1,142 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <xcb/xcb.h>
#include <fcntl.h>
#include "bspwm.h"
#include "common.h"
const char subscribe[] = "subscribe";
int get_socket(void) {
struct sockaddr_un sock;
char *host;
int displaynumber, screennumber;
int fd;
xcb_parse_display(NULL, &host, &displaynumber, &screennumber);
sock.sun_family = AF_UNIX;
snprintf(
sock.sun_path,
sizeof(sock.sun_path), "/tmp/bspwm%s_%i_%i-socket",
host, displaynumber, screennumber
);
free(host);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (connect(
fd,
(struct sockaddr *) &sock,
sizeof(sock)
) == -1) {
return -1;
} else {
return fd;
}
}
int should_be_shown(char c) {
return c == 'O' || c == 'o' || c == 'F' || c == 'U' || c == 'u';
}
int is_a_desktop(char c) {
return c == 'O' || c == 'o' || c == 'F' || c == 'f' || c == 'U' || c == 'u';
}
/* XXX: this function has the potential to buffer overflow by ONE BYTE.
* probably fix this? */
void print_desktop_status(char *in, char *out, int outlen) {
int written;
int i;
char c;
/* flags */
int read_colon;
int skip_to_next_colon;
int read_until_colon;
int is_first_desktop;
int last_was_desktop;
i = 0;
written = 0;
read_colon = 1;
skip_to_next_colon = 0;
read_until_colon = 0;
is_first_desktop = 1;
last_was_desktop = 0;
for(;;) {
c = in[i];
if(!c) break;
if(written == outlen) break;
if (skip_to_next_colon) {
if (c == ':') {
skip_to_next_colon = 0;
read_until_colon = 0;
read_colon = 1;
} else if (read_until_colon) {
out[written] = c;
written++;
}
} else if (read_colon && should_be_shown(c)) {
if (!is_first_desktop) {
out[written] = ' ';
written++;
}
switch(c) {
case 'O':
case 'F': /* fallthrough */
out[written] = '*';
written++;
break;
}
skip_to_next_colon = 1;
read_until_colon = 1;
read_colon = 0;
is_first_desktop = 0;
last_was_desktop = 1;
} else if (read_colon && is_a_desktop(c)) {
last_was_desktop = 1;
} else {
if(last_was_desktop) {
break;
}
}
i++;
}
out[written] = '\0';
}
int mod_bspwm(char *config, char *name, char *pipename) {
struct message msg;
int fd, bspcfd;
char in[BUFFER_SIZE];
strcpy(msg.name, name);
msg.flags = 0;
fd = open(pipename, O_WRONLY);
bspcfd = get_socket();
send(bspcfd, subscribe, sizeof(subscribe), 0);
for(;;) {
int recvd = recv(bspcfd, in, BUFFER_SIZE, 0);
print_desktop_status(in, msg.content, 512);
write(fd, &msg, sizeof(msg));
memset(msg.content, 0, 512);
}
return 0;
}

View File

@ -0,0 +1,6 @@
#ifndef STATUS_BSPWM_H
#define STATUS_BSPWM_H
int mod_bspwm(char *config, char *name, char *pipename);
#endif

View File

@ -0,0 +1,21 @@
#ifndef STATUS_COMMON_H
#define STATUS_COMMON_H
#define LENGTH(x) sizeof(x) / sizeof(x[0])
#define BUFFER_SIZE 512
struct module {
int (*fork_callback)(char *config, char *name, char *pipename);
char name[16];
char config[512];
char buffer[512];
int buflen;
};
struct message {
int flags;
char name[16];
char content[512];
};
#endif

View File

@ -0,0 +1,91 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <time.h>
#include <fcntl.h>
#include <xcb/xcb.h>
#include <string.h>
#include "common.h"
#include "battery.h"
#include "battstatus.h"
#include "bspwm.h"
#include "time.h"
struct module mods[] = {
{mod_battery, "battery", "BAT0", { '\0' }},
{mod_battstatus, "battstatus", "BAT0", { '\0' }},
{mod_time, "time", "", { '\0' }},
/* {mod_bspwm, "bspwm", "", { '\0' }}, not working at the moment */
};
void create_module_proc(int index, char *pipename) {
pid_t pid = fork();
if (pid == 0) { /* we're the child */
mods[index].fork_callback(
mods[index].config,
mods[index].name,
pipename
);
}
}
void create_module_procs(char *pipename) {
for(int i = 0; i < LENGTH(mods); i++) {
create_module_proc(i, pipename);
}
}
void redraw() {
/* get the progress' module's value, convert it to int, and then
* figure out how much of the screen should be shaded in */
printf("\033[H\033[2J");
for(int i = 0; i < LENGTH(mods); i++) {
if (i == 0) printf("%s ", mods[i].buffer);
else printf("| %s ", mods[i].buffer);
}
fflush(stdout);
}
static char NAMED_PIPE[] = "/home/usr/.cache/statusbar_pipe";
int main(void) {
char pipename[BUFFER_SIZE];
srand(time(NULL));
strcpy(pipename, &NAMED_PIPE);
pipename[sizeof(NAMED_PIPE) - 1] = 'A' + (rand() % 26);
pipename[sizeof(NAMED_PIPE)] = 'A' + (rand() % 26);
pipename[sizeof(NAMED_PIPE) + 1] = '\0';
mkfifo(pipename, 0666);
int fd = open(pipename, O_RDWR);
struct message msg;
create_module_procs(pipename);
for (;;) {
int ret = read(fd, &msg, sizeof(msg));
if(ret < 0) {
printf("error while reading message from child\n");
}
for(int i = 0; i < LENGTH(mods); i++) {
if(strcmp(mods[i].name, msg.name) == 0) {
mods[i].buflen = strlen(msg.content);
strcpy(mods[i].buffer, msg.content);
redraw();
break;
}
}
}
return 0;
}

View File

@ -0,0 +1,9 @@
with import <nixpkgs> {};
pkgs.mkShell {
nativeBuildInputs = [
gdb
gnumake
pkg-config
xorg.libxcb
];
}

View File

@ -0,0 +1,27 @@
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include "common.h"
#include "time.h"
int mod_time(char *config, char *name, char *pipename) {
struct message msg;
time_t now;
struct tm *tm;
int fd;
strcpy(msg.name, name);
msg.flags = 0;
fd = open(pipename, O_WRONLY);
for(;;) {
time(&now);
tm = localtime(&now);
strftime(msg.content, 512, "%H:%M", tm);
write(fd, &msg, sizeof(msg));
sleep(60);
}
}

View File

@ -0,0 +1,6 @@
#ifndef STATUS_TIME_H
#define STATUS_TIME_H
int mod_time(char *config, char *name, char *pipename);
#endif

View File

@ -1,4 +1,13 @@
# mode - change the current effective sxhkd configuration # mode - change the current effective sxhkd configuration
pkill sxhkd if [ -n "$1" ]; then
sxhkd -c ~/.config/sxhkd/$1 & disown pkill sxhkd
sxhkd -c ~/.config/sxhkd/$1 & disown
[ -f "~/.config/sxhkd/$1.sh ] && ~/.config/sxhkd/$1.sh
exit
fi
# we need a menu
choice=$(ls ~/.config/sxhkd | tmenu)
$0 $choice

12
builds/utils/sh/statuswrap Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
geos=$(
xrandr | \
grep ' connected' | \
grep -o '[0-9]*x[0-9]*+[0-9]*+[0-9]*' | \
awk -F'[x+]' '{print $1 "x20+" $3 "+" $4}'
)
for i in $geos; do
st -c statusbar -p -g "$i" -e statusbar & disown
done

4
builds/utils/sh/testing Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
st &
statusbar

View File

@ -1,41 +0,0 @@
{ stdenv
, lib
, fetchgit
, pkg-config
, libX11
, libXft
, libXinerama
, fontconfig
, freetype
, ncurses
, extraLibs ? [ ]
}:
stdenv.mkDerivation rec {
pname = "xbattmon";
version = "69.19";
src = fetchgit {
url = "https://git.beepboop.systems/rndusr/xbattmon";
sha256 = "sha256-mM5pjyBw+1lJoaXt0BNiXmqGRt0U2ABENitA8K/EZ9E=";
};
nativeBuildInputs = [ pkg-config fontconfig freetype ncurses ];
buildInputs = [ libX11 libXft libXinerama ] ++ extraLibs;
buildPhase = ''
./configure
make
'';
installPhase = ''
mkdir -p $out/bin
cp ${pname} $out/bin
'';
meta = with lib; {
description = "Customized builds of the st terminal emulator";
homepage = "https://git.beepboop.systems/rndusr/st";
license = licenses.mit;
};
}

View File

@ -91,12 +91,12 @@
}, },
"locked": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-B6H6Z595aKacBDVAbEc8gXeEr2YLZNm6JK43XPSKo10=", "narHash": "sha256-YmGlTX2Y5d6aQzqZ1IzVp1CnbyXuHE1Fwwtf9nB40zE=",
"path": "/nix/store/q8dkdvbif26q9vnvh19prj5qdlk8qrny-source/builds", "path": "/nix/store/arzg5zcsb349c5rz3kaflqiszdvfbqny-source/builds",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/nix/store/q8dkdvbif26q9vnvh19prj5qdlk8qrny-source/builds", "path": "/nix/store/arzg5zcsb349c5rz3kaflqiszdvfbqny-source/builds",
"type": "path" "type": "path"
} }
} }

View File

@ -54,3 +54,6 @@ export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
# source the bashrc(s) # source the bashrc(s)
[ -f $HOME/.config/bash/bashrc ] && . $HOME/.config/bash/bashrc [ -f $HOME/.config/bash/bashrc ] && . $HOME/.config/bash/bashrc
[ -f $HOME/.bashrc ] && . $HOME/.bashrc [ -f $HOME/.bashrc ] && . $HOME/.bashrc
# if we're interactive and the tty is /dev/tty1 then start xorg
[ "$(tty)" = "/dev/tty1" ] && sx

View File

@ -1,11 +1,21 @@
#!/bin/sh #!/bin/sh
# rndusr's bspwmrc # rndusr's bspwmrc
bspc monitor -d 1 2 3 4 5 6 7 8 9
bspc rule -a st-gpg-menu state=floating
bspc rule -a statusbar border=off sticky=on state=floating manage=off
bspc rule -a tmenu-prompt border=on sticky=on state=floating
bspc rule -a Xmessage border=on state=floating
bspc rule -a Zathura state=tiled
bspc rule -a generic-st-window state=floating manage=on sticky=on border=on
bspc rule -a floating-feh state=floating
# post-wm boilerplate # post-wm boilerplate
statuswrap
wallpaper wallpaper
disp disp
polybar & HOME=".config/xscreensaver" xscreensaver --no-splash &
dunst &
# set up the color scheme # set up the color scheme
bspc config normal_border_color "#161510" bspc config normal_border_color "#161510"
@ -16,13 +26,5 @@ bspc config pointer_follows_focus true
bspc config pointer_follows_monitor true bspc config pointer_follows_monitor true
bspc config focus_follows_pointer true bspc config focus_follows_pointer true
bspc config window_gap 3 bspc config window_gap 0
#bspc config top_padding 20 bspc config top_padding 20
bspc rule -a st-gpg-menu state=floating
bspc rule -a statusbar border=off sticky=on state=floating manage=off
bspc rule -a tmenu-prompt border=on sticky=on state=floating
bspc rule -a Xmessage border=on state=floating
bspc rule -a Zathura state=tiled
bspc rule -a generic-st-window state=floating manage=on sticky=on border=on
bspc rule -a floating-feh state=floating

View File

@ -8,5 +8,8 @@
programs.chromium = { programs.chromium = {
enable = true; enable = true;
package = pkgs.ungoogled-chromium; package = pkgs.ungoogled-chromium;
extensions = [
{ id = "ecnphlgnajanjnkcmbpancdjoidceilk"; }
];
}; };
} }

View File

@ -80,20 +80,6 @@ globals.vimtex_view_method = 'zathura'
-- }}} -- }}}
-- autocommands {{{ -- autocommands {{{
-- autocmds for sxhkd and bspwm config files
vim.api.nvim_create_autocmd({"BufWrite"}, {
pattern = {"bspwmrc"},
callback = function()
vim.fn.system("bspc wm -r")
end
})
vim.api.nvim_create_autocmd({"BufWrite"}, {
pattern = {"sxhkdrc"},
callback = function()
vim.fn.system("killall sxhkd -USR1")
end
})
function setTabbing(lang, width) function setTabbing(lang, width)
vim.api.nvim_create_autocmd({"Filetype"}, { vim.api.nvim_create_autocmd({"Filetype"}, {
pattern = {lang}, pattern = {lang},
@ -153,19 +139,8 @@ local packer = require('packer').startup(function(use)
use 'hrsh7th/nvim-cmp' use 'hrsh7th/nvim-cmp'
use 'hrsh7th/cmp-nvim-lsp' use 'hrsh7th/cmp-nvim-lsp'
use 'L3MON4D3/LuaSnip' use 'L3MON4D3/LuaSnip'
use 'https://github.com/vimwiki/vimwiki.git'
use 'lervag/vimtex' use 'lervag/vimtex'
use 'https://github.com/protex/better-digraphs.nvim' use 'https://github.com/protex/better-digraphs.nvim'
use 'https://github.com/itchyny/calendar.vim'
use {
"folke/which-key.nvim",
config = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
-- require("which-key").setup {
-- }
end
}
if packer_bootstrap then if packer_bootstrap then
require('packer').sync() require('packer').sync()

View File

@ -7,5 +7,8 @@
".config/sxhkd/sxhkdrc" = { ".config/sxhkd/sxhkdrc" = {
source = ./sxhkdrc; source = ./sxhkdrc;
}; };
".config/sxhkd/mouse" = {
source = ./mouse;
};
}; };
} }

7
modules/anki.nix Normal file
View File

@ -0,0 +1,7 @@
{ lib, config, pkgs, ...}:
{
environment.systemPackages = with pkgs; [
anki-bin
];
}

View File

@ -10,7 +10,6 @@
inputs.utilpkg.packages.x86_64-linux.st inputs.utilpkg.packages.x86_64-linux.st
inputs.utilpkg.packages.x86_64-linux.rebuild inputs.utilpkg.packages.x86_64-linux.rebuild
inputs.utilpkg.packages.x86_64-linux.utils inputs.utilpkg.packages.x86_64-linux.utils
inputs.utilpkg.packages.x86_64-linux.xbattmon
pkgs.man-pages pkgs.man-pages
]; ];
@ -26,7 +25,7 @@
users.users.usr = { users.users.usr = {
isNormalUser = true; isNormalUser = true;
extraGroups = [ "wheel" ]; extraGroups = [ "wheel" "networkmanager" ];
initialPassword = "usr"; initialPassword = "usr";
}; };
} }

10
modules/media.nix Normal file
View File

@ -0,0 +1,10 @@
{ lib, config, pkgs, ...}:
{
environment.systemPackages = with pkgs; [
musescore
audacity
libsForQt5.kdenlive
anki-bin
];
}

25
modules/power-control.nix Normal file
View File

@ -0,0 +1,25 @@
{ lib, config, pkgs, inputs, ...}:
{
# let regular users control power
security.sudo = {
enable = true;
extraRules = [{
commands = [
{
command = "${pkgs.systemd}/bin/systemctl suspend";
options = [ "NOPASSWD" ];
}
{
command = "${pkgs.systemd}/bin/reboot";
options = [ "NOPASSWD" ];
}
{
command = "${pkgs.systemd}/bin/poweroff";
options = [ "NOPASSWD" ];
}
];
groups = [ "wheel" ];
}];
};
}

7
modules/sxiv.nix Normal file
View File

@ -0,0 +1,7 @@
{ lib, config, pkgs, ...}:
{
environment.systemPackages = with pkgs; [
sxiv
];
}

View File

@ -6,11 +6,13 @@
./gnupg.nix ./gnupg.nix
./fonts.nix ./fonts.nix
./pulse.nix ./pulse.nix
./sxiv.nix
]; ];
environment.systemPackages = [ environment.systemPackages = with pkgs; [
pkgs.bspwm bspwm
pkgs.sxhkd sxhkd
xscreensaver
]; ];
services.xserver = { services.xserver = {