This commit is contained in:
2025-08-03 20:02:48 +02:00
parent 55a090959d
commit c22eab800c
15 changed files with 4 additions and 515 deletions

View File

@@ -1 +0,0 @@
x86_64-linux

View File

@@ -1,245 +0,0 @@
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Determine the operating system
export OS=$(uname)
# Primary network interface
if [[ "$OS" != "Darwin" ]]; then
export PRIMARY_IFACE=$(ip -o -4 route show to default | awk '{print $5}')
echo -e "${GREEN}Found primary network interface $PRIMARY_IFACE${NC}"
fi
# Custom print function
_print() {
if [[ "$OS" == "Darwin" ]]; then
echo -e "$1"
else
echo "$1"
fi
}
# Custom prompt function
_prompt() {
local message="$1"
local variable="$2"
_print "$message"
read -r $variable
}
insert_secrets_output() {
local pattern="outputs = { self, darwin, nix-homebrew, homebrew-bundle, homebrew-core, homebrew-cask, home-manager, nixpkgs, disko, agenix } @inputs:"
local insert_text="secrets "
awk -v pat="$pattern" -v insert="$insert_text" '
$0 ~ pat {
sub(/} @inputs:/, ", " insert "} @inputs:"); # Replace the closing brace with the insert text followed by the brace
gsub(/ ,/, ","); # Correct any spaces before commas
print
next
}
{ print }
' flake.nix > flake.nix.tmp
mv flake.nix.tmp flake.nix
}
insert_secrets_input() {
# Define file path
FILE_PATH="flake.nix"
# Backup the original file
cp "$FILE_PATH" "${FILE_PATH}.bak"
# Temporary file for the text to insert
TEMP_FILE="temp_insert.txt"
# Write the formatted text to the temporary file
cat > "$TEMP_FILE" << 'EOF'
secrets = {
url = "git+ssh://git@github.com/%GITHUB_USER%/%GITHUB_SECRETS_REPO%.git";
flake = false;
};
EOF
# Check if the 'secrets' block already exists
if grep -q 'url = "git+ssh://git@github.com/%GITHUB_USER%/%GITHUB_SECRETS_REPO%.git"' "$FILE_PATH"; then
echo "The 'secrets' block already exists in the file."
rm "$TEMP_FILE"
rm "${FILE_PATH}.bak"
exit 0
fi
# Find the start and end line numbers of the 'disko' block
START_LINE=$(grep -n 'disko = {' "$FILE_PATH" | head -n 1 | cut -d: -f1)
END_LINE=$(tail -n +$START_LINE "$FILE_PATH" | grep -n '};' | head -n 1 | cut -d: -f1)
END_LINE=$((START_LINE + END_LINE - 1))
# Create a new file with the insertion
{
sed -n "1,${END_LINE}p" "$FILE_PATH"
cat "$TEMP_FILE"
sed -n "$((END_LINE + 1)),\$p" "$FILE_PATH"
} > "${FILE_PATH}.new"
# Replace the original file with the new file
mv "${FILE_PATH}.new" "$FILE_PATH"
# Clean up the temporary files
rm "$TEMP_FILE"
rm "${FILE_PATH}.bak"
}
ask_for_star() {
_print "${YELLOW}Would you like to support my work by starring my GitHub repo? yes/no [yes]: ${NC}"
local response
read -r response
response=${response:-yes} # Set default response to 'yes' if input is empty
if [[ "$response" =~ ^[Yy](es)?$ ]] || [[ -z "$response" ]]; then
if [[ "$OS" == "Darwin" ]]; then
open "https://github.com/dustinlyons/nixos-config"
else
xdg-open "https://github.com/dustinlyons/nixos-config"
fi
fi
}
ask_for_star
# Fetch username from the system
export USERNAME=$(whoami)
# If the username is 'nixos' or 'root', ask the user for their username
if [[ "$USERNAME" == "nixos" ]] || [[ "$USERNAME" == "root" ]]; then
_prompt "${YELLOW}You're running as $USERNAME. Please enter your desired username: ${NC}" USERNAME
fi
# Check if git is available
if command -v git >/dev/null 2>&1; then
# Fetch email and name from git config
export GIT_EMAIL=$(git config --get user.email)
export GIT_NAME=$(git config --get user.name)
else
_print "${RED}Git is not available on this system.${NC}"
fi
# If git email is not found or git is not available, ask the user
if [[ -z "$GIT_EMAIL" ]]; then
_prompt "${YELLOW}Please enter your email: ${NC}" GIT_EMAIL
fi
# If git name is not found or git is not available, ask the user
if [[ -z "$GIT_NAME" ]]; then
_prompt "${YELLOW}Please enter your name: ${NC}" GIT_NAME
fi
_prompt "${YELLOW}Please enter your Github username: ${NC}" GITHUB_USER
_prompt "${YELLOW}Please enter your Github secrets repository name: ${NC}" GITHUB_SECRETS_REPO
export GITHUB_USER
export GITHUB_SECRETS_REPO
select_boot_disk() {
local disks
local _boot_disk
_print "${YELLOW}Available disks:${NC}"
disks=$(lsblk -nd --output NAME,SIZE | grep -v loop)
echo "$disks"
# Warning message for data deletion
_print "${RED}WARNING: All data on the chosen disk will be erased during the installation!${NC}"
_prompt "${YELLOW}Please enter the name of your boot disk (e.g., sda, nvme0n1). Do not include the full path ("/dev/"): ${NC}" _boot_disk
# Confirmation for disk selection to prevent accidental data loss
_print "${YELLOW}You have selected $_boot_disk as the boot disk. This will delete everything on this disk. Are you sure? (Y/N): ${NC}"
read -r confirmation
if [[ "$confirmation" =~ ^[Yy]$ ]]; then
export BOOT_DISK=$_boot_disk
else
_print "${RED}Disk selection cancelled by the user. Please run the script again to select the correct disk.${NC}"
exit 1
fi
}
# Set hostname and find primary disk if this is NixOS
if [[ "$OS" != "Darwin" ]]; then
_prompt "${YELLOW}Please enter a hostname for the system: ${NC}" HOST_NAME
export HOST_NAME
select_boot_disk
fi
# Confirmation step
confirm_details() {
_print "${GREEN}Username: $USERNAME"
_print "Email: $GIT_EMAIL"
_print "Name: $GIT_NAME${NC}"
if([[ "$OS" != "Darwin" ]]); then
_print "${GREEN}Primary interface: $PRIMARY_IFACE"
_print "Boot disk: $BOOT_DISK"
_print "Hostname: $HOST_NAME${NC}"
fi
_print "${GREEN}Secrets repository: $GITHUB_USER/$GITHUB_SECRETS_REPO${NC}"
_prompt "${YELLOW}Is this correct? yes/no: ${NC}" choice
case "$choice" in
[Nn] | [Nn][Oo] )
_print "${RED}Exiting script.${NC}"
exit 1
;;
[Yy] | [Yy][Ee][Ss] )
_print "${GREEN}Continuing...${NC}"
;;
* )
_print "${RED}Invalid option. Exiting script.${NC}"
exit 1
;;
esac
}
# Call the confirmation function
confirm_details
# Function to replace tokens in each file
replace_tokens() {
local file="$1"
if [[ $(basename $1) != "apply" ]]; then
if [[ "$OS" == "Darwin" ]]; then
# macOS
LC_ALL=C LANG=C sed -i '' -e "s/%USER%/$USERNAME/g" "$file"
LC_ALL=C LANG=C sed -i '' -e "s/%EMAIL%/$GIT_EMAIL/g" "$file"
LC_ALL=C LANG=C sed -i '' -e "s/%NAME%/$GIT_NAME/g" "$file"
LC_ALL=C LANG=C sed -i '' -e "s/%GITHUB_USER%/$GITHUB_USER/g" "$file"
LC_ALL=C LANG=C sed -i '' -e "s/%GITHUB_SECRETS_REPO%/$GITHUB_SECRETS_REPO/g" "$file"
else
# Linux or other
sed -i -e "s/%USER%/$USERNAME/g" "$file"
sed -i -e "s/%EMAIL%/$GIT_EMAIL/g" "$file"
sed -i -e "s/%NAME%/$GIT_NAME/g" "$file"
sed -i -e "s/%INTERFACE%/$PRIMARY_IFACE/g" "$file"
sed -i -e "s/%DISK%/$BOOT_DISK/g" "$file"
sed -i -e "s/%HOST%/$HOST_NAME/g" "$file"
sed -i -e "s/%GITHUB_USER%/$GITHUB_USER/g" "$file"
sed -i -e "s/%GITHUB_SECRETS_REPO%/$GITHUB_SECRETS_REPO/g" "$file"
fi
fi
}
# Insert secrets repo into flake
insert_secrets_input
insert_secrets_output
# Traverse directories and call replace_tokens on each Nix file
export -f replace_tokens
find . -type f -exec bash -c 'replace_tokens "$0"' {} \;
echo "$USERNAME" > /tmp/username.txt
_print "${GREEN}User $USERNAME information applied.${NC}"

View File

@@ -1,19 +0,0 @@
#!/bin/sh -e
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
NC='\033[0m'
SYSTEM_TYPE="x86_64-darwin"
FLAKE_SYSTEM="darwinConfigurations.${SYSTEM_TYPE}.system"
export NIXPKGS_ALLOW_UNFREE=1
echo "${YELLOW}Starting build...${NC}"
nix --extra-experimental-features 'nix-command flakes' build .#$FLAKE_SYSTEM $@
echo "${YELLOW}Cleaning up...${NC}"
unlink ./result
echo "${GREEN}Switch to new generation complete!${NC}"

View File

@@ -1,23 +0,0 @@
#!/bin/sh -e
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
NC='\033[0m'
SYSTEM_TYPE="x86_64-darwin"
FLAKE_SYSTEM="darwinConfigurations.${SYSTEM_TYPE}.system"
export NIXPKGS_ALLOW_UNFREE=1
echo "${YELLOW}Starting build...${NC}"
nix --extra-experimental-features 'nix-command flakes' build .#$FLAKE_SYSTEM $@
echo "${YELLOW}Switching to new generation...${NC}"
# See https://github.com/nix-darwin/nix-darwin/issues/1457 on why we need sudo
sudo ./result/sw/bin/darwin-rebuild switch --flake .#${SYSTEM_TYPE} $@
echo "${YELLOW}Cleaning up...${NC}"
unlink ./result
echo "${GREEN}Switch to new generation complete!${NC}"

View File

@@ -1,33 +0,0 @@
#!/usr/bin/env bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
username=${USER}
export SSH_DIR=/Users/${username}/.ssh
lint_keys() {
if [[ -f "${SSH_DIR}/id_ed25519" && -f "${SSH_DIR}/id_ed25519.pub" && -f "${SSH_DIR}/id_ed25519_agenix" && -f "${SSH_DIR}/id_ed25519_agenix.pub" ]]; then
echo -e "${GREEN}All SSH keys are present.${NC}"
else
echo -e "${RED}Some SSH keys are missing.${NC}"
if [[ ! -f "${SSH_DIR}/id_ed25519" ]]; then
echo -e "${RED}Missing: id_ed25519${NC}"
fi
if [[ ! -f "${SSH_DIR}/id_ed25519.pub" ]]; then
echo -e "${RED}Missing: id_ed25519.pub${NC}"
fi
if [[ ! -f "${SSH_DIR}/id_ed25519_agenix" ]]; then
echo -e "${RED}Missing: id_ed25519_agenix${NC}"
fi
if [[ ! -f "${SSH_DIR}/id_ed25519_agenix.pub" ]]; then
echo -e "${RED}Missing: id_ed25519_agenix.pub${NC}"
fi
echo -e "${GREEN}Run the createKeys command to generate the missing keys.${NC}"
exit 1
fi
}
lint_keys

View File

@@ -1,68 +0,0 @@
#!/usr/bin/env bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
username=${USER}
export SSH_DIR=/Users/${username}/.ssh
handle_no_usb() {
echo -e ${RED}No USB drive found or mounted.${NC}"
echo -e ${GREEN}If you have not yet set up your keys, run the script to generate new SSH keys.${NC}"
exit 1
}
mount_usb() {
MOUNT_PATH=""
for dev in $(diskutil list | grep -o 'disk[0-9]'); do
MOUNT_PATH="$(diskutil info /dev/${dev} | grep \"Mount Point\" | awk -F: '{print $2}' | xargs)"
if [ -n "${MOUNT_PATH}" ]; then
echo -e "${GREEN}USB drive found at ${MOUNT_PATH}.${NC}"
break
fi
done
if [ -z "${MOUNT_PATH}" ]; then
echo -e "${RED}No USB drive found.${NC}"
fi
}
copy_keys() {
if [ -n "${MOUNT_PATH}" ]; then
cp "${MOUNT_PATH}/id_ed25519_agenix.pub" ${SSH_DIR}
cp "${MOUNT_PATH}/id_ed25519_agenix" ${SSH_DIR}
chmod 600 ${SSH_DIR}/id_ed25519_{agenix,agenix.pub}
else
echo -e "${RED}No USB drive found. Aborting.${NC}"
exit 1
fi
}
setup_ssh_directory() {
mkdir -p ${SSH_DIR}
}
set_keys() {
cp ${MOUNT_PATH}/id_ed25519_github.pub ${SSH_DIR}/id_ed25519.pub
cp ${MOUNT_PATH}/id_ed25519_github ${SSH_DIR}/id_ed25519
chmod 600 ${SSH_DIR}/id_ed25519
chmod 644 ${SSH_DIR}/id_ed25519.pub
}
change_ownership() {
chown ${username}:staff ${SSH_DIR}/id_ed25519{,.pub}
chown ${username}:staff ${SSH_DIR}/id_ed25519_{agenix,agenix.pub}
}
setup_ssh_directory
mount_usb
if [ -z "${MOUNT_PATH}" ]; then
handle_no_usb
else
copy_keys
set_keys
change_ownership
fi

View File

@@ -1,46 +0,0 @@
#!/usr/bin/env bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
username=${USER}
export SSH_DIR=/Users/${username}/.ssh
setup_ssh_directory() {
mkdir -p ${SSH_DIR}
}
prompt_for_key_generation() {
local key_name=$1
if [[ -f "${SSH_DIR}/${key_name}" ]]; then
echo -e "${RED}Existing SSH key found for ${key_name}.${NC}"
cat "${SSH_DIR}/${key_name}.pub"
read -p "Do you want to replace it? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 0 # Indicate key should be replaced
else
return 1 # Indicate key should be kept
fi
fi
return 0 # Indicate no key exists, so it should be created
}
generate_key() {
local key_name=$1
if prompt_for_key_generation "$key_name"; then
ssh-keygen -t ed25519 -f "${SSH_DIR}/${key_name}" -N ""
chown ${username}:staff "${SSH_DIR}/${key_name}"{,.pub}
else
echo -e "${GREEN}Kept existing ${key_name}.${NC}"
fi
}
setup_ssh_directory
generate_key "id_ed25519"
generate_key "id_ed25519_agenix"
echo -e "${GREEN}SSH key setup complete.${NC}"
echo -e "${GREEN}Remember to add the necessary keys to Github or other services as required.${NC}"

View File

@@ -35,8 +35,8 @@
outputs = { self, darwin, nix-homebrew, homebrew-bundle, homebrew-core, homebrew-cask, home-manager, nixpkgs, disko, agenix, secrets } @inputs: outputs = { self, darwin, nix-homebrew, homebrew-bundle, homebrew-core, homebrew-cask, home-manager, nixpkgs, disko, agenix, secrets } @inputs:
let let
user = "cschmatzler"; user = "cschmatzler";
linuxSystems = [ "x86_64-linux" "aarch64-linux" ]; linuxSystems = [ "x86_64-linux" ];
darwinSystems = [ "aarch64-darwin" "x86_64-darwin" ]; darwinSystems = [ "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs (linuxSystems ++ darwinSystems) f; forAllSystems = f: nixpkgs.lib.genAttrs (linuxSystems ++ darwinSystems) f;
devShell = system: let pkgs = nixpkgs.legacyPackages.${system}; in { devShell = system: let pkgs = nixpkgs.legacyPackages.${system}; in {
default = with pkgs; mkShell { default = with pkgs; mkShell {

View File

@@ -36,22 +36,9 @@ let user = "cschmatzler"; in
# Load configuration that is shared across systems # Load configuration that is shared across systems
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
emacs-unstable
agenix.packages."${pkgs.system}".default agenix.packages."${pkgs.system}".default
] ++ (import ../../modules/shared/packages.nix { inherit pkgs; }); ] ++ (import ../../modules/shared/packages.nix { inherit pkgs; });
launchd.user.agents.emacs.path = [ config.environment.systemPath ];
launchd.user.agents.emacs.serviceConfig = {
KeepAlive = true;
ProgramArguments = [
"/bin/sh"
"-c"
"/bin/wait4path ${pkgs.emacs}/bin/emacs && exec ${pkgs.emacs}/bin/emacs --fg-daemon"
];
StandardErrorPath = "/tmp/emacs.err.log";
StandardOutPath = "/tmp/emacs.out.log";
};
system = { system = {
checks.verifyNixPath = false; checks.verifyNixPath = false;
primaryUser = user; primaryUser = user;

View File

@@ -219,16 +219,6 @@ let user = "cschmatzler";
gvfs.enable = true; # Mount, trash, and other functionalities gvfs.enable = true; # Mount, trash, and other functionalities
tumbler.enable = true; # Thumbnail support for images tumbler.enable = true; # Thumbnail support for images
# Emacs runs as a daemon
#emacs = {
# enable = true;
# package = pkgs.emacs-unstable;
#};
};
# When emacs builds from no cache, it exceeds the 90s timeout default
systemd.user.services.emacs = {
serviceConfig.TimeoutStartSec = "7min";
}; };
# Enable CUPS to print documents # Enable CUPS to print documents

View File

@@ -1,34 +1,2 @@
{ user, config, pkgs, ... }: { user, config, pkgs, ... }:
{}
let
xdg_configHome = "${config.users.users.${user}.home}/.config";
xdg_dataHome = "${config.users.users.${user}.home}/.local/share";
xdg_stateHome = "${config.users.users.${user}.home}/.local/state"; in
{
# Raycast script so that "Run Emacs" is available and uses Emacs daemon
"${xdg_dataHome}/bin/emacsclient" = {
executable = true;
text = ''
#!/bin/zsh
#
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Run Emacs
# @raycast.mode silent
#
# Optional parameters:
# @raycast.packageName Emacs
# @raycast.icon ${xdg_dataHome}/img/icons/Emacs.icns
# @raycast.iconDark ${xdg_dataHome}/img/icons/Emacs.icns
if [[ $1 = "-t" ]]; then
# Terminal mode
${pkgs.emacs}/bin/emacsclient -t $@
else
# GUI mode
${pkgs.emacs}/bin/emacsclient -c -n $@
fi
'';
};
}

View File

@@ -2,11 +2,6 @@
let let
user = "cschmatzler"; user = "cschmatzler";
# Define the content of your file as a derivation
myEmacsLauncher = pkgs.writeScript "emacs-launcher.command" ''
#!/bin/sh
emacsclient -c -n &
'';
sharedFiles = import ../shared/files.nix { inherit config pkgs; }; sharedFiles = import ../shared/files.nix { inherit config pkgs; };
additionalFiles = import ./files.nix { inherit user config pkgs; }; additionalFiles = import ./files.nix { inherit user config pkgs; };
in in
@@ -54,7 +49,6 @@ in
file = lib.mkMerge [ file = lib.mkMerge [
sharedFiles sharedFiles
additionalFiles additionalFiles
{ "emacs-launcher.command".source = myEmacsLauncher; }
]; ];
stateVersion = "23.11"; stateVersion = "23.11";
@@ -81,10 +75,6 @@ in
{ path = "/System/Applications/Photos.app/"; } { path = "/System/Applications/Photos.app/"; }
{ path = "/System/Applications/Photo Booth.app/"; } { path = "/System/Applications/Photo Booth.app/"; }
{ path = "/System/Applications/System Settings.app/"; } { path = "/System/Applications/System Settings.app/"; }
{
path = toString myEmacsLauncher;
section = "others";
}
{ {
path = "${config.users.users.${user}.home}/Downloads"; path = "${config.users.users.${user}.home}/Downloads";
section = "others"; section = "others";

View File

@@ -31,7 +31,6 @@ shared-packages ++ [
rofi rofi
rofi-calc rofi-calc
postgresql postgresql
libtool # for Emacs vterm
# Screenshot and recording tools # Screenshot and recording tools
flameshot flameshot
@@ -42,7 +41,6 @@ shared-packages ++ [
tree tree
unixtools.ifconfig unixtools.ifconfig
unixtools.netstat unixtools.netstat
xclip # For the org-download package in Emacs
xorg.xwininfo # Provides a cursor to click and learn about windows xorg.xwininfo # Provides a cursor to click and learn about windows
xorg.xrandr xorg.xrandr

View File

@@ -1,8 +1,5 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
let
emacsOverlaySha256 = "0rvpskk1z996arcj48ch4g08lvid6r856m0x5376y7lfjxlsawga";
in
{ {
nixpkgs = { nixpkgs = {
@@ -19,11 +16,6 @@ in
map (n: import (path + ("/" + n))) map (n: import (path + ("/" + n)))
(filter (n: match ".*\\.nix" n != null || (filter (n: match ".*\\.nix" n != null ||
pathExists (path + ("/" + n + "/default.nix"))) pathExists (path + ("/" + n + "/default.nix")))
(attrNames (readDir path))) (attrNames (readDir path)));
++ [(import (builtins.fetchTarball {
url = "https://github.com/nix-community/emacs-overlay/archive/refs/heads/master.tar.gz";
sha256 = emacsOverlaySha256;
}))];
}; };
} }

View File

@@ -6,7 +6,6 @@ with pkgs; [
bat bat
docker docker
docker-compose docker-compose
ghostty
gnupg gnupg
iosevka iosevka
jq jq