forked from xremap/nix-flake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
155 lines (146 loc) · 5.17 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
{
description = "Flake that configures Xremap, a key remapper for Linux";
inputs = {
# Nixpkgs will be pinned to unstable to get the latest Rust
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
# Development deps
devshell.url = "github:numtide/devshell";
treefmt-nix.url = "github:numtide/treefmt-nix";
# Utils for building Rust stuff
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
# fenix = {
# url = "github:nix-community/fenix";
# inputs.nixpkgs.follows = "nixpkgs";
# inputs.rust-analyzer-src.follows = "";
# };
# advisory-db = {
# url = "github:rustsec/advisory-db";
# flake = false;
# };
# The Rust source for xremap
xremap = {
url = "github:k0kubun/xremap?ref=v0.10.0";
flake = false;
};
hyprland = {
url = "github:hyprwm/Hyprland";
};
home-manager.url = "github:nix-community/home-manager";
};
outputs =
inputs@{ flake-parts, self, ... }:
flake-parts.lib.mkFlake { inherit inputs; } (
{ withSystem, flake-parts-lib, ... }:
let
inherit (flake-parts-lib) importApply;
in
{
imports = [
inputs.devshell.flakeModule
inputs.flake-parts.flakeModules.easyOverlay
inputs.treefmt-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
];
perSystem =
{ config, pkgs, ... }:
let
craneLib = inputs.crane.mkLib pkgs;
inherit (pkgs) lib;
in
{
packages = import ./overlay {
inherit (inputs) xremap;
inherit craneLib pkgs;
};
# This way all packages get immediately added to the overlay except for the one called literally called "default"
overlayAttrs = builtins.removeAttrs config.packages [ "default" ];
# Development setup
devshells.default = {
env = [
{
name = "RUST_SRC_PATH";
value = pkgs.rustPlatform.rustLibSrc;
}
];
commands =
[
{
help = "Build xremap (no features)";
name = "build-xremap-no-features";
command = "nix build .#";
}
{
help = "Build xremap with features one by one";
name = "test-build-all-features";
command = ''
set -euo pipefail
features=( "gnome" "hypr" "sway" "x11" "wlroots" "kde" )
for feature in "''${features[@]}"; do
echo "Building feature $feature"
nix build .#xremap-''${feature}
echo "Build successful"
done
'';
}
{
help = "SSH into the dev VM. Disregards the known hosts file";
name = "vm-ssh";
command = ''ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 64022 alice@localhost'';
}
]
++ (
# Construct runners for all development VMs
let
definedVMs = self.nixosConfigurations;
namesOfVMs = builtins.attrNames definedVMs;
getVMcomment =
vmName:
if builtins.hasAttr "_comment" definedVMs.${vmName} then definedVMs.${vmName}._comment else "";
in
map (nixosSystem: {
help = "Run VM for testing ${nixosSystem}";
name = "vm-run-${nixosSystem}";
command = ''
echo "Launching VM"
echo "${getVMcomment nixosSystem}"
nix run .#nixosConfigurations.${nixosSystem}.config.system.build.vm
'';
}) namesOfVMs
);
packages = builtins.attrValues {
inherit (pkgs) cargo rustc rustfmt;
inherit (pkgs.rustPackages) clippy;
};
};
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt-rfc-style.enable = true;
statix.enable = true;
deadnix.enable = true;
};
};
checks = import ./checks { inherit self pkgs lib; };
};
flake = {
nixosModules.default = importApply ./modules {
localFlake = self;
inherit withSystem;
};
homeManagerModules.default = importApply ./homeManagerModules {
localFlake = self;
inherit withSystem;
};
# nixosConfigurations = import ./nixosConfigurations { localFlake = self; inherit inputs; }; # TODO: restore
localLib = import ./lib { localFlake = self; };
};
}
);
}