-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
181 lines (165 loc) · 5.76 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{
description = "my keeb";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
keymap_drawer = {
url = "github:caksoylar/keymap-drawer?rev=6defcaf80edd0bc916e747ac6041bd232b738c5f";
flake = false;
};
poetry2nix = {
url = "github:nix-community/poetry2nix?rev=528d500ea826383cc126a9be1e633fc92b19ce5d";
inputs.nixpkgs.follows = "nixpkgs";
};
# must be git not github for submodules
qmk_firmware = {
url =
"git+https://github.com/Bastardkb/bastardkb-qmk?ref=bkb-master&submodules=1&shallow=1";
flake = false;
};
svalboard_firmware = {
url = "git+https://github.com/svalboard/vial-qmk?ref=vial&submodules=1&shallow=1";
flake = false;
};
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
imports = [
# inputs.haskell-flake.flakeModule
inputs.treefmt-nix.flakeModule
inputs.flake-root.flakeModule
];
perSystem =
{ pkgs
, lib
, config
, system
, ...
}:
let
inherit (inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) defaultPoetryOverrides mkPoetryApplication;
in
{
packages.drawer = mkPoetryApplication {
projectDir = inputs.keymap_drawer;
overrides = defaultPoetryOverrides.extend
(self: super: {
deptry = super.deptry.overridePythonAttrs
(
old: {
buildInputs = (old.buildInputs or [ ]) ++ [ super.poetry ];
}
);
});
};
treefmt.config = {
inherit (config.flake-root) projectRootFile;
package = pkgs.treefmt;
programs.nixpkgs-fmt.enable = true;
};
packages.shijushichishi = pkgs.stdenv.mkDerivation rec {
name = "svalboard.uf2";
src = inputs.svalboard_firmware;
nativeBuildInputs = [ pkgs.qmk ];
buildInputs = with pkgs; [
cacert
];
# this allows us to not need the .git folder
SKIP_VERSION = "1";
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
postUnpack = ''
ln -s ${
./svalboard/yuanw/.
} $sourceRoot/keyboards/svalboard/keymaps/yuanw
'';
buildPhase = ''
make VERBOSE=1 svalboard/trackball/right:yuanw
make VERBOSE=1 svalboard/trackball/left:yuanw
'';
installPhase = ''
ls
mkdir $out
mkdir -p $out/share
mv *.uf2 $out/share
'';
};
packages.firmware = pkgs.stdenv.mkDerivation rec {
name = "firmware.uf2";
src = inputs.qmk_firmware;
nativeBuildInputs = [ pkgs.qmk ];
buildInputs = with pkgs; [
cacert
(python3.withPackages (ps: [ ps.pyyaml ]))
];
postUnpack = ''
ln -s ${
./qmk/yuanw/.
} $sourceRoot/keyboards/bastardkb/charybdis/3x5/keymaps/yuanw
ln -s ${./process.py} $sourceRoot/process.py
'';
# this allows us to not need the .git folder
SKIP_VERSION = "1";
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
buildPhase = ''
make bastardkb/charybdis/3x5:yuanw
${pkgs.qmk}/bin/qmk -v c2json -kb bastardkb/charybdis/3x5 -km yuanw ./keyboards/bastardkb/charybdis/3x5/keymaps/yuanw/keymap.c > reiryoku.json
mkdir $out
mkdir -p $out/share
'';
installPhase = ''
mv bastardkb_charybdis_3x5_yuanw.uf2 $out/share
mv reiryoku.json $out/share
'';
};
packages.flash = pkgs.writeScriptBin "reiryoku-flash" ''
cd ${inputs.qmk_firmware}
${pkgs.qmk}/bin/qmk flash ${config.packages.firmware}/share/bastardkb_charybdis_3x5_yuanw.uf2
'';
packages.draw = pkgs.writeShellApplication {
name = "reiryoku-draw";
runtimeInputs = with pkgs;
[
config.packages.drawer
(python3.withPackages (ps: [ ps.pyyaml ]))
];
text = ''
keymap parse -c 10 -q ${config.packages.firmware}/share/reiryoku.json > reiryoku.yaml
sed -i -E "s/LAYOUT_charybdis_3x5/LAYOUT/g" reiryoku.yaml
keymap draw reiryoku.yaml > reiryoku.svg
python process.py
keymap draw output.yaml > reiryoku.svg
'';
};
# Default shell.
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
(python3.withPackages (ps: [ ps.pyyaml ]))
];
# See https://haskell.flake.page/devshell#composing-devshells
inputsFrom = [
config.flake-root.devShell
config.treefmt.build.devShell
];
};
packages.default = config.packages.firmware;
apps.flash = {
type = "app";
program = config.packages.flash;
};
apps.draw = {
type = "app";
program = config.packages.draw;
};
apps.default = config.apps.flash;
};
};
}