mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-12 02:28:37 +02:00
dendritic: rewrote entire config
This commit is contained in:
@@ -0,0 +1 @@
|
||||
./utilities are more for collection of small application/settings that big configuration that should be in ../application
|
||||
@@ -0,0 +1,60 @@
|
||||
{ self, ... }: {
|
||||
flake.nixosModules.audioAndMedia = {pkgs, ...}: {
|
||||
# Enable sound with pipewire.
|
||||
services.pulseaudio.enable = false;
|
||||
security.rtkit.enable = true;
|
||||
services.pipewire = {
|
||||
enable = true;
|
||||
alsa.enable = true;
|
||||
alsa.support32Bit = true;
|
||||
pulse.enable = true;
|
||||
# If you want to use JACK applications, uncomment this
|
||||
#jack.enable = true;
|
||||
|
||||
# use the example session manager (no others are packaged yet so this is enabled by default,
|
||||
# no need to redefine it in your config for now)
|
||||
#media-session.enable = true;
|
||||
};
|
||||
environment.systemPackages = with pkgs; [
|
||||
self.packages.${pkgs.system}.custom-changeAudioOutput
|
||||
kdePackages.okular
|
||||
kdePackages.dolphin
|
||||
pulseaudio # sound server
|
||||
playerctl # controls media player
|
||||
pavucontrol # PulseAudio Volume Control
|
||||
mplayer # Movie player that supports many video formats
|
||||
krita # image edition
|
||||
yt-dlp # some youtube downloader
|
||||
vlc
|
||||
#mprisence # Highly customizable Discord Rich Presence for MPRIS media players on Linux
|
||||
#gif-for-cli # Render gifs as ASCII art in your cli
|
||||
#rembg # background remover
|
||||
gpu-screen-recorder
|
||||
inkscape
|
||||
];
|
||||
|
||||
security.wrappers.gsr-kms-server = {
|
||||
# to remove the password prompt when using gpu-screen-recorder
|
||||
owner = "root";
|
||||
group = "root";
|
||||
capabilities = "cap_sys_admin+ep";
|
||||
source = "${pkgs.gpu-screen-recorder}/bin/gsr-kms-server";
|
||||
};
|
||||
};
|
||||
flake.packages.custom-changeAudioOutput = { pkgs, ...}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-changeAudioOutput";
|
||||
runtimeInputs = with pkgs; [
|
||||
fzf
|
||||
pulseaudio
|
||||
jq
|
||||
];
|
||||
text = ''
|
||||
select=$(pactl -f json list sinks | jq -r '.[].name' | fzf)
|
||||
if [[ -n "$select" ]]; then
|
||||
pactl set-default-sink "$select"
|
||||
fi
|
||||
pkill -f "kitty.*Select audio output"
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
{ self, ... }: {
|
||||
flake.nixosModules.autoCleanup-laptop = {pkgs, ...}: {
|
||||
# Ensure your script is available system-wide
|
||||
environment.systemPackages = [
|
||||
self.packages.${pkgs.system}.custom-cleanNix-laptop
|
||||
];
|
||||
users.users.tomasr = {
|
||||
linger = true; # lingering is required
|
||||
};
|
||||
|
||||
systemd.user.services.custom-cleanNix = {
|
||||
description = "NixOS configuration auto cleanup";
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
|
||||
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
|
||||
|
||||
# safety for long rebuilds
|
||||
TimeoutStartSec = "45min";
|
||||
TimeoutStopSec = "10min";
|
||||
|
||||
# avoid overlap
|
||||
RemainAfterExit = true;
|
||||
|
||||
# tweaks that should make the system run normally during the rebuilds
|
||||
Nice = 10;
|
||||
IOSchedulingClass = "best-effort";
|
||||
IOSchedulingPriority = 7;
|
||||
};
|
||||
};
|
||||
|
||||
# Systemd USER timer
|
||||
systemd.user.timers.custom-cleanNix = {
|
||||
wantedBy = ["timers.target"];
|
||||
|
||||
timerConfig = {
|
||||
OnCalendar = "Sat *-*-* 20:00:00"; # runs saturday night. If for whatever reason something breaks. I have whole sunday to fix it.
|
||||
|
||||
Persistent = true; # if it happens during shutted down
|
||||
|
||||
# avoids thundering herd on boot
|
||||
RandomizedDelaySec = "2h";
|
||||
};
|
||||
};
|
||||
};
|
||||
flake.packages.custom-cleanNix-laptop = {pkgs, ...}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-cleanNix";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
git
|
||||
nixos-rebuild
|
||||
matrix-commander-rs
|
||||
libnotify
|
||||
alejandra
|
||||
deadnix
|
||||
];
|
||||
|
||||
text = ''
|
||||
set -e
|
||||
|
||||
FLAKE_DIR="/home/tomasr/nixos"
|
||||
FLAKE="$FLAKE_DIR#laptop"
|
||||
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
|
||||
|
||||
ERROR_FILE=$(mktemp)
|
||||
|
||||
# snapshot current state
|
||||
git -C "$FLAKE_DIR" add -A
|
||||
git -C "$FLAKE_DIR" commit --allow-empty -m "snapshot pre-cleanup-$TIME"
|
||||
git -C "$FLAKE_DIR" tag "pre-cleanup-$TIME" HEAD
|
||||
|
||||
# the echos are to separate what each one is doing. Just for curiosity
|
||||
echo "deadnix scans your Nix code and removes or reports unused (dead) variables and bindings"
|
||||
deadnix --edit "$FLAKE_DIR" # removes unused code
|
||||
echo "--------------------------------------------------------------"
|
||||
echo "statix lints your Nix code to find stylistic issues, bad patterns, and potential mistakes."
|
||||
statix fix "$FLAKE_DIR" # check other linting issues
|
||||
echo "--------------------------------------------------------------"
|
||||
echo "alejandra formats your Nix code consistently according to a strict, opinionated style."
|
||||
alejandra "$FLAKE_DIR" # formats the config
|
||||
echo "--------------------------------------------------------------"
|
||||
|
||||
if sudo /run/current-system/sw/bin/nixos-rebuild switch --flake "$FLAKE" 2> "$ERROR_FILE"; then # use /run/.../bin/ uses the sudoless rule
|
||||
|
||||
if ! git -C "$FLAKE_DIR" diff --quiet HEAD; then
|
||||
git -C "$FLAKE_DIR" add -A
|
||||
git -C "$FLAKE_DIR" commit -m "Auto: cleanup-$TIME"
|
||||
git -C "$FLAKE_DIR" push
|
||||
|
||||
notify-send "Nix auto cleanup" "Everything OK"
|
||||
|
||||
matrix-commander-rs --verbose -m "Nix auto cleanup. Everything OK.<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
|
||||
--html \
|
||||
-r "\!7j-78_02dHROeLj4Ns8F12eo4IiZGv4zNsQ_1-WlyIU"
|
||||
else
|
||||
notify-send "Nix auto cleanup" "No changes"
|
||||
git -C "$FLAKE_DIR" push
|
||||
fi
|
||||
|
||||
else
|
||||
ERROR_MSG=$(cat "$ERROR_FILE")
|
||||
|
||||
notify-send -u critical "Nix auto cleanup" "FAILED"
|
||||
|
||||
matrix-commander-rs --verbose -m "Nix auto cleanup failed.<br>Error: <pre>$ERROR_MSG</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
|
||||
--html \
|
||||
-r "\!7j-78_02dHROeLj4Ns8F12eo4IiZGv4zNsQ_1-WlyIU"
|
||||
|
||||
git -C "$FLAKE_DIR" reset --hard "pre-cleanup-$TIME"
|
||||
fi
|
||||
git -C "$FLAKE_DIR" tag -d "pre-cleanup-$TIME" # removes the tag
|
||||
|
||||
rm -f "$ERROR_FILE"
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
{ self, ... }: {
|
||||
flake.nixosModules.autoUpdate-laptop = {pkgs, ...}: {
|
||||
# Ensure your script is available system-wide
|
||||
environment.systemPackages = [
|
||||
self.packages.${pkgs.system}.custom-autoupdate-laptop
|
||||
];
|
||||
users.users.tomasr = {
|
||||
linger = true; # lingering is required
|
||||
};
|
||||
|
||||
systemd.user.services.custom-autoupdate = {
|
||||
description = "NixOS flake auto update";
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
|
||||
ExecStart = "/run/current-system/sw/bin/custom-autoupdate";
|
||||
|
||||
# safety for long rebuilds
|
||||
TimeoutStartSec = "45min";
|
||||
TimeoutStopSec = "10min";
|
||||
|
||||
# avoid overlap
|
||||
RemainAfterExit = true;
|
||||
|
||||
# tweaks that should make the system run normally during the rebuilds
|
||||
Nice = 10;
|
||||
IOSchedulingClass = "best-effort";
|
||||
IOSchedulingPriority = 7;
|
||||
};
|
||||
};
|
||||
|
||||
# Systemd USER timer
|
||||
systemd.user.timers.custom-autoupdate = {
|
||||
wantedBy = ["timers.target"];
|
||||
|
||||
timerConfig = {
|
||||
OnCalendar = "Fri *-*-* 20:00:00"; # runs friday night. If for whatever reason something breaks. I have whole week-end to fix it.
|
||||
|
||||
Persistent = true; # if it happens during shutted down
|
||||
|
||||
# avoids thundering herd on boot
|
||||
RandomizedDelaySec = "2h";
|
||||
};
|
||||
};
|
||||
};
|
||||
flake.packages.custom-autoupdate-laptop = {pkgs, ...}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-autoupdate";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
git
|
||||
nixos-rebuild
|
||||
matrix-commander-rs
|
||||
libnotify
|
||||
];
|
||||
|
||||
text = ''
|
||||
set -e
|
||||
|
||||
FLAKE_DIR="/home/tomasr/nixos"
|
||||
FLAKE="$FLAKE_DIR#laptop"
|
||||
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
|
||||
|
||||
ERROR_FILE=$(mktemp)
|
||||
|
||||
# snapshot current state
|
||||
git -C "$FLAKE_DIR" add -A
|
||||
git -C "$FLAKE_DIR" commit --allow-empty -m "snapshot pre-autoupdate-$TIME"
|
||||
git -C "$FLAKE_DIR" tag "pre-autoupdate-$TIME" HEAD
|
||||
|
||||
# update lock only
|
||||
nix flake update --flake "$FLAKE_DIR"
|
||||
|
||||
if sudo /run/current-system/sw/bin/nixos-rebuild switch --flake "$FLAKE" 2> "$ERROR_FILE"; then # use /run/.../bin/ uses the sudoless rule
|
||||
|
||||
if ! git -C "$FLAKE_DIR" diff --quiet -- flake.lock; then
|
||||
git -C "$FLAKE_DIR" add flake.lock
|
||||
git -C "$FLAKE_DIR" commit -m "flake.lock: autoupdate-$TIME"
|
||||
git -C "$FLAKE_DIR" push
|
||||
|
||||
notify-send "Flake autoupdate" "Rebuild OK"
|
||||
|
||||
matrix-commander-rs --verbose -m "Flake rebuild succesfull.<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
|
||||
--html \
|
||||
-r "\!7j-78_02dHROeLj4Ns8F12eo4IiZGv4zNsQ_1-WlyIU"
|
||||
else
|
||||
notify-send "Flake autoupdate" "No changes"
|
||||
git -C "$FLAKE_DIR" push
|
||||
fi
|
||||
|
||||
else
|
||||
ERROR_MSG=$(cat "$ERROR_FILE")
|
||||
|
||||
notify-send -u critical "Flake autoupdate" "FAILED"
|
||||
|
||||
matrix-commander-rs --verbose -m "Flake rebuild failed.<br>Error: <pre>$ERROR_MSG</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
|
||||
--html \
|
||||
-r "\!7j-78_02dHROeLj4Ns8F12eo4IiZGv4zNsQ_1-WlyIU"
|
||||
|
||||
git -C "$FLAKE_DIR" reset --hard "pre-autoupdate-$TIME"
|
||||
fi
|
||||
|
||||
git -C "$FLAKE_DIR" tag -d "pre-autoupdate-$TIME" # removes the tag
|
||||
|
||||
rm -f "$ERROR_FILE"
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{ self, ...}: {
|
||||
flake.nixosModules.notifications = { pkgs, ... }: {
|
||||
environment.systemPackages = with pkgs; [
|
||||
libnotify # Library that sends desktop notifications to a notification daemon
|
||||
socat # Utility for bidirectional data transfer between two independent data channels (used to communicate between hyprland and swww to change wallpapers dinamically)
|
||||
matrix-commander-rs # matrix client used to send notifications from scripts to my phone
|
||||
# battery notifications
|
||||
self.packages.${pkgs.system}.custom-batterynotify
|
||||
self.packages.${pkgs.system}.custom-batterywarning
|
||||
# checks if matrix-commander-rs is installed and logged in
|
||||
self.packages.${pkgs.system}.custom-checkMatrix
|
||||
self.packages.${pkgs.system}.custom-gitnotify # checks if git is set up
|
||||
self.packages.${pkgs.system}.custom-checkKdrive # check if kdrive is set up with rclone
|
||||
];
|
||||
};
|
||||
flake.packages.custom-checkMatrix = { pkgs, ...}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-checkMatrix";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
matrix-commander-rs
|
||||
libnotify
|
||||
];
|
||||
|
||||
text = ''
|
||||
expected="@totorile1:unredacted.org"
|
||||
|
||||
current="$(matrix-commander-rs --whoami | tr -d '\n')"
|
||||
|
||||
if [ "$current" != "$expected" ]; then
|
||||
notify-send "matrix-commander-rs" \
|
||||
"You are not logged in as @totorile1:unredacted.org\nLog:\n$current"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
flake.packages.custom-gitnotify = { pkgs, ...}:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-gitnotify";
|
||||
runtimeInputs = with pkgs; [
|
||||
git
|
||||
libnotify
|
||||
];
|
||||
text = ''
|
||||
# Check if git is installed
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
NAME=$(git config --global user.name)
|
||||
EMAIL=$(git config --global user.email)
|
||||
|
||||
if [[ -z "$NAME" || -z "$EMAIL" ]]; then
|
||||
notify-send \
|
||||
"Git not configured" \
|
||||
"Set your identity\n or remove this warning by removing the custom-gitnotify line in\n ~/nixos/modules/applications/hyprland.nix"
|
||||
matrix-commander-rs --verbose -m "Git not configured.<br>Set your identify or remove this warning by removing the custom-gitnotify in ~/nixos/modules/applications/hyprland.nix<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
|
||||
--html \
|
||||
-r "\!7j-78_02dHROeLj4Ns8F12eo4IiZGv4zNsQ_1-WlyIU"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.nixosModules.development = { pkgs, pkgs-unstable, ... }: {
|
||||
programs.nix-ld.enable = true; #Run unpatched dynamic binaries on NixOS. For example lets run ./a.out from gcc
|
||||
environment.systemPackages = with pkgs; [
|
||||
gcc
|
||||
jq # json parser used in some scripts
|
||||
jp # lightweight and flexible cli JSON parser
|
||||
(pkgs-unstable.python314.withPackages (ps:
|
||||
with ps; [
|
||||
matplotlib
|
||||
networkx
|
||||
scipy
|
||||
]))
|
||||
python313Packages.pygments # used for ccat (comment of colorize plugin from oh-my-zsh)
|
||||
pkg-config
|
||||
gdb
|
||||
raylib
|
||||
glfw # raylib and some dependecies
|
||||
gnumake
|
||||
go
|
||||
direnv
|
||||
cling # c interpreter used for coding
|
||||
# lsp
|
||||
clang-tools
|
||||
python311Packages.python-lsp-server
|
||||
ltex-ls-plus
|
||||
pylint
|
||||
black
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
{ self, ... }: let cacheTime = "10"; in {
|
||||
flake.nixosModules.documentation = { pkgs, ... }: {
|
||||
# unfortunatly this adds a lot of computation when nix rebuilds
|
||||
documentation.man.generateCaches = true; # used for the man script
|
||||
|
||||
environment.pathsToLink = [
|
||||
# see https://wiki.nixos.org/wiki/Documentation_Gaps#How_do_manpages_work?_Or:_environment.pathsToLink_and_buildEnv
|
||||
"/share/applications"
|
||||
"/share/xdg-desktop-portal"
|
||||
];
|
||||
environment.systemPackages = [
|
||||
pkgs.manix
|
||||
self.packages.${pkgs.system}.custom-man
|
||||
self.packages.${pkgs.system}.custom-manix
|
||||
];
|
||||
};
|
||||
flake.packages.custom-man = { pkgs, ... }:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-man";
|
||||
runtimeInputs = with pkgs; [
|
||||
man
|
||||
ripgrep
|
||||
fzf
|
||||
];
|
||||
text = ''
|
||||
CACHE_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}"
|
||||
CACHE_FILE="$CACHE_DIR/custom-man-options.txt"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
REGENERATE=0
|
||||
|
||||
# check if -r flag was passed
|
||||
if [ "''${1:-}" = "-r" ]; then
|
||||
REGENERATE=1
|
||||
fi
|
||||
|
||||
|
||||
# regenerate if file does not exist or is older than cacheTime days
|
||||
if [ ! -f "$CACHE_FILE" ] || [ "$(find "$CACHE_FILE" -mtime +${cacheTime} -print)" ]; then
|
||||
REGENERATE=1
|
||||
fi
|
||||
|
||||
if [ $REGENERATE -eq 1 ]; then
|
||||
echo "(Re)building custom-manix cache..."
|
||||
mkdir -p "$(dirname "$CACHE_FILE")"
|
||||
man -k . > "$CACHE_FILE"
|
||||
fi
|
||||
|
||||
# read from cache and pipe into fzf
|
||||
cat "$CACHE_FILE" \
|
||||
| fzf --preview "man {1}" \
|
||||
| xargs man
|
||||
'';
|
||||
};
|
||||
flake.packages.custom-manix = { pkgs, ... }:
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-manix";
|
||||
runtimeInputs = with pkgs; [
|
||||
manix
|
||||
ripgrep
|
||||
fzf
|
||||
];
|
||||
text = ''
|
||||
CACHE_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}"
|
||||
CACHE_FILE="$CACHE_DIR/custom-manix-options.txt"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
REGENERATE=0
|
||||
|
||||
# check if -r flag was passed
|
||||
if [ "''${1:-}" = "-r" ]; then
|
||||
REGENERATE=1
|
||||
fi
|
||||
|
||||
|
||||
# regenerate if file does not exist or is older than cacheTime days
|
||||
if [ ! -f "$CACHE_FILE" ] || [ "$(find "$CACHE_FILE" -mtime +${cacheTime} -print)" ]; then
|
||||
REGENERATE=1
|
||||
fi
|
||||
|
||||
if [ $REGENERATE -eq 1 ]; then
|
||||
echo "(Re)building custom-manix cache..."
|
||||
mkdir -p "$(dirname "$CACHE_FILE")"
|
||||
manix "" | rg -N '^(?:\x1b\[[0-9;]*m)*# ' | sed 's/\x1b\[[0-9;]*m//g; s/^# //' | rg -Nv '^(<|.*https?://)' > "$CACHE_FILE"
|
||||
fi
|
||||
|
||||
# read from cache and pipe into fzf
|
||||
cat "$CACHE_FILE" \
|
||||
| fzf --preview "manix {}" \
|
||||
| xargs manix
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{ ... }: {
|
||||
flake.nixosModules.latex = {pkgs, ...}: {
|
||||
environment.systemPackages = with pkgs; [
|
||||
texlab
|
||||
ltex-ls-plus
|
||||
biber
|
||||
(pkgs.texliveMedium.withPackages (
|
||||
ps:
|
||||
with ps; [
|
||||
# these few pkgs are used in the CV template
|
||||
titlesec # allows creating custom \section
|
||||
marvosym # some symboles
|
||||
ebgaramond # Use the EB Garamond font
|
||||
microtype # To enable letterspacing
|
||||
fontaxes
|
||||
# these few pkgs were used for my TM
|
||||
svg
|
||||
catchfile
|
||||
caption
|
||||
transparent
|
||||
cfr-lm
|
||||
svn-prov
|
||||
nfssext-cfr
|
||||
hyphenat
|
||||
csquotes
|
||||
enumitem
|
||||
chngcntr
|
||||
tcolorbox
|
||||
pdfcol
|
||||
wrapfig
|
||||
tocloft
|
||||
lastpage
|
||||
biblatex
|
||||
biblatex-iso690
|
||||
libertine
|
||||
minted
|
||||
upquote
|
||||
lipsum
|
||||
footmisc
|
||||
#(setq org-latex-compiler "lualatex")
|
||||
#(setq org-preview-latex-default-process 'dvisvgm)
|
||||
]
|
||||
))
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{ ... }: {
|
||||
flake.nixosModules.networking = {pkgs, ...}: {
|
||||
environment.systemPackages = with pkgs; [
|
||||
wget
|
||||
networkmanagerapplet # NetworkManager control applet
|
||||
inetutils # collections of network programs such as telnet
|
||||
];
|
||||
#networking.Name = "nixos"; # Define your hostname.
|
||||
#networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
|
||||
|
||||
# Configure network proxy if necessary
|
||||
#networking.proxy.default = "http://user:password@proxy:port/";
|
||||
#networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
|
||||
|
||||
# Enable networking
|
||||
networking.networkmanager.enable = true;
|
||||
|
||||
# Enable the OpenSSH daemon.
|
||||
# services.openssh.enable = true;
|
||||
|
||||
# Open ports in the firewall.
|
||||
# networking.firewall.allowedTCPPorts = [ ... ];
|
||||
# networking.firewall.allowedUDPPorts = [ ... ];
|
||||
# Or disable the firewall altogether.
|
||||
networking.firewall.enable = false;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
{ inputs, ... }:
|
||||
{
|
||||
flake.nixosModules.nixUtils-laptop = { ... }: {
|
||||
# nixpkgs-review crashed my laptop multiple times. We must reduce how much ressources it can take.
|
||||
# for reference, my laptop is a 12 core ryzen 7
|
||||
nix.settings.max-jobs = 6;
|
||||
nix.settings.cores = 6;
|
||||
};
|
||||
flake.nixosModules.nixUtils = { pkgs-unstable, ... }: {
|
||||
# Garbage collector of generations
|
||||
nix.gc = {
|
||||
automatic = true;
|
||||
dates = "weekly";
|
||||
options = "--delete-older-than 7d"; # every week delete generations older than a month
|
||||
};
|
||||
|
||||
#manix is unhappy without this
|
||||
nix.nixPath = [
|
||||
"nixpkgs=${inputs.nixpkgs.outPath}"
|
||||
"home-manager=${inputs.home-manager.outPath}"
|
||||
];
|
||||
|
||||
#adds nixos experimental features:
|
||||
nix.settings.experimental-features = ["nix-command" "flakes"];
|
||||
|
||||
environment.systemPackages = with pkgs-unstable; [
|
||||
nixpkgs-review
|
||||
nixfmt-tree
|
||||
treefmt
|
||||
nixd
|
||||
deadnix
|
||||
alejandra
|
||||
vimPluginsUpdater # used for building plugins
|
||||
nix-index
|
||||
statix
|
||||
];
|
||||
};
|
||||
flake.packages.custom-trimmer = { pkgs, ... }:
|
||||
# https://gist.github.com/MaxwellDupre/3077cd229490cf93ecab08ef2a79c852
|
||||
# better garbage collector
|
||||
pkgs.writeShellApplication {
|
||||
name = "custom-trimmer";
|
||||
runtimeInputs = with pkgs; [
|
||||
nix
|
||||
];
|
||||
text = ''
|
||||
set -euo pipefail
|
||||
|
||||
## Defaults
|
||||
keepGensDef=30; keepDaysDef=7
|
||||
keepGens=$keepGensDef; keepDays=$keepDaysDef
|
||||
|
||||
## Usage
|
||||
usage () {
|
||||
printf "Usage:\n\t ./trim-generations.sh <keep-generations> <keep-days> <profile> \n\n
|
||||
(defaults are: Keep-Gens=%d Keep-Days=%d Profile=user)\n\n" "$keepGensDef" "$keepDaysDef"
|
||||
printf "If you enter any parameters, you must enter all three, or none to use defaults.\n"
|
||||
printf "Example:\n\t trim-generations.sh 15 10 home-manager\n"
|
||||
printf " this will work on the home-manager profile and keep all generations from the\n"
|
||||
printf "last 10 days, and keep at least 15 generations no matter how old.\n"
|
||||
printf "\nProfiles available are:\tuser, home-manager, channels, system (root)\n"
|
||||
printf "\n-h or --help prints this help text."
|
||||
}
|
||||
|
||||
if [ $# -eq 1 ]; then # if help requested
|
||||
if [ "$1" = "-h" ]; then
|
||||
usage
|
||||
exit 1;
|
||||
fi
|
||||
if [ "$1" = "--help" ]; then
|
||||
usage
|
||||
exit 2;
|
||||
fi
|
||||
printf "Dont recognise your option exiting..\n\n"
|
||||
usage
|
||||
exit 3;
|
||||
|
||||
elif [ $# -eq 0 ]; then # print the defaults
|
||||
printf "The current defaults are:\n Keep-Gens=%d Keep-Days=%d \n\n" "$keepGensDef" "$keepDaysDef"
|
||||
read -r -p "Keep these defaults? (y/n):" answer
|
||||
|
||||
case "$answer" in
|
||||
[yY1] )
|
||||
printf "Using defaults..\n"
|
||||
;;
|
||||
[nN0] ) printf "ok, doing nothing, exiting..\n"
|
||||
exit 6;
|
||||
;;
|
||||
* ) printf "%b" "Doing nothing, exiting.."
|
||||
exit 7;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
## Handle parameters (and change if root)
|
||||
if [[ $EUID -ne 0 ]]; then # if not root
|
||||
profile=$(readlink /home/"$USER"/.nix-profile)
|
||||
else
|
||||
if [ -d /nix/var/nix/profiles/system ]; then # maybe this or the other
|
||||
profile="/nix/var/nix/profiles/system"
|
||||
elif [ -d /nix/var/nix/profiles/default ]; then
|
||||
profile="/nix/var/nix/profiles/default"
|
||||
else
|
||||
echo "Cant find profile for root. Exiting"
|
||||
exit 8
|
||||
fi
|
||||
fi
|
||||
if (( $# < 1 )); then
|
||||
printf "Keeping default: %d generations OR %d days, whichever is more\n" "$keepGensDef" "$keepDaysDef"
|
||||
elif [[ $# -le 2 ]]; then
|
||||
printf "\nError: Not enough arguments.\n\n" >&2
|
||||
usage
|
||||
exit 1
|
||||
elif (( $# > 4)); then
|
||||
printf "\nError: Too many arguments.\n\n" >&2
|
||||
usage
|
||||
exit 2
|
||||
else
|
||||
if [ "$1" -lt 1 ]; then
|
||||
printf "using Gen numbers less than 1 not recommended. Setting to min=1\n"
|
||||
read -r -p "is that ok? (y/n): " answer
|
||||
printf "%s" "$answer"
|
||||
case "$answer" in
|
||||
[yY1] )
|
||||
printf "ok, continuing..\n"
|
||||
;;
|
||||
[nN0] )
|
||||
printf "ok, doing nothing, exiting..\n"
|
||||
exit 6;
|
||||
;;
|
||||
* )
|
||||
printf "%b" "Doing nothing, exiting.."
|
||||
exit 7;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [ "$2" -lt 0 ]; then
|
||||
printf "using negative days number not recommended. Setting to min=0\n"
|
||||
read -r -p "is that ok? (y/n): " answer
|
||||
|
||||
case "$answer" in
|
||||
[yY1] )
|
||||
printf "ok, continuing..\n"
|
||||
;;
|
||||
[nN0] )
|
||||
printf "ok, doing nothing, exiting..\n"
|
||||
exit 6;
|
||||
;;
|
||||
* )
|
||||
printf "%b" "Doing nothing, exiting.."
|
||||
exit 7;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
keepGens=$1; keepDays=$2;
|
||||
(( keepGens < 1 )) && keepGens=1
|
||||
(( keepDays < 0 )) && keepDays=0
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
if [[ $3 == "user" ]] || [[ $3 == "default" ]]; then
|
||||
profile=$(readlink /home/"$USER"/.nix-profile)
|
||||
elif [[ $3 == "home-manager" ]]; then
|
||||
# home-manager defaults to $XDG_STATE_HOME; otherwise, use
|
||||
# `home-manager generations` and `nix-store --query --roots
|
||||
# /nix/store/...` to figure out what reference is keeping the old
|
||||
# generations alive.
|
||||
profile="''${XDG_STATE_HOME:-$HOME/.local/state}/nix/profiles/home-manager"
|
||||
elif [[ $3 == "channels" ]]; then
|
||||
profile="/nix/var/nix/profiles/per-user/$USER/channels"
|
||||
else
|
||||
printf "\nError: Do not understand your third argument. Should be one of: (user / home-manager/ channels)\n\n"
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
else
|
||||
if [[ $3 == "system" ]]; then
|
||||
profile="/nix/var/nix/profiles/system"
|
||||
elif [[ $3 == "user" ]] || [[ $3 == "default" ]]; then
|
||||
profile="/nix/var/nix/profiles/default"
|
||||
else
|
||||
printf "\nError: Do not understand your third argument. Should be one of: (user / system)\n\n"
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
printf "OK! \t Keep Gens = %s \t Keep Days = %s \n\n" "$keepGens" "$keepDays"
|
||||
|
||||
|
||||
fi
|
||||
|
||||
printf "Operating on profile: %s \t \n\n" "$profile"
|
||||
|
||||
## Runs at the end, to decide whether to delete profiles that match chosen parameters.
|
||||
choose () {
|
||||
local default="$1"
|
||||
local prompt="$2"
|
||||
local answer
|
||||
|
||||
read -r -p "$prompt" answer
|
||||
[ -z "$answer" ] && answer="$default"
|
||||
|
||||
case "$answer" in
|
||||
[yY1] ) #printf "answered yes!\n"
|
||||
nix-env --delete-generations -p "$profile" "''${!gens[@]}"
|
||||
exit 0
|
||||
;;
|
||||
[nN0] ) printf "Ok doing nothing exiting..\n"
|
||||
exit 6;
|
||||
;;
|
||||
* ) printf "%b" "Unexpected answer '$answer'!" >&2
|
||||
exit 7;
|
||||
;;
|
||||
esac
|
||||
} # end of function choose
|
||||
|
||||
# printf "profile = %s \n\n" "$profile"
|
||||
## Query nix-env for generations list
|
||||
#IFS=$'\n' nixGens=( $(nix-env --list-generations -p "$profile" | sed 's:^\s*::; s:\s*$::' | tr '\t' ' ' | tr -s ' ') )
|
||||
# gave errors replaced by:
|
||||
mapfile -t nixGens < <(
|
||||
nix-env --list-generations -p "$profile" |
|
||||
sed 's:^\s*::; s:\s*$::' |
|
||||
tr '\t' ' ' |
|
||||
tr -s ' '
|
||||
)
|
||||
timeNow=$(date +%s)
|
||||
|
||||
## Get info on oldest generation
|
||||
IFS=' ' read -r -a oldestGenArr <<< "''${nixGens[0]}"
|
||||
oldestGen=''${oldestGenArr[0]}
|
||||
oldestDate=''${oldestGenArr[1]}
|
||||
printf "%-30s %s\n" "oldest generation:" "$oldestGen"
|
||||
#oldestDate=''${nixGens[0]:3:19}
|
||||
printf "%-30s %s\n" "oldest generation created:" "$oldestDate"
|
||||
oldestTime=$(date -d "$oldestDate" +%s)
|
||||
oldestElapsedSecs=$((timeNow-oldestTime))
|
||||
oldestElapsedMins=$((oldestElapsedSecs/60))
|
||||
oldestElapsedHours=$((oldestElapsedMins/60))
|
||||
oldestElapsedDays=$((oldestElapsedHours/24))
|
||||
printf "%-30s %s\n" "minutes before now:" "$oldestElapsedMins"
|
||||
printf "%-30s %s\n" "hours before now:" "$oldestElapsedHours"
|
||||
printf "%-30s %s\n\n" "days before now:" "$oldestElapsedDays"
|
||||
|
||||
## Get info on current generation
|
||||
for i in "''${nixGens[@]}"; do
|
||||
IFS=' ' read -r -a iGenArr <<< "$i"
|
||||
genNumber=''${iGenArr[0]}
|
||||
genDate=''${iGenArr[1]}
|
||||
if [[ "$i" =~ current ]]; then
|
||||
currentGen=$genNumber
|
||||
printf "%-30s %s\n" "current generation:" "$currentGen"
|
||||
currentDate=$genDate
|
||||
printf "%-30s %s\n" "current generation created:" "$currentDate"
|
||||
currentTime=$(date -d "$currentDate" +%s)
|
||||
currentElapsedSecs=$((timeNow-currentTime))
|
||||
currentElapsedMins=$((currentElapsedSecs/60))
|
||||
currentElapsedHours=$((currentElapsedMins/60))
|
||||
currentElapsedDays=$((currentElapsedHours/24))
|
||||
printf "%-30s %s\n" "minutes before now:" "$currentElapsedMins"
|
||||
printf "%-30s %s\n" "hours before now:" "$currentElapsedHours"
|
||||
printf "%-30s %s\n\n" "days before now:" "$currentElapsedDays"
|
||||
fi
|
||||
done
|
||||
|
||||
## Compare oldest and current generations
|
||||
timeBetweenOldestAndCurrent=$((currentTime-oldestTime))
|
||||
elapsedDays=$((timeBetweenOldestAndCurrent/60/60/24))
|
||||
generationsDiff=$((currentGen-oldestGen))
|
||||
|
||||
## Figure out what we should do, based on generations and options
|
||||
if [[ elapsedDays -le keepDays ]]; then
|
||||
printf "All generations are no more than %s days older than current generation. \nOldest gen days difference from current gen: %s \n\n\tNothing to do!\n" "$keepDays" "$elapsedDays"
|
||||
exit 4;
|
||||
elif [[ generationsDiff -lt keepGens ]]; then
|
||||
printf "Oldest generation (%d) is only %d generations behind current (%d). \n\n\t Nothing to do!\n" "$oldestGen" "$generationsDiff" "$currentGen"
|
||||
exit 5;
|
||||
else
|
||||
printf "\tSomething to do...\n"
|
||||
declare -a gens
|
||||
for i in "''${nixGens[@]}"; do
|
||||
IFS=' ' read -r -a iGenArr <<< "$i"
|
||||
genNumber=''${iGenArr[0]}
|
||||
genDiff=$((currentGen-genNumber))
|
||||
genDate=''${iGenArr[1]}
|
||||
genTime=$(date -d "$genDate" +%s)
|
||||
elapsedSecs=$((timeNow-genTime))
|
||||
genDaysOld=$((elapsedSecs/60/60/24))
|
||||
if [[ genDaysOld -gt keepDays ]] && [[ genDiff -ge keepGens ]]; then
|
||||
gens["$genNumber"]="$genDate, $genDaysOld day(s) old"
|
||||
fi
|
||||
done
|
||||
printf "\nFound the following generation(s) to delete:\n"
|
||||
for K in "''${!gens[@]}"; do
|
||||
printf "generation %d \t ''${gens[$K]}\n" "$K"
|
||||
done
|
||||
printf "\n"
|
||||
choose "y" "Do you want to delete these? [Y/n]: "
|
||||
fi
|
||||
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{ ... }: {
|
||||
flake.nixosModules.office = {pkgs, ...}: {
|
||||
environment.systemPackages = with pkgs; [
|
||||
libreoffice
|
||||
birdtray
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{ ... }: {
|
||||
flake.nixosModules.ollama = {pkgs-unstable, ...}: {
|
||||
services.ollama = {
|
||||
enable = true;
|
||||
package = pkgs-unstable.ollama-vulkan;
|
||||
#port = 11434;
|
||||
#host = "127.0.0.1:11434";
|
||||
# loadModels load them directly into ram at startup. Doesn't download them.
|
||||
#loadModels = [ "mistral:7b" ]; # don't forget the :xxxxx for ex: "mixtral" don't work
|
||||
#syncModels = true;
|
||||
};
|
||||
systemd.services.ollama.serviceConfig.ExecStartPost = [
|
||||
# use this to auto download models
|
||||
"${pkgs-unstable.ollama-vulkan}/bin/ollama pull mistral:7b"
|
||||
];
|
||||
/*
|
||||
services.open-webui = {
|
||||
enable = true;
|
||||
port = 8080;
|
||||
environment = {
|
||||
OLLAMA_BASE_URL = "http://127.0.0.1:11434";
|
||||
WEBUI_AUTH = "True";
|
||||
};
|
||||
};
|
||||
*/
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{ ... }: {
|
||||
flake.nixosModules.otherUtils = # try to keep packages here at a minium. Preferably use a dedicated file
|
||||
{
|
||||
pkgs,
|
||||
pkgs-unstable,
|
||||
...
|
||||
}: {
|
||||
environment.systemPackages = with pkgs; [
|
||||
gnome-calculator
|
||||
snapshot
|
||||
gnome-characters
|
||||
#tree # shows dir in tree # we use eza now
|
||||
brightnessctl # control brightness
|
||||
powertop
|
||||
fzf
|
||||
bottom # Cross-platform graphical process/system monitor with a customizable interface
|
||||
tomato-c # pomodoro timer
|
||||
#hyprshot
|
||||
mailcap
|
||||
fuzzel
|
||||
usbutils # used for lsusb
|
||||
(pkgs.callPackage ../../modules/scripts/tomato.nix {})
|
||||
(pkgs.callPackage ../../modules/scripts/syllabes.nix {}) # python script to get number of syllabes in french
|
||||
pkgs-unstable.bitwarden-desktop
|
||||
fluffychat # matrix client
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user