go: use env file instead of home.sessionVariables (#7751)
This commit is contained in:
parent
987b114082
commit
768a7042a6
13 changed files with 301 additions and 80 deletions
|
|
@ -1 +1,9 @@
|
|||
{ go-telemetry = ./go-telemetry.nix; }
|
||||
{
|
||||
go-telemetry = ./go-telemetry.nix;
|
||||
go-example-config = ./example-config.nix;
|
||||
go-suboptions-unset = ./suboptions-unset.nix;
|
||||
go-packages-default-gopath = ./packages-default-gopath.nix;
|
||||
go-packages-custom-gopath = ./packages-custom-gopath.nix;
|
||||
go-packages-invalid-main-gopath = ./packages-invalid-main-gopath.nix;
|
||||
go-old-options = ./old-options.nix;
|
||||
}
|
||||
|
|
|
|||
7
tests/modules/programs/go/env
Normal file
7
tests/modules/programs/go/env
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
CXX=g++
|
||||
GCCGO=gccgo
|
||||
GOAMD64=v1
|
||||
GOARCH=amd64
|
||||
GOAUTH=netrc
|
||||
GOPATH=/home/hm-user/mygo:/another/go:/yet/another/go
|
||||
GOPRIVATE=*.corp.example.com,rsc.io/private
|
||||
3
tests/modules/programs/go/env-old-options
Normal file
3
tests/modules/programs/go/env-old-options
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
GOBIN=/home/hm-user/.local/bin.go
|
||||
GOPATH=/home/hm-user/mygo:/home/hm-user/another/go:/home/hm-user/yet/another/go
|
||||
GOPRIVATE=*.corp.example.com,rsc.io/private
|
||||
5
tests/modules/programs/go/env-suboptions-unset
Normal file
5
tests/modules/programs/go/env-suboptions-unset
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
CXX=g++
|
||||
GCCGO=gccgo
|
||||
GOAMD64=v1
|
||||
GOARCH=amd64
|
||||
GOAUTH=netrc
|
||||
33
tests/modules/programs/go/example-config.nix
Normal file
33
tests/modules/programs/go/example-config.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{ pkgs, config, ... }:
|
||||
|
||||
{
|
||||
programs.go = {
|
||||
enable = true;
|
||||
env = {
|
||||
GOPATH = [
|
||||
"${config.home.homeDirectory}/mygo"
|
||||
"/another/go"
|
||||
"/yet/another/go"
|
||||
];
|
||||
GOPRIVATE = [
|
||||
"*.corp.example.com"
|
||||
"rsc.io/private"
|
||||
];
|
||||
CXX = "g++";
|
||||
GCCGO = "gccgo";
|
||||
GOAMD64 = "v1";
|
||||
GOARCH = "amd64";
|
||||
GOAUTH = "netrc";
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script =
|
||||
let
|
||||
goCfgDir = if !pkgs.stdenv.isDarwin then ".config/go" else "Library/Application Support/go";
|
||||
in
|
||||
''
|
||||
assertFileExists "home-files/${goCfgDir}/env"
|
||||
assertFileContent "home-files/${goCfgDir}/env" \
|
||||
${./env}
|
||||
'';
|
||||
}
|
||||
40
tests/modules/programs/go/old-options.nix
Normal file
40
tests/modules/programs/go/old-options.nix
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
lib,
|
||||
options,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
programs.go = {
|
||||
enable = true;
|
||||
goPath = "mygo";
|
||||
extraGoPaths = [
|
||||
"another/go"
|
||||
"yet/another/go"
|
||||
];
|
||||
goBin = ".local/bin.go";
|
||||
goPrivate = [
|
||||
"*.corp.example.com"
|
||||
"rsc.io/private"
|
||||
];
|
||||
};
|
||||
|
||||
test.asserts.warnings.expected = [
|
||||
"The option `programs.go.goPrivate' defined in ${lib.showFiles options.programs.go.goPrivate.files} has been renamed to `programs.go.env.GOPRIVATE'."
|
||||
"The option `programs.go.goBin' defined in ${lib.showFiles options.programs.go.goBin.files} has been changed to `programs.go.env.GOBIN' that has a different type. Please read `programs.go.env.GOBIN' documentation and update your configuration accordingly."
|
||||
"The option `programs.go.extraGoPaths' defined in ${lib.showFiles options.programs.go.extraGoPaths.files} has been changed to `programs.go.env.GOPATH' that has a different type. Please read `programs.go.env.GOPATH' documentation and update your configuration accordingly."
|
||||
"The option `programs.go.goPath' defined in ${lib.showFiles options.programs.go.goPath.files} has been changed to `programs.go.env.GOPATH' that has a different type. Please read `programs.go.env.GOPATH' documentation and update your configuration accordingly."
|
||||
];
|
||||
|
||||
nmt.script =
|
||||
let
|
||||
goCfgDir = if !pkgs.stdenv.isDarwin then ".config/go" else "Library/Application\ Support/go";
|
||||
in
|
||||
''
|
||||
assertFileExists "home-files/${goCfgDir}/env"
|
||||
assertFileContent "home-files/${goCfgDir}/env" \
|
||||
${./env-old-options}
|
||||
'';
|
||||
}
|
||||
22
tests/modules/programs/go/packages-custom-gopath.nix
Normal file
22
tests/modules/programs/go/packages-custom-gopath.nix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.go = {
|
||||
enable = true;
|
||||
env.GOPATH = [
|
||||
"${config.home.homeDirectory}/mygo"
|
||||
"/another/go"
|
||||
"/yet/another/go"
|
||||
];
|
||||
|
||||
packages = {
|
||||
"golang.org/x/text" = ./packages/text;
|
||||
"golang.org/x/time" = ./packages/time;
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/mygo/src/golang.org/x/text/main.go
|
||||
assertFileExists home-files/mygo/src/golang.org/x/time/main.go
|
||||
'';
|
||||
}
|
||||
14
tests/modules/programs/go/packages-default-gopath.nix
Normal file
14
tests/modules/programs/go/packages-default-gopath.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
programs.go = {
|
||||
enable = true;
|
||||
packages = {
|
||||
"golang.org/x/text" = ./packages/text;
|
||||
"golang.org/x/time" = ./packages/time;
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/go/src/golang.org/x/text/main.go
|
||||
assertFileExists home-files/go/src/golang.org/x/time/main.go
|
||||
'';
|
||||
}
|
||||
20
tests/modules/programs/go/packages-invalid-main-gopath.nix
Normal file
20
tests/modules/programs/go/packages-invalid-main-gopath.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.go = {
|
||||
enable = true;
|
||||
env.GOPATH = [
|
||||
"/not/my/home/mygo"
|
||||
"/another/go"
|
||||
"/yet/another/go"
|
||||
];
|
||||
|
||||
packages = {
|
||||
"golang.org/x/text" = ./packages/text;
|
||||
"golang.org/x/time" = ./packages/time;
|
||||
};
|
||||
};
|
||||
test.asserts.assertions.expected = [
|
||||
"The first element of `programs.go.env.GOPATH must be an absolute path that points to a directory inside ${config.home.homeDirectory} if `programs.go.packages` is set."
|
||||
];
|
||||
}
|
||||
7
tests/modules/programs/go/packages/text/main.go
Normal file
7
tests/modules/programs/go/packages/text/main.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello Home-Manager from 'text'!")
|
||||
}
|
||||
7
tests/modules/programs/go/packages/time/main.go
Normal file
7
tests/modules/programs/go/packages/time/main.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello Home-Manager from 'time'!")
|
||||
}
|
||||
24
tests/modules/programs/go/suboptions-unset.nix
Normal file
24
tests/modules/programs/go/suboptions-unset.nix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{ pkgs, config, ... }:
|
||||
|
||||
{
|
||||
programs.go = {
|
||||
enable = true;
|
||||
env = {
|
||||
CXX = "g++";
|
||||
GCCGO = "gccgo";
|
||||
GOAMD64 = "v1";
|
||||
GOARCH = "amd64";
|
||||
GOAUTH = "netrc";
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script =
|
||||
let
|
||||
goCfgDir = if !pkgs.stdenv.isDarwin then ".config/go" else "Library/Application\ Support/go";
|
||||
in
|
||||
''
|
||||
assertFileExists "home-files/${goCfgDir}/env"
|
||||
assertFileContent "home-files/${goCfgDir}/env" \
|
||||
${./env-suboptions-unset}
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue