Compare commits

..

13 commits

25 changed files with 191 additions and 103 deletions

View file

@ -34,9 +34,8 @@
};
})) // {
valhalla = {
"DerGeret Windows" = import ./profiles/DerGeret/config.nix;
"der-geret Arch Linux" = import ./profiles/DerGeret/Arch/config.nix;
"manu-surface Arch Linux" = import ./profiles/ManuSurface/Arch/config.nix;
DerGeret = import ./profiles/machines/manuel/DerGeret/Arch/config.nix;
ManuSurface = import ./profiles/machines/manuel/ManuSurface/Arch/config.nix;
};
};
}

15
lib/eval-attribute.nix Normal file
View file

@ -0,0 +1,15 @@
let
inherit (nixpkgs) lib;
nixpkgs = import <nixpkgs> { config = {}; overlay = []; };
property = (builtins.getEnv "PROPERTY");
processor = if (builtins.stringLength property > 0)
then
(_: lib.attrsets.getAttrFromPath (lib.strings.splitString "." property) _)
else
(_: _);
in
_: processor (lib.evalModules {
modules = [
_
];
}).config

View file

@ -6,7 +6,7 @@ begin
echo "$dir/install.fish"
end
CONFIG_MODULE="$dir/config.nix" \
CONFIG_NAME="DerGeret" \
ARCH_HOSTNAME="der-geret" \
USER_DISPLAYNAME="Manuel Thalmann" \
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish"

View file

@ -1,6 +1,5 @@
#!/bin/pwsh
$env:WIN_COMPUTER_NAME = "DerGeret";
$env:SETUP_SCRIPT_NAME = "$PSScriptRoot/Restore.ps1";
$env:CONFIG_MODULE = "$PSScriptRoot/../config.nix";
$env:CONFIG_NAME = $env:WIN_COMPUTER_NAME;
. "$PSScriptRoot/../../../../../scripts/Windows/OS/Setup.ps1";

View file

@ -1,6 +1,5 @@
#!/bin/pwsh
$env:WIN_COMPUTER_NAME ??= "win11";
$env:SETUP_SCRIPT_NAME ??= "$PSScriptRoot/Install.ps1";
$env:CONFIG_MODULE ??= "$PSScriptRoot/../config.nix";
. "$PSScriptRoot/../../../../../scripts/Windows/OS/Setup.ps1";

View file

@ -1,4 +1,2 @@
#!/bin/pwsh
$env:SETUP_SCRIPT_NAME ??= "$PSScriptRoot/Install.ps1";
. "$PSScriptRoot/../../../../Generic/Windows/Setup.ps1";

View file

@ -11,7 +11,7 @@ begin
echo "$dir/install.fish"
end
CONFIG_MODULE="$(status dirname)/config.nix" \
CONFIG_NAME="ManuSurface" \
ARCH_HOSTNAME="manu-surface" \
USER_DISPLAYNAME="Manuel Thalmann" \
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish";

View file

@ -24,7 +24,7 @@ if [ (id -u) -eq 0 ]
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
end > "$sudoConfig"
and sudo --preserve-env="CONFIG_MODULE" --user "$name" "$INSTALLER_SCRIPT"
and sudo --preserve-env="CONFIG_NAME" --user "$name" "$INSTALLER_SCRIPT"
rm "$sudoConfig"
userdel -r "$name"
else

View file

@ -39,7 +39,7 @@ function runSetup
function wrapScript -S
printf %s\n \
"cd $PROJECT_CLONE_ROOT" \
"export CONFIG_MODULE=$(string escape (getCloneFile "$CONFIG_MODULE"))" \
"export CONFIG_NAME=$(string escape (getCloneFile "$CONFIG_NAME"))" \
"$argv"
end

View file

@ -15,18 +15,10 @@ $null = New-Module {
)
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
$zipFile = [System.IO.Compression.ZipFile]::OpenRead((Get-Package Selenium.WebDriver).Source);
$webDriver = ($zipFile.Entries | Where-Object { $_.FullName -like "lib/net6.0/WebDriver.dll" })[0];
$stream = [System.IO.MemoryStream]::new();
$reader = [System.IO.StreamReader]($webDriver).Open();
$reader.BaseStream.CopyTo($stream);
[byte[]]$bytes = $stream.ToArray();
$reader.Close();
$reader.Dispose();
$stream.Close();
$stream.Dispose();
$zipFile.Dispose();
$null = [System.Reflection.Assembly]::Load($bytes);
$packageRoot = Split-Path -Parent (Get-Package Selenium.WebDriver).Source;
$file = Join-Path $packageRoot "lib/netstandard2.0/WebDriver.dll";
$env:SE_MANAGER_PATH = Join-Path $packageRoot "manager" ($IsWindows ? "windows" : "linux") "selenium-manager$($IsWindows ? ".exe" : '')";
$null = [System.Reflection.Assembly]::LoadFile($file);
}
& $Action;

View file

@ -1,4 +1,5 @@
using namespace Microsoft.Win32;
using namespace System.Management.Automation.Host;
using namespace System.Security.AccessControl;
using namespace System.Security.Principal;
@ -32,6 +33,54 @@ $null = New-Module {
[string] $finishedOption = "Finished";
[RegistryKey] $key = $null;
<#
.SYNOPSIS
Prompts the user to select a profile to act on.
#>
function Show-ProfileNamePrompt {
. "$PSScriptRoot/../../Windows/Types/WindowsInstallerAction.ps1";
$profiles = & {
. "$PSScriptRoot/SoftwareManagement.ps1";
if (Test-Command "wsl") {
return Invoke-ConfigScript "getProfiles";
} else {
return Get-ChildItem "$PSScriptRoot/../../../.config" | ForEach-Object { Split-Path -LeafBase $_ };
}
};
$choice = $Host.UI.PromptForChoice(
"Select Profile",
(& {
switch (Get-Stage) {
([WindowsInstallerAction]::Backup) {
"Which profile do you wish to back up?";
}
([WindowsInstallerAction]::Install) {
"Which profile do you wish to install?";
}
$null {
"Which profile do you wish to set up?";
}
}
}),
(& {
for ($i = 0; $i -lt $profiles.Count; $i++) {
[ChoiceDescription]"&$i - $($profiles[$i])";
}
[ChoiceDescription]"&Abort";
}),
$profiles.Count);
if ($choice -eq $profiles.Count) {
exit;
} else {
$env:CONFIG_NAME = $profiles[$choice];
}
}
<#
.SYNOPSIS
Converts the specified path to linux and escapes it for the use in a script.
@ -115,16 +164,29 @@ $null = New-Module {
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
if ($env:CONFIG_MODULE) {
if ($env:CONFIG_NAME) {
$output = & {
if (-not $IsWindows) {
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
fish -c ". $escapedPath; $Script";
} else {
$cleanup = { };
$projectRoot = "$PSScriptRoot/../../..";
$archisoDir = "$projectRoot/archiso";
function fish {
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
}
if (Test-Path -PathType Container "$archisoDir") {
$git = {
git -C "$projectRoot" -c safe.directory="$("$(Resolve-Path $projectRoot)".Replace("\", "/"))" @args;
};
& $git rm -r --cached "$archisoDir" *> $null;
$cleanup = { & $git restore --staged "$archisoDir" };
}
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
if (-not $?) {
@ -132,6 +194,8 @@ $null = New-Module {
} else {
$output;
}
& $cleanup *> $null;
}
}
@ -443,21 +507,6 @@ $null = New-Module {
Set-SetupOption $finishedOption $true;
}
<#
.SYNOPSIS
Checks whether the specified software collection is enabled.
.PARAMETER Name
The name of the collection to check.
#>
function Test-Collection {
param(
[string] $Name
)
Get-Config "$(Get-ConfigRootName).software.$Name";
}
<#
.SYNOPSIS
Checks whether the running system is a QEMU virtual machine.

View file

@ -52,6 +52,8 @@ $null = New-Module {
$modules[$i] = @($modules[$i]);
}
}
return $modules;
}
function Start-Operation {
@ -78,12 +80,7 @@ $null = New-Module {
$Global:ErrorActionPreference = $NonInteractive.IsPresent ? 'Continue' : 'Inquire';
if ($IsWindows) {
$env:WSLENV = "CONFIG_MODULE/p";
if ($env:CONFIG_MODULE) {
$env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE;
}
$env:WSLENV = "CONFIG_NAME";
New-Alias -Force "sudo" gsudo;
}
@ -148,7 +145,7 @@ $null = New-Module {
Start-Sleep 0.1;
}
foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) {
foreach ($name in @("INSTALLER_SCRIPT")) {
$variable = Get-Item "Env:\$name";
$path = Join-Path `
@ -232,7 +229,7 @@ $null = New-Module {
if (-not (Test-PSPackage Selenium.WebDriver)) {
Write-Host "Installing browser automation tools…";
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies;
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.24.0 -SkipDependencies;
continue;
}
@ -421,7 +418,8 @@ $null = New-Module {
}
foreach ($module in (Get-RequiredModules)) {
Uninstall-Module -Force -Name $module[0];
Remove-Module -Force $module[0];
Uninstall-Module -Force -Name $module[0] -ErrorAction SilentlyContinue;
}
}
};

View file

@ -54,12 +54,18 @@ $null = New-Module {
$null = $Names.Add($Name);
$Names.AddRange($AdditionalNames);
[string[]] $arguments = $ArgumentList + (& {
if ($Action -eq 'install') {
@("--accept-package-agreements")
};
});
foreach ($name in $Names) {
if ($Force.IsPresent -or (& $Guard $name $PSBoundParameters)) {
winget $Action `
--accept-source-agreements `
--source winget `
$ArgumentList `
@arguments `
--exact --id $name ;
} else {
Write-Host "Package ``$name`` is already installed"
@ -137,7 +143,6 @@ $null = New-Module {
)
& $wingetRunner @PSBoundParameters `
-ArgumentList @($PSBoundParameters.ArgumentList + @("--accept-package-agreements")) `
-Guard {
param($Name, $Parameters)
if (Test-WingetPackage @Parameters) {

View file

@ -1,11 +1,16 @@
#!/bin/env fish
function isConfigured -S
set -q "$CONFIG_MODULE"
set -q "$CONFIG_NAME"
end
function getProfiles -S
source "$(status dirname)/eval-flake.fish";
evalFlake "" "" --apply "builtins.attrNames" --json
end
function getConfig -S -a property
source "$(status dirname)/eval-module.fish"
evalModule "$CONFIG_MODULE" "$property" $argv[2..]
source "$(status dirname)/eval-flake.fish"
evalFlake "$CONFIG_NAME" "$property" $argv[2..]
end
function getAttributes -S -a property

View file

@ -0,0 +1,27 @@
#!/bin/env fish
function evalFlake --argument-names config property
set -l argv $argv[3..]
argparse --ignore-unknown "apply=" "json" -- $argv
if [ -z "$_flag_json" ]
set -a argv --raw
else
set -a argv --json
end
if [ -z "$_flag_apply" ]
set _flag_apply "_: _"
end
if [ -n "$config" ]
set config ".$config"
set _flag_apply "_: ($_flag_apply) ((import $(status dirname)/../../../lib/eval-attribute.nix) _)"
end
ROOT="$(realpath (status dirname))/../../.." \
PROPERTY="$property" \
nix eval --impure --extra-experimental-features "nix-command flakes" \
--apply "$_flag_apply" \
"$(status dirname)/../../..#valhalla$config" \
$argv
end

View file

@ -48,10 +48,10 @@ Start-SoftwareInstaller @PSBoundParameters `
}
if ($IsWindows) {
[System.Environment]::SetEnvironmentVariable($varName, $path, "User");
[System.Environment]::SetEnvironmentVariable($varName, "%AppData%/$([System.IO.Path]::GetRelativePath($env:AppData, $path))", "User");
} else {
. "$PSScriptRoot/../aliae/Manage.ps1";
Add-EnvironmentVariable -User $Arguments.Name $varName $path;
Add-EnvironmentVariable -User $Arguments.Name $varName ($path).Replace("~", "{{ .Home }}");
}
}
};

View file

@ -28,20 +28,7 @@ $null = New-Module {
$configArgs = @("--system");
}
<#
.SYNOPSIS
Gets the specified git configuration.
.PARAMETER Name
THe name of the configuration to get.
#>
function Get-GitConfig {
param(
[string] $Name
)
Get-Config "$root.git.$Name";
}
$config = Get-Config "$root.git";
<#
.SYNOPSIS
@ -52,7 +39,7 @@ $null = New-Module {
}
if ((-not $IsWindows) -or $User) {
$branch = Get-GitConfig "defaultBranch";
$branch = $config.defaultBranch;
if ($branch) {
Set-GitConfig "init.defaultBranch" $branch;
@ -76,8 +63,8 @@ $null = New-Module {
. {
$dir = New-TemporaryDirectory;
$key = "flow";
$mainBranch = Get-GitConfig "$key.mainBranch";
$devBranch = Get-GitConfig "$key.devBranch";
$mainBranch = $config."$key".mainBranch;
$devBranch = $config."$key".devBranch;
& {
git -C "$dir" init;
@ -103,7 +90,7 @@ $null = New-Module {
};
# Aliases
[PSCustomObject] $aliases = Get-GitConfig "aliases";
[PSCustomObject] $aliases = $config.aliases;
if ($aliases) {
foreach ($alias in ($aliases | Get-Member -MemberType Properties)) {

View file

@ -26,7 +26,7 @@ begin
"Terminal=false" (
printf "%s " \
"Exec=env" \
"CONFIG_MODULE=$(echo "$CONFIG_MODULE" | string escape)" \
"CONFIG_NAME=$(echo "$CONFIG_NAME" | string escape)" \
"konsole -e fish $(realpath (status filename) | string escape) userConfig"
)
end | sudo -u "$name" tee "$entryPoint" > /dev/null
@ -36,7 +36,7 @@ begin
rm "$entryPoint"
rm ~"$name"/.config/plasma-welcomerc
else if [ -n "$name" ] && [ "$name" != "$USER" ]
sudo -Eu "$name" CONFIG_MODULE="$CONFIG_MODULE" fish "$(status filename)" userConfig
sudo -Eu "$name" CONFIG_NAME="$CONFIG_NAME" fish "$(status filename)" userConfig
else
systemctl --user enable rclone.service
echo "Please complete the setup of your rclone configurations!"

View file

@ -0,0 +1,3 @@
#!/bin/pwsh
. "$PSScriptRoot/Manage.ps1";
Start-WindowsInstallation;

View file

@ -2,16 +2,18 @@
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
function Start-Setup {
param($ConfigurationName)
. "$PSScriptRoot/../../Common/Scripts/Config.ps1";
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
$Global:InformationPreference = "Continue";
$Global:ErrorActionPreference = "Inquire";
$env:CONFIG_NAME ??= $ConfigurationName;
$null = $env:WIN_COMPUTER_NAME;
$null = $env:SETUP_SCRIPT_NAME;
$null = $env:CONFIG_MODULE;
$env:WSLENV = "CONFIG_MODULE/p";
$valhallaConfig = ConvertFrom-Json (Get-Content "$env:CONFIG_MODULE.json");
$null = $env:SETUP_SCRIPT_NAME ??= "$PSScriptRoot/Install.ps1";
$env:WSLENV = "CONFIG_NAME";
Show-ProfileNamePrompt;
$valhallaConfig = ConvertFrom-Json (Get-Content "$PSScriptRoot/../../../.config/$env:CONFIG_NAME.json");
[xml]$unattendedConfig = [xml]::new();
$unattendedConfig.PreserveWhitespace = $true;
@ -233,7 +235,7 @@ function Start-Setup {
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
"`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" +
"`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" +
"`$env:CONFIG_MODULE = $(Get-ScriptPathInjection $env:CONFIG_MODULE);" +
"`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
"& (Join-Path `$env:PWSH_PATH pwsh) `$env:INSTALLER_SCRIPT;") `
-Description "Install PowerShell Core and git and run setup script";
@ -264,4 +266,4 @@ function Start-Setup {
& "$SETUP_DRIVE\setup.exe" /Unattend:$unattendedConfigFile;
}
Start-Setup
Start-Setup @args;

View file

@ -24,13 +24,16 @@ function Deploy-SoftwareAction {
$install = $true;
}
$hardware = Get-Config "valhalla.hardware";
$collections = Get-Config "valhalla.windows.software";
# Drivers
& {
$driverPath = "$PSScriptRoot/../Drivers";
$mbPath = "$driverPath/ROG Zenith Extreme Alpha";
if ($install) {
if (Get-Config "valhalla.hardware.elgatoWave") {
if ($hardware.elgatoWave) {
if (-not (Test-ChocoPackage wavelink)) {
Install-ChocoPackage wavelink -ArgumentList '--install-arguments="/norestart"';
Remove-DesktopIcon "*Wave Link*";
@ -40,7 +43,7 @@ function Deploy-SoftwareAction {
}
}
foreach ($component in (Get-Config "valhalla.hardware.components")) {
foreach ($component in $hardware.components) {
switcH ($component) {
("ROG Zenith Extreme Alpha") {
& "$mbPath/MarvellEthernet/Manage.ps1" @arguments;
@ -56,22 +59,22 @@ function Deploy-SoftwareAction {
}
if ($install) {
if (Get-Config "valhalla.hardware.amdCPU") {
if ($hardware.amdCPU) {
Install-ChocoPackage amd-ryzen-master;
# ToDo: backup Ryzen energy saving plan
}
if (Get-Config "valhalla.hardware.nvidiaGPU") {
if ($hardware.nvidiaGPU) {
Install-ChocoPackage geforce-game-ready-driver;
Remove-DesktopIcon "*Geforce*";
}
if (Get-Config "valhalla.hardware.corsairDevice") {
if ($hardware.corsairDevice) {
Install-ChocoPackage icue;
}
}
if (Get-Config "valhalla.hardware.eyeX") {
if ($hardware.eyeX) {
& "$driverPath/Tobii EyeX/Manage.ps1" @arguments;
}
};
@ -83,12 +86,12 @@ function Deploy-SoftwareAction {
# Windows Config
& "$softwarePath/Windows/Manage.ps1" @arguments;
if (Get-Config "valhalla.hardware.logitechG") {
if ($hardware.logitechG) {
& "$softwarePath/LGHub/Manage.ps1" @arguments;
}
# Essentials
if (Test-Collection "essential") {
if ($collections.essential) {
& "$softwarePath/aliae/Main.ps1" @arguments;
& "$softwarePath/OpenSSH/Manage.ps1" @arguments;
& "$softwarePath/PowerShell/Manage.ps1" @arguments;
@ -115,7 +118,7 @@ function Deploy-SoftwareAction {
}
# Common Software
if (Test-Collection "common") {
if ($collections.common) {
& "$softwarePath/WinSCP/Manage.ps1" @arguments;
& "$softwarePath/Thunderbird/Manage.ps1" @arguments;
& "$softwarePath/PuTTY/Manage.ps1" @arguments;
@ -137,7 +140,7 @@ function Deploy-SoftwareAction {
}
}
if (Test-Collection "desktopExperience") {
if ($collections.desktopExperience) {
if ($install) {
# Fonts
Install-ChocoPackage nerd-fonts-CascadiaCode;
@ -170,7 +173,7 @@ function Deploy-SoftwareAction {
Remove-DesktopIcon "GIMP*";
Remove-DesktopIcon "GPU-Z*";
Remove-DesktopIcon "WinDirStat*";
Remove-DesktopIcon "*HWMonior*";
Remove-DesktopIcon "*HWMonitor*";
Remove-DesktopIcon "ImgBurn*";
Remove-DesktopIcon "InkScape*";
Remove-DesktopIcon "Krita*";
@ -192,12 +195,12 @@ function Deploy-SoftwareAction {
& "$softwarePath/Firefox/Manage.ps1" @arguments;
& "$softwarePath/MSEdgeRedirect/Manage.ps1" @arguments;
if (Test-Collection "fileSync") {
if ($collections.fileSync) {
& "$softwarePath/Nextcloud/Main.ps1" @arguments;
}
}
if (Test-Collection "socialMedia") {
if ($collections.socialMedia) {
if ($install) {
Install-ChocoPackage `
signal `
@ -214,7 +217,7 @@ function Deploy-SoftwareAction {
}
}
if (Test-Collection "media") {
if ($collections.media) {
if ($install) {
Install-ChocoPackage `
k-litecodecpackmega `
@ -230,7 +233,7 @@ function Deploy-SoftwareAction {
}
}
if (Test-Collection "coding") {
if ($collections.coding) {
if ($install) {
& "$softwarePath/vscode/Main.ps1" @arguments;
@ -256,7 +259,7 @@ function Deploy-SoftwareAction {
}
# Gaming
if (Test-Collection "gaming") {
if ($collections.gaming) {
if ($install) {
Install-ChocoPackage `
goggalaxy `

View file

@ -55,7 +55,7 @@ $null = New-Module {
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection (Resolve-Path $env:BACKUP_ARCHIVE));" : "") +
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
"`$env:CONFIG_MODULE = $(ConvertTo-Injection (Resolve-Path $env:CONFIG_MODULE));" +
"`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
"& `$env:INSTALLER_SCRIPT;";
}

View file

@ -54,6 +54,10 @@ function Test-WslDistribution {
#>
function Install-Wsl {
wsl --install --no-launch;
# Microsoft broke WSL - Quelle surprise!
# ToDo: Remove this workaround once it's unbroken
. "$PSScriptRoot/../../Common/Scripts/Software.ps1";
Install-SetupPackage "https://github.com/microsoft/WSL/releases/download/2.3.17/wsl.2.3.17.0.x64.msi" -ArgumentList "/Quiet";
}
<#

View file

@ -209,9 +209,11 @@ begin
begin
source "$dir/../scripts/Common/Scripts/config.fish"
find "$projectPath/profiles" -type f -name "*.nix" | while read -l file
set -l CONFIG_MODULE "$file"
getConfig "valhalla.windows.config" --json > "$file.json"
for name in (getProfiles | jq '.[]' --raw-output0 | string split0)
set -l CONFIG_NAME "$name"
set -l file "$projectPath/.config/$name.json"
mkdir -p (dirname $file)
getConfig "valhalla.windows.config" --json > "$file"
end
end

View file

@ -1,2 +1,3 @@
$env:SETUP_DRIVE = (ConvertFrom-Csv ((wmic volume where "Label='$env:SETUP_LABEL'" get DriveLetter) | ForEach-Object { "$_".Trim(); })).DriveLetter;
Set-Location (Join-Path $env:SETUP_DRIVE $env:LOCAL_PROJECT_PATH)
& ./scripts/Windows/OS/Setup.ps1;