Move unix related functions to the WSL script

This commit is contained in:
Manuel Thalmann 2024-09-28 16:13:07 +02:00
parent df86ea2980
commit 3022ee9f41
3 changed files with 37 additions and 9 deletions

View file

@ -4,6 +4,7 @@ using namespace System.Management.Automation.Host;
$null = New-Module { $null = New-Module {
. "$PSScriptRoot/SoftwareManagement.ps1"; . "$PSScriptRoot/SoftwareManagement.ps1";
. "$PSScriptRoot/../../Windows/Scripts/Registry.ps1"; . "$PSScriptRoot/../../Windows/Scripts/Registry.ps1";
. "$PSScriptRoot/../../Windows/Scripts/WSL.ps1";
. "$PSScriptRoot/../../Windows/Types/WindowsInstallerAction.ps1"; . "$PSScriptRoot/../../Windows/Types/WindowsInstallerAction.ps1";
<# <#
@ -67,7 +68,6 @@ $null = New-Module {
[string] $Script [string] $Script
) )
. "$PSScriptRoot/../../Windows/Scripts/WSL.ps1";
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish"; $scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
if ($env:CONFIG_NAME -or ($Script -eq "getProfiles")) { if ($env:CONFIG_NAME -or ($Script -eq "getProfiles")) {
@ -80,10 +80,6 @@ $null = New-Module {
$projectRoot = "$PSScriptRoot/../../.."; $projectRoot = "$PSScriptRoot/../../..";
$archisoDir = "$projectRoot/archiso"; $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") { if (Test-Path -PathType Container "$archisoDir") {
$git = { $git = {
git -C "$projectRoot" -c safe.directory="$("$(Resolve-Path $projectRoot)".Replace("\", "/"))" @args; git -C "$projectRoot" -c safe.directory="$("$(Resolve-Path $projectRoot)".Replace("\", "/"))" @args;
@ -93,7 +89,7 @@ $null = New-Module {
$cleanup = { & $git restore --staged "$archisoDir" }; $cleanup = { & $git restore --staged "$archisoDir" };
} }
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script"; $output = Invoke-Fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
if (-not $?) { if (-not $?) {
Write-Error "The configuration could not be retrieved!"; Write-Error "The configuration could not be retrieved!";

View file

@ -243,9 +243,8 @@ $null = New-Module {
continue; continue;
} }
if (-not (wsl --shell-type login type -t nix)) { if (-not (Test-Nix)) {
wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes; Install-Nix;
wsl --shutdown;
continue; continue;
} }

View file

@ -126,6 +126,39 @@ function Unregister-WslDistribution {
Move-Item $tempDisk $wslDisk; Move-Item $tempDisk $wslDisk;
} }
<#
.SYNOPSIS
Checks whether `nix` is installed in WSL.
#>
function Test-Nix {
wsl --shell-type login type -t nix;
}
<#
.SYNOPSIS
Installs `nix` in WSL.
#>
function Install-Nix {
wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes;
wsl --shutdown;
}
<#
.SYNOPSIS
Execute a `nix` command in WSL.
#>
function Invoke-Nix {
wsl --shell-type login nix --extra-experimental-features "nix-command flakes" @args;
}
<#
.SYNOPSIS
Execute a `fish` command in WSL.
#>
function Invoke-Fish {
Invoke-Nix run nixpkgs`#fish `-- @args;
}
<# <#
.SYNOPSIS .SYNOPSIS
Converts the specified path to linux and escapes it for the use in a script. Converts the specified path to linux and escapes it for the use in a script.