Skip to content

Commit a411f6a

Browse files
authored
refactor(nix): drop flake-parts dependency (#170)
The features used from flake-parts can be trivially replicated with the Nixpkgs lib itself Signed-off-by: Harsh Shandilya <[email protected]>
1 parent 4112ebe commit a411f6a

File tree

2 files changed

+123
-148
lines changed

2 files changed

+123
-148
lines changed

Diff for: flake.lock

-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+123-114
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33

44
inputs = {
55
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
6-
parts.url = "github:hercules-ci/flake-parts";
76
systems.url = "github:nix-systems/default";
87
};
98

10-
outputs = inputs @ { self, parts, ... }: parts.lib.mkFlake { inherit inputs; } {
11-
systems = import inputs.systems;
12-
13-
perSystem = { pkgs, ... }: {
14-
formatter = pkgs.nixpkgs-fmt;
15-
16-
devShells.default = pkgs.mkShell { buildInputs = [ pkgs.go_1_23 ]; };
17-
18-
packages.default =
19-
pkgs.buildGo124Module {
9+
outputs =
10+
{ self
11+
, nixpkgs
12+
, systems
13+
,
14+
}:
15+
let
16+
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (s: f nixpkgs.legacyPackages.${s});
17+
in
18+
{
19+
formatter = eachSystem (pkgs: pkgs.nixpkgs-fmt);
20+
21+
devShells = eachSystem (pkgs: {
22+
default = pkgs.mkShell { buildInputs = [ pkgs.go_1_23 ]; };
23+
});
24+
25+
packages = eachSystem (pkgs: {
26+
default = pkgs.buildGo124Module {
2027
pname = "golink";
21-
version =
22-
if (self ? shortRev)
23-
then self.shortRev
24-
else "dev";
28+
version = if (self ? shortRev) then self.shortRev else "dev";
2529
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
2630
ldflags =
2731
let
28-
tsVersion = with builtins; head (match
29-
".*tailscale.com v([0-9]+\.[0-9]+\.[0-9]+-?[a-zA-Z]?).*"
30-
(readFile ./go.mod));
32+
tsVersion =
33+
with builtins;
34+
head (match ".*tailscale.com v([0-9]+\.[0-9]+\.[0-9]+-?[a-zA-Z]?).*" (readFile ./go.mod));
3135
in
3236
[
3337
"-w"
@@ -37,114 +41,119 @@
3741
];
3842
vendorHash = "sha256-k3BxPRTgoJM0oCixDVA2k44ztdAUZO4IcO2/QB19HvU="; # SHA based on vendoring go.mod
3943
};
40-
};
44+
});
4145

42-
flake.overlays.default = final: prev: {
43-
golink = self.packages.${prev.system}.default;
44-
};
46+
overlays.default = final: prev: {
47+
golink = self.packages.${prev.system}.default;
48+
};
4549

46-
flake.nixosModules.default = { config, lib, pkgs, ... }:
47-
let
48-
cfg = config.services.golink;
49-
inherit (lib)
50-
concatStringsSep
51-
escapeShellArg
52-
mkEnableOption
53-
mkIf
54-
mkOption
55-
optionalString
56-
optionals
57-
types
58-
;
59-
in
60-
{
61-
options.services.golink = {
62-
enable = mkEnableOption "Enable golink";
63-
64-
package = mkOption {
65-
type = types.package;
66-
description = ''
67-
golink package to use
68-
'';
69-
default = pkgs.golink;
70-
};
50+
nixosModules.default =
51+
{ config
52+
, lib
53+
, pkgs
54+
, ...
55+
}:
56+
let
57+
cfg = config.services.golink;
58+
inherit (lib)
59+
concatStringsSep
60+
escapeShellArg
61+
mkEnableOption
62+
mkIf
63+
mkOption
64+
optionalString
65+
optionals
66+
types
67+
;
68+
in
69+
{
70+
options.services.golink = {
71+
enable = mkEnableOption "Enable golink";
72+
73+
package = mkOption {
74+
type = types.package;
75+
description = ''
76+
golink package to use
77+
'';
78+
default = pkgs.golink;
79+
};
7180

72-
dataDir = mkOption {
73-
type = types.path;
74-
default = "/var/lib/golink";
75-
description = "Path to data dir";
76-
};
81+
dataDir = mkOption {
82+
type = types.path;
83+
default = "/var/lib/golink";
84+
description = "Path to data dir";
85+
};
7786

78-
user = mkOption {
79-
type = types.str;
80-
default = "golink";
81-
description = "User account under which golink runs.";
82-
};
87+
user = mkOption {
88+
type = types.str;
89+
default = "golink";
90+
description = "User account under which golink runs.";
91+
};
8392

84-
group = mkOption {
85-
type = types.str;
86-
default = "golink";
87-
description = "Group account under which golink runs.";
88-
};
93+
group = mkOption {
94+
type = types.str;
95+
default = "golink";
96+
description = "Group account under which golink runs.";
97+
};
8998

90-
databaseFile = mkOption {
91-
type = types.path;
92-
default = "/var/lib/golink/golink.db";
93-
description = "Path to SQLite database";
94-
};
99+
databaseFile = mkOption {
100+
type = types.path;
101+
default = "/var/lib/golink/golink.db";
102+
description = "Path to SQLite database";
103+
};
95104

96-
tailscaleAuthKeyFile = mkOption {
97-
type = types.nullOr types.path;
98-
default = null;
99-
description = ''
100-
Path to the file containing the Tailscale Auth Key.
101-
If null, manual authorization with the tailnet is required.
102-
Check `journalctl -eu golink` for the login link.
103-
'';
104-
};
105+
tailscaleAuthKeyFile = mkOption {
106+
type = types.nullOr types.path;
107+
default = null;
108+
description = ''
109+
Path to the file containing the Tailscale Auth Key.
110+
If null, manual authorization with the tailnet is required.
111+
Check `journalctl -eu golink` for the login link.
112+
'';
113+
};
105114

106-
verbose = mkOption {
107-
type = types.bool;
108-
default = false;
115+
verbose = mkOption {
116+
type = types.bool;
117+
default = false;
118+
};
109119
};
110-
};
111120

112-
config = mkIf cfg.enable {
113-
nixpkgs.overlays = [ self.overlays.default ];
114-
115-
users.groups."${cfg.group}" = { };
116-
users.users."${cfg.user}" = {
117-
home = cfg.dataDir;
118-
createHome = true;
119-
group = "${cfg.group}";
120-
isSystemUser = true;
121-
isNormalUser = false;
122-
description = "user for golink service";
123-
};
121+
config = mkIf cfg.enable {
122+
nixpkgs.overlays = [ self.overlays.default ];
123+
124+
users.groups."${cfg.group}" = { };
125+
users.users."${cfg.user}" = {
126+
home = cfg.dataDir;
127+
createHome = true;
128+
group = "${cfg.group}";
129+
isSystemUser = true;
130+
isNormalUser = false;
131+
description = "user for golink service";
132+
};
124133

125-
systemd.services.golink = {
126-
enable = true;
127-
script =
128-
let
129-
args = [ "--sqlitedb ${cfg.databaseFile}" ] ++ optionals cfg.verbose [ "--verbose" ];
130-
in
131-
''
132-
${optionalString (cfg.tailscaleAuthKeyFile != null) ''
133-
export TS_AUTHKEY="$(head -n1 ${escapeShellArg cfg.tailscaleAuthKeyFile})"
134-
''}
135-
136-
${cfg.package}/bin/golink ${concatStringsSep " " args}
137-
'';
138-
wantedBy = [ "multi-user.target" ];
139-
serviceConfig = {
140-
User = cfg.user;
141-
Group = cfg.group;
142-
Restart = "always";
143-
RestartSec = "15";
144-
WorkingDirectory = "${cfg.dataDir}";
134+
systemd.services.golink = {
135+
enable = true;
136+
script =
137+
let
138+
args = [ "--sqlitedb ${cfg.databaseFile}" ] ++ optionals cfg.verbose [ "--verbose" ];
139+
in
140+
''
141+
${optionalString (cfg.tailscaleAuthKeyFile != null) ''
142+
export TS_AUTHKEY="$(head -n1 ${escapeShellArg cfg.tailscaleAuthKeyFile})"
143+
''}
144+
145+
${cfg.package}/bin/golink ${concatStringsSep " " args}
146+
'';
147+
wantedBy = [ "multi-user.target" ];
148+
serviceConfig = {
149+
User = cfg.user;
150+
Group = cfg.group;
151+
Restart = "always";
152+
RestartSec = "15";
153+
WorkingDirectory = "${cfg.dataDir}";
154+
};
145155
};
146156
};
147157
};
148-
};
149-
};
158+
};
150159
}

0 commit comments

Comments
 (0)