My nixos configuration
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial version of the switcher

+573
+4
flake.nix
··· 55 55 self.packages.x86_64-linux.rnix-lsp 56 56 self.packages.x86_64-linux.statix 57 57 self.packages.x86_64-linux.alejandra 58 + pkgs.rust-analyzer 59 + pkgs.rustc 60 + pkgs.cargo 61 + pkgs.rustfmt 58 62 ]; 59 63 }; 60 64 };
+1
packages/default.nix
··· 21 21 "elixir-lsp" = upkgs.beam.packages.erlang.callPackage ./elixir-lsp {}; 22 22 "erlang-ls" = upkgs.beam.packages.erlang.callPackage ./erlang-ls {}; 23 23 "rofi/unicode" = upkgs.callPackage ./rofi-unicode {}; 24 + "switcher" = upkgs.callPackage ./switcher {}; 24 25 "zx" = upkgs.nodePackages.zx; 25 26 "angular" = nodePkgs."@angular/cli"; 26 27
+1
packages/switcher/.gitignore
··· 1 + target
+460
packages/switcher/Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 3 4 + 5 + [[package]] 6 + name = "autocfg" 7 + version = "1.1.0" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 10 + 11 + [[package]] 12 + name = "bitflags" 13 + version = "1.3.2" 14 + source = "registry+https://github.com/rust-lang/crates.io-index" 15 + checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 16 + 17 + [[package]] 18 + name = "bytes" 19 + version = "1.1.0" 20 + source = "registry+https://github.com/rust-lang/crates.io-index" 21 + checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" 22 + 23 + [[package]] 24 + name = "cfg-if" 25 + version = "1.0.0" 26 + source = "registry+https://github.com/rust-lang/crates.io-index" 27 + checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 28 + 29 + [[package]] 30 + name = "futures" 31 + version = "0.3.21" 32 + source = "registry+https://github.com/rust-lang/crates.io-index" 33 + checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" 34 + dependencies = [ 35 + "futures-channel", 36 + "futures-core", 37 + "futures-executor", 38 + "futures-io", 39 + "futures-sink", 40 + "futures-task", 41 + "futures-util", 42 + ] 43 + 44 + [[package]] 45 + name = "futures-channel" 46 + version = "0.3.21" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" 49 + dependencies = [ 50 + "futures-core", 51 + "futures-sink", 52 + ] 53 + 54 + [[package]] 55 + name = "futures-core" 56 + version = "0.3.21" 57 + source = "registry+https://github.com/rust-lang/crates.io-index" 58 + checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" 59 + 60 + [[package]] 61 + name = "futures-executor" 62 + version = "0.3.21" 63 + source = "registry+https://github.com/rust-lang/crates.io-index" 64 + checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" 65 + dependencies = [ 66 + "futures-core", 67 + "futures-task", 68 + "futures-util", 69 + ] 70 + 71 + [[package]] 72 + name = "futures-io" 73 + version = "0.3.21" 74 + source = "registry+https://github.com/rust-lang/crates.io-index" 75 + checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" 76 + 77 + [[package]] 78 + name = "futures-macro" 79 + version = "0.3.21" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" 82 + dependencies = [ 83 + "proc-macro2", 84 + "quote", 85 + "syn", 86 + ] 87 + 88 + [[package]] 89 + name = "futures-sink" 90 + version = "0.3.21" 91 + source = "registry+https://github.com/rust-lang/crates.io-index" 92 + checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" 93 + 94 + [[package]] 95 + name = "futures-task" 96 + version = "0.3.21" 97 + source = "registry+https://github.com/rust-lang/crates.io-index" 98 + checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" 99 + 100 + [[package]] 101 + name = "futures-util" 102 + version = "0.3.21" 103 + source = "registry+https://github.com/rust-lang/crates.io-index" 104 + checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" 105 + dependencies = [ 106 + "futures-channel", 107 + "futures-core", 108 + "futures-io", 109 + "futures-macro", 110 + "futures-sink", 111 + "futures-task", 112 + "memchr", 113 + "pin-project-lite", 114 + "pin-utils", 115 + "slab", 116 + ] 117 + 118 + [[package]] 119 + name = "hermit-abi" 120 + version = "0.1.19" 121 + source = "registry+https://github.com/rust-lang/crates.io-index" 122 + checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 123 + dependencies = [ 124 + "libc", 125 + ] 126 + 127 + [[package]] 128 + name = "itoa" 129 + version = "1.0.1" 130 + source = "registry+https://github.com/rust-lang/crates.io-index" 131 + checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" 132 + 133 + [[package]] 134 + name = "libc" 135 + version = "0.2.121" 136 + source = "registry+https://github.com/rust-lang/crates.io-index" 137 + checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" 138 + 139 + [[package]] 140 + name = "lock_api" 141 + version = "0.4.7" 142 + source = "registry+https://github.com/rust-lang/crates.io-index" 143 + checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" 144 + dependencies = [ 145 + "autocfg", 146 + "scopeguard", 147 + ] 148 + 149 + [[package]] 150 + name = "log" 151 + version = "0.4.16" 152 + source = "registry+https://github.com/rust-lang/crates.io-index" 153 + checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" 154 + dependencies = [ 155 + "cfg-if", 156 + ] 157 + 158 + [[package]] 159 + name = "memchr" 160 + version = "2.4.1" 161 + source = "registry+https://github.com/rust-lang/crates.io-index" 162 + checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 163 + 164 + [[package]] 165 + name = "mio" 166 + version = "0.8.2" 167 + source = "registry+https://github.com/rust-lang/crates.io-index" 168 + checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" 169 + dependencies = [ 170 + "libc", 171 + "log", 172 + "miow", 173 + "ntapi", 174 + "wasi", 175 + "winapi", 176 + ] 177 + 178 + [[package]] 179 + name = "miow" 180 + version = "0.3.7" 181 + source = "registry+https://github.com/rust-lang/crates.io-index" 182 + checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 183 + dependencies = [ 184 + "winapi", 185 + ] 186 + 187 + [[package]] 188 + name = "ntapi" 189 + version = "0.3.7" 190 + source = "registry+https://github.com/rust-lang/crates.io-index" 191 + checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" 192 + dependencies = [ 193 + "winapi", 194 + ] 195 + 196 + [[package]] 197 + name = "num_cpus" 198 + version = "1.13.1" 199 + source = "registry+https://github.com/rust-lang/crates.io-index" 200 + checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" 201 + dependencies = [ 202 + "hermit-abi", 203 + "libc", 204 + ] 205 + 206 + [[package]] 207 + name = "once_cell" 208 + version = "1.10.0" 209 + source = "registry+https://github.com/rust-lang/crates.io-index" 210 + checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" 211 + 212 + [[package]] 213 + name = "parking_lot" 214 + version = "0.12.0" 215 + source = "registry+https://github.com/rust-lang/crates.io-index" 216 + checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" 217 + dependencies = [ 218 + "lock_api", 219 + "parking_lot_core", 220 + ] 221 + 222 + [[package]] 223 + name = "parking_lot_core" 224 + version = "0.9.2" 225 + source = "registry+https://github.com/rust-lang/crates.io-index" 226 + checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37" 227 + dependencies = [ 228 + "cfg-if", 229 + "libc", 230 + "redox_syscall", 231 + "smallvec", 232 + "windows-sys", 233 + ] 234 + 235 + [[package]] 236 + name = "pin-project-lite" 237 + version = "0.2.8" 238 + source = "registry+https://github.com/rust-lang/crates.io-index" 239 + checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" 240 + 241 + [[package]] 242 + name = "pin-utils" 243 + version = "0.1.0" 244 + source = "registry+https://github.com/rust-lang/crates.io-index" 245 + checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 246 + 247 + [[package]] 248 + name = "proc-macro2" 249 + version = "1.0.36" 250 + source = "registry+https://github.com/rust-lang/crates.io-index" 251 + checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 252 + dependencies = [ 253 + "unicode-xid", 254 + ] 255 + 256 + [[package]] 257 + name = "quote" 258 + version = "1.0.17" 259 + source = "registry+https://github.com/rust-lang/crates.io-index" 260 + checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58" 261 + dependencies = [ 262 + "proc-macro2", 263 + ] 264 + 265 + [[package]] 266 + name = "redox_syscall" 267 + version = "0.2.13" 268 + source = "registry+https://github.com/rust-lang/crates.io-index" 269 + checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" 270 + dependencies = [ 271 + "bitflags", 272 + ] 273 + 274 + [[package]] 275 + name = "ryu" 276 + version = "1.0.9" 277 + source = "registry+https://github.com/rust-lang/crates.io-index" 278 + checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" 279 + 280 + [[package]] 281 + name = "scopeguard" 282 + version = "1.1.0" 283 + source = "registry+https://github.com/rust-lang/crates.io-index" 284 + checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 285 + 286 + [[package]] 287 + name = "serde" 288 + version = "1.0.136" 289 + source = "registry+https://github.com/rust-lang/crates.io-index" 290 + checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" 291 + 292 + [[package]] 293 + name = "serde_json" 294 + version = "1.0.79" 295 + source = "registry+https://github.com/rust-lang/crates.io-index" 296 + checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" 297 + dependencies = [ 298 + "itoa", 299 + "ryu", 300 + "serde", 301 + ] 302 + 303 + [[package]] 304 + name = "signal-hook-registry" 305 + version = "1.4.0" 306 + source = "registry+https://github.com/rust-lang/crates.io-index" 307 + checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" 308 + dependencies = [ 309 + "libc", 310 + ] 311 + 312 + [[package]] 313 + name = "slab" 314 + version = "0.4.6" 315 + source = "registry+https://github.com/rust-lang/crates.io-index" 316 + checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" 317 + 318 + [[package]] 319 + name = "smallvec" 320 + version = "1.8.0" 321 + source = "registry+https://github.com/rust-lang/crates.io-index" 322 + checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" 323 + 324 + [[package]] 325 + name = "socket2" 326 + version = "0.4.4" 327 + source = "registry+https://github.com/rust-lang/crates.io-index" 328 + checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" 329 + dependencies = [ 330 + "libc", 331 + "winapi", 332 + ] 333 + 334 + [[package]] 335 + name = "switcher" 336 + version = "0.1.0" 337 + dependencies = [ 338 + "futures", 339 + "serde_json", 340 + "tokio", 341 + ] 342 + 343 + [[package]] 344 + name = "syn" 345 + version = "1.0.90" 346 + source = "registry+https://github.com/rust-lang/crates.io-index" 347 + checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f" 348 + dependencies = [ 349 + "proc-macro2", 350 + "quote", 351 + "unicode-xid", 352 + ] 353 + 354 + [[package]] 355 + name = "tokio" 356 + version = "1.17.0" 357 + source = "registry+https://github.com/rust-lang/crates.io-index" 358 + checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" 359 + dependencies = [ 360 + "bytes", 361 + "libc", 362 + "memchr", 363 + "mio", 364 + "num_cpus", 365 + "once_cell", 366 + "parking_lot", 367 + "pin-project-lite", 368 + "signal-hook-registry", 369 + "socket2", 370 + "tokio-macros", 371 + "winapi", 372 + ] 373 + 374 + [[package]] 375 + name = "tokio-macros" 376 + version = "1.7.0" 377 + source = "registry+https://github.com/rust-lang/crates.io-index" 378 + checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" 379 + dependencies = [ 380 + "proc-macro2", 381 + "quote", 382 + "syn", 383 + ] 384 + 385 + [[package]] 386 + name = "unicode-xid" 387 + version = "0.2.2" 388 + source = "registry+https://github.com/rust-lang/crates.io-index" 389 + checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 390 + 391 + [[package]] 392 + name = "wasi" 393 + version = "0.11.0+wasi-snapshot-preview1" 394 + source = "registry+https://github.com/rust-lang/crates.io-index" 395 + checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 396 + 397 + [[package]] 398 + name = "winapi" 399 + version = "0.3.9" 400 + source = "registry+https://github.com/rust-lang/crates.io-index" 401 + checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 402 + dependencies = [ 403 + "winapi-i686-pc-windows-gnu", 404 + "winapi-x86_64-pc-windows-gnu", 405 + ] 406 + 407 + [[package]] 408 + name = "winapi-i686-pc-windows-gnu" 409 + version = "0.4.0" 410 + source = "registry+https://github.com/rust-lang/crates.io-index" 411 + checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 412 + 413 + [[package]] 414 + name = "winapi-x86_64-pc-windows-gnu" 415 + version = "0.4.0" 416 + source = "registry+https://github.com/rust-lang/crates.io-index" 417 + checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 418 + 419 + [[package]] 420 + name = "windows-sys" 421 + version = "0.34.0" 422 + source = "registry+https://github.com/rust-lang/crates.io-index" 423 + checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825" 424 + dependencies = [ 425 + "windows_aarch64_msvc", 426 + "windows_i686_gnu", 427 + "windows_i686_msvc", 428 + "windows_x86_64_gnu", 429 + "windows_x86_64_msvc", 430 + ] 431 + 432 + [[package]] 433 + name = "windows_aarch64_msvc" 434 + version = "0.34.0" 435 + source = "registry+https://github.com/rust-lang/crates.io-index" 436 + checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" 437 + 438 + [[package]] 439 + name = "windows_i686_gnu" 440 + version = "0.34.0" 441 + source = "registry+https://github.com/rust-lang/crates.io-index" 442 + checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" 443 + 444 + [[package]] 445 + name = "windows_i686_msvc" 446 + version = "0.34.0" 447 + source = "registry+https://github.com/rust-lang/crates.io-index" 448 + checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" 449 + 450 + [[package]] 451 + name = "windows_x86_64_gnu" 452 + version = "0.34.0" 453 + source = "registry+https://github.com/rust-lang/crates.io-index" 454 + checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" 455 + 456 + [[package]] 457 + name = "windows_x86_64_msvc" 458 + version = "0.34.0" 459 + source = "registry+https://github.com/rust-lang/crates.io-index" 460 + checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
+14
packages/switcher/Cargo.toml
··· 1 + [package] 2 + name = "switcher" 3 + version = "0.1.0" 4 + edition = "2021" 5 + 6 + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 + 8 + [dependencies] 9 + serde_json = "1" 10 + futures = "0.3" 11 + 12 + [dependencies.tokio] 13 + version = "1" 14 + features = ["full"]
+9
packages/switcher/default.nix
··· 1 + {rustPlatform}: 2 + rustPlatform.buildRustPackage { 3 + pname = "nobbz-switcher"; 4 + version = "0.1.0"; 5 + 6 + src = ./.; 7 + 8 + cargoSha256 = "sha256-UWNgqQLWl/WJ1lZEg0arCHzwC06SYPYLNKnBcIxvDmQ="; 9 + }
+84
packages/switcher/src/main.rs
··· 1 + use futures::future; 2 + use std::{error::Error, fmt::Display, io::Error as IoError, path::Path, process::ExitStatus, str}; 3 + use tokio::{self, process::Command}; 4 + 5 + const OWNER: &str = "nobbz"; 6 + const REPO: &str = "nixos-config"; 7 + 8 + const BRANCH: &str = "main"; 9 + 10 + async fn get_command_out(cmd: &mut Command) -> String { 11 + let out = cmd.output().await.unwrap().stdout; 12 + 13 + str::from_utf8(&out).unwrap().trim().to_string() 14 + } 15 + 16 + async fn spawn_command(cmd: &mut Command) -> Result<ExitStatus, IoError> { 17 + cmd.spawn().unwrap().wait().await 18 + } 19 + 20 + async fn retrieve_sha<S1, S2, S3>(owner: S1, repo: S2, branch: S3) -> String 21 + where 22 + S1: Display, 23 + S2: Display, 24 + S3: Display, 25 + { 26 + let endpoint = format!("/repos/{}/{}/commits/{}", owner, repo, branch); 27 + 28 + get_command_out(Command::new("gh").args(["api", &endpoint, "--jq", ".sha"])).await 29 + } 30 + 31 + async fn get_hostname() -> String { 32 + get_command_out(&mut Command::new("hostname")).await 33 + } 34 + 35 + async fn get_username() -> String { 36 + get_command_out(&mut Command::new("whoami")).await 37 + } 38 + 39 + async fn get_tempfldr() -> String { 40 + get_command_out(&mut Command::new("mktemp").arg("-d")).await 41 + } 42 + 43 + #[tokio::main] 44 + async fn main() -> Result<(), Box<dyn Error>> { 45 + let sha1_promise = retrieve_sha(OWNER, REPO, BRANCH); 46 + let host_promise = get_hostname(); 47 + let user_promise = get_username(); 48 + let temp_promise = get_tempfldr(); 49 + 50 + let (sha1, host, user, temp) = 51 + future::join4(sha1_promise, host_promise, user_promise, temp_promise).await; 52 + 53 + let flake_url = format!("github:{}/{}?ref={}", OWNER, REPO, sha1); 54 + let nixos_config = format!("{}#nixos/config/{}", flake_url, host); 55 + let nixos_rebuild = format!("{}#{}", flake_url, host); 56 + let home_config = format!("{}#home/config/{}@{}", flake_url, user, host); 57 + let home_manager = format!("{}#{}@{}", flake_url, user, host); 58 + let out_link = Path::new(&temp).join("result"); 59 + 60 + spawn_command(Command::new("nix").args([ 61 + "build", 62 + "--keep-going", 63 + "-L", 64 + "--out-link", 65 + &out_link.as_os_str().to_str().unwrap(), 66 + &nixos_config, 67 + &home_config, 68 + ])) 69 + .await?; 70 + 71 + spawn_command(Command::new("sudo").args([ 72 + "nixos-rebuild", 73 + "switch", 74 + "--flake", 75 + &nixos_rebuild, 76 + ])) 77 + .await?; 78 + 79 + spawn_command(Command::new("home-manager").args(["switch", "--flake", &home_manager])).await?; 80 + 81 + spawn_command(Command::new("rm").args(["-rfv", &temp])).await?; 82 + 83 + Ok(()) 84 + }