├── .cz.toml ├── .envrc ├── .github └── workflows │ └── build_nix.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── default.nix ├── flake.lock ├── flake.nix ├── shell.nix └── src └── main.rs /.cz.toml: -------------------------------------------------------------------------------- 1 | [tool.commitizen] 2 | name = "cz_conventional_commits" 3 | version_provider = "cargo" 4 | tag_format = "$version" 5 | update_changelog_on_bump = true 6 | major_version_zero = true 7 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /.github/workflows/build_nix.yml: -------------------------------------------------------------------------------- 1 | name: "Build legacy Nix package on Ubuntu" 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: cachix/install-nix-action@v12 12 | - name: Building package 13 | run: nix-build . -A defaultPackage.x86_64-linux 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.0 (2023-05-12) 2 | 3 | ### Feat 4 | 5 | - **install**: display packages when only repo is provided 6 | 7 | ## 0.4.1 (2023-05-12) 8 | 9 | ### Fix 10 | 11 | - **install**: improve help with flake example 12 | 13 | ## 0.4.0 (2023-05-12) 14 | 15 | ### Feat 16 | 17 | - add `--teacher` flag 18 | 19 | ### Fix 20 | 21 | - show aliases in help 22 | 23 | ## 0.3.0 (2023-01-15) 24 | 25 | ### Feat 26 | 27 | - add upgrade cmd 28 | 29 | ## 0.2.1 (2023-01-15) 30 | 31 | ### Fix 32 | 33 | - **install**: improve message dispaly 34 | 35 | ## 0.2.0 (2023-01-14) 36 | 37 | ### Feat 38 | 39 | - add spinner to install command 40 | - add option to remove multiple packages 41 | - add ls 42 | - initial commit 43 | 44 | ### Fix 45 | 46 | - remove references to shell 47 | - attempt to make flake work 48 | - try to fix flake 49 | - add lock 50 | - minor typos 51 | -------------------------------------------------------------------------------- /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 = "aho-corasick" 7 | version = "0.7.20" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "bitflags" 16 | version = "1.3.2" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 19 | 20 | [[package]] 21 | name = "cc" 22 | version = "1.0.78" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" 25 | 26 | [[package]] 27 | name = "clap" 28 | version = "4.0.32" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" 31 | dependencies = [ 32 | "bitflags", 33 | "clap_derive", 34 | "clap_lex", 35 | "is-terminal", 36 | "once_cell", 37 | "strsim", 38 | "termcolor", 39 | ] 40 | 41 | [[package]] 42 | name = "clap_derive" 43 | version = "4.0.21" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" 46 | dependencies = [ 47 | "heck", 48 | "proc-macro-error", 49 | "proc-macro2", 50 | "quote", 51 | "syn", 52 | ] 53 | 54 | [[package]] 55 | name = "clap_lex" 56 | version = "0.3.0" 57 | source = "registry+https://github.com/rust-lang/crates.io-index" 58 | checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" 59 | dependencies = [ 60 | "os_str_bytes", 61 | ] 62 | 63 | [[package]] 64 | name = "console" 65 | version = "0.15.4" 66 | source = "registry+https://github.com/rust-lang/crates.io-index" 67 | checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a" 68 | dependencies = [ 69 | "encode_unicode", 70 | "lazy_static", 71 | "libc", 72 | "unicode-width", 73 | "windows-sys", 74 | ] 75 | 76 | [[package]] 77 | name = "encode_unicode" 78 | version = "0.3.6" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" 81 | 82 | [[package]] 83 | name = "errno" 84 | version = "0.2.8" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" 87 | dependencies = [ 88 | "errno-dragonfly", 89 | "libc", 90 | "winapi", 91 | ] 92 | 93 | [[package]] 94 | name = "errno-dragonfly" 95 | version = "0.1.2" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" 98 | dependencies = [ 99 | "cc", 100 | "libc", 101 | ] 102 | 103 | [[package]] 104 | name = "heck" 105 | version = "0.4.0" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" 108 | 109 | [[package]] 110 | name = "hermit-abi" 111 | version = "0.2.6" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" 114 | dependencies = [ 115 | "libc", 116 | ] 117 | 118 | [[package]] 119 | name = "indicatif" 120 | version = "0.17.2" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "4295cbb7573c16d310e99e713cf9e75101eb190ab31fccd35f2d2691b4352b19" 123 | dependencies = [ 124 | "console", 125 | "number_prefix", 126 | "portable-atomic", 127 | "unicode-width", 128 | ] 129 | 130 | [[package]] 131 | name = "io-lifetimes" 132 | version = "1.0.3" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" 135 | dependencies = [ 136 | "libc", 137 | "windows-sys", 138 | ] 139 | 140 | [[package]] 141 | name = "is-terminal" 142 | version = "0.4.2" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" 145 | dependencies = [ 146 | "hermit-abi", 147 | "io-lifetimes", 148 | "rustix", 149 | "windows-sys", 150 | ] 151 | 152 | [[package]] 153 | name = "itoa" 154 | version = "1.0.6" 155 | source = "registry+https://github.com/rust-lang/crates.io-index" 156 | checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" 157 | 158 | [[package]] 159 | name = "lazy_static" 160 | version = "1.4.0" 161 | source = "registry+https://github.com/rust-lang/crates.io-index" 162 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 163 | 164 | [[package]] 165 | name = "libc" 166 | version = "0.2.139" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" 169 | 170 | [[package]] 171 | name = "linux-raw-sys" 172 | version = "0.1.4" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" 175 | 176 | [[package]] 177 | name = "memchr" 178 | version = "2.5.0" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 181 | 182 | [[package]] 183 | name = "npt" 184 | version = "0.4.1" 185 | dependencies = [ 186 | "clap", 187 | "indicatif", 188 | "regex", 189 | "serde_json", 190 | ] 191 | 192 | [[package]] 193 | name = "number_prefix" 194 | version = "0.4.0" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" 197 | 198 | [[package]] 199 | name = "once_cell" 200 | version = "1.17.0" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" 203 | 204 | [[package]] 205 | name = "os_str_bytes" 206 | version = "6.4.1" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" 209 | 210 | [[package]] 211 | name = "portable-atomic" 212 | version = "0.3.19" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | checksum = "26f6a7b87c2e435a3241addceeeff740ff8b7e76b74c13bf9acb17fa454ea00b" 215 | 216 | [[package]] 217 | name = "proc-macro-error" 218 | version = "1.0.4" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 221 | dependencies = [ 222 | "proc-macro-error-attr", 223 | "proc-macro2", 224 | "quote", 225 | "syn", 226 | "version_check", 227 | ] 228 | 229 | [[package]] 230 | name = "proc-macro-error-attr" 231 | version = "1.0.4" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 234 | dependencies = [ 235 | "proc-macro2", 236 | "quote", 237 | "version_check", 238 | ] 239 | 240 | [[package]] 241 | name = "proc-macro2" 242 | version = "1.0.49" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" 245 | dependencies = [ 246 | "unicode-ident", 247 | ] 248 | 249 | [[package]] 250 | name = "quote" 251 | version = "1.0.23" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" 254 | dependencies = [ 255 | "proc-macro2", 256 | ] 257 | 258 | [[package]] 259 | name = "regex" 260 | version = "1.7.1" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" 263 | dependencies = [ 264 | "aho-corasick", 265 | "memchr", 266 | "regex-syntax", 267 | ] 268 | 269 | [[package]] 270 | name = "regex-syntax" 271 | version = "0.6.28" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" 274 | 275 | [[package]] 276 | name = "rustix" 277 | version = "0.36.6" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" 280 | dependencies = [ 281 | "bitflags", 282 | "errno", 283 | "io-lifetimes", 284 | "libc", 285 | "linux-raw-sys", 286 | "windows-sys", 287 | ] 288 | 289 | [[package]] 290 | name = "ryu" 291 | version = "1.0.13" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" 294 | 295 | [[package]] 296 | name = "serde" 297 | version = "1.0.163" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" 300 | 301 | [[package]] 302 | name = "serde_json" 303 | version = "1.0.96" 304 | source = "registry+https://github.com/rust-lang/crates.io-index" 305 | checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" 306 | dependencies = [ 307 | "itoa", 308 | "ryu", 309 | "serde", 310 | ] 311 | 312 | [[package]] 313 | name = "strsim" 314 | version = "0.10.0" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 317 | 318 | [[package]] 319 | name = "syn" 320 | version = "1.0.107" 321 | source = "registry+https://github.com/rust-lang/crates.io-index" 322 | checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" 323 | dependencies = [ 324 | "proc-macro2", 325 | "quote", 326 | "unicode-ident", 327 | ] 328 | 329 | [[package]] 330 | name = "termcolor" 331 | version = "1.1.3" 332 | source = "registry+https://github.com/rust-lang/crates.io-index" 333 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 334 | dependencies = [ 335 | "winapi-util", 336 | ] 337 | 338 | [[package]] 339 | name = "unicode-ident" 340 | version = "1.0.6" 341 | source = "registry+https://github.com/rust-lang/crates.io-index" 342 | checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" 343 | 344 | [[package]] 345 | name = "unicode-width" 346 | version = "0.1.10" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" 349 | 350 | [[package]] 351 | name = "version_check" 352 | version = "0.9.4" 353 | source = "registry+https://github.com/rust-lang/crates.io-index" 354 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 355 | 356 | [[package]] 357 | name = "winapi" 358 | version = "0.3.9" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 361 | dependencies = [ 362 | "winapi-i686-pc-windows-gnu", 363 | "winapi-x86_64-pc-windows-gnu", 364 | ] 365 | 366 | [[package]] 367 | name = "winapi-i686-pc-windows-gnu" 368 | version = "0.4.0" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 371 | 372 | [[package]] 373 | name = "winapi-util" 374 | version = "0.1.5" 375 | source = "registry+https://github.com/rust-lang/crates.io-index" 376 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 377 | dependencies = [ 378 | "winapi", 379 | ] 380 | 381 | [[package]] 382 | name = "winapi-x86_64-pc-windows-gnu" 383 | version = "0.4.0" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 386 | 387 | [[package]] 388 | name = "windows-sys" 389 | version = "0.42.0" 390 | source = "registry+https://github.com/rust-lang/crates.io-index" 391 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 392 | dependencies = [ 393 | "windows_aarch64_gnullvm", 394 | "windows_aarch64_msvc", 395 | "windows_i686_gnu", 396 | "windows_i686_msvc", 397 | "windows_x86_64_gnu", 398 | "windows_x86_64_gnullvm", 399 | "windows_x86_64_msvc", 400 | ] 401 | 402 | [[package]] 403 | name = "windows_aarch64_gnullvm" 404 | version = "0.42.0" 405 | source = "registry+https://github.com/rust-lang/crates.io-index" 406 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 407 | 408 | [[package]] 409 | name = "windows_aarch64_msvc" 410 | version = "0.42.0" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 413 | 414 | [[package]] 415 | name = "windows_i686_gnu" 416 | version = "0.42.0" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 419 | 420 | [[package]] 421 | name = "windows_i686_msvc" 422 | version = "0.42.0" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 425 | 426 | [[package]] 427 | name = "windows_x86_64_gnu" 428 | version = "0.42.0" 429 | source = "registry+https://github.com/rust-lang/crates.io-index" 430 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 431 | 432 | [[package]] 433 | name = "windows_x86_64_gnullvm" 434 | version = "0.42.0" 435 | source = "registry+https://github.com/rust-lang/crates.io-index" 436 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 437 | 438 | [[package]] 439 | name = "windows_x86_64_msvc" 440 | version = "0.42.0" 441 | source = "registry+https://github.com/rust-lang/crates.io-index" 442 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 443 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "npt" 3 | description = "Nix Package Tool" 4 | version = "0.5.0" 5 | edition = "2021" 6 | authors = ["Santiago Fraire Willemoës "] 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | clap = { version = "4.0.32", features = ["derive"] } 11 | indicatif = "0.17.2" 12 | regex = "1.7.1" 13 | serde_json = "1.0.96" 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NPT 2 | 3 | > Nix Package Tool 4 | 5 | A (humble) successor to linux's `apt`, which makes life easier when using [nix](https://nixos.org/) as a package manager. 6 | 7 | This is a tool I'm using in my nix journey, it's supposed to ease the transition from other 8 | package managers to nix. 9 | 10 | The idea is to use [nix profiles](https://nixos.org/manual/nix/stable/package-management/profiles.html) in the way you'd use `apt` or `brew`. 11 | 12 | It is a work in progress, but feel free to play with it. 13 | 14 | ## Requirements 15 | 16 | - Install [nix the package manager](https://nixos.org/download.html) 17 | - [Enable flakes](https://nixos.wiki/wiki/Flakes#Enable_flakes) 18 | 19 | Or just use the [nix installer](https://github.com/DeterminateSystems/nix-installer) 20 | 21 | ```sh 22 | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install 23 | ``` 24 | 25 | ## Goals 26 | 27 | - Help the transition from traditional package managers (`apt`, `brew`, `pacman`, etc) to nix 28 | - Good and intuitive UX 29 | - Learn nix while using, this can display the commands executed `npt --teacher install ` 30 | 31 | ## Installation 32 | 33 | ```sh 34 | nix profile install 'github:woile/npt#npt' 35 | ``` 36 | 37 | ## Usage 38 | 39 | ```$ npt --help 40 | Nix Package Tool 41 | 42 | Usage: npt [OPTIONS] 43 | 44 | Commands: 45 | install Install packages for the profile, if no repository provided, it defaults to nixpkgs [aliases: i] 46 | list List installed packages [aliases: ls] 47 | upgrade Update all or specific packages [aliases: u] 48 | search Find a package in the registry, if no repository provided, it defaults to nixpkgs [aliases: s] 49 | remove Remove one or more packages [aliases: rm] 50 | help Print this message or the help of the given subcommand(s) 51 | 52 | Options: 53 | -t, --teacher 54 | -h, --help Print help information 55 | -V, --version Print version information 56 | ``` 57 | 58 | ## TODO 59 | 60 | - [ ] How to make search accept a repo only? 61 | - [ ] How to make search accept a regex? 62 | - [ ] Accept a package or expression in the List command 63 | - [ ] Implement `update` command 64 | - [ ] provide compiled tar's to speed up flakes 65 | 66 | ## Contributing 67 | 68 | 1. Make changes 69 | 2. Create a git commit 70 | 3. Run 71 | 72 | ```sh 73 | nix flake update 74 | ``` 75 | 76 | 4. Create a git commit -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | (import ( 2 | fetchTarball { 3 | url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; 4 | sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } 5 | ) { 6 | src = ./.; 7 | }).defaultNix 8 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "naersk": { 4 | "inputs": { 5 | "nixpkgs": "nixpkgs" 6 | }, 7 | "locked": { 8 | "lastModified": 1679567394, 9 | "narHash": "sha256-ZvLuzPeARDLiQUt6zSZFGOs+HZmE+3g4QURc8mkBsfM=", 10 | "owner": "nix-community", 11 | "repo": "naersk", 12 | "rev": "88cd22380154a2c36799fe8098888f0f59861a15", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "nix-community", 17 | "ref": "master", 18 | "repo": "naersk", 19 | "type": "github" 20 | } 21 | }, 22 | "nixpkgs": { 23 | "locked": { 24 | "lastModified": 1683777345, 25 | "narHash": "sha256-V2p/A4RpEGqEZussOnHYMU6XglxBJGCODdzoyvcwig8=", 26 | "owner": "NixOS", 27 | "repo": "nixpkgs", 28 | "rev": "635a306fc8ede2e34cb3dd0d6d0a5d49362150ed", 29 | "type": "github" 30 | }, 31 | "original": { 32 | "id": "nixpkgs", 33 | "type": "indirect" 34 | } 35 | }, 36 | "nixpkgs_2": { 37 | "locked": { 38 | "lastModified": 1683777345, 39 | "narHash": "sha256-V2p/A4RpEGqEZussOnHYMU6XglxBJGCODdzoyvcwig8=", 40 | "owner": "NixOS", 41 | "repo": "nixpkgs", 42 | "rev": "635a306fc8ede2e34cb3dd0d6d0a5d49362150ed", 43 | "type": "github" 44 | }, 45 | "original": { 46 | "owner": "NixOS", 47 | "ref": "nixpkgs-unstable", 48 | "repo": "nixpkgs", 49 | "type": "github" 50 | } 51 | }, 52 | "root": { 53 | "inputs": { 54 | "naersk": "naersk", 55 | "nixpkgs": "nixpkgs_2", 56 | "utils": "utils" 57 | } 58 | }, 59 | "systems": { 60 | "locked": { 61 | "lastModified": 1681028828, 62 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 63 | "owner": "nix-systems", 64 | "repo": "default", 65 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 66 | "type": "github" 67 | }, 68 | "original": { 69 | "owner": "nix-systems", 70 | "repo": "default", 71 | "type": "github" 72 | } 73 | }, 74 | "utils": { 75 | "inputs": { 76 | "systems": "systems" 77 | }, 78 | "locked": { 79 | "lastModified": 1681202837, 80 | "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", 81 | "owner": "numtide", 82 | "repo": "flake-utils", 83 | "rev": "cfacdce06f30d2b68473a46042957675eebb3401", 84 | "type": "github" 85 | }, 86 | "original": { 87 | "owner": "numtide", 88 | "repo": "flake-utils", 89 | "type": "github" 90 | } 91 | } 92 | }, 93 | "root": "root", 94 | "version": 7 95 | } 96 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | naersk.url = "github:nix-community/naersk/master"; 4 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 5 | utils.url = "github:numtide/flake-utils"; 6 | }; 7 | 8 | outputs = { self, nixpkgs, utils, naersk }: 9 | utils.lib.eachDefaultSystem (system: 10 | let 11 | cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); 12 | pkgs = import nixpkgs { inherit system; }; 13 | naersk-lib = pkgs.callPackage naersk { }; 14 | in 15 | { 16 | packages.npt = naersk-lib.buildPackage ./.; 17 | defaultPackage = naersk-lib.buildPackage ./.; 18 | 19 | devShell = with pkgs; mkShell { 20 | buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ]; 21 | RUST_SRC_PATH = rustPlatform.rustLibSrc; 22 | shellHook = '' 23 | $SHELL 24 | ''; 25 | }; 26 | 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | (import ( 2 | fetchTarball { 3 | url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; 4 | sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } 5 | ) { 6 | src = ./.; 7 | }).shellNix 8 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::{Parser, Subcommand}; 2 | use indicatif::{ProgressBar, ProgressStyle}; 3 | use serde_json::Value; 4 | use std::borrow::Cow; 5 | use std::ffi::OsStr; 6 | use std::fmt::{Debug, Display}; 7 | use std::io::{self, BufRead, BufReader}; 8 | 9 | use std::process::{exit, Command, Stdio}; 10 | use std::time::Duration; 11 | 12 | #[derive(Parser, Debug)] 13 | #[command(author, version, about)] 14 | struct Cli { 15 | #[clap(short, long, alias = "t")] 16 | teacher: bool, 17 | 18 | #[command(subcommand)] 19 | command: Commands, 20 | } 21 | 22 | #[derive(Debug, Subcommand)] 23 | enum Commands { 24 | /// Install packages for the current profile 25 | /// 26 | /// If no repository provided, it defaults to nixpkgs 27 | /// 28 | /// In order to install a flake you need to provide the repository + package name, 29 | /// separated by `#`. 30 | /// 31 | /// For example, to install `wpa_passphrase` from https://github.com/woile/wpa_passphrase_rs 32 | /// 33 | /// `npt i github:woile/wpa_passphrase_rs#wpa_passphrase` 34 | /// 35 | /// You can also show the available packages in a flake, given you 36 | /// end it with `#` 37 | /// 38 | /// `npt i github:nix-community/nurl#` 39 | #[command(arg_required_else_help = true, visible_alias = "i")] 40 | Install { 41 | /// Name of packages, optionally preceeded by the repository#. Examples: `htop`, `nixpkgs#htop` 42 | packages: Vec, 43 | }, 44 | 45 | /// List installed packages 46 | #[command(visible_alias = "ls")] 47 | List, 48 | 49 | /// Update all or specific packages 50 | #[command(visible_alias = "u")] 51 | Upgrade, 52 | // { 53 | // /// Name of packages, optionally preceeded by the repository#. Examples: `htop`, `nixpkgs#htop` 54 | // packages: Option> 55 | // }, 56 | /// Find a package in the registry, if no repository provided, it defaults to nixpkgs 57 | #[command(arg_required_else_help = true, visible_alias = "s")] 58 | Search { 59 | /// Regex used to find the package. Examples: `nixpkgs#gnome3` or `gnome3` 60 | package: Package, 61 | }, 62 | 63 | /// Remove one or more packages 64 | #[command(arg_required_else_help = true, visible_alias = "rm")] 65 | Remove { packages: Vec }, 66 | } 67 | 68 | /// Package can follow the format repo#name or just the name 69 | #[derive(Debug, Clone, PartialEq)] 70 | struct Package { 71 | repo: String, 72 | name: String, 73 | fullname: String, 74 | } 75 | 76 | impl Package { 77 | fn is_just_repo(&self) -> bool { 78 | self.name.is_empty() 79 | } 80 | } 81 | 82 | impl Display for Package { 83 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 84 | write!(f, "{}", self.fullname) 85 | } 86 | } 87 | 88 | impl> From for Package { 89 | fn from(name: T) -> Self { 90 | let items: Vec<&str> = name.as_ref().split("#").collect(); 91 | let is_just_repo = name.as_ref().trim().ends_with("#"); 92 | if items.len() == 1 && !is_just_repo { 93 | let name = items 94 | .get(0) 95 | .cloned() 96 | .expect("Error while processing the package name"); 97 | 98 | return Self { 99 | repo: "nixpkgs".into(), 100 | name: name.into(), 101 | fullname: format!("nixpkgs#{name}"), 102 | }; 103 | } else if is_just_repo { 104 | let repo = items 105 | .get(0) 106 | .cloned() 107 | .expect("Error while processing repository"); 108 | 109 | return Self { 110 | repo: repo.into(), 111 | name: String::new(), 112 | fullname: format!("{repo}"), 113 | }; 114 | } 115 | 116 | let repo = items 117 | .get(0) 118 | .cloned() 119 | .expect("Error while processing repository"); 120 | 121 | let name = items 122 | .get(1) 123 | .cloned() 124 | .expect("Error while processing the package name"); 125 | 126 | return Self { 127 | repo: repo.into(), 128 | name: name.into(), 129 | fullname: format!("{repo}#{name}"), 130 | }; 131 | } 132 | } 133 | impl Into for Package { 134 | fn into(self) -> String { 135 | return format!("{}#{}", self.repo, self.name); 136 | } 137 | } 138 | 139 | impl AsRef for Package { 140 | fn as_ref(&self) -> &OsStr { 141 | &OsStr::new(&self.fullname) 142 | } 143 | } 144 | 145 | #[derive(Debug, Clone, PartialEq)] 146 | struct ListedPackage { 147 | position: String, 148 | store_path: String, 149 | } 150 | 151 | impl ListedPackage { 152 | fn new(position: String, store_path: String) -> Self { 153 | Self { 154 | position, 155 | store_path, 156 | } 157 | } 158 | } 159 | 160 | fn main() { 161 | let args = Cli::parse(); 162 | let is_teacher = args.teacher; 163 | let cmd = Command::new("nix").arg("--version").output(); 164 | if let Err(_) = cmd { 165 | println!("`nix` the package manager not found in your system.\n"); 166 | println!("Installation:"); 167 | println!("\thttps://nixos.org/download.html"); 168 | exit(1); 169 | } 170 | 171 | let spinner_style = ProgressStyle::with_template("{prefix:.bold.dim}{spinner} {wide_msg}") 172 | .unwrap() 173 | .tick_chars("⠁⠂⠄⠠⠐⠈ "); 174 | 175 | match args.command { 176 | Commands::Install { packages } => { 177 | println!("Installing package(s)...\n"); 178 | 179 | let justrepos = Vec::from_iter(packages.iter().filter(|p| p.is_just_repo()).to_owned()); 180 | 181 | if justrepos.len() > 0 { 182 | let mut cmd = Command::new("nix"); 183 | cmd.arg("eval") 184 | .arg("--impure") 185 | .arg("--raw") 186 | .arg("--expr") 187 | .arg("builtins.currentSystem") 188 | .stdout(Stdio::piped()) 189 | .stderr(Stdio::piped()) 190 | .stdin(Stdio::null()); 191 | let child = cmd.spawn().expect("nix command failed to run."); 192 | let output = child.wait_with_output().expect("Could not wait command"); 193 | let arch = String::from_utf8_lossy(&output.stdout); 194 | 195 | for package_repo in justrepos { 196 | let mut cmd = Command::new("nix"); 197 | cmd.arg("flake") 198 | .arg("show") 199 | .args(&[&package_repo]) 200 | .args(&["--json"]) 201 | .stdout(Stdio::piped()) 202 | .stderr(Stdio::piped()) 203 | .stdin(Stdio::null()); 204 | eprintln!("Available packages for '{package_repo}'\n"); 205 | let child = cmd.spawn().expect("nix command failed to run."); 206 | let output = child.wait_with_output().expect("Could not wait command"); 207 | 208 | let v: Value = serde_json::from_str(&String::from_utf8_lossy(&output.stdout)) 209 | .expect("Could not parse"); 210 | if output.status.success() { 211 | // let packages_for_arch = ]; 212 | if let Value::Object(map) = &v["packages"][arch.as_ref()] { 213 | for (key, value) in map { 214 | println!("- {}: {}", key, value["name"]); 215 | } 216 | } 217 | println!(""); 218 | // println!("V: {}", ); 219 | // eprintln!("{}", String::from_utf8_lossy(&output.stdout)); 220 | } else { 221 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 222 | } 223 | } 224 | 225 | exit(2); 226 | } 227 | 228 | let mut cmd = Command::new("nix"); 229 | cmd.arg("profile") 230 | .arg("install") 231 | .args(&packages) 232 | .stdout(Stdio::piped()) 233 | .stderr(Stdio::piped()) 234 | .stdin(Stdio::null()); 235 | 236 | if is_teacher { 237 | let string_cmd = command_as_string(&cmd); 238 | println!("Learn mode on!"); 239 | println!("Nix command created:"); 240 | println!("\n\t{string_cmd}\n"); 241 | } 242 | 243 | let mut child = cmd.spawn().expect("nix command failed to run."); 244 | let pkgs = packages 245 | .into_iter() 246 | .map(|p| p.into()) 247 | .collect::>() 248 | .join(" "); 249 | let pb = ProgressBar::new_spinner(); 250 | pb.enable_steady_tick(Duration::from_millis(300)); 251 | pb.set_style(spinner_style.clone()); 252 | pb.set_message(pkgs.to_owned()); 253 | for line in BufReader::new(child.stderr.take().unwrap()).lines() { 254 | let line = line.unwrap(); 255 | let stripped_line = line.trim(); 256 | if !stripped_line.is_empty() { 257 | pb.set_message(stripped_line.to_owned()); 258 | } 259 | pb.tick(); 260 | } 261 | 262 | let output = child.wait_with_output().expect("Could not wait command"); 263 | if output.status.success() { 264 | println!("{}", String::from_utf8_lossy(&output.stdout)); 265 | } else { 266 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 267 | } 268 | } 269 | Commands::Search { package } => { 270 | let mut cmd = Command::new("nix"); 271 | cmd.arg("search") 272 | .arg(&package.fullname) 273 | .stdout(Stdio::piped()) 274 | .stderr(Stdio::piped()) 275 | .stdin(Stdio::null()); 276 | if is_teacher { 277 | let string_cmd = command_as_string(&cmd); 278 | println!("Learn mode on!"); 279 | println!("Nix command created:"); 280 | println!("\n\t{string_cmd}\n"); 281 | } 282 | println!("Searching for the package `{}`...\n", &package); 283 | let child = cmd.spawn().expect("nix command failed to run."); 284 | let output = child.wait_with_output().expect("Could not wait command"); 285 | if output.status.success() { 286 | println!("{}", String::from_utf8_lossy(&output.stdout)); 287 | } else { 288 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 289 | } 290 | } 291 | Commands::Remove { packages } => { 292 | let mut cmd = Command::new("nix"); 293 | cmd.arg("profile") 294 | .arg("list") 295 | .stdout(Stdio::piped()) 296 | .stderr(Stdio::piped()) 297 | .stdin(Stdio::null()); 298 | if is_teacher { 299 | let string_cmd = command_as_string(&cmd); 300 | println!("Learn mode on!"); 301 | println!("Nix command created:"); 302 | println!("\n\t{string_cmd}\n"); 303 | } 304 | println!("Checking installed packages..."); 305 | let out = cmd.output().expect("`nix profile list` failed to run."); 306 | let found = String::from_utf8(out.stdout).expect("Failed to parse strings"); 307 | let found_pkgs = found 308 | .split("\n") 309 | .filter_map(|pkg| { 310 | let chunks = pkg.split_whitespace().take(4).collect::>(); 311 | if let [position, _, _, store_path] = chunks[..] { 312 | let keep = packages.iter().any(|p| store_path.contains(&p.name)); 313 | if !keep { 314 | return None; 315 | } 316 | // let pos = position.trim().to_string().parse::().expect("Not a number"); 317 | return Some(ListedPackage::new( 318 | position.trim().to_string(), 319 | store_path.to_string(), 320 | )); 321 | } 322 | return None; 323 | }) 324 | .collect::>(); 325 | if found_pkgs.len() == 0 { 326 | println!("Package not found"); 327 | exit(0); 328 | } 329 | println!("Packages found\n"); 330 | println!("Position\tStore Path"); 331 | for pkg in found_pkgs.iter() { 332 | println!("{}\t\t{}", pkg.position, pkg.store_path); 333 | } 334 | println!("\nWhat do you want to do next?"); 335 | println!("Remove [a]ll, [n]one, or space separated positions [int]: "); 336 | // NEXT: Add by position[int], or by keep only [!int] 337 | // println!("Type your answer:"); 338 | let mut buffer = String::new(); 339 | let stdin = io::stdin(); // We get `Stdin` here. 340 | stdin 341 | .read_line(&mut buffer) 342 | .expect("Could not read user input"); 343 | 344 | let option = buffer.to_lowercase(); 345 | 346 | match option.trim() { 347 | "a" => { 348 | println!("Removing all found packages..."); 349 | let positions = found_pkgs 350 | .iter() 351 | .map(|p| p.position.as_ref()) 352 | .collect::>(); 353 | let mut cmd = Command::new("nix"); 354 | cmd.arg("profile").arg("remove").args(&positions); 355 | if is_teacher { 356 | let string_cmd = command_as_string(&cmd); 357 | 358 | println!("Nix command created:"); 359 | println!("\n\t{string_cmd}\n"); 360 | } 361 | let child = cmd.spawn().expect("nix command failed to run."); 362 | let output = child.wait_with_output().expect("Could not wait command"); 363 | if output.status.success() { 364 | println!("{}", String::from_utf8_lossy(&output.stdout)); 365 | } else { 366 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 367 | } 368 | } 369 | "n" => { 370 | println!("Chosen: none"); 371 | exit(0); 372 | } 373 | _ => { 374 | let positions: Vec = option 375 | .chars() 376 | .filter(|c| c.is_ascii_digit()) 377 | .map(String::from) 378 | .collect(); 379 | println!("Removing packages {}...", option); 380 | 381 | let mut cmd = Command::new("nix"); 382 | cmd.arg("profile").arg("remove").args(&positions); 383 | 384 | if is_teacher { 385 | let string_cmd = command_as_string(&cmd); 386 | println!("Nix command created:"); 387 | println!("\n\t{string_cmd}\n"); 388 | } 389 | let child = cmd.spawn().expect("nix command failed to run."); 390 | let output = child.wait_with_output().expect("Could not wait command"); 391 | if output.status.success() { 392 | println!("{}", String::from_utf8_lossy(&output.stdout)); 393 | } else { 394 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 395 | } 396 | exit(1); 397 | } 398 | } 399 | } 400 | Commands::Upgrade => { 401 | println!("Upgrading all packages..."); 402 | //# nix profile upgrade '.*' 403 | // let items = packages.clone().map_or(vec![".*".to_string()], |pkgs| { 404 | // pkgs.iter() 405 | // .map(|pkg| { 406 | // let escapedrepo = regex::escape(&pkg.repo); 407 | // let escapedpkg = regex::escape(&pkg.name); 408 | // let regex = format!(".*{escapedrepo}.*{escapedpkg}.*"); 409 | // return regex; 410 | // }) 411 | // .collect::>() 412 | // }); 413 | let items = vec![".*".to_string()]; 414 | let mut cmd = Command::new("nix"); 415 | cmd.arg("profile") 416 | .arg("upgrade") 417 | .args(&items) 418 | .stdout(Stdio::piped()) 419 | .stderr(Stdio::piped()) 420 | .stdin(Stdio::null()); 421 | 422 | if is_teacher { 423 | let string_cmd = command_as_string(&cmd); 424 | println!("Learn mode on!"); 425 | println!("Nix command created:"); 426 | println!("\n\t{string_cmd}\n"); 427 | } 428 | let mut child = cmd.spawn().expect("nix command failed to run."); 429 | let pb = ProgressBar::new_spinner(); 430 | // let pkgs = packages 431 | // .map_or(vec![".*".to_string()], |pkgs| { 432 | // pkgs.into_iter().map(|p| p.into()).collect::>() 433 | // }) 434 | // .join(" "); 435 | pb.enable_steady_tick(Duration::from_millis(300)); 436 | pb.set_style(spinner_style.clone()); 437 | // pb.set_message(pkgs.to_owned()); 438 | for line in BufReader::new(child.stderr.take().unwrap()).lines() { 439 | let line = line.unwrap(); 440 | let stripped_line = line.trim(); 441 | if !stripped_line.is_empty() { 442 | pb.set_message(stripped_line.to_owned()); 443 | } 444 | pb.tick(); 445 | } 446 | let output = child.wait_with_output().expect("Could not wait command"); 447 | if output.status.success() { 448 | println!("{}", String::from_utf8_lossy(&output.stdout)); 449 | } else { 450 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 451 | } 452 | } 453 | Commands::List => { 454 | let mut cmd = Command::new("nix"); 455 | cmd.arg("profile") 456 | .arg("list") 457 | .stdout(Stdio::piped()) 458 | .stderr(Stdio::piped()) 459 | .stdin(Stdio::null()); 460 | if is_teacher { 461 | let string_cmd = command_as_string(&cmd); 462 | println!("Learn mode on!"); 463 | println!("Nix command created:"); 464 | println!("\n\t{string_cmd}\n"); 465 | } 466 | let output = cmd.output().expect("nix failed to run."); 467 | if output.status.success() { 468 | println!("{}", String::from_utf8_lossy(&output.stdout)); 469 | } else { 470 | eprintln!("{}", String::from_utf8_lossy(&output.stderr)); 471 | } 472 | } 473 | } 474 | } 475 | 476 | fn command_as_string(cmd: &Command) -> String { 477 | let program = &cmd.get_program().to_string_lossy(); 478 | let args = &cmd 479 | .get_args() 480 | .into_iter() 481 | .map(OsStr::to_string_lossy) 482 | .collect::>>() 483 | .join(" "); 484 | 485 | format!("{program} {args}") 486 | } 487 | 488 | #[cfg(test)] 489 | mod test { 490 | use crate::Package; 491 | 492 | #[test] 493 | fn test_package_from() { 494 | let items = [ 495 | ( 496 | "nixpkgs#htop", 497 | Package { 498 | repo: "nixpkgs".into(), 499 | name: "htop".into(), 500 | fullname: "nixpkgs#htop".into(), 501 | }, 502 | ), 503 | ( 504 | "htop", 505 | Package { 506 | repo: "nixpkgs".into(), 507 | name: "htop".into(), 508 | fullname: "nixpkgs#htop".into(), 509 | }, 510 | ), 511 | ( 512 | "nixpkgs/release-20.09#hello", 513 | Package { 514 | repo: "nixpkgs/release-20.09".into(), 515 | name: "hello".into(), 516 | fullname: "nixpkgs/release-20.09#hello".into(), 517 | }, 518 | ), 519 | ( 520 | "nixpkgs/d73407e8e6002646acfdef0e39ace088bacc83da#hello", 521 | Package { 522 | repo: "nixpkgs/d73407e8e6002646acfdef0e39ace088bacc83da".into(), 523 | name: "hello".into(), 524 | fullname: "nixpkgs/d73407e8e6002646acfdef0e39ace088bacc83da#hello".into(), 525 | }, 526 | ), 527 | ( 528 | "nixpkgs#bash^man", 529 | Package { 530 | repo: "nixpkgs".into(), 531 | name: "bash^man".into(), 532 | fullname: "nixpkgs#bash^man".into(), 533 | }, 534 | ), 535 | ]; 536 | for (input, expected) in items.into_iter() { 537 | let p = Package::from(input); 538 | assert_eq!(p, expected) 539 | } 540 | } 541 | } 542 | --------------------------------------------------------------------------------