Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs

smaller flake files by collapsing single attrs (#46)

authored by oeiuwq.com and committed by

GitHub 71cc6ec1 7b037ae4

+51 -104
+14 -50
dev/flake.nix
··· 5 5 outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 6 6 7 7 inputs = { 8 - den = { 9 - url = "github:vic/den"; 10 - }; 8 + den.url = "github:vic/den"; 11 9 devshell = { 12 - inputs = { 13 - nixpkgs = { 14 - follows = "nixpkgs"; 15 - }; 16 - }; 10 + inputs.nixpkgs.follows = "nixpkgs"; 17 11 url = "github:numtide/devshell"; 18 12 }; 19 - flake-aspects = { 20 - url = "github:vic/flake-aspects"; 21 - }; 22 - flake-file = { 23 - url = "path:.."; 24 - }; 13 + flake-aspects.url = "github:vic/flake-aspects"; 14 + flake-file.url = "path:.."; 25 15 flake-parts = { 26 - inputs = { 27 - nixpkgs-lib = { 28 - follows = "nixpkgs-lib"; 29 - }; 30 - }; 16 + inputs.nixpkgs-lib.follows = "nixpkgs-lib"; 31 17 url = "github:hercules-ci/flake-parts"; 32 18 }; 33 - import-tree = { 34 - url = "github:vic/import-tree"; 35 - }; 19 + import-tree.url = "github:vic/import-tree"; 36 20 nix-auto-follow = { 37 - inputs = { 38 - nixpkgs = { 39 - follows = "nixpkgs"; 40 - }; 41 - }; 21 + inputs.nixpkgs.follows = "nixpkgs"; 42 22 url = "github:fzakaria/nix-auto-follow"; 43 23 }; 44 24 nix-unit = { 45 25 inputs = { 46 - flake-parts = { 47 - follows = "flake-parts"; 48 - }; 49 - nixpkgs = { 50 - follows = "nixpkgs"; 51 - }; 52 - treefmt-nix = { 53 - follows = "treefmt-nix"; 54 - }; 26 + flake-parts.follows = "flake-parts"; 27 + nixpkgs.follows = "nixpkgs"; 28 + treefmt-nix.follows = "treefmt-nix"; 55 29 }; 56 30 url = "github:nix-community/nix-unit"; 57 31 }; 58 - nixpkgs = { 59 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 60 - }; 61 - nixpkgs-lib = { 62 - follows = "nixpkgs"; 63 - }; 64 - systems = { 65 - url = "github:nix-systems/default"; 66 - }; 32 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 33 + nixpkgs-lib.follows = "nixpkgs"; 34 + systems.url = "github:nix-systems/default"; 67 35 treefmt-nix = { 68 - inputs = { 69 - nixpkgs = { 70 - follows = "nixpkgs"; 71 - }; 72 - }; 36 + inputs.nixpkgs.follows = "nixpkgs"; 73 37 url = "github:numtide/treefmt-nix"; 74 38 }; 75 39 };
+20 -1
modules/write-flake.nix
··· 26 26 addHeader 27 27 ]; 28 28 29 + nixAttr = 30 + name: value: 31 + let 32 + childIsAttr = builtins.isAttrs value; 33 + childIsOne = builtins.length (builtins.attrNames value) == 1; 34 + nested = lib.head (lib.mapAttrsToList nixAttr value); 35 + in 36 + if childIsAttr && childIsOne then 37 + { 38 + name = "${name}.${nested.name}"; 39 + value = nested.value; 40 + } 41 + else 42 + { 43 + inherit name; 44 + value = value; 45 + }; 46 + 29 47 # expr to code 30 48 nixCode = 31 49 x: ··· 33 51 lib.strings.escapeNixString x 34 52 else if lib.isAttrs x then 35 53 lib.pipe x [ 36 - (lib.mapAttrsToList (name: value: ''${name} = ${nixCode value}; '')) 54 + (lib.mapAttrsToList nixAttr) 55 + (map ({ name, value }: ''${name} = ${nixCode value}; '')) 37 56 (values: ''{ ${lib.concatStringsSep " " values} }'') 38 57 ] 39 58 else if lib.isList x then
+4 -12
templates/default/flake.nix
··· 5 5 outputs = inputs: import ./outputs.nix inputs; 6 6 7 7 inputs = { 8 - flake-file = { 9 - url = "github:vic/flake-file"; 10 - }; 11 - flake-parts = { 12 - url = "github:hercules-ci/flake-parts"; 13 - }; 14 - nixpkgs = { 15 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 16 - }; 17 - systems = { 18 - url = "github:nix-systems/default"; 19 - }; 8 + flake-file.url = "github:vic/flake-file"; 9 + flake-parts.url = "github:hercules-ci/flake-parts"; 10 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 11 + systems.url = "github:nix-systems/default"; 20 12 }; 21 13 22 14 }
+8 -26
templates/dendritic/flake.nix
··· 5 5 outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 6 6 7 7 inputs = { 8 - den = { 9 - url = "github:vic/den"; 10 - }; 11 - flake-aspects = { 12 - url = "github:vic/flake-aspects"; 13 - }; 14 - flake-file = { 15 - url = "github:vic/flake-file"; 16 - }; 8 + den.url = "github:vic/den"; 9 + flake-aspects.url = "github:vic/flake-aspects"; 10 + flake-file.url = "github:vic/flake-file"; 17 11 flake-parts = { 18 - inputs = { 19 - nixpkgs-lib = { 20 - follows = "nixpkgs-lib"; 21 - }; 22 - }; 12 + inputs.nixpkgs-lib.follows = "nixpkgs-lib"; 23 13 url = "github:hercules-ci/flake-parts"; 24 14 }; 25 - import-tree = { 26 - url = "github:vic/import-tree"; 27 - }; 28 - nixpkgs = { 29 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 30 - }; 31 - nixpkgs-lib = { 32 - follows = "nixpkgs"; 33 - }; 34 - systems = { 35 - url = "github:nix-systems/default"; 36 - }; 15 + import-tree.url = "github:vic/import-tree"; 16 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 17 + nixpkgs-lib.follows = "nixpkgs"; 18 + systems.url = "github:nix-systems/default"; 37 19 }; 38 20 39 21 }
+5 -15
templates/parts/flake.nix
··· 10 10 }; 11 11 12 12 inputs = { 13 - flake-file = { 14 - url = "github:vic/flake-file"; 15 - }; 16 - flake-parts = { 17 - url = "github:hercules-ci/flake-parts"; 18 - }; 19 - nixpkgs = { 20 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 21 - }; 22 - systems = { 23 - url = "github:nix-systems/default"; 24 - }; 25 - treefmt-nix = { 26 - url = "github:numtide/treefmt-nix"; 27 - }; 13 + flake-file.url = "github:vic/flake-file"; 14 + flake-parts.url = "github:hercules-ci/flake-parts"; 15 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 16 + systems.url = "github:nix-systems/default"; 17 + treefmt-nix.url = "github:numtide/treefmt-nix"; 28 18 }; 29 19 30 20 }