├── .gitignore ├── LICENSE.md ├── README.md ├── allArches.nix ├── defaultArches.nix ├── defaultLinuxArches.nix ├── flake.lock └── flake.nix /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | !.gitignore 4 | !flake.lock 5 | 6 | !*.md 7 | !*.nix 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2023-present RGBCube 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FlakeTools 2 | 3 | A simpler and less bug-prone flake-utils alternative. 4 | 5 | Currently has only the basics, but I will expand the functionality soon. 6 | 7 | ## API 8 | 9 | ### `eachDefaultArch :: (string -> attrset) -> attrset` 10 | ### `eachDefaultLinuxArch :: (string -> attrset) -> attrset` (only Linux architectures) 11 | 12 | Equivalent to `recursiveUpdateMap defaultArches`. 13 | 14 | Calls the given function with the most commonly used architectures 15 | (currently these are `aarch64-darwin`, `aarch64-linux`, `x86_64-darwin` and `x86_64-linux`). 16 | Then it merges them together using nixpkgs' `lib.recursiveUpdate`. 17 | 18 | > [!WARNING] 19 | > `eachDefaultArch` does NOT insert the arch into the attribute set 20 | > unlike flake-utils, so you have to manually use it like so: 21 | 22 | ```nix 23 | { 24 | description = "Blazingly fast tool written in Rust."; 25 | 26 | inputs = { 27 | nixpkgs = { 28 | url = "github:NixOS/nixpkgs/nixos-unstable"; 29 | }; 30 | 31 | flakeTools = { 32 | url = "github:RGBCube/FlakeTools"; 33 | inputs.nixpkgs.follows = "nixpkgs"; 34 | }; 35 | }; 36 | 37 | outputs = { self, nixpkgs, flakeTools, ... }: flakeTools.eachArch (system: { 38 | packages.${system}.default = ; 39 | }) 40 | } 41 | ``` 42 | 43 | > [!NOTE] 44 | > This also applies to `eachArch`. 45 | 46 | ### `eachArch :: (string -> attrset) -> attrset` 47 | 48 | Equivalent to `recursiveUpdateMap allArches`. 49 | 50 | Calls the given function with **all** architectures nixpkgs supports. 51 | Then it merges them together using nixpkgs' `lib.recursiveUpdate`. 52 | 53 | > [!WARNING] 54 | > You probably want to use `eachDefaultArch` instead, 55 | > since this will take a while when running `nix flake check`. 56 | 57 | ### `allArches :: [ string ]` 58 | 59 | List of all architectures nixpkgs supports. 60 | 61 | ### `defaultArches :: [ string ]` 62 | 63 | List of the most commonly used architectures. 64 | Currently these are `aarch64-darwin`, `aarch64-linux`, `x86_64-darwin` and `x86_64-linux`. 65 | 66 | ### `recursiveUpdateMap :: (string -> attrset) -> list -> attrset` 67 | 68 | Makes a single set from a provided `function` and a `list` 69 | by mapping and then recursively updating each item together. 70 | 71 | It first takes the list and applies the function to each item: 72 | 73 | `[ 1 2 3 ] => [ (f 1) (f 2) (f 3) ]` 74 | 75 | Assuming our function was `i: { squares."${i}" = i*i; "}`, this step would give us this: 76 | 77 | `[ { squares."1" = 1; } { squares."2" = 4; } { squares."3" = 9; } ]` 78 | 79 | Then it recursively updates them into a single attribute set, giving us our result: 80 | 81 | `{ squares = { "1" = 1; "2" = 4; "3" = 9; }; }` 82 | 83 | ## License 84 | 85 | ``` 86 | MIT License 87 | 88 | Copyright (c) 2023-present RGBCube 89 | 90 | Permission is hereby granted, free of charge, to any person obtaining a copy 91 | of this software and associated documentation files (the "Software"), to deal 92 | in the Software without restriction, including without limitation the rights 93 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 94 | copies of the Software, and to permit persons to whom the Software is 95 | furnished to do so, subject to the following conditions: 96 | 97 | The above copyright notice and this permission notice shall be included in all 98 | copies or substantial portions of the Software. 99 | 100 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 101 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 102 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 103 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 104 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 105 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 106 | SOFTWARE. 107 | ``` 108 | -------------------------------------------------------------------------------- /allArches.nix: -------------------------------------------------------------------------------- 1 | [ 2 | "aarch64-darwin" 3 | "aarch64-genode" 4 | "aarch64-linux" 5 | "aarch64-netbsd" 6 | "aarch64-none" 7 | "aarch64_be-none" 8 | "arm-none" 9 | "armv5tel-linux" 10 | "armv6l-linux" 11 | "armv6l-netbsd" 12 | "armv6l-none" 13 | "armv7a-darwin" 14 | "armv7a-linux" 15 | "armv7a-netbsd" 16 | "armv7l-linux" 17 | "armv7l-netbsd" 18 | "avr-none" 19 | "i686-cygwin" 20 | "i686-darwin" 21 | "i686-freebsd13" 22 | "i686-genode" 23 | "i686-linux" 24 | "i686-netbsd" 25 | "i686-none" 26 | "i686-openbsd" 27 | "i686-windows" 28 | "javascript-ghcjs" 29 | "m68k-linux" 30 | "m68k-netbsd" 31 | "m68k-none" 32 | "microblaze-linux" 33 | "microblaze-none" 34 | "microblazeel-linux" 35 | "microblazeel-none" 36 | "mips64el-linux" 37 | "mipsel-linux" 38 | "mipsel-netbsd" 39 | "mmix-mmixware" 40 | "msp430-none" 41 | "or1k-none" 42 | "powerpc-netbsd" 43 | "powerpc-none" 44 | "powerpc64-linux" 45 | "powerpc64le-linux" 46 | "powerpcle-none" 47 | "riscv32-linux" 48 | "riscv32-netbsd" 49 | "riscv32-none" 50 | "riscv64-linux" 51 | "riscv64-netbsd" 52 | "riscv64-none" 53 | "rx-none" 54 | "s390-linux" 55 | "s390-none" 56 | "s390x-linux" 57 | "s390x-none" 58 | "vc4-none" 59 | "wasm32-wasi" 60 | "wasm64-wasi" 61 | "x86_64-cygwin" 62 | "x86_64-darwin" 63 | "x86_64-freebsd13" 64 | "x86_64-genode" 65 | "x86_64-linux" 66 | "x86_64-netbsd" 67 | "x86_64-none" 68 | "x86_64-openbsd" 69 | "x86_64-redox" 70 | "x86_64-solaris" 71 | "x86_64-windows" 72 | ] 73 | -------------------------------------------------------------------------------- /defaultArches.nix: -------------------------------------------------------------------------------- 1 | [ 2 | "aarch64-darwin" 3 | "aarch64-linux" 4 | "x86_64-darwin" 5 | "x86_64-linux" 6 | ] 7 | -------------------------------------------------------------------------------- /defaultLinuxArches.nix: -------------------------------------------------------------------------------- 1 | [ 2 | "aarch64-linux" 3 | "x86_64-linux" 4 | ] 5 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1700671922, 6 | "narHash": "sha256-XPh/AHD14O+oaztjSb53c3Gh9K1JQHNBOTdn0dvtJpM=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "4784a12198f7434971d5bb8aa6f111acef662ff4", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-23.11", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = " A simpler and less bug-prone flake-utils alternative. "; 3 | 4 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; 5 | 6 | outputs = { self, nixpkgs, ... }: { 7 | # Makes a single set from a provided `function` and a `list` 8 | # by mapping and then recursively updating each item together. 9 | # 10 | # It first takes the list and applies the function to each item: 11 | # 12 | # `[ 1 2 3 ] => [ (f 1) (f 2) (f 3) ]` 13 | # 14 | # Assuming our function was `i: { squares."${i}" = i*i; "}`, this step would give us this: 15 | # 16 | # `[ { squares."1" = 1; } { squares."2" = 4; } { squares."3" = 9; } ]` 17 | # 18 | # Then it recursively updates them into a single attribute set, giving us our result: 19 | # 20 | # `{ squares = { "1" = 1; "2" = 4; "3" = 9; }; }` 21 | recursiveUpdateMap = function: list: 22 | builtins.foldl' nixpkgs.lib.recursiveUpdate {} (builtins.map function list); 23 | 24 | # List of all architectures nixpkgs supports. 25 | allArches = import ./allArches.nix; 26 | 27 | # List of the most commonly used architectures. 28 | # Currently these are aarch64-darwin, aarch64-linux, x86_64-darwin and x86_64-linux. 29 | defaultArches = import ./defaultArches.nix; 30 | 31 | # Lis of the most commonly used Linux architectures. 32 | # Currently these are aarch64-linux and x86_64-linux. 33 | defaultLinuxArches = import ./defaultLinuxArches.nix; 34 | 35 | # Equivalent to `recursiveUpdateMap allArches`. 36 | # 37 | # Calls the given function with **all** architectures nixpkgs supports. 38 | # Then it merges them together using nixpkgs' `lib.recursiveUpdate`. 39 | # 40 | # WARNING: You probably want to use `eachDefaultArch` instead, 41 | # since this will take a while when running `nix flake check`. 42 | eachArch = function: self.recursiveUpdateMap function self.allArches; 43 | 44 | # Equivalent to `recursiveUpdateMap defaultArches`. 45 | # 46 | # Calls the given function with the most commonly used architectures 47 | # (currently these are aarch64-darwin, aarch64-linux, x86_64-darwin and x86_64-linux). 48 | # Then it merges them together using nixpkgs' `lib.recursiveUpdate`. 49 | eachDefaultArch = function: self.recursiveUpdateMap function self.defaultArches; 50 | 51 | # Equivalent to `recursiveUpdateMap defaultLinuxArches`. 52 | # 53 | # Calls the given function with the most commonly used linux architectures 54 | # (currently these are aarch64-darwin, aarch64-linux, x86_64-darwin and x86_64-linux). 55 | # Then it merges them together using nixpkgs' `lib.recursiveUpdate`. 56 | eachDefaultLinuxArch = function: self.recursiveUpdateMap function self.defaultLinuxArches; 57 | }; 58 | } 59 | --------------------------------------------------------------------------------