1
1
function WSL-Install () {
2
+ $id = [guid ]::NewGuid().ToString()
3
+
2
4
# Build docker image from the provided tarball
3
5
$tmpdir = $ (mktemp - d)
4
6
Copy-Item $PSScriptRoot / Dockerfile $tmpdir
5
7
Copy-Item nixos- wsl- installer.tar.gz $tmpdir
6
- docker build - t local: nixos- wsl $tmpdir | Write-Host
8
+ docker build - t nixos- wsl: $id $tmpdir | Write-Host
7
9
Remove-Item $tmpdir - Recurse - Force
8
10
9
11
# Spawn a new docker container
10
- $id = docker run - di -- privileged -- init local: nixos- wsl / bin/ sh
12
+ docker run - di -- privileged -- init -- name $id nixos- wsl: $id / bin/ sh | Out-Null
11
13
if ($LASTEXITCODE -ne 0 ) {
12
- throw " Failed to launch docker container"
14
+ throw " Failed to launch container"
13
15
}
14
16
15
17
return $id
@@ -19,9 +21,22 @@ function WSL-Launch([string]$id, [string]$command) {
19
21
docker exec - t $id / nix/ nixos- wsl/ entrypoint - c " $command "
20
22
}
21
23
24
+ # TODO: WSL-CopyFile
25
+
26
+ function WSL-Shutdown ([string ]$id ) {
27
+ docker stop $id
28
+ if ($LASTEXITCODE -ne 0 ) {
29
+ throw " Failed to stop container"
30
+ }
31
+ }
32
+
22
33
function WSL-Uninstall ([string ]$id ) {
23
34
docker rm -f $id
24
35
if ($LASTEXITCODE -ne 0 ) {
25
- throw " Failed to remove docker container"
36
+ throw " Failed to remove container"
37
+ }
38
+ docker rmi nixos- wsl:$id
39
+ if ($LASTEXITCODE -ne 0 ) {
40
+ throw " Failed to remove image"
26
41
}
27
42
}
0 commit comments