From c0f162b4eaebce63ee08ffbe3c2106423c9ddfe7 Mon Sep 17 00:00:00 2001 From: foglar Date: Sat, 4 Jan 2025 10:26:17 +0100 Subject: [PATCH] Install script initialization --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 43 +++++++++++++++++++++++++++++++++++++++++++ install.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 install.sh diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6f88465 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1735834308, + "narHash": "sha256-dklw3AXr3OGO4/XT1Tu3Xz9n/we8GctZZ75ZWVqAVhk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6df24922a1400241dae323af55f30e4318a6ca65", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..46b85ef --- /dev/null +++ b/flake.nix @@ -0,0 +1,43 @@ +{ + description = "Install script flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = {self, ...} @ inputs: let + # Systems that can run the install script: + supportedSystems = ["aarch64-linux" "i686-linux" "x86_64-linux"]; + + # Function to generate a set based on supported systems: + forAllSystems = inputs.nixpkgs.lib.genAttrs supportedSystems; + + # Attribute set of nixpkgs for each system: + nixpkgsFor = + forAllSystems (system: import inputs.nixpkgs {inherit system;}); + in { + # Install script + packages = forAllSystems (system: let + pkgs = nixpkgsFor.${system}; + in { + default = self.packages.${system}.install; + + install = pkgs.writeShellApplication { + name = "install"; + runtimeInputs = with pkgs; [git busybox gum]; + text = '' + ${./install.sh} "$@" + ''; + }; + }); + + apps = forAllSystems (system: { + default = self.apps.${system}.install; + + install = { + type = "app"; + program = "${self.packages.${system}.install}/bin/install"; + }; + }); + }; +} diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..848a581 --- /dev/null +++ b/install.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +if [ $# -gt 0 ]; then + SCRIPT_DIR=$1 +else + SCRIPT_DIR=~/.dotfiles +fi + +if [ -d $SCRIPT_DIR ]; then + gum confirm "The directory $SCRIPT_DIR already exists. Do you want to delete it?" && yes | rm -rv $SCRIPT_DIR +fi + +nixos_profile=$(gum choose kogami ginoza) +download_wallpapers=$(gum confirm "Do you want to download wallpapers (it may take longer)?" && echo true || echo false) + +if [ -d $SCRIPT_DIR ]; then + gum log --structured --level warn "The directory $SCRIPT_DIR already exists. Downloading updates..." + cd $SCRIPT_DIR && git pull +else + nix-shell -p git --command "git clone https://git.foglar.tech/foglar/dotfiles.git $SCRIPT_DIR" +fi + +sudo nixos-generate-config --show-hardware-config >$SCRIPT_DIR/kogami/hardware-configuration.nix +gum log --structured --level info "Creating hardware configuration..." file $SCRIPT_DIR/kogami/hardware-configuration.nix +sudo nixos-generate-config --show-hardware-config >$SCRIPT_DIR/ginoza/hardware-configuration.nix +gum log --structured --level info "Creating hardware configuration..." file $SCRIPT_DIR/kogami/hardware-configuration.nix + +# Username +sed -i "0,/shinya/s//$(whoami)/" $SCRIPT_DIR/flake.nix +gum log --structured --level info "Setting user name in flake.nix..." file $SCRIPT_DIR/flake.nix +# Set hostname by selected profile +sed -i "0,/kogami/s//$profile/" $SCRIPT_DIR/flake.nix +gum log --structured --level info "Setting hostname in flake.nix..." file $SCRIPT_DIR/flake.nix +# Set dotfiles path as $SCRIPT_DIR path +#! IMPORTANT + +# Editor +if [ -z $EDITOR ]; then + EDITOR=nano +fi +gum log --structured --level info "Opening flake.nix in $EDITOR..." file $SCRIPT_DIR/flake.nix +$EDITOR $SCRIPT_DIR/flake.nix + +gum log --structured --level info "Building configuration for $profile..." profile $profile +sudo nixos-rebuild build --flake $SCRIPT_DIR#"${profile}" + +# Wallpapers +if [ $download_wallpapers = true ]; then + gum log --structured --level info "Downloading wallpapers..." profile $profile + nix-shell -p git --command "git clone https://git.foglar.tech/foglar/wallpapers.git ~/Pictures/wallpapers" +fi + +gum confirm "Do you want to reboot now?" && systemctl reboot || gum log --structured --level info "Please reboot later, to switch to the new configuration"