Add NixOS support

This commit is contained in:
2025-03-24 13:24:03 +00:00
parent a7c30f5e34
commit bdd61b9e37
5 changed files with 122 additions and 19 deletions

91
configuration.nix Normal file
View File

@@ -0,0 +1,91 @@
{ config, pkgs, ... }:
{
imports = [ ./hardware-configuration.nix ];
nixpkgs.config.allowUnfree = true;
# Bootloader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
# Enable networking
networking.hostName = "trudepc";
networking.networkmanager.enable = true;
# Select internationalisation properties.
time.timeZone = "Europe/Lisbon";
i18n.defaultLocale = "en_US.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "pt_PT.UTF-8";
LC_IDENTIFICATION = "pt_PT.UTF-8";
LC_MEASUREMENT = "pt_PT.UTF-8";
LC_MONETARY = "pt_PT.UTF-8";
LC_NAME = "pt_PT.UTF-8";
LC_NUMERIC = "pt_PT.UTF-8";
LC_PAPER = "pt_PT.UTF-8";
LC_TELEPHONE = "pt_PT.UTF-8";
LC_TIME = "pt_PT.UTF-8";
};
# Enable the GNOME windowing system.
services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;
services.printing.enable = true; # CUPS
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;
};
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
# Configure keymap in X11
services.xserver.xkb = {
layout = "us";
variant = "altgr-intl";
};
# Define a user account. Don't forget to set a password with passwd.
users.users.trude = {
isNormalUser = true;
description = "TrudeEH";
extraGroups = [ "networkmanager" "wheel" ];
packages = with pkgs; [ # GUI and user apps
vscode brave discord prismlauncher
];
};
# System packages
environment.systemPackages = with pkgs; [
git curl wget pass lynis bat
neovim tmux htop fzf
];
programs.gnupg.agent.enable = true;
programs.steam = {
enable = true;
remotePlay.openFirewall = true;
dedicatedServer.openFirewall = true;
};
# Firewall
networking.firewall.allowedTCPPorts = [ 22 ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Allow running executables.
programs.nix-ld = {
enable = true;
libraries = with pkgs; [
# Add any missing dynamic libraries for unpacked programs here.
];
};
system.stateVersion = "24.11"; # Don't change this value.
}

View File

@@ -37,6 +37,7 @@ resize-with-right-button=true
[org/gnome/mutter] [org/gnome/mutter]
edge-tiling=true edge-tiling=true
dynamic-workspaces=true
[org/gnome/shell] [org/gnome/shell]
disabled-extensions=['tiling-assistant@ubuntu.com', 'ubuntu-dock@ubuntu.com', 'ding@rastersoft.com'] disabled-extensions=['tiling-assistant@ubuntu.com', 'ubuntu-dock@ubuntu.com', 'ding@rastersoft.com']
@@ -103,3 +104,6 @@ play-sound=true
[org/gnome/TextEditor] [org/gnome/TextEditor]
highlight-current-line=true highlight-current-line=true
show-map=true show-map=true
[org/gnome/desktop/sound]
event-sounds=true

View File

@@ -84,13 +84,6 @@ alias cat="bat"
set completion-ignore-case On set completion-ignore-case On
# bash-completion
if [[ "$OSTYPE" != "darwin"* ]] && [ ! -f /usr/share/bash-completion/bash_completion ]; then
p i bash-completion
fi
. /usr/share/bash-completion/bash_completion
export OFLAGS="--ozone-platform-hint=auto" export OFLAGS="--ozone-platform-hint=auto"
export PATH=$PATH:$HOME/.local/bin export PATH=$PATH:$HOME/.local/bin

View File

@@ -37,15 +37,13 @@ install_gnome_extension() {
fi fi
} }
mkdir -p "$HOME/dotfiles/logs"
# Clone Dotfiles if not already present # Clone Dotfiles if not already present
cd "$HOME/dotfiles" cd "$HOME/dotfiles"
if [ "$(pwd)" != "$HOME/dotfiles" ]; then if [ "$(pwd)" != "$HOME/dotfiles" ]; then
printf "${YELLOW}Cloning dotfiles repository...${NC}\n" printf "${YELLOW}Cloning dotfiles repository...${NC}\n"
git clone https://github.com/TrudeEH/dotfiles --depth 1 git clone https://github.com/TrudeEH/dotfiles --depth 1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
printf "${RED}Error cloning dotfiles repository. Exiting...${NC}\n" printf "${RED}Error cloning dotfiles repository. Is git installed? Exiting...${NC}\n"
exit 2 exit 2
fi fi
cd dotfiles || exit cd dotfiles || exit
@@ -62,6 +60,18 @@ fi
source ./scripts/p.sh source ./scripts/p.sh
# NixOS
if grep -qi "nixos" /etc/os-release; then
printf "${CYAN}NixOS detected.${NC}\n"
nixos=true
sudo cp -f /etc/nixos/configuration.nix /etc/nixos/configuration.nix.bak
sudo cp -f configuration.nix /etc/nixos/configuration.nix
sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos
p
fi
mkdir -p "$HOME/dotfiles/logs"
printf "${CYAN}\n" printf "${CYAN}\n"
printf "####################\n" printf "####################\n"
printf "#" printf "#"
@@ -73,14 +83,16 @@ printf "${CYAN}Desktop: ${PURPLE}%s${NC}\n" "$XDG_CURRENT_DESKTOP"
printf "\n" printf "\n"
# Install Programs # Install Programs
programs=(neovim curl git tmux htop fzf gcc make tldr pass lynis bat) if [ -z "$nixos" ]; then
programs=(neovim curl git tmux htop fzf gcc make tldr pass lynis bat)
if [[ "$OSTYPE" != "darwin"* ]]; then if [[ "$OSTYPE" != "darwin"* ]]; then
programs+=(ufw s-tui) programs+=(ufw s-tui)
fi
p i "${programs[@]}"
fi fi
p i "${programs[@]}"
# Copy files # Copy files
printf "${YELLOW}Installing Dotfiles...${NC}\n" printf "${YELLOW}Installing Dotfiles...${NC}\n"
cp -r "$HOME/dotfiles/home/." "$HOME" cp -r "$HOME/dotfiles/home/." "$HOME"
@@ -121,7 +133,7 @@ else
fi fi
# UFW Firewall # UFW Firewall
if [[ "$OSTYPE" != "darwin"* ]]; then if [ -z "$nixos" ] && [[ "$OSTYPE" != "darwin"* ]]; then
printf "${YELLOW}Setting up UFW...${NC}\n" printf "${YELLOW}Setting up UFW...${NC}\n"
sudo ufw default deny incoming sudo ufw default deny incoming
sudo ufw default allow outgoing sudo ufw default allow outgoing
@@ -137,7 +149,7 @@ if [[ "$OSTYPE" != "darwin"* ]]; then
else else
printf "${GREEN}UFW setup successfully.${NC}\n" printf "${GREEN}UFW setup successfully.${NC}\n"
fi fi
else elif [[ "$OSTYPE" == "darwin"* ]]; then
printf "${YELLOW}Enabling macOS Firewall...${NC}\n" printf "${YELLOW}Enabling macOS Firewall...${NC}\n"
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then

View File

@@ -52,10 +52,13 @@ p() (
if [[ ${packageManagers[@]} =~ "nix" ]]; then if [[ ${packageManagers[@]} =~ "nix" ]]; then
printf "%b\n" "${YELLOW}Updating nix...${ENDCOLOR}" printf "%b\n" "${YELLOW}Updating nix...${ENDCOLOR}"
nix-channel --update nix-channel --update
nix-collect-garbage --delete-older-than 7d nix-collect-garbage --delete-older-than 7d &>/dev/null
if command -v nixos-rebuild >/dev/null 2>&1; then if command -v nixos-rebuild >/dev/null 2>&1; then
sudo nix-channel --update sudo nix-channel --update
sudo nixos-rebuild switch printf "${YELLOW}Rebuilding NixOS...${NC}\n"
sudo nixos-rebuild switch &>/tmp/nixos_rebuild.log || (
cat /tmp/nixos_rebuild.log | grep --color error && false
)
fi fi
fi fi
if [[ ${packageManagers[@]} =~ "brew" ]]; then if [[ ${packageManagers[@]} =~ "brew" ]]; then