Compare commits

...

15 commits

23 changed files with 217 additions and 134 deletions

View file

@ -6,7 +6,7 @@
flake-utils.url = "github:numtide/flake-utils?ref=b1d9ab70662946ef0850d488da1c9019f3a9752a";
};
outputs = { self, flake-utils, nixpkgs }: flake-utils.lib.eachDefaultSystem (
outputs = { self, flake-utils, nixpkgs }: (flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
@ -32,5 +32,11 @@
packages = {
archiso = pkgs.archiso;
};
});
})) // {
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;
};
};
}

View file

@ -109,25 +109,33 @@ $null = New-Module {
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
if (-not $IsWindows) {
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
fish -c ". $escapedPath; $Script";
} else {
function fish {
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
}
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
if (-not $?) {
Write-Error "The configuration could not be retrieved!";
} else {
if (-not ($output | Test-Json)) {
Write-Error "The value ``$output`` is not valid JSON.";
if ($env:CONFIG_MODULE) {
$output = & {
if (-not $IsWindows) {
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
fish -c ". $escapedPath; $Script";
} else {
$output | ConvertFrom-Json;
function fish {
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
}
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
if (-not $?) {
Write-Error "The configuration could not be retrieved!";
} else {
$output;
}
}
}
if (-not ($output | Test-Json)) {
Write-Error "The value ``$output`` is not valid JSON.";
} else {
$output | ConvertFrom-Json;
}
} else {
$null;
}
}
@ -148,6 +156,14 @@ $null = New-Module {
Invoke-ConfigScript "getConfig $Name --json $ArgumentList";
}
<#
.SYNOPSIS
Gets the name of the config root.
#>
function Get-ConfigRootName {
return "valhalla$($IsWindows ? ".windows" : '')";
}
<#
.SYNOPSIS
Gets a user configuration.
@ -160,13 +176,13 @@ $null = New-Module {
#>
function Get-UserConfig {
param(
[string] $UserName = $env:UserName,
[string] $UserName = ($IsWindows ? $env:UserName : $env:USER),
[Parameter(Mandatory, Position = 0)]
[string] $Name
)
if ((Get-Users) -contains $UserName) {
Get-Config "valhalla.windows.users.$UserName.$Name";
Get-Config "$(Get-ConfigRootName).users.$UserName.$Name";
} else {
return $null;
}
@ -194,7 +210,7 @@ $null = New-Module {
function Get-Users {
[OutputType([string[]])]
param()
Get-Attributes "valhalla.windows.users";
Get-Attributes "$(Get-ConfigRootName).users";
}
<#
@ -204,7 +220,7 @@ $null = New-Module {
function Get-SetupUser {
[OutputType([string])]
param()
Get-Config "valhalla.windows.setupUser";
Get-Config "$(Get-ConfigRootName).setupUser";
}
<#
@ -408,7 +424,7 @@ $null = New-Module {
Checks whether the current user is the setup user.
#>
function Test-SetupUser {
$env:UserName -eq (Get-Config "valhalla.windows.setupUser");
($IsWindows ? $env:UserName : $env:USER) -eq (Get-SetupUser);
}
<#

View file

@ -91,7 +91,10 @@ $null = New-Module {
#>
function Disable-OneShotListener {
Unregister-ScheduledTask -Confirm:$false $oneShotTaskName;
Remove-LocalUser (& $getUserName);
$user = Get-LocalUser (& $getUserName);
[string] $sid = $user.SID;
Remove-LocalUser $user;
Get-CimInstance Win32_UserProfile | Where-Object { $_.SID -eq $sid } | Remove-CimInstance;
}
<#
@ -141,7 +144,10 @@ $null = New-Module {
if (Test-Path $errorPath) {
$errorMessage = Get-Content $errorPath;
Remove-Item $errorPath;
Write-Error $errorMessage;
if ($errorMessage) {
Write-Error $errorMessage;
}
}
}

View file

@ -241,20 +241,21 @@ $null = New-Module {
Write-Host "Installing $Name";
& $Installer @argumentList;
}
& $installHandler @argumentList -Action ([InstallerAction]::Configure);
if (-not (Test-SetupUser)) {
& $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser);
}
# ToDo: Automatically configure after installation
} elseif ($Action -eq ([InstallerAction]::Configure)) {
if ($Configurator) {
Write-Host "Configuring $Name";
& $Configurator @argumentList;
}
if (-not (Test-SetupUser)) {
$argumentList.Add("action", [InstallerAction]::ConfigureUser);
& $installHandler @argumentList;
}
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) {
if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) {
$Arguments.Add($userArgument, ($env:UserName));
$Arguments.Add($userArgument, ($IsWindows ? $env:UserName : $env:USER));
}
if ($UserConfigurator) {

View file

@ -8,13 +8,6 @@ param (
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
Add-PowerShellProfileStatement `
-System `

View file

@ -8,13 +8,6 @@ param (
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
[string] $globalDir = $null;
$indicator = "# Profile Files";

View file

@ -8,11 +8,18 @@ $null = New-Module {
.PARAMETER Name
The name of the module to install.
.PARAMETER NativeOnly
A value indicating whether the module is installed in Windows PowerShell only.
.PARAMETER NoProfile
A value indicating whether the module is not added to the profile script of users.
#>
function Get-ModuleInstallerComponents {
param(
[string] $Name,
[switch] $NativeOnly
[switch] $NativeOnly,
[switch] $NoProfile
)
@{
@ -46,12 +53,14 @@ $null = New-Module {
[hashtable] $Arguments
)
$name = $Arguments.Name;
if (-not $NoProfile) {
$name = $Arguments.Name;
Add-PowerShellProfileStatement `
-DefaultUser `
-Category $name `
-Script "Import-Module `"$name`";";
Add-PowerShellProfileStatement `
-DefaultUser `
-Category $name `
-Script "Import-Module `"$name`";";
}
};
}
}

View file

@ -4,15 +4,123 @@ param (
)
. "$PSScriptRoot/../../Scripts/Software.ps1";
. "$PSScriptRoot/../../Scripts/System.ps1";
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
$null = New-Module {
param(
[hashtable] $Parameters
)
$configure = {
param(
[scriptblock] $Installer
[string] $User
)
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
$root = "valhalla";
if ($User) {
$root = "$root$($IsWindows ? ".windows" : '').users.$User";
$sudoArgs = @("-u", $User);
$configArgs = @("--global");
} else {
$sudoArgs = @();
$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";
}
<#
.SYNOPSIS
Sets a configuration option in git.
#>
function Set-GitConfig {
sudo @sudoArgs git config @configArgs $args;
}
if ((-not $IsWindows) -or $User) {
$branch = Get-GitConfig "defaultBranch";
if ($branch) {
Set-GitConfig "init.defaultBranch" $branch;
}
}
if ($User) {
$displayName = Get-UserConfig "displayName";
$mailAddress = Get-UserConfig "mailAddress";
if ($displayName) {
Set-GitConfig "user.name" $displayName;
}
if ($mailAddress) {
Set-GitConfig "user.email" $mailAddress;
}
}
# Git Flow
. {
$dir = New-TemporaryDirectory;
$key = "flow";
$mainBranch = Get-GitConfig "$key.mainBranch";
$devBranch = Get-GitConfig "$key.devBranch";
& {
git -C "$dir" init;
git -C "$dir" config user.name "PortValhalla";
git -C "$dir" config user.email "no-reply@valhal.la";
git -C "$dir" commit --allow-empty -m "Initial commit";
git -C "$dir" branch master;
git -C "$dir" branch dev;
git -C "$dir" flow init --defaults;
} | Out-Null;
if ($mainBranch) {
git -C "$dir" branch $mainBranch | Out-Null;;
sudo @sudoArgs git -C "$dir" flow config set @configArgs master $mainBranch;
}
if ($devBranch) {
git -C "$dir" branch $devBranch | Out-Null;
sudo @sudoArgs git -C "$dir" flow config set @configArgs develop $devBranch;
}
Remove-Item -Recurse -Force $dir;
};
# Aliases
[PSCustomObject] $aliases = Get-GitConfig "aliases";
if ($aliases) {
foreach ($alias in ($aliases | Get-Member -MemberType Properties)) {
Set-GitConfig "alias.$($alias.Name)" $aliases.$($alias.Name);
}
}
};
Start-SoftwareInstaller @Parameters `
-Configurator {
& $configure @PSBoundParameters;
} `
-UserConfigurator {
param(
[hashtable] $Arguments
)
& $configure -User $Arguments.Name;
};
} $PSBoundParameters;

View file

@ -1,3 +1,4 @@
enum OneShotTask {
InitializeMSAccount
DisableUAC
}

View file

@ -134,16 +134,16 @@ $null = New-Module {
}
}
if (-not (Test-Command "git")) {
Install-ChocoPackage git;
refreshenv;
continue;
}
if (-not (Test-Winget)) {
. "$PSScriptRoot/../Software/winget/Manage.ps1";
continue;
}
if (-not (Test-Command "git")) {
Install-WingetPackage Git.Git;
refreshenv;
continue;
}
if (-not (& { $null = wsl --status; $?; })) {
wsl --install --no-launch;
@ -594,12 +594,18 @@ $null = New-Module {
}
}
(([UserStage]::Configure)) {
$adminGroup = @{
SID = [SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null);
}
Deploy-SoftwareAction -Action ([InstallerAction]::ConfigureUser);
Remove-LocalGroupMember -Member "$user" @adminGroup -ErrorAction SilentlyContinue;
Remove-LocalGroupMember -Member "$name" @adminGroup -ErrorAction SilentlyContinue;
foreach ($group in Get-UserConfig "groups") {
Add-LocalGroupMember -Member "$user" -Name "$group";
Add-LocalGroupMember -Member "$name" -Name "$group";
}
Set-UserStage ([UserStage]::Completed);
}
}
}

View file

@ -13,7 +13,6 @@ Start-SoftwareInstaller @PSBoundParameters `
)
Install-ChocoPackage firefox;
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator {
Write-Host "Making Firefox the default browser…";

View file

@ -12,7 +12,6 @@ Start-SoftwareInstaller @PSBoundParameters `
)
Install-ChocoPackage MSEdgeRedirect;
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
$configPath = "HKLM:\SOFTWARE\Robert Maehl Software\MSEdgeRedirect";

View file

@ -22,7 +22,6 @@ Start-SoftwareInstaller @PSBoundParameters `
refreshenv;
Set-UserPermissions $env:NVS_HOME;
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
nvs add latest;

View file

@ -13,7 +13,6 @@ Start-SoftwareInstaller @PSBoundParameters `
)
Install-WingetPackage JanDeDobbeleer.OhMyPosh -ArgumentList "--scope","machine";
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
. "$PSScriptRoot/../../../Common/Software/Oh My Posh/Manage.ps1" `

View file

@ -8,13 +8,6 @@ param(
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator {
Set-Service ssh-agent -StartupType AutomaticDelayedStart;
};

View file

@ -6,7 +6,7 @@ param (
. "$PSScriptRoot/../../../Common/Software/PowerShell/Module.ps1";
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
$parameters = Get-ModuleInstallerComponents "PinnedItem" -NativeOnly;
$parameters = Get-ModuleInstallerComponents "PinnedItem" -NativeOnly -NoProfile;
foreach ($key in $PSBoundParameters.Keys) {
$parameters.Add($key, $PSBoundParameters.TryGetValue($key));

View file

@ -7,13 +7,6 @@ param (
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
. "$PSScriptRoot/../../../Common/Software/PowerShell/Manage.ps1" `
-Action ([InstallerAction]::Configure);

View file

@ -15,7 +15,6 @@ Start-SoftwareInstaller @PSBoundParameters `
)
Install-ChocoPackage thunderbird -ArgumentList "--params",'"/NoTaskbarShortcut /NoDesktopShortcut"'
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator {
Write-Host "Making Thunderbird the default mail program…";

View file

@ -16,7 +16,6 @@ Start-SoftwareInstaller @PSBoundParameters `
)
Install-ChocoPackage winscp;
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator {
Remove-DesktopIcon "WinSCP*";

View file

@ -12,13 +12,6 @@ param(
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator {
$dir = New-TemporaryDirectory;
Push-Location $dir;

View file

@ -8,13 +8,6 @@ param(
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
param(
[scriptblock] $Installer
)
& $Installer -Action ([InstallerAction]::Configure)
} `
-Configurator {
[string] $backup = $null;
$nativeProfile = powershell -c '$PROFILE';

View file

@ -7,38 +7,13 @@ param (
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Scripts/Config.ps1";
$null = New-Module {
& {
param(
[hashtable] $Parameters
)
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
<#
.SYNOPSIS
Gets a configuration value related to git.
.PARAMETER Name
The name of the configuration to get.
.PARAMETER User
The name of the user to get the configuration for.
#>
function Get-GitOption {
param(
[Parameter(Mandatory)]
[string] $Name,
[string] $User
)
$config = "git.$Name";
if ($User) {
Get-UserConfig -UserName $User -Name $config;
} else {
Get-Config $config;
}
}
$base = "$PSScriptRoot/../../../Common/Software/git/Manage.ps1";
Start-SoftwareInstaller @Parameters `
-Installer {
@ -47,18 +22,22 @@ $null = New-Module {
)
$params = "/WindowsTerminalProfile";
$defaultBranch = Get-GitOption "defaultBranch";
$defaultBranch = Get-Config "valhalla.git.defaultBranch";
if ($defaultBranch) {
$params += " /DefaultBranchName:`"$defaultBranch`"";
}
Install-ChocoPackage git -ArgumentList "--params",$params;
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
& "$PSScriptRoot/../../../Common/Software/git/Manage.ps1" @Parameters;
};
& $base ([InstallerAction]::Configure);
} `
-UserConfigurator {
param(
$Arguments
)
Export-ModuleMember -Function @();
} -ArgumentList $PSBoundParameters
& $base ([InstallerAction]::ConfigureUser) @PSBoundParameterrs;
};
} $PSBoundParameters;

View file

@ -14,7 +14,6 @@ Start-SoftwareInstaller @PSBoundParameters `
Install-ChocoPackage zoxide;
Install-WingetPackage junegunn.fzf;
& $Installer -Action ([InstallerAction]::Configure);
} `
-Configurator {
Add-PowerShellProfileStatement `