This commit is contained in:
gabrielkheisa 2024-11-13 21:50:35 +07:00
commit cb85be417c
2 changed files with 101 additions and 0 deletions

67
flake.nix Normal file
View File

@ -0,0 +1,67 @@
# flake.nix
{
description = "Portable Ubuntu setup with XFCE, XRDP, and swap";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
home-manager.url = "github:nix-community/home-manager";
};
outputs = { self, nixpkgs, home-manager }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
in {
# Define the dev shell environment with XFCE, XRDP, and utilities
devShell.${system} = pkgs.mkShell {
buildInputs = [
pkgs.xfce
pkgs.xfce.xfce4-terminal
pkgs.xrdp
];
};
# Configuration for Home Manager, setting up XFCE and XRDP
homeConfigurations.gabriel = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs { inherit system; };
home.username = "gabriel";
home.homeDirectory = "/home/gabriel";
programs.bash.enable = true;
programs.xfce.enable = true;
services.xrdp.enable = true;
};
# System-level configuration for creating swap, user, etc.
systemConfigurations.ubuntuSetup = pkgs.lib.mkDefault {
users.users.gabriel = {
isNormalUser = true;
shell = pkgs.bashInteractive;
password = "hashedPassword"; # You can replace this with a more secure password handling mechanism
};
# Create a 2GB swap file
systemd.services.swapfile = {
enable = true;
serviceConfig.ExecStart = ''
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
'';
wantedBy = [ "multi-user.target" ];
};
# Set up the swap entry in /etc/fstab
system.fstab = [
{
device = "/swapfile";
mountPoint = "none";
fsType = "swap";
options = "sw";
}
];
};
};
}

34
setup.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Step 1: Generate a random 8-character alphanumeric password
PASSWORD=$(openssl rand -base64 6 | tr -dc 'A-Za-z0-9' | head -c 8)
# Step 2: Write the password to password.txt
echo "$PASSWORD" > password.txt
echo "Password saved to password.txt."
# Step 3: Echo the password to the terminal
echo "The generated password is: $PASSWORD"
# Step 4: Install Nix
echo "Installing Nix package manager..."
curl -L https://nixos.org/nix/install | sh
. ~/.nix-profile/etc/profile.d/nix.sh
# Step 5: Enable Flakes
echo "Enabling Flakes in Nix configuration..."
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" | tee -a ~/.config/nix/nix.conf
# Step 6: Install Home Manager
echo "Installing Home Manager..."
nix-channel --add https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
# Step 7: Run the Nix Flake to install and configure XFCE, XRDP, etc.
echo "Setting up environment with Nix Flake and Home Manager..."
nix develop
home-manager switch --flake .#gabriel
echo "Setup complete! XFCE, XRDP, and environment configurations applied."