diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index 90e82ae9..4396aa50 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -4,6 +4,7 @@ using namespace System.Management.Automation.Host; $null = New-Module { . "$PSScriptRoot/SoftwareManagement.ps1"; . "$PSScriptRoot/../../Windows/Scripts/Registry.ps1"; + . "$PSScriptRoot/../../Windows/Scripts/WSL.ps1"; . "$PSScriptRoot/../../Windows/Types/WindowsInstallerAction.ps1"; <# @@ -67,7 +68,6 @@ $null = New-Module { [string] $Script ) - . "$PSScriptRoot/../../Windows/Scripts/WSL.ps1"; $scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish"; if ($env:CONFIG_NAME -or ($Script -eq "getProfiles")) { @@ -80,10 +80,6 @@ $null = New-Module { $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; @@ -93,7 +89,7 @@ $null = New-Module { $cleanup = { & $git restore --staged "$archisoDir" }; } - $output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script"; + $output = Invoke-Fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script"; if (-not $?) { Write-Error "The configuration could not be retrieved!"; diff --git a/scripts/Common/Scripts/Operations.ps1 b/scripts/Common/Scripts/Operations.ps1 index 0e2e5efe..24fd1e73 100644 --- a/scripts/Common/Scripts/Operations.ps1 +++ b/scripts/Common/Scripts/Operations.ps1 @@ -243,9 +243,8 @@ $null = New-Module { continue; } - if (-not (wsl --shell-type login type -t nix)) { - wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes; - wsl --shutdown; + if (-not (Test-Nix)) { + Install-Nix; continue; } diff --git a/scripts/Windows/Scripts/WSL.ps1 b/scripts/Windows/Scripts/WSL.ps1 index bbce2654..385fada8 100644 --- a/scripts/Windows/Scripts/WSL.ps1 +++ b/scripts/Windows/Scripts/WSL.ps1 @@ -126,6 +126,39 @@ function Unregister-WslDistribution { 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 Converts the specified path to linux and escapes it for the use in a script.