Install script initialization
This commit is contained in:
parent
3c878c6edd
commit
c0f162b4ea
27
flake.lock
Normal file
27
flake.lock
Normal file
@ -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
|
||||||
|
}
|
||||||
43
flake.nix
Normal file
43
flake.nix
Normal file
@ -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";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
53
install.sh
Executable file
53
install.sh
Executable file
@ -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"
|
||||||
Loading…
Reference in New Issue
Block a user