├── .github └── workflows │ └── flakehub-publish-tagged.yml ├── .gitignore ├── LICENSE ├── README.md ├── flake.lock ├── flake.nix └── packages └── flake ├── default.nix ├── filter-flake.sh ├── filter-flakes.sh ├── flake.sh ├── get-registry-flakes.sh └── help ├── boot.sh ├── build-system.sh ├── build.sh ├── check.sh ├── dev.sh ├── flake.sh ├── init.sh ├── new.sh ├── option.sh ├── run.sh ├── show.sh ├── switch.sh ├── test.sh └── update.sh /.github/workflows/flakehub-publish-tagged.yml: -------------------------------------------------------------------------------- 1 | name: "Publish tags to FlakeHub" 2 | on: 3 | push: 4 | tags: 5 | - "v?[0-9]+.[0-9]+.[0-9]+*" 6 | workflow_dispatch: 7 | inputs: 8 | tag: 9 | description: "The existing tag to publish to FlakeHub" 10 | type: "string" 11 | required: true 12 | jobs: 13 | flakehub-publish: 14 | runs-on: "ubuntu-latest" 15 | permissions: 16 | id-token: "write" 17 | contents: "read" 18 | steps: 19 | - uses: "actions/checkout@v3" 20 | with: 21 | ref: "${{ (inputs.tag != null) && format('refs/tags/{0}', inputs.tag) || '' }}" 22 | - uses: "DeterminateSystems/nix-installer-action@main" 23 | - uses: "DeterminateSystems/flakehub-push@main" 24 | with: 25 | visibility: "public" 26 | name: "snowfallorg/flake" 27 | tag: "${{ inputs.tag }}" 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Nix 2 | result 3 | .direnv 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ TERMS 6 | AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, and 11 | distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 14 | owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the 17 | union of the acting entity and all other entities that control, are controlled 18 | by, or are under common control with that entity. For the purposes of this 19 | definition, "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or otherwise, or (ii) 21 | ownership of fifty percent (50%) or more of the outstanding shares, or (iii) 22 | beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean 25 | an individual or Legal Entity exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation source, and 29 | configuration files. 30 | 31 | "Object" form shall mean any form resulting 32 | from mechanical transformation or translation of a Source form, including but not 33 | limited to compiled object code, generated documentation, and conversions to 34 | other media types. 35 | 36 | "Work" shall mean the work of authorship, 37 | whether in Source or Object form, made available under the License, as indicated 38 | by a copyright notice that is included in or attached to the work (an example is 39 | provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any 42 | work, whether in Source or Object form, that is based on (or derived from) the 43 | Work and for which the editorial revisions, annotations, elaborations, or other 44 | modifications represent, as a whole, an original work of authorship. For the 45 | purposes of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, the Work 47 | and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work 50 | of authorship, including the original version of the Work and any modifications 51 | or additions to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner or by an 53 | individual or Legal Entity authorized to submit on behalf of the copyright owner. 54 | For the purposes of this definition, "submitted" means any form of electronic, 55 | verbal, or written communication sent to the Licensor or its representatives, 56 | including but not limited to communication on electronic mailing lists, source 57 | code control systems, and issue tracking systems that are managed by, or on 58 | behalf of, the Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise designated in 60 | writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of 63 | whom a Contribution has been received by Licensor and subsequently incorporated 64 | within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and 67 | conditions of this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license 69 | to reproduce, prepare Derivative Works of, publicly display, publicly perform, 70 | sublicense, and distribute the Work and such Derivative Works in Source or Object 71 | form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of this 74 | License, each Contributor hereby grants to You a perpetual, worldwide, 75 | non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this 76 | section) patent license to make, have made, use, offer to sell, sell, import, and 77 | otherwise transfer the Work, where such license applies only to those patent 78 | claims licensable by such Contributor that are necessarily infringed by their 79 | Contribution(s) alone or by combination of their Contribution(s) with the Work to 80 | which such Contribution(s) was submitted. If You institute patent litigation 81 | against any entity (including a cross-claim or counterclaim in a lawsuit) 82 | alleging that the Work or a Contribution incorporated within the Work constitutes 83 | direct or contributory patent infringement, then any patent licenses granted to 84 | You under this License for that Work shall terminate as of the date such 85 | litigation is filed. 86 | 87 | 4. Redistribution. You may reproduce and distribute 88 | copies of the Work or Derivative Works thereof in any medium, with or without 89 | modifications, and in Source or Object form, provided that You meet the following 90 | conditions: 91 | 92 | (a) You must give any other recipients of the Work or 93 | Derivative Works a copy of this License; and 94 | 95 | (b) You must cause any 96 | modified files to carry prominent notices stating that You changed the files; 97 | and 98 | 99 | (c) You must retain, in the Source form of any Derivative Works that 100 | You distribute, all copyright, patent, trademark, and attribution notices from 101 | the Source form of the Work, excluding those notices that do not pertain to any 102 | part of the Derivative Works; and 103 | 104 | (d) If the Work includes a "NOTICE" text 105 | file as part of its distribution, then any Derivative Works that You distribute 106 | must include a readable copy of the attribution notices contained within such 107 | NOTICE file, excluding those notices that do not pertain to any part of the 108 | Derivative Works, in at least one of the following places: within a NOTICE text 109 | file distributed as part of the Derivative Works; within the Source form or 110 | documentation, if provided along with the Derivative Works; or, within a display 111 | generated by the Derivative Works, if and wherever such third-party notices 112 | normally appear. The contents of the NOTICE file are for informational purposes 113 | only and do not modify the License. You may add Your own attribution notices 114 | within Derivative Works that You distribute, alongside or as an addendum to the 115 | NOTICE text from the Work, provided that such additional attribution notices 116 | cannot be construed as modifying the License. 117 | 118 | You may add Your own 119 | copyright statement to Your modifications and may provide additional or different 120 | license terms and conditions for use, reproduction, or distribution of Your 121 | modifications, or for any such Derivative Works as a whole, provided Your use, 122 | reproduction, and distribution of the Work otherwise complies with the conditions 123 | stated in this License. 124 | 125 | 5. Submission of Contributions. Unless You explicitly 126 | state otherwise, any Contribution intentionally submitted for inclusion in the 127 | Work by You to the Licensor shall be under the terms and conditions of this 128 | License, without any additional terms or conditions. Notwithstanding the above, 129 | nothing herein shall supersede or modify the terms of any separate license 130 | agreement you may have executed with Licensor regarding such Contributions. 131 | 132 | 6. Trademarks. This License does not grant permission to use the trade names, 133 | trademarks, service marks, or product names of the Licensor, except as required 134 | for reasonable and customary use in describing the origin of the Work and 135 | reproducing the content of the NOTICE file. 136 | 137 | 7. Disclaimer of Warranty. Unless 138 | required by applicable law or agreed to in writing, Licensor provides the Work 139 | (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT 140 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, 141 | without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, 142 | MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible 143 | for determining the appropriateness of using or redistributing the Work and 144 | assume any risks associated with Your exercise of permissions under this 145 | License. 146 | 147 | 8. Limitation of Liability. In no event and under no legal theory, 148 | whether in tort (including negligence), contract, or otherwise, unless required 149 | by applicable law (such as deliberate and grossly negligent acts) or agreed to in 150 | writing, shall any Contributor be liable to You for damages, including any 151 | direct, indirect, special, incidental, or consequential damages of any character 152 | arising as a result of this License or out of the use or inability to use the 153 | Work (including but not limited to damages for loss of goodwill, work stoppage, 154 | computer failure or malfunction, or any and all other commercial damages or 155 | losses), even if such Contributor has been advised of the possibility of such 156 | damages. 157 | 158 | 9. Accepting Warranty or Additional Liability. While redistributing 159 | the Work or Derivative Works thereof, You may choose to offer, and charge a fee 160 | for, acceptance of support, warranty, indemnity, or other liability obligations 161 | and/or rights consistent with this License. However, in accepting such 162 | obligations, You may act only on Your own behalf and on Your sole responsibility, 163 | not on behalf of any other Contributor, and only if You agree to indemnify, 164 | defend, and hold each Contributor harmless for any liability incurred by, or 165 | claims asserted against, such Contributor by reason of your accepting any such 166 | warranty or additional liability. END OF TERMS AND CONDITIONS 167 | 168 | APPENDIX: How to apply the Apache License to your work. 169 | 170 | To apply the Apache License to your work, 171 | attach the following boilerplate notice, with the fields enclosed by brackets 172 | "[]" replaced with your own identifying information. (Don't include the 173 | brackets!) The text should be enclosed in the appropriate comment syntax for the 174 | file format. We also recommend that a file or class name and description of 175 | purpose be included on the same "printed page" as the copyright notice for easier 176 | identification within third-party archives. 177 | 178 | Copyright 2023 Jake Hamilton 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | 190 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 191 | 192 | See the License for the specific language governing permissions and 193 | limitations under the License. 194 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Snowfall Flake 2 | 3 | 4 | Nix Flakes Ready 5 | 6 | 7 | Built With Snowfall 8 | 9 | 10 |

11 | 15 |    16 |

17 | 18 | > Simplified Nix Flakes on the command line. 19 | 20 | ## Installation 21 | 22 | ### Nix Profile 23 | 24 | You can install this package imperatively with the following command. 25 | 26 | ```bash 27 | nix profile install github:snowfallorg/flake 28 | ``` 29 | 30 | ### Nix Configuration 31 | 32 | You can install this package by adding it as an input to your Nix Flake. 33 | 34 | ```nix 35 | { 36 | description = "My system flake"; 37 | 38 | inputs = { 39 | nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; 40 | unstable.url = "github:nixos/nixpkgs/nixos-unstable"; 41 | 42 | # Snowfall Lib is not required, but will make configuration easier for you. 43 | snowfall-lib = { 44 | url = "github:snowfallorg/lib"; 45 | inputs.nixpkgs.follows = "nixpkgs"; 46 | }; 47 | 48 | snowfall-flake = { 49 | url = "github:snowfallorg/flake"; 50 | # Flake requires some packages that aren't on 22.05, but are available on unstable. 51 | inputs.nixpkgs.follows = "unstable"; 52 | }; 53 | }; 54 | 55 | outputs = inputs: 56 | inputs.snowfall-lib.mkFlake { 57 | inherit inputs; 58 | src = ./.; 59 | 60 | overlays = with inputs; [ 61 | # Use the overlay provided by this flake. 62 | snowfall-flake.overlay 63 | 64 | # There is also a named overlay, though the output is the same. 65 | snowfall-flake.overlays."package/flake" 66 | ]; 67 | }; 68 | } 69 | ``` 70 | 71 | If you've added the overlay from this flake, then in your system configuration you 72 | can add the `snowfallorg.flake` package. 73 | 74 | ```nix 75 | { pkgs }: 76 | 77 | { 78 | environment.systemPackages = with pkgs; [ 79 | snowfallorg.flake 80 | ]; 81 | } 82 | ``` 83 | 84 | ## Usage 85 | 86 | ### `flake new` 87 | 88 | Create new projects from flake templates. 89 | 90 | ```bash 91 | # Create a new flake and directory my-project with the default template. 92 | flake new my-project 93 | 94 | # Create a new flake and directory my-project with a custom template. 95 | flake new my-project --template github:snowfallorg/templates#package 96 | 97 | # Create a new flake and directory my-project with a template selected from a list. 98 | flake new my-project --pick 99 | ``` 100 | 101 | ### `flake init` 102 | 103 | Initialize a flake in an existing project. 104 | 105 | ```bash 106 | # Create a new flake in the current directory with the default template. 107 | flake init 108 | 109 | # Create a new flake in the current directory with a custom template. 110 | flake init --template github:snowfallorg/templates#package 111 | 112 | # Create a new flake in the current directory with a template selected from a list. 113 | flake init --pick 114 | ``` 115 | 116 | ### `flake dev` 117 | 118 | Run development shells. 119 | 120 | ```bash 121 | # Open the default development shell of the flake in the current directory. 122 | flake dev 123 | 124 | # Open a specific development shell of the flake in the current directory. 125 | flake dev my-shell 126 | 127 | # Open a development shell from a specific flake. 128 | flake dev github:snowfall/dotbox#dotbox 129 | 130 | # Pick a development shell from the current directory. 131 | flake dev --pick 132 | 133 | # Pick a development shell from a specific flake. 134 | flake dev github:snowfall/dotbox --pick 135 | ``` 136 | 137 | ### `flake run` 138 | 139 | Run apps from Nix Flakes. 140 | 141 | ```bash 142 | # Run the default app of the flake in the current directory. 143 | flake run 144 | 145 | # Run a specific app of the flake in the current directory. 146 | flake run my-package 147 | 148 | # Run a specific app from a specific flake. 149 | flake run github:snowfall/dotbox#dotbox 150 | 151 | # Pick an app to run from the current directory. 152 | flake run --pick 153 | 154 | # Pick an app to run from a specific flake. 155 | flake run github:snowfall/dotbox --pick 156 | ``` 157 | 158 | ### `flake build` 159 | 160 | Build packages from Nix Flakes. 161 | 162 | ```bash 163 | # Build the default package of the flake in the current directory. 164 | flake build 165 | 166 | # Build a specific package of the flake in the current directory. 167 | flake build my-package 168 | 169 | # Build a package from a specific flake. 170 | flake build github:snowfall/dotbox#dotbox 171 | 172 | # Pick a package to build from the current directory. 173 | flake build --pick 174 | 175 | # Pick a package to build from a specific flake. 176 | flake build github:snowfall/dotbox --pick 177 | ``` 178 | 179 | ### `flake switch` 180 | 181 | Rebuild and switch system configuration with support for both NixOS and nix-darwin. 182 | 183 | ```bash 184 | # Switch to configuration with the same hostname from the flake in the current directory. 185 | flake switch 186 | 187 | # Switch to specific configuration from the flake in the current directory. 188 | flake switch my-system 189 | 190 | # Pick a configuration to switch to from the flake in the current directory. 191 | flake switch --pick 192 | 193 | # Switch to configuration from a specific flake. 194 | flake switch github:jakehamilton/config#bismuth 195 | 196 | # Pick configuration from a specific flake. 197 | flake switch github:jakehamilton/config --pick 198 | ``` 199 | 200 | ### `flake test` 201 | 202 | Test a system configuration 203 | 204 | ```bash 205 | flake test 206 | 207 | DESCRIPTION 208 | 209 | Test a system configuration with support for both NixOS and nix-darwin. 210 | 211 | USAGE 212 | 213 | $ flake test [options] 214 | 215 | OPTIONS 216 | 217 | --help, -h Show this help message 218 | --debug Show debug messages 219 | --show-trace Show a trace when a Nix command fails 220 | 221 | EXAMPLES 222 | 223 | # Test a configuration with the same hostname from the flake in the current directory. 224 | $ flake test 225 | 226 | # Test a specific configuration from the flake in the current directory. 227 | $ flake test my-system 228 | 229 | # Pick a configuration to test from the flake in the current directory. 230 | $ flake test --pick 231 | 232 | # Test a configuration from a specific flake. 233 | $ flake test github:jakehamilton/config#bismuth 234 | 235 | # Pick configuration from a specific flake. 236 | $ flake test github:jakehamilton/config --pick 237 | ``` 238 | 239 | ### `flake boot` 240 | 241 | Update the system's bootable generations. 242 | 243 | ```bash 244 | flake boot 245 | 246 | DESCRIPTION 247 | 248 | Set a NixOS configuration as the bootable system. 249 | 250 | USAGE 251 | 252 | $ flake boot [options] 253 | 254 | OPTIONS 255 | 256 | --help, -h Show this help message 257 | --debug Show debug messages 258 | --show-trace Show a trace when a Nix command fails 259 | 260 | EXAMPLES 261 | 262 | # Boot a configuration with the same hostname from the flake in the current directory. 263 | $ flake boot 264 | 265 | # Boot a specific configuration from the flake in the current directory. 266 | $ flake boot my-system 267 | 268 | # Pick a configuration to boot from the flake in the current directory. 269 | $ flake boot --pick 270 | 271 | # Boot a configuration from a specific flake. 272 | $ flake boot github:jakehamilton/config#bismuth 273 | 274 | # Pick configuration from a specific flake. 275 | $ flake boot github:jakehamilton/config --pick 276 | ``` 277 | 278 | ### `flake show` 279 | 280 | Show flake outputs. 281 | 282 | ```bash 283 | flake show 284 | 285 | DESCRIPTION 286 | 287 | Show the outputs of a Nix Flake. 288 | 289 | USAGE 290 | 291 | $ flake show [options] 292 | 293 | OPTIONS 294 | 295 | --help, -h Show this help message 296 | --debug Show debug messages 297 | --show-trace Show a trace when a Nix command fails 298 | 299 | EXAMPLES 300 | 301 | # Show outputs from the flake in the current directory. 302 | $ flake show 303 | 304 | # Show outputs from a specific flake. 305 | $ flake show github:jakehamilton/config 306 | ``` 307 | 308 | ### `flake update` 309 | 310 | Update a Nix Flake's inputs. 311 | 312 | ```bash 313 | # Update all flake inputs. 314 | flake update 315 | 316 | # Update one or more specific inputs. 317 | flake update nixpkgs snowfall-lib 318 | 319 | # Pick inputs to update from a list. 320 | flake update --pick 321 | ``` 322 | 323 | ### `flake build-` 324 | 325 | Build a NixOS, nix-darwin, and other types of systems. 326 | 327 | > See `flake build-system --help` for more information. 328 | 329 | ```bash 330 | # Build the system with the same hostname from the flake in the current directory. 331 | flake build-system 332 | 333 | # Build the NixOS system with the same hostname from the flake in the current directory. 334 | flake build-nixos 335 | 336 | # Build a specific nix-darwin system from the flake in the current directory. 337 | flake build-darwin my-system 338 | 339 | # Build the system with the same hostname from a specific flake. 340 | flake build-system github:jakehamilton/config#bismuth 341 | 342 | # Pick and build a system from the flake in the current directory 343 | flake build-system --pick 344 | 345 | # Pick and build a system from a specific flake. 346 | flake build-system github:jakehamilton/config --pick 347 | 348 | # Build a specific ISO from the flake in the current directory. 349 | flake build-iso my-iso-system 350 | ``` 351 | 352 | ### `flake option` 353 | 354 | Show NixOS options from Nix Flakes. 355 | 356 | ```bash 357 | 358 | 359 | flake option 360 | 361 | DESCRIPTION 362 | 363 | Show NixOS options from Nix Flakes. 364 | 365 | USAGE 366 | 367 | flake option [option] [options] 368 | flake option [option] [options] 369 | flake option [option] [options] 370 | 371 | OPTIONS 372 | 373 | --pick, -p Pick options from a list 374 | 375 | --help, -h Show this help message 376 | --debug Show debug messages 377 | --show-trace Show a trace when a Nix command fails 378 | 379 | EXAMPLES 380 | 381 | # Show options for the current host in the current directory. 382 | $ flake option 383 | 384 | # Show options for a specific host. 385 | $ flake option my-host 386 | 387 | # Show a specific option for a specific host. 388 | $ flake option my-host services.openssh 389 | 390 | # Show options for a flake's host. 391 | $ flake option github:jakehamilton/config#bismuth 392 | 393 | # Show a specific option for a flake's host. 394 | $ flake option github:jakehamilton/config#bismuth services.openssh 395 | 396 | # Pick options for the flake in the current directory. 397 | $ flake option --pick 398 | 399 | # Pick options from a specific flake. 400 | $ flake option github:jakehamilton/config --pick 401 | 402 | ``` 403 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-compat": { 4 | "flake": false, 5 | "locked": { 6 | "lastModified": 1696426674, 7 | "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", 8 | "owner": "edolstra", 9 | "repo": "flake-compat", 10 | "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", 11 | "type": "github" 12 | }, 13 | "original": { 14 | "owner": "edolstra", 15 | "ref": "v1.0.1", 16 | "repo": "flake-compat", 17 | "type": "github" 18 | } 19 | }, 20 | "flake-compat_2": { 21 | "flake": false, 22 | "locked": { 23 | "lastModified": 1650374568, 24 | "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", 25 | "owner": "edolstra", 26 | "repo": "flake-compat", 27 | "rev": "b4a34015c698c7793d592d66adbab377907a2be8", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "edolstra", 32 | "repo": "flake-compat", 33 | "type": "github" 34 | } 35 | }, 36 | "flake-utils": { 37 | "locked": { 38 | "lastModified": 1644229661, 39 | "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", 40 | "owner": "numtide", 41 | "repo": "flake-utils", 42 | "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", 43 | "type": "github" 44 | }, 45 | "original": { 46 | "owner": "numtide", 47 | "repo": "flake-utils", 48 | "type": "github" 49 | } 50 | }, 51 | "flake-utils-plus": { 52 | "inputs": { 53 | "flake-utils": "flake-utils" 54 | }, 55 | "locked": { 56 | "lastModified": 1715533576, 57 | "narHash": "sha256-fT4ppWeCJ0uR300EH3i7kmgRZnAVxrH+XtK09jQWihk=", 58 | "owner": "gytis-ivaskevicius", 59 | "repo": "flake-utils-plus", 60 | "rev": "3542fe9126dc492e53ddd252bb0260fe035f2c0f", 61 | "type": "github" 62 | }, 63 | "original": { 64 | "owner": "gytis-ivaskevicius", 65 | "repo": "flake-utils-plus", 66 | "rev": "3542fe9126dc492e53ddd252bb0260fe035f2c0f", 67 | "type": "github" 68 | } 69 | }, 70 | "nixpkgs": { 71 | "locked": { 72 | "lastModified": 1704290814, 73 | "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", 74 | "owner": "nixos", 75 | "repo": "nixpkgs", 76 | "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", 77 | "type": "github" 78 | }, 79 | "original": { 80 | "owner": "nixos", 81 | "ref": "nixos-23.05", 82 | "repo": "nixpkgs", 83 | "type": "github" 84 | } 85 | }, 86 | "root": { 87 | "inputs": { 88 | "flake-compat": "flake-compat", 89 | "nixpkgs": "nixpkgs", 90 | "snowfall-lib": "snowfall-lib" 91 | } 92 | }, 93 | "snowfall-lib": { 94 | "inputs": { 95 | "flake-compat": "flake-compat_2", 96 | "flake-utils-plus": "flake-utils-plus", 97 | "nixpkgs": [ 98 | "nixpkgs" 99 | ] 100 | }, 101 | "locked": { 102 | "lastModified": 1716675292, 103 | "narHash": "sha256-7TFvVE4HR/b65/0AAhewYHEJzUXxIEJn82ow5bCkrDo=", 104 | "owner": "snowfallorg", 105 | "repo": "lib", 106 | "rev": "5d6e9f235735393c28e1145bec919610b172a20f", 107 | "type": "github" 108 | }, 109 | "original": { 110 | "owner": "snowfallorg", 111 | "ref": "v3.0.2", 112 | "repo": "lib", 113 | "type": "github" 114 | } 115 | } 116 | }, 117 | "root": "root", 118 | "version": 7 119 | } 120 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Snowfall Flake"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; 6 | 7 | flake-compat = { 8 | url = "github:edolstra/flake-compat?ref=v1.0.1"; 9 | flake = false; 10 | }; 11 | 12 | snowfall-lib = { 13 | url = "github:snowfallorg/lib?ref=v3.0.2"; 14 | inputs.nixpkgs.follows = "nixpkgs"; 15 | }; 16 | }; 17 | 18 | outputs = inputs: 19 | inputs.snowfall-lib.mkFlake { 20 | inherit inputs; 21 | src = ./.; 22 | 23 | snowfall = { 24 | namespace = "snowfallorg"; 25 | }; 26 | 27 | alias.packages.default = "flake"; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /packages/flake/default.nix: -------------------------------------------------------------------------------- 1 | { lib 2 | , stdenvNoCC 3 | , replaceVarsWith 4 | , gum 5 | , nixos-option 6 | , writeShellApplication 7 | , inputs 8 | , ... 9 | }: 10 | 11 | let 12 | substitute = args: builtins.readFile (replaceVarsWith args); 13 | 14 | filter-flake = writeShellApplication { 15 | name = "filter-flake"; 16 | text = builtins.readFile ./filter-flake.sh; 17 | checkPhase = ""; 18 | }; 19 | filter-flakes = writeShellApplication { 20 | name = "filter-flakes"; 21 | text = builtins.readFile ./filter-flakes.sh; 22 | checkPhase = ""; 23 | runtimeInputs = [ 24 | filter-flake 25 | ]; 26 | }; 27 | get-registry-flakes = writeShellApplication { 28 | name = "get-registry-flakes"; 29 | text = builtins.readFile ./get-registry-flakes.sh; 30 | checkPhase = ""; 31 | }; 32 | in 33 | writeShellApplication { 34 | name = "flake"; 35 | text = substitute { 36 | src = ./flake.sh; 37 | 38 | replacements = { 39 | help = ./help; 40 | flakeCompat = inputs.flake-compat; 41 | isDarwin = if stdenvNoCC.isDarwin then "true" else "false"; 42 | }; 43 | }; 44 | checkPhase = ""; 45 | runtimeInputs = [ 46 | gum 47 | filter-flakes 48 | get-registry-flakes 49 | nixos-option 50 | ]; 51 | } 52 | -------------------------------------------------------------------------------- /packages/flake/filter-flake.sh: -------------------------------------------------------------------------------- 1 | # @NOTE(jakehamilton): Some flakes like github:nix-community/emacs-overlay do not 2 | # provide lock files. This causes `nix eval` to error out as it can't write a new 3 | # lock file. Instead, we'll ignore this item and move on to others that play nicely. 4 | set +e 5 | 6 | # @NOTE(jakehamilton): We redirect stderr to /dev/null due to Nix complaining about 7 | # lock files on some flakes. The `nix eval` command does not provide a way to resolve 8 | # this, so we have to ignore errors here unfortunately. 9 | has_target=$(nix eval --impure --raw --expr "\ 10 | let 11 | flake = builtins.getFlake \"$2\"; 12 | outputNames = builtins.attrNames (flake.\"$1\" or {}); 13 | totalOutputs = builtins.length outputNames; 14 | in 15 | if flake ? \"$1\" && totalOutputs != 0 then 16 | \"true\" 17 | else 18 | \"false\" 19 | " 2>/dev/null) 20 | 21 | if [[ "$has_target" == true ]]; then 22 | echo "$2" 23 | fi 24 | 25 | set -e 26 | -------------------------------------------------------------------------------- /packages/flake/filter-flakes.sh: -------------------------------------------------------------------------------- 1 | target=$1 2 | shift 3 | 4 | # Usage: split 5 | split() { 6 | IFS=$'\n' read -d "" -ra arr <<< "${1//$2/$'\n'}" 7 | printf '%s\n' "${arr[@]}" 8 | } 9 | 10 | result=$(echo "$(split "$@" " ")" | xargs -P 10 -I {} bash -c "filter-flake ${target} {}") 11 | 12 | echo "$result" 13 | -------------------------------------------------------------------------------- /packages/flake/flake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #==============================# 4 | # Global # 5 | #==============================# 6 | 7 | DEBUG=${DEBUG:-"false"} 8 | 9 | #==============================# 10 | # Injected # 11 | #==============================# 12 | 13 | is_darwin="@isDarwin@" 14 | help_root="@help@" 15 | 16 | #==============================# 17 | # Logging # 18 | #==============================# 19 | 20 | text_reset="\e[m" 21 | text_bold="\e[1m" 22 | text_dim="\e[2m" 23 | text_italic="\e[3m" 24 | text_underline="\e[4m" 25 | text_blink="\e[5m" 26 | text_highlight="\e[7m" 27 | text_hidden="\e[8m" 28 | text_strike="\e[9m" 29 | 30 | text_fg_red="\e[38;5;1m" 31 | text_fg_green="\e[38;5;2m" 32 | text_fg_yellow="\e[38;5;3m" 33 | text_fg_blue="\e[38;5;4m" 34 | text_fg_magenta="\e[38;5;5m" 35 | text_fg_cyan="\e[38;5;6m" 36 | text_fg_white="\e[38;5;7m" 37 | text_fg_dim="\e[38;5;8m" 38 | 39 | text_bg_red="\e[48;5;1m" 40 | text_bg_green="\e[48;5;2m" 41 | text_bg_yellow="\e[48;5;3m" 42 | text_bg_blue="\e[48;5;4m" 43 | text_bg_magenta="\e[48;5;5m" 44 | text_bg_cyan="\e[48;5;6m" 45 | text_bg_white="\e[48;5;7m" 46 | text_bg_dim="\e[48;5;8m" 47 | 48 | # Usage: log_info 49 | log_info() { 50 | echo -e "${text_fg_blue}info${text_reset} $1" 51 | } 52 | 53 | # Usage: log_todo 54 | log_todo() { 55 | echo -e "${text_bg_magenta}${text_fg_white}todo${text_reset} $1" 56 | } 57 | 58 | # Usage: log_debug 59 | log_debug() { 60 | if [[ $DEBUG == true ]]; then 61 | echo -e "${text_fg_dim}debug${text_reset} $1" 62 | fi 63 | } 64 | 65 | # Usage: log_warn 66 | log_warn() { 67 | echo -e "${text_fg_yellow}warn${text_reset} $1" 68 | } 69 | 70 | # Usage: log_error 71 | log_error() { 72 | echo -e "${text_fg_red}error${text_reset} $1" 73 | } 74 | 75 | # Usage: log_fatal [exit-code] 76 | log_fatal() { 77 | echo -e "${text_fg_white}${text_bg_red}fatal${text_reset} $1" 78 | 79 | if [ -z ${2:-} ]; then 80 | exit 1 81 | else 82 | exit $2 83 | fi 84 | } 85 | 86 | # Usage: clear_previous_line [number] 87 | clear_line() { 88 | echo -e "\e[${1:-"1"}A\e[2K" 89 | } 90 | 91 | # Usage: 92 | # rewrite_line 93 | # rewrite_line 94 | rewrite_line() { 95 | if [[ $# == 1 ]]; then 96 | echo -e "\e[1A\e[2K${1}" 97 | else 98 | echo -e "\e[${1}A\e[2K${2}" 99 | fi 100 | } 101 | 102 | #==============================# 103 | # Options # 104 | #==============================# 105 | positional_args=() 106 | 107 | opt_help=false 108 | opt_pick=false 109 | opt_show_trace=false 110 | opt_all_systems=false 111 | opt_template= 112 | 113 | # Usage: missing_value