Add a function for retrieving nix options

This commit is contained in:
Manuel Thalmann 2024-08-01 16:12:58 +02:00
parent 9cd44db4e8
commit dac832c8bb

View file

@ -13,6 +13,28 @@ $null = New-Module {
[string] $finishedOption = "Finished";
[RegistryKey] $key = $null;
<#
.SYNOPSIS
Converts the specified path to linux and escapes it for the use in a script.
.PARAMETER Path
The path to convert.
#>
function ConvertTo-LinuxPath {
param(
[string] $Path
)
$job = Start-Job {
$env:Value = Resolve-Path $Using:Path;
$env:WSLENV = "Value/p";
$result = wsl -- bash -c 'echo "$Value"';
wsl -e printf "%q" "$result";
};
Receive-Job -Wait $job;
}
<#
.SYNOPSIS
Gets the registry key containing options related to the setup.
@ -38,6 +60,27 @@ $null = New-Module {
return $key;
}
<#
.SYNOPSIS
Gets a configuration option.
.PARAMETER Name
The name of the option to get.
#>
function Get-Config {
param(
[string] $Name
)
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
function fish {
wsl -- nix --extra-experimental-features "nix-command flakes" nixpkgs`#fish $args
}
fish -c ". $(ConvertTo-LinuxPath $scriptPath); getConfig $Name --json" | ConvertFrom-Json;
}
<#
.SYNOPSIS
Gets the value of an option related to the setup.