-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
flake.nix
140 lines (127 loc) · 4 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Nix flake for LazySSH.
#
# At the time of writing, Nix flakes are experimental. It's likely you're not
# on a version of Nix that supports flakes just yet. In that case, import this
# as follows:
#
# ```
# let
# lazyssh = import (fetchTarball {
# # Replace `<REV>` with the exact Git commit hash you want.
# url = "https://github.com/stephank/lazyssh/archive/<REV>.tar.gz";
# # Easiest way to find this hash is to just try a build.
# sha256 = "0000000000000000000000000000000000000000000000000000";
# });
# in
# # Your code here...
# ```
#
# But if you ARE using flakes, you can use this as an input:
#
# ```
# {
# inputs.lazyssh.url = github:stephank/lazyssh;
# outputs = { self, lazyssh }: {
# # Your code here...
# };
# }
# ```
#
# In either case, you then use one of the `lazyssh` attributes. This flake
# provides a stand-alone package, a Nixpkgs overlay, and modules for NixOS,
# nix-darwin and home-manager.
#
# TODO: Declarative configuration for LazySSH.
{
description = "LazySSH";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable;
outputs = { self, nixpkgs }:
with nixpkgs.lib;
let
# Common options for NixOS, nix-darwin and home-manager modules.
moduleOptions = {
configFile = mkOption {
description = "Configuration file to use.";
type = types.str;
};
};
# mkCmd builds the LazySSH command-line for running it as a service.
mkCmd = system: configFile:
[ "${self.defaultPackage.${system}}/bin/lazyssh" "-config" configFile ];
in {
# Stand-alone LazySSH package, for all supported systems.
defaultPackage = mapAttrs (system: pkgs:
pkgs.buildGoModule {
name = "lazyssh";
src = ./.;
vendorSha256 = "h3YZz9TRPJgu0kHbC8D4u+uHQnBMf8VbteyoSiypjEM=";
}
) nixpkgs.legacyPackages;
# Nixpkgs overlay that defines LazySSH.
overlay = overlaySelf: overlaySuper: {
lazyssh = self.defaultPackage.${overlaySuper.system};
};
# NixOS module to run LazySSH as a systemd service.
#
# Note that this creates a dedicated `lazyssh` user. If you'd rather run
# LazySSH within your personal user account, the home-manager module is
# preferred.
#
# Alternatively, use the Nixpkgs overlay and manually setup the service
# however you want.
nixosModule = { config, pkgs, ... }:
let cfg = config.services.lazyssh;
in {
options.services.lazyssh = moduleOptions;
config = {
users.users.lazyssh.isSystemUser = true;
systemd.services.lazyssh = {
description = "LazySSH";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = escapeShellArgs (mkCmd pkgs.system cfg.configFile);
Restart = "on-failure";
User = "lazyssh";
};
};
};
};
# Nix-darwin module to run LazySSH as a launchd user agent.
darwinModule = { config, pkgs, ... }:
let cfg = config.services.lazyssh;
in {
options.services.lazyssh = moduleOptions;
config = {
launchd.user.agents.lazyssh = {
serviceConfig = {
ProgramArguments = mkCmd pkgs.system cfg.configFile;
RunAtLoad = true;
KeepAlive = true;
};
};
};
};
# Home-manager module to run LazySSH as a systemd user service.
#
# This only works on Linux. On Mac, the nix-darwin module is perferred.
#
# Alternatively, use the Nixpkgs overlay and manually setup the service
# however you want.
homeManagerModule = { config, pkgs, ... }:
let cfg = config.services.lazyssh;
in {
options.services.lazyssh = moduleOptions;
config = {
systemd.user.services.lazyssh = {
Unit.Description = "LazySSH";
Service = {
ExecStart = escapeShellArgs (mkCmd pkgs.system cfg.configFile);
Restart = "on-failure";
};
Install.WantedBy = [ "default.target" ];
};
};
};
};
}