This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
forked from nyiyui/qrystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
107 lines (99 loc) · 3.79 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
{
inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
let
# to work with older version of flakes
lastModifiedDate =
self.lastModifiedDate or self.lastModified or "19700101";
# Generate a user-friendly version number.
version = (builtins.substring 0 8 lastModifiedDate) + "-"
+ (if (self ? rev) then self.rev else "dirty");
# System types to support.
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
libFor = forAllSystems (system: import (nixpkgs + "/lib"));
nixosLibFor = forAllSystems (system: import (nixpkgs + "/nixos/lib"));
in flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = import nixpkgs { inherit system; };
lib = import (nixpkgs + "/lib") { inherit system; };
nixosLib = import (nixpkgs + "/nixos/lib") { inherit system; };
ldflags = pkgs: [
"-X github.com/nyiyui/qrystal/mio.CommandBash=${pkgs.bash}/bin/bash"
"-X github.com/nyiyui/qrystal/mio.CommandWg=${pkgs.wireguard-tools}/bin/wg"
"-X github.com/nyiyui/qrystal/mio.CommandWgQuick=${pkgs.wireguard-tools}/bin/wg-quick"
"-X github.com/nyiyui/qrystal/node.CommandIp=${pkgs.iproute2}/bin/ip"
"-X github.com/nyiyui/qrystal/node.CommandIptables=${pkgs.iptables}/bin/iptables"
"-race"
];
in rec {
devShells = let pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [
bash
go_1_19
git
protobuf
protoc-gen-go
protoc-gen-go-grpc
nixfmt
govulncheck
];
};
};
packages = let
pkgs = nixpkgsFor.${system};
lib = libFor.${system};
common = {
inherit version;
src = ./.;
ldflags = ldflags pkgs;
tags = [ "nix" "sdnotify" ];
#vendorSha256 = pkgs.lib.fakeSha256;
vendorSha256 =
"2f8ac98cfcc7d7a6388b8bb286c63b6e627f6d4619d87e6821b59d46b8a58bb7";
};
in {
runner = pkgs.buildGoModule (common // {
pname = "runner";
subPackages = [
"cmd/runner"
"cmd/runner-mio"
"cmd/runner-node"
"cmd/runner-hokuto"
];
ldflags = (ldflags pkgs) ++ [
"-X github.com/nyiyui/qrystal/runner.NodeUser=qrystal-node"
];
postInstall = ''
mkdir $out/lib
cp $src/mio/dev-add.sh $out/lib
cp $src/mio/dev-remove.sh $out/lib
'';
});
cs = pkgs.buildGoModule (common // {
pname = "cs";
subPackages = [ "cmd/cs" ];
});
etc = pkgs.buildGoModule (common // {
name = "etc";
# NOTE: specifying subPackages makes buildGoModule not test other packages :(
});
sd-notify-test = pkgs.buildGoModule (common // {
pname = "sd-notify-test";
subPackages = [ "cmd/sd-notify-test" ];
});
};
checks = (import ./test.nix) {
inherit self system nixpkgsFor libFor nixosLibFor ldflags;
};
nixosModules = ((import ./nixos-modules.nix) {
inherit self system nixpkgsFor libFor nixosLibFor ldflags packages;
}).nixosModules;
});
}