Compare commits

...

16 commits

23 changed files with 354 additions and 94 deletions

View file

@ -0,0 +1,44 @@
{ lib, ... }:
let
inherit (lib)
mkEnableOption
mkOption
types
;
syncType = types.submodule (
{ ... }: {
options = {
remotePath = mkOption {
type = types.str;
description = "The path to the folder on the cloud to sync.";
};
localPath = mkOption {
type = types.str;
description = "The path to sync the cloud content to.";
};
virtualFiles = (mkEnableOption "virtual file support") // {
default = true;
};
};
});
in {
options = {
valhalla.windows.users = mkOption {
type = types.attrsOf (types.submodule (
{ ... }: {
options = {
nextcloud = {
folderSyncs = mkOption {
type = types.listOf syncType;
description = "The folders to synchronize.";
default = [];
};
};
};
}));
};
};
}

View file

@ -1,11 +1,10 @@
{ config, lib, ... }: { lib, ... }:
let let
inherit (lib) inherit (lib)
mkOption mkOption
types types
; ;
cfg = config.valhalla;
capitalize = (import ../text.nix { inherit lib; }).capitalize; capitalize = (import ../text.nix { inherit lib; }).capitalize;
userType = types.submodule ( userType = types.submodule (
@ -65,18 +64,30 @@
type = types.attrsOf linuxUserType; type = types.attrsOf linuxUserType;
}; };
windows.users = mkOption { windows = mkOption {
type = types.attrsOf winUserType; type = types.submoduleWith {
modules = [
({ config, options, ... }: {
options = {
users = mkOption {
type = types.attrsOf winUserType;
};
winUsers = mkOption {
type = options.users.type;
description = "Blablabla";
default = (lib.attrsets.concatMapAttrs (
name: options: {
${capitalize name} = options // {
groups = [];
};
}) config.users);
};
};
})
];
};
}; };
}; };
}; };
config = {
valhalla.windows.users = lib.mkForce (lib.attrsets.concatMapAttrs (
name: options: {
${capitalize name} = options // {
groups = [];
};
}) cfg.users);
};
} }

View file

@ -7,6 +7,7 @@
in { in {
imports = [ imports = [
./packages/git.nix ./packages/git.nix
./packages/nextcloud.nix
./packages/oh-my-posh.nix ./packages/oh-my-posh.nix
./packages/rclone.nix ./packages/rclone.nix
./hardware.nix ./hardware.nix

View file

@ -11,7 +11,7 @@
linuxPercentage = 30; linuxPercentage = 30;
}; };
users.Manuel = { users.manuel = {
microsoftAccount = true; microsoftAccount = true;
groups = ["Administrators"]; groups = ["Administrators"];
}; };

View file

@ -63,6 +63,26 @@
}; };
}; };
windows.users.manuel = {
nextcloud = {
folderSyncs =
let
localPath = "C:/tools/RetroArch-Win64";
remotePath = "/Saved Games/RetroArch";
in [
{
remotePath = "${remotePath}/Saves";
localPath = "${localPath}/saves";
virtualFiles = false;
}
{
remotePath = "${remotePath}/System";
localPath = "${localPath}/system";
}
];
};
};
timeZone = "Europe/Zurich"; timeZone = "Europe/Zurich";
keyMap = "de_CH-latin1"; keyMap = "de_CH-latin1";
keyboardLayout = "ch"; keyboardLayout = "ch";

View file

@ -164,6 +164,14 @@ $null = New-Module {
return "valhalla.$($IsWindows ? "windows" : "linux")"; return "valhalla.$($IsWindows ? "windows" : "linux")";
} }
<#
.SYNOPSIS
Gets the name of the user root.
#>
function Get-UserRootName {
return "$(Get-ConfigRootName).$($IsWindows ? "winUsers" : "users")";
};
<# <#
.SYNOPSIS .SYNOPSIS
Gets a user configuration. Gets a user configuration.
@ -182,7 +190,7 @@ $null = New-Module {
) )
if ((Get-Users) -contains $UserName) { if ((Get-Users) -contains $UserName) {
Get-Config "$(Get-ConfigRootName).users.$UserName.$Name"; Get-Config "$(Get-UserRootName).$UserName.$Name";
} else { } else {
return $null; return $null;
} }
@ -210,7 +218,7 @@ $null = New-Module {
function Get-Users { function Get-Users {
[OutputType([string[]])] [OutputType([string[]])]
param() param()
Get-Attributes "$(Get-ConfigRootName).users"; Get-Attributes "$(Get-UserRootName)";
} }
<# <#

View file

@ -244,7 +244,7 @@ $null = New-Module {
& $installHandler @argumentList -Action ([InstallerAction]::Configure); & $installHandler @argumentList -Action ([InstallerAction]::Configure);
if (-not (Test-SetupUser)) { if ($UserConfigurator -and (-not (Test-SetupUser))) {
& $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser); & $installHandler @argumentList -Action ([InstallerAction]::ConfigureUser);
} }
# ToDo: Automatically configure after installation # ToDo: Automatically configure after installation

View file

@ -30,6 +30,27 @@ function Remove-DesktopIcon {
} }
} }
<#
.SYNOPSIS
Adds a new shortcut to the start menu.
.PARAMETER Name
The name of the icon to create.
.PARAMETER Target
The file to link to.
#>
function Add-StartMenuIcon {
param(
[string] $Name,
[string] $Target
)
Import-Module KnownFolders;
Import-Module "$env:ChocolateyInstall/helpers/chocolateyInstaller.psm1";
Install-ChocolateyShortcut -ShortcutFilePath "$((Get-KnownFolder "Common Programs").Path)/$Name.lnk" -TargetPath ((Get-Item $Target).FullName);
}
<# <#
.SYNOPSIS .SYNOPSIS
Removes icons from the task bar. Removes icons from the task bar.

View file

@ -34,7 +34,7 @@ Start-SoftwareInstaller @PSBoundParameters `
$root = "$($IsWindows ? $env:AppData : "~/.config")/oh-my-posh"; $root = "$($IsWindows ? $env:AppData : "~/.config")/oh-my-posh";
$path = Join-Path $root "$($theme.name).omp.json"; $path = Join-Path $root "$($theme.name).omp.json";
$null = New-Item -Force -ItemType Directory $root; $null = New-Item -Force -ItemType Directory $root;
Copy-Item $theme.source $path; Set-Content $path (wsl cat $theme.source);
$theme = [string] $path; $theme = [string] $path;
} }

View file

@ -26,7 +26,7 @@ $null = New-Module {
Name = "$Name"; Name = "$Name";
Value = "$Value"; Value = "$Value";
} ` } `
".alias |= . + [{ name: env.Name, value: env.Value }]" ` ".alias |= [((. // [])[] | select(.name != env.Name))] + [{ name: env.Name, value: env.Value }]" `
-User $User; -User $User;
} }
@ -52,7 +52,7 @@ $null = New-Module {
Name = "$Name"; Name = "$Name";
Value = "$Value"; Value = "$Value";
} ` } `
".env |= . + [{ name: env.Name, value: env.Value }]" ` ".env |= [((. // [])[] | select(.name != env.Name))] + [{ name: env.Name, value: env.Value }]" `
-User $User; -User $User;
} }

View file

@ -10,28 +10,35 @@ begin
function configureSW -V dir function configureSW -V dir
source "$dir/../bash/profile.fish" source "$dir/../bash/profile.fish"
source "$dir/../fish/profile.fish" source "$dir/../fish/profile.fish"
set -l file /etc/aliae/aliae.yml set -l file (pwsh -CommandWithArgs '. $args[0]; Get-GlobalConfigPath' "$dir/Constants.ps1");
echo "export ALIAE_CONFIG=$(string escape "$file")" | sudo tee /etc/profile.d/aliae.sh > /dev/null
sudo install -Dm644 "$dir/aliae.yml" "$file" sudo install -Dm644 "$dir/aliae.yml" "$file"
begin begin
printf %s\n \ printf %s\n \
"# aliae" \ "if [ -f $(string escape $file) ]" \
'eval "$(aliae init bash)"' \ 'then' \
" eval \"\$(aliae init bash --config $(string escape $file))\"" \
'fi' \
'' \
'if [ -n "$ALIAE_CONFIG" ] && [ -f "$ALIAE_CONFIG" ] || [ -f ~/.aliae.yaml ]' \
'then' \
' eval "$(aliae init bash)"' \
'fi' \
'' \
'eval "$(aliae completion bash)"' 'eval "$(aliae completion bash)"'
end | installBashProfile "aliae" "aliae" end | installBashProfile "aliae" "aliae"
begin
printf %s\n "" \
"# aliae" \
'eval "$(aliae init bash)"' \
'eval "$(aliae completion bash)"'
end | sudo tee /etc/skel/.bashrc > /dev/null
if type -q fish if type -q fish
begin begin
printf %s\n \ printf %s\n \
"aliae init fish | source" \ "if [ -f $(string escape $file) ]" \
" eval \"\$(aliae init bash --config $(string escape $file))\"" \
'end' \
'' \
'if [ -n "$ALIAE_CONFIG" ] && [ -f "$ALIAE_CONFIG" ] || [ -f ~/.aliae.yaml ]' \
' aliae init fish | source' \
'end' \
'' \
"aliae completion fish | source" "aliae completion fish | source"
end | installFishProfile "aliae" "aliae" end | installFishProfile "aliae" "aliae"
end end

View file

@ -0,0 +1,26 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Scripts/SoftwareManagement.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-UserConfigurator {
param(
$Arguments
)
$bins = @("codium", "codium-insiders", "code", "code-insiders");
$extensions = @("zokugun.sync-settings", "zokugun.vsix-manager");
$user = $Arguments.Name;
foreach ($bin in $bins) {
if (Test-Command "$bin") {
foreach ($extension in $extensions) {
sudo -u "$user" "$bin" --install-extension "$extension";
}
}
}
};

View file

@ -2,19 +2,9 @@
begin begin
set -l dir (status dirname) set -l dir (status dirname)
source "$dir/../../Scripts/software.fish" source "$dir/../../Scripts/software.fish"
source "$dir/../../../Common/Software/aliae/main.fish"
function userConfig -a name function userConfig -V dir -a name
set -l bins codium codium-insiders code code-insiders pwsh "$dir/Main.ps1" ConfigureUser;
set -l extensions zokugun.{sync-settings,vsix-manager}
for bin in $bins
if type -q "$bin"
for extension in $extensions
sudo -u "$name" "$bin" --install-extension "$extension"
end
end
end
end end
runInstaller $argv runInstaller $argv

View file

@ -181,6 +181,7 @@ $null = New-Module {
Install-ChocoPackage selenium-gecko-driver firefox; Install-ChocoPackage selenium-gecko-driver firefox;
Invoke-Hook "Install-PSModules" -Fallback { Invoke-Hook "Install-PSModules" -Fallback {
Install-Module -Scope AllUsers -AcceptLicense -Force KnownFolders;
Install-Module -Scope AllUsers -AcceptLicense -Force PSWindowsUpdate; Install-Module -Scope AllUsers -AcceptLicense -Force PSWindowsUpdate;
Install-Module -Scope AllUsers -AcceptLicense -Force PSScriptAnalyzer; Install-Module -Scope AllUsers -AcceptLicense -Force PSScriptAnalyzer;
Install-Module -Scope AllUsers -AcceptLicense -AllowPrerelease -AllowClobber -Force LocalAccounts; Install-Module -Scope AllUsers -AcceptLicense -AllowPrerelease -AllowClobber -Force LocalAccounts;
@ -326,6 +327,10 @@ $null = New-Module {
& "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments; & "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments;
& "$softwarePath/Oh My Posh/Manage.ps1" @arguments; & "$softwarePath/Oh My Posh/Manage.ps1" @arguments;
if (Get-Config "valhalla.windows.dualboot") {
& "$softwarePath/Ext4Fsd/Manage.ps1" @arguments;
}
if ($install) { if ($install) {
Install-ChocoPackage ` Install-ChocoPackage `
procexp ` procexp `
@ -416,7 +421,7 @@ $null = New-Module {
& "$softwarePath/MSEdgeRedirect/Manage.ps1" @arguments; & "$softwarePath/MSEdgeRedirect/Manage.ps1" @arguments;
if (Test-Collection "fileSync") { if (Test-Collection "fileSync") {
& "$softwarePath/Nextcloud/Manage.ps1" @arguments; & "$softwarePath/Nextcloud/Main.ps1" @arguments;
} }
} }
@ -454,8 +459,7 @@ $null = New-Module {
if (Test-Collection "coding") { if (Test-Collection "coding") {
if ($install) { if ($install) {
Install-ChocoPackage vscode -ArgumentList "--params","/NoDesktopIcon"; & "$softwarePath/vscode/Main.ps1" @arguments;
Install-ChocoPackage vscodium -ArgumentList "--params","/NoDesktopIcon /AssociateWithFiles";
Install-ChocoPackage ` Install-ChocoPackage `
gh ` gh `

View file

@ -0,0 +1,12 @@
param (
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-SetupPackage "https://github.com/bobranten/Ext4Fsd/releases/download/v0.71/Ext2Fsd-0.71-setup.exe";
};

View file

@ -0,0 +1,125 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
& {
param($Parameters)
<#
.SYNOPSIS
Gets the path to the Nextcloud configuration file.
#>
function Get-ConfigFile {
return "$env:APPDATA/Nextcloud/nextcloud.cfg";
}
<#
.SYNOPSIS
Adds a new nextcloud sync to the current user.
#>
function Add-NextcloudSync {
param(
[string] $RemotePath,
[string] $LocalPath,
[switch] $VirtualFiles
)
Write-Host "Adding a Nextcloud sync";
Write-Host "$RemotePath <=> $LocalPath";
$configName = "Folders";
$virtualName = "WithPlaceholders";
$LocalPath = $LocalPath.Replace("\", "/");
$RemotePath = $RemotePath.Replace("\", "/");
$oldContent = Get-Content (Get-ConfigFile);
$additionalSettings = @();
$pattern = "^\d+\\$configName(?:$virtualName)?\\(\d+)";
$folderID = (
$oldContent | `
Where-Object { $_ -match "$pattern" } | `
ForEach-Object { $_ -replace "$pattern.*$","`$1" } | `
Sort-Object -Unique | `
Measure-Object -Maximum).Maximum + 1;
if ($VirtualFiles.IsPresent) {
$configName += $virtualName;
$additionalSettings = @("0\$configName\$folderID\virtualFilesMode=wincfapi");
}
$newSettings = (
@(
"0\$configName\$folderID\localPath=$LocalPath",
"0\$configName\$folderID\targetPath=$RemotePath"
) + $additionalSettings
) -join "`n";
& {
$accountSectionEntered = $false;
$accountSectionLeft = $false;
for ($i = 0; $i -lt $oldContent.Count; $i++) {
$line = $oldContent[$i];
if ($line -eq "[Accounts]") {
$accountSectionEntered = $true;
}
if ($line -eq "" -and $accountSectionEntered) {
$accountSectionLeft = $true;
$newSettings;
}
$line;
if (
(-not $accountSectionLeft) -and
($i -eq ($oldContent.Count - 1))) {
$newSettings;
}
}
} | Set-Content (Get-ConfigFile);
}
Start-SoftwareInstaller @Parameters `
-Installer {
Install-ChocoPackage nextcloud-client -ArgumentList "-y","--params='/KeepUpdateCheck'";
} `
-UserConfigurator {
param($Arguments)
$user = $Arguments.Name;
& {
$syncs = Get-UserConfig -UserName $user "nextcloud.folderSyncs";
$configExists = { (Test-Path (Get-ConfigFile) ) };
if ($syncs.Count -gt 0) {
if (-not (& $configExists)) {
while (-not (& $configExists)) {
Read-Host "Please log in to the Nextcloud app and hit enter to continue";
if (-not (& $configExists)) {
Write-Error -ErrorAction Continue "The login seems to have failed. Please try again.";
}
}
}
Write-Host "Stopping Nextcloud process";
$nextcloudProcess = Get-Process nextcloud;
$nextcloudPath = [string]$nextcloudProcess[0].Path;
$nextcloudProcess | Stop-Process -Force;
foreach ($sync in $syncs) {
Add-NextcloudSync -LocalPath $sync.localPath -RemotePath $sync.remotePath -VirtualFiles:$sync.virtualFiles;
}
Write-Host "Restarting Nextcloud";
Start-Process $nextcloudPath;
}
};
};
} $PSBoundParameters;

View file

@ -1,32 +0,0 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-ChocoPackage nextcloud-client -ArgumentList "-y","--params='/KeepUpdateCheck'";
} `
-UserConfigurator {
if (-not (Test-Path $context.GetNextcloudConfigFile())) {
Write-Information "Setting up Nextcloud configuration";
Write-Information "Ensuring all Let's Encrypt certificates are cached";
$null = Invoke-WebRequest https://valid-isrgrootx1.letsencrypt.org/;
while (-not (Test-Path $context.GetNextcloudConfigFile())) {
Write-Host "Nextcloud has been installed!";
Read-Host "Please log in in the Nextcloud app and hit enter to continue";
if (-not (Test-Path $context.GetNextcloudConfigFile())) {
Write-Error "The login seems to have failed. Please try again.";
}
}
$context.Reboot();
exit;
}
};

View file

@ -4,12 +4,14 @@ param(
) )
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Scripts/System.ps1";
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Installer { -Installer {
Install-ChocoPackage retroarch; Install-ChocoPackage retroarch;
# ToDo: Add start menu shortcut } `
# ToDo: Add function for this purpose -Configurator {
Add-StartMenuIcon "RetroArch" "C:\tools\RetroArch-Win64\retroarch.exe";
}; };
# ToDo: Add restoration # ToDo: Add restoration

View file

@ -12,10 +12,10 @@ Start-SoftwareInstaller @PSBoundParameters `
Write-Information "Enabling the ``$feature`` feature…"; Write-Information "Enabling the ``$feature`` feature…";
choco install --source windowsFeatures -y $feature; choco install --source windowsFeatures -y $feature;
} }
Install-WingetPackage Nadeo.TrackManiaNationsForever;
Remove-DesktopIcon "*TmNationsForever*";
} }
Install-WingetPackage Nadeo.TrackManiaNationsForever;
Remove-DesktopIcon "*TmNationsForever*";
}; };
# ToDo: Add restoration # ToDo: Add restoration

View file

@ -11,10 +11,6 @@ param(
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Installer { -Installer {
param(
[scriptblock] $Installer
)
Install-ChocoPackage winscp; Install-ChocoPackage winscp;
} ` } `
-Configurator { -Configurator {

View file

@ -7,9 +7,10 @@ param (
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
& { & {
param($Parameters)
$base = "$PSScriptRoot/../../../Common/Software/aliae/Manage.ps1"; $base = "$PSScriptRoot/../../../Common/Software/aliae/Manage.ps1";
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @Parameters `
-Installer { -Installer {
Install-WingetPackage JanDeDobbeleer.Aliae; Install-WingetPackage JanDeDobbeleer.Aliae;
} ` } `
@ -19,4 +20,4 @@ param (
-UserConfigurator { -UserConfigurator {
. $base -Action ([InstallerAction]::ConfigureUser); . $base -Action ([InstallerAction]::ConfigureUser);
}; };
}; } $PSBoundParameters;

View file

@ -17,10 +17,6 @@ param (
Start-SoftwareInstaller @Parameters ` Start-SoftwareInstaller @Parameters `
-Installer { -Installer {
param(
[scriptblock] $Installer
)
$params = "/WindowsTerminalProfile"; $params = "/WindowsTerminalProfile";
$defaultBranch = Get-Config "valhalla.git.defaultBranch"; $defaultBranch = Get-Config "valhalla.git.defaultBranch";

View file

@ -0,0 +1,28 @@
param(
$Action,
[hashtable] $Arguments
)
& {
param (
[hashtable] $Parameters
)
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
$base = "$PSScriptRoot/../../../Common/Software/vscode/Main.ps1";
Start-SoftwareInstaller @Parameters `
-Installer {
Install-ChocoPackage vscode -ArgumentList "--params","/NoDesktopIcon";
Install-ChocoPackage vscodium -ArgumentList "--params","/NoDesktopIcon /AssociateWithFiles";
refreshenv;
} `
-UserConfigurator {
param(
$Arguments
)
& $base ([InstallerAction]::ConfigureUser) @PSBoundParameters;
};
} $PSBoundParameters;