Skip to content

Commit

Permalink
refac(scripts): use nix writers
Browse files Browse the repository at this point in the history
  • Loading branch information
workflow committed Jul 20, 2024
1 parent dc2d9fc commit bde9652
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 60 deletions.
72 changes: 25 additions & 47 deletions home.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
{
inputs,
lib,
pkgs,
secrets,
osConfig,
...
}: let
homePackages = with pkgs; [
unstable.aichat
alejandra # nix formatter
bluetuith
find-cursor
twentythreeeleven.galaxy-buds-client
helvum # GTK patchbay for Pipewire
unstable.hoppscotch # Open-Source Postman
twentythreeeleven.jetbrains.idea-ultimate
lolcat
neo-cowsay
networkmanager_dmenu
nix-tree
rclone
restic
];

homeScripts = with scripts; [
dlfile
font-smoke-test
macgyver-status
tailscale-ip
];

hostName = osConfig.networking.hostName;

imports =
Expand Down Expand Up @@ -82,29 +105,11 @@ in {
executable = true;
};

# Dlfile (reverse drag-and-drop with dragon)
"bin/dlfile" = {
text = scripts.dlfile;
executable = true;
};

# Duplicati
".backup/duplicati-config-nix/${hostName}+Full+Backup-duplicati-config.json.aes" = lib.mkIf (secrets ? duplicatiConfig) {
source = lib.attrsets.attrByPath ["${hostName}"] {} secrets.duplicatiConfig;
};

# Font smoke-test
"bin/font-smoke-test" = {
text = scripts.font-smoke-test;
executable = true;
};

# Generate gitignores
"bin/gen-gitignore" = {
text = scripts.gen-gitignore;
executable = true;
};

# gh (Github CLI)
".config/gh/config.yml".source = ./dotfiles/gh.config.yml;

Expand All @@ -117,12 +122,6 @@ in {
executable = true;
};

# Get Macgyver status
"bin/macgyver-status" = {
text = scripts.macgyver-status;
executable = true;
};

# Parcellite
".config/parcellite/parcelliterc".source = ./dotfiles/parcelliterc;

Expand Down Expand Up @@ -165,12 +164,6 @@ in {
# Syncthing tray
".config/syncthingtray.ini".source = ./dotfiles/syncthingtray.ini;

# Get tailscale IP if online
"bin/tailscale-ip" = {
text = scripts.tailscale-ip;
executable = true;
};

# Variety
".config/variety/variety.conf".source = ./dotfiles/variety.conf;
};
Expand All @@ -180,22 +173,7 @@ in {
options = ["grp:ctrls_toggle" "eurosign:e" "caps:escape_shifted_capslock" "terminate:ctrl_alt_bksp"];
};

packages = with pkgs; [
unstable.aichat
alejandra # nix formatter
bluetuith
find-cursor
twentythreeeleven.galaxy-buds-client
helvum # GTK patchbay for Pipewire
unstable.hoppscotch # Open-Source Postman
twentythreeeleven.jetbrains.idea-ultimate
lolcat
neo-cowsay
networkmanager_dmenu
nix-tree
rclone
restic
];
packages = homePackages ++ homeScripts;

sessionVariables = {
PATH = "$HOME/bin:$PATH";
Expand Down
19 changes: 6 additions & 13 deletions lib/scripts.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{pkgs}: let
shebang = "#!${pkgs.bash}/bin/bash";
in {
dlfile = ''
${shebang}
# Provides the ability to download a file by dropping it into a window
{pkgs, ...}: {
# Provides the ability to download a file by dropping it into a window
dlfile = pkgs.writers.writeBashBin "dlfile" ''
url=$(dragon -t -x)
if [ -n "$url" ]; then
Expand Down Expand Up @@ -33,8 +29,7 @@ in {
'';

# Looted from https://gist.github.com/elijahmanor/c10e5787bf9ac6b8c276e47e6745826c, much obliged
font-smoke-test = ''
${shebang}
font-smoke-test = pkgs.writers.writeBashBin "font-smoke-test" ''
set -e
printf "%b\n" "Normal"
Expand All @@ -47,8 +42,7 @@ in {
'';

# Get the current tailscale ip if tailscale is up
tailscale-ip = ''
${shebang}
tailscale-ip = pkgs.writers.writeBashBin "tailscale-ip" ''
set -euo pipefail
isOnline=$(tailscale status --json | jq -r '.Self.Online')
Expand All @@ -61,8 +55,7 @@ in {
'';

# Get the current macgyver status
macgyver-status = ''
${shebang}
macgyver-status = pkgs.writers.writeBashBin "macgyver-status" ''
output=$(systemctl status macgyver | grep 'Active:' | awk '{print $2}')
if [ "$output" = "active" ]; then
Expand Down

0 comments on commit bde9652

Please sign in to comment.