-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
109 lines (92 loc) · 3.61 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
description = "TaserudConsulting/goprocmgr";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
flake-utils,
nixpkgs,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
in {
packages = flake-utils.lib.flattenTree {
default = pkgs.buildGoModule (let
versionTag = "1.5.0";
pname = "goprocmgr";
version = "${versionTag}.${nixpkgs.lib.substring 0 8 self.lastModifiedDate}.${self.shortRev or "dirty"}";
in {
inherit pname version;
nativeBuildInputs = [
pkgs.pandoc
pkgs.installShellFiles
];
prePatch = ''
substituteInPlace CLI.md main.go --replace-fail "%undefined-version%" ${version}
'';
postBuild = ''
pandoc -s -t man CLI.md -o goprocmgr.1
'';
postInstall = ''
install -Dm644 goprocmgr.1 $out/share/man/man1/goprocmgr.1
installShellCompletion --cmd goprocmgr contrib/completions/goprocmgr.{fish,bash}
'';
src = ./.;
vendorHash = "sha256-aA+FeMBLhvh4pg3W4eHEfBtOf5oUnDDUkKnHEQA/+vI=";
});
};
devShells = flake-utils.lib.flattenTree {
default = pkgs.mkShell {
buildInputs = [
pkgs.gnumake
pkgs.delve # debugging
pkgs.go # language
pkgs.gopls # language server
];
};
};
checks = flake-utils.lib.flattenTree {
default = pkgs.nixosTest {
name = "goprocmgr-integration-test";
nodes.machine = {
config,
pkgs,
...
}: {
# Install package
environment.systemPackages = [
self.packages.${system}.default
];
# Create service
systemd.services.${self.packages.${system}.default.pname} = {
description = self.packages.${system}.default.pname;
after = ["network.target"];
wantedBy = ["multi-user.target"];
serviceConfig.ExecStart = "${self.packages.${system}.default}/bin/${self.packages.${system}.default.pname}";
serviceConfig.Restart = "always";
};
};
testScript = ''
machine.start()
machine.wait_for_unit("${self.packages.${system}.default.pname}.service")
# Check version output from command line util
version = machine.succeed("${self.packages.${system}.default.pname} -version")
assert '${self.packages.${system}.default.pname} version ${self.packages.${system}.default.version}' in version, \
"Version output mismatch, got: '" + version + "', expected '${self.packages.${system}.default.version}'"
# Test connecting to the running instance
machine.succeed("${self.packages.${system}.default.pname} -list")
# Test adding a new server
machine.succeed("${self.packages.${system}.default.pname} -add 'echo hello; sleep 1; echo world'")
# Fetch the list of servers and check that the new server is in the list
list = machine.succeed("${self.packages.${system}.default.pname} -list")
assert 'echo hello; sleep 1; echo world' in list, "Expected 'echo hello; sleep 1; echo world' in list, got: '" + list + "'"
assert 'tmp' in list, "Expected 'tmp' in list, got: '" + list + "'"
'';
};
};
formatter = pkgs.alejandra;
});
}