From cb85be417cfda79f107865de414be2d9d55c92a1 Mon Sep 17 00:00:00 2001 From: gabrielkheisa Date: Wed, 13 Nov 2024 21:50:35 +0700 Subject: [PATCH] first --- flake.nix | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 34 ++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 flake.nix create mode 100644 setup.sh diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..143e869 --- /dev/null +++ b/flake.nix @@ -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"; + } + ]; + }; + }; +} diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..86cf841 --- /dev/null +++ b/setup.sh @@ -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 '' -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."