this repo has no description
0
fork

Configure Feed

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

tangled.org init

+582 -389
+1 -1
LICENSE
··· 1 1 MIT License 2 2 3 - Copyright (c) 2023 siluam 3 + Copyright (c) 2023 simple 4 4 5 5 Permission is hereby granted, free of charge, to any person obtaining a copy 6 6 of this software and associated documentation files (the "Software"), to deal
+22 -21
README.md
··· 1 - # siluam 1 + # simple 2 + 3 + This allows users to import flakes using `import <path to flake>`, 4 + or import them using a local fork of `simple` using `import <path to flake> <path to local fork>` 5 + or `import <path to local fork> <path to flake>`. 2 6 3 7 ```nix 4 8 let 5 - siluam = ssrc: 6 - import (let 7 - lock = if (builtins.pathExists ./flake.lock) then 8 - (builtins.fromJSON (builtins.readFile ./flake.lock)) 9 - else 10 - { }; 11 - locked = lock.nodes.siluam.locked or { rev = "main"; }; 12 - url = locked.url or "https://github.com/siluam/siluam/archive/${ 13 - locked.rev or "main" 14 - }.tar.gz"; 15 - in if ((ssrc != ./.) && (builtins.pathExists ssrc)) then 16 - ssrc 17 - else if (builtins ? getFlake) then 18 - (builtins.getFlake url) 19 - else 20 - (fetchTarball { 21 - inherit url; 22 - ${if (locked ? narHash) then "sha256" else null} = locked.narHash; 23 - })); 24 - in (siluam ./. ./.) // { __functor = self: ssrc: siluam ssrc ./.; } 9 + nodes = if (builtins.pathExists ./flake.lock) then 10 + (builtins.fromJSON (builtins.readFile ./flake.lock)) 11 + else { 12 + root.inputs.simple = "simple"; 13 + simple.locked.rev = "main"; 14 + }; 15 + inherit (nodes.${nodes.root.inputs.simple}) locked; 16 + url = 17 + locked.url or "https://tangled.org/@syvl.org/simple/archive/${locked.rev}"; 18 + simple = if (builtins ? getFlake) then 19 + (builtins.getFlake url) 20 + else 21 + (import (fetchTarball { 22 + inherit url; 23 + ${if (locked ? narHash) then "sha256" else null} = locked.narHash; 24 + })); 25 + in (builtins.getFlake or simple) (toString ./.) 25 26 ```
+10 -33
default.nix
··· 1 1 let 2 - siluam = src: 3 - with import ./lib.nix; 4 - let 5 - self = mkFlake { src = ./.; }; 6 - flake = if (src == ./.) then 7 - self 8 - else 9 - (mkFlake { 10 - inherit src; 11 - inherit (self) flake-compat; 12 - }); 13 - nixpkgs = flake.inputs.nixpkgs or self.inputs.nixpkgs; 14 - inherit (nixpkgs) lib legacyPackages; 15 - flakeAttrs = lib.filterAttrs (n: isAttrsOnly) flake; 16 - swap = system: builtins.mapAttrs (n: builtins.getAttr system) flakeAttrs; 17 - assign = system: 18 - builtins.mapAttrs (n: v: v // { currentSystem = v.${system}; }) 19 - (lib.filterAttrs (n: builtins.hasAttr system) flakeAttrs); 20 - assignPkgs = current: attrs: 21 - (genAttrs [ "legacyPackages" "pkgs" ] (pkgs: 22 - if current then 23 - legacyPackages.${builtins.currentSystem} 24 - else 25 - (legacyPackages // { 26 - currentSystem = legacyPackages.${builtins.currentSystem}; 27 - }))) // attrs; 28 - in { 29 - inherit lib; 30 - } // flake // { 31 - currentSystem = assignPkgs true 32 - (flake.${builtins.currentSystem} or (swap builtins.currentSystem)); 33 - } // (assignPkgs false (assign builtins.currentSystem)); 34 - in (siluam ./.) // { __functor = self: siluam; } 2 + inherit (builtins.fromJSON (builtins.readFile ./flake.lock)) nodes; 3 + inherit (nodes.${nodes.root.inputs.flake-compat}) locked; 4 + in if (builtins ? getFlake) then 5 + (builtins.getFlake (toString ./.)) 6 + else 7 + ((import builtins.fetchTarball { 8 + url = 9 + locked.url or "https://github.com/edolstra/flake-compat/archive/${locked.rev}.tar.gz"; 10 + sha256 = locked.narHash; 11 + }) { src = ./.; }).defaultNix
+9 -10
flake.lock
··· 16 16 "type": "github" 17 17 } 18 18 }, 19 - "nixpkgs": { 19 + "nixpkgs-lib": { 20 20 "locked": { 21 - "lastModified": 1753115646, 22 - "narHash": "sha256-yLuz5cz5Z+sn8DRAfNkrd2Z1cV6DaYO9JMrEz4KZo/c=", 23 - "owner": "nixos", 24 - "repo": "nixpkgs", 25 - "rev": "92c2e04a475523e723c67ef872d8037379073681", 21 + "lastModified": 1754788789, 22 + "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", 23 + "owner": "nix-community", 24 + "repo": "nixpkgs.lib", 25 + "rev": "a73b9c743612e4244d865a2fdee11865283c04e6", 26 26 "type": "github" 27 27 }, 28 28 "original": { 29 - "owner": "nixos", 30 - "ref": "nixos-25.05", 31 - "repo": "nixpkgs", 29 + "owner": "nix-community", 30 + "repo": "nixpkgs.lib", 32 31 "type": "github" 33 32 } 34 33 }, 35 34 "root": { 36 35 "inputs": { 37 36 "flake-compat": "flake-compat", 38 - "nixpkgs": "nixpkgs" 37 + "nixpkgs-lib": "nixpkgs-lib" 39 38 } 40 39 } 41 40 },
+19 -7
flake.nix
··· 1 1 { 2 2 inputs.flake-compat.url = "github:edolstra/flake-compat"; 3 3 inputs.flake-compat.flake = false; 4 - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05"; 5 - outputs = { ... }: 4 + inputs.nixpkgs-lib.url = "github:nix-community/nixpkgs.lib"; 5 + outputs = inputs@{ flake-compat, nixpkgs-lib, ... }: 6 6 let 7 - siluam = { 8 - lib = import ./lib.nix; 9 - # TODO: Add the legacyPackages and pkgs here 10 - }; 11 - in { __functor = self: import ./.; } // siluam; 7 + lib = nixpkgs-lib.lib.extend 8 + (import ./lib { system = builtins.currentSystem or "x86_64-linux"; }); 9 + inherit (lib.syvl) mk getFlake; 10 + in mk { 11 + inherit inputs; 12 + outputs = [ 13 + (top@{ system, ... }: { packages.hello = null; }) 14 + { 15 + inherit mk; 16 + __functor = self: src: 17 + if ((builtins.isAttrs src) || (lib.isFunction src)) then 18 + (mk src) 19 + else 20 + (getFlake { inherit src flake-compat; }); 21 + } 22 + ]; 23 + }; 12 24 }
-306
lib.nix
··· 1 - rec { 2 - inherit (builtins) trace; 3 - traceVal = value: trace value value; 4 - traceValSeq = value: trace (builtins.deepSeq value value) value; 5 - 6 - optionalAttrs = cond: attrs: if cond then attrs else { }; 7 - optionalString = cond: string: if cond then string else ""; 8 - 9 - stringToCharacters = s: 10 - builtins.genList (p: builtins.substring p 1 s) (builtins.stringLength s); 11 - lowerChars = stringToCharacters "abcdefghijklmnopqrstuvwxyz"; 12 - upperChars = stringToCharacters "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 13 - toLower = builtins.replaceStrings upperChars lowerChars; 14 - toUpper = builtins.replaceStrings lowerChars upperChars; 15 - 16 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix#L747C1-L762C56 17 - /* Generate an attribute set by mapping a function over a list of 18 - attribute names. 19 - 20 - Example: 21 - genAttrs [ "foo" "bar" ] (name: "x_" + name) 22 - => { foo = "x_foo"; bar = "x_bar"; } 23 - 24 - Type: 25 - genAttrs :: [ String ] -> (String -> Any) -> AttrSet 26 - */ 27 - genAttrs = 28 - # Names of values in the resulting attribute set. 29 - names: 30 - # A function, given the name of the attribute, returns the attribute's value. 31 - f: 32 - builtins.listToAttrs (map (name: { 33 - inherit name; 34 - value = f name; 35 - }) names); 36 - 37 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/lists.nix#L856C1-L864C73 38 - /* Remove duplicate elements from the list. O(n^2) complexity. 39 - 40 - Type: unique :: [a] -> [a] 41 - 42 - Example: 43 - unique [ 3 2 3 4 ] 44 - => [ 3 2 4 ] 45 - */ 46 - unique = 47 - builtins.foldl' (acc: e: if builtins.elem e acc then acc else acc ++ [ e ]) 48 - [ ]; 49 - 50 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/lists.nix#L866C1-L876C59 51 - /* Check if list contains only unique elements. O(n^2) complexity. 52 - 53 - Type: allUnique :: [a] -> bool 54 - 55 - Example: 56 - allUnique [ 3 2 3 4 ] 57 - => false 58 - allUnique [ 3 2 4 1 ] 59 - => true 60 - */ 61 - allUnique = list: (builtins.length (unique list) == builtins.length list); 62 - 63 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/strings.nix#L259C1-L284C53 64 - /* Determine whether a string has given prefix. 65 - 66 - Type: hasPrefix :: string -> string -> bool 67 - 68 - Example: 69 - hasPrefix "foo" "foobar" 70 - => true 71 - hasPrefix "foo" "barfoo" 72 - => false 73 - */ 74 - hasPrefix = 75 - # Prefix to check for 76 - pref: 77 - # Input string 78 - str: 79 - # Before 23.05, paths would be copied to the store before converting them 80 - # to strings and comparing. This was surprising and confusing. 81 - if (builtins.isPath pref) then 82 - abort '' 83 - lib.strings.hasPrefix: The first argument (${ 84 - toString pref 85 - }) is a path value, but only strings are supported. 86 - There is almost certainly a bug in the calling code, since this function always returns `false` in such a case. 87 - This function also copies the path to the Nix store, which may not be what you want. 88 - This behavior is deprecated. 89 - You might want to use `lib.path.hasPrefix` instead, which correctly supports paths.'' 90 - else 91 - (builtins.substring 0 (builtins.stringLength pref) str == pref); 92 - 93 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix#L616C1-L633C66 94 - /* Like `mapAttrs`, but allows the name of each attribute to be 95 - changed in addition to the value. The applied function should 96 - return both the new name and value as a `nameValuePair`. 97 - 98 - Example: 99 - mapAttrs' (name: value: nameValuePair ("foo_" + name) ("bar-" + value)) 100 - { x = "a"; y = "b"; } 101 - => { foo_x = "bar-a"; foo_y = "bar-b"; } 102 - 103 - Type: 104 - mapAttrs' :: (String -> Any -> { name :: String; value :: Any; }) -> AttrSet -> AttrSet 105 - */ 106 - mapAttrs' = 107 - # A function, given an attribute's name and value, returns a new `nameValuePair`. 108 - f: 109 - # Attribute set to map over. 110 - set: 111 - builtins.listToAttrs 112 - (map (attr: f attr set.${attr}) (builtins.attrNames set)); 113 - 114 - mapAttrNames = f: 115 - mapAttrs' (name: value: { 116 - name = f name value; 117 - inherit value; 118 - }); 119 - 120 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix#L636C1-L653C56 121 - /* Call a function for each attribute in the given set and return 122 - the result in a list. 123 - 124 - Example: 125 - mapAttrsToList (name: value: name + value) 126 - { x = "a"; y = "b"; } 127 - => [ "xa" "yb" ] 128 - 129 - Type: 130 - mapAttrsToList :: (String -> a -> b) -> AttrSet -> [b] 131 - */ 132 - mapAttrsToList = 133 - # A function, given an attribute's name and value, returns a new value. 134 - f: 135 - # Attribute set to map over. 136 - attrs: 137 - map (name: f name attrs.${name}) (builtins.attrNames attrs); 138 - 139 - # Taken From: https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix#L765C1-L780C47 140 - /* Check whether the argument is a derivation. Any set with 141 - `{ type = "derivation"; }` counts as a derivation. 142 - 143 - Example: 144 - nixpkgs = import <nixpkgs> {} 145 - isDerivation nixpkgs.ruby 146 - => true 147 - isDerivation "foobar" 148 - => false 149 - 150 - Type: 151 - isDerivation :: Any -> Bool 152 - */ 153 - isDerivation = 154 - # Value to check. 155 - value: 156 - value.type or null == "derivation"; 157 - 158 - isAttrsOnly = value: (builtins.isAttrs value) && (!(isDerivation value)); 159 - 160 - processInputs = inputs: 161 - builtins.mapAttrs (n: sourceInfo: rec { 162 - inherit sourceInfo; 163 - inherit (sourceInfo) outPath; 164 - _type = toLower (sourceInfo.repository.type or sourceInfo.type); 165 - inputs = { }; 166 - outputs = { }; 167 - lastModified = 0; 168 - lastModifiedDate = ""; 169 - rev = sourceInfo.revision or sourceInfo.rev; 170 - shortRev = builtins.substring 0 7 rev; 171 - }) inputs; 172 - 173 - mkOutPath = args@{ src, owner ? "", repo ? "", rev ? "master", ... }: 174 - let 175 - name = args.name or repo; 176 - flakeLock = let path = src + "/flake.lock"; 177 - in optionalAttrs (builtins.pathExists path) 178 - (builtins.fromJSON (builtins.readFile path)); 179 - nivLock = let path = src + "/nix/sources.nix"; 180 - in optionalAttrs (builtins.pathExists path) (import path); 181 - npinsLock = let path = src + "/npins"; 182 - in optionalAttrs (builtins.pathExists path) (import path); 183 - lock = flakeLock.nodes.${name}.locked or { inherit rev; }; 184 - in if (name != "") then 185 - (nivLock.${name} or npinsLock.${name} or { 186 - outPath = if ((owner != "") && (repo != "")) then 187 - (fetchTarball { 188 - url = 189 - lock.url or "https://github.com/${owner}/${repo}/archive/${lock.rev}.tar.gz"; 190 - ${if (lock ? narHash) then "sha256" else null} = lock.narHash; 191 - }) 192 - else 193 - src; 194 - }).outPath 195 - else 196 - src; 197 - 198 - mkFlake = args@{ src, shell ? false, ... }: 199 - let 200 - srcString = toString src; 201 - flake = if (builtins ? getFlake) then 202 - (builtins.getFlake srcString) 203 - else 204 - (let 205 - flake-compat = args.flake-compat or (import (mkOutPath { 206 - inherit src; 207 - owner = "edolstra"; 208 - repo = "flake-compat"; 209 - }) src); 210 - outPath = let path = mkOutPath args; 211 - in if (srcString == (toString path)) then 212 - src 213 - else 214 - (builtins.unsafeDiscardStringContext path); 215 - in flake-compat { src = outPath; }).${ 216 - if shell then "shellNix" else "defaultNix" 217 - }; 218 - in flake // { 219 - inputs = mkInputs { 220 - inherit src; 221 - inherit (flake) inputs; 222 - }; 223 - }; 224 - 225 - # TODO: Remove the tryEval from here 226 - # recursiveUpdateAll' = delim: a: b: 227 - # let a-names = attrNames a; 228 - # in (mapAttrs (n: v: 229 - # let e = tryEval v; 230 - # in if (e.success && (isAttrsOnly v)) then 231 - # (if (any (attr: 232 - # let g = tryEval attr; 233 - # in g.success 234 - # && ((isAttrsOnly attr) || (isList attr) || (isString attr))) 235 - # (attrValues v)) then 236 - # (recursiveUpdateAll' delim v (b.${n} or { })) 237 - # else 238 - # (v // (b.${n} or { }))) 239 - # else if (isList v) then 240 - # (v ++ (b.${n} or [ ])) 241 - # else if ((delim != null) && (isString v)) then 242 - # (if (hasAttr n b) then (v + delim + b.${n}) else v) 243 - # else 244 - # (b.${n} or v)) a) // (removeAttrs b a-names); 245 - recursiveUpdateAll' = delim: a: b: 246 - let a-names = builtins.attrNames a; 247 - in (builtins.mapAttrs (n: v: 248 - 249 - # TODO: Is this `tryEval' necessary? 250 - let e = builtins.tryEval v; 251 - in if (e.success && (builtins.any (x: x) [ (isAttrsOnly v) ])) then 252 - 253 - # TODO: Need this to merge mkShells 254 - # in if (e.success && ((isAttrsOnly v) || (v ? shellHook))) then 255 - 256 - # (if (any (attr: (isAttrs attr) || (isList attr) || (isString attr)) 257 - # (attrValues v)) then 258 - # (recursiveUpdateAll' delim v (b.${n} or { })) 259 - # else 260 - # (v // (b.${n} or { }))) 261 - (recursiveUpdateAll' delim v (b.${n} or { })) 262 - else if (e.success && (isDerivation v) 263 - && (b.${n}.__append__ or false)) then 264 - (recursiveUpdateAll' delim v (removeAttrs b.${n} [ "__append__" ])) 265 - else if (builtins.isList v) then 266 - (v ++ (b.${n} or [ ])) 267 - else if ((delim != null) && (builtins.isString v)) then 268 - (if (builtins.hasAttr n b) then (v + delim + b.${n}) else v) 269 - else 270 - (b.${n} or (if (n == "overridePythonAttrs") then "" else v))) a) 271 - // (removeAttrs b a-names); 272 - recursiveUpdateAll = recursiveUpdateAll' null; 273 - 274 - mkInputs = 275 - args@{ src, inputs ? { }, niv ? true, npins ? true, overrides ? { }, ... }: 276 - let 277 - mkFlakes = default: manager: 278 - let 279 - managerIsString = builtins.isString manager; 280 - bool = managerIsString || ((builtins.isBool manager) && manager); 281 - path = 282 - optionalString bool (if managerIsString then manager else default); 283 - rootPath = src + "/${path}"; 284 - in optionalAttrs (bool && (builtins.pathExists rootPath)) 285 - (builtins.mapAttrs (name: v: 286 - let 287 - outPath = if (hasPrefix "/" v.outPath) then 288 - (builtins.unsafeDiscardStringContext v.outPath) 289 - else 290 - (src + "/${v.outPath}"); 291 - flakePath = outPath + "/flake.nix"; 292 - in if (builtins.pathExists flakePath) then 293 - (mkFlake { 294 - inherit name; 295 - src = outPath; 296 - owner = v.repository.owner or v.owner; 297 - repo = v.repository.repo or v.repo; 298 - inherit (v) rev; 299 - }) 300 - else 301 - (processInputs v)) (import rootPath)); 302 - in builtins.foldl' (a: b: a // b) inputs (mapAttrsToList mkFlakes { 303 - "nix/sources.nix" = niv; 304 - npins = npins; 305 - }); 306 - }
+201
lib/default.nix
··· 1 + inheritance@{ system, ... }: 2 + final: prev: 3 + with final; 4 + let 5 + silicon = rec { 6 + _name = "syvl"; 7 + isAttrsOnly = value: (builtins.isAttrs value) && (!(isDerivation value)); 8 + 9 + # TODO: Remove the tryEval from here 10 + # recursiveUpdateAll' = delim: a: b: 11 + # let a-names = attrNames a; 12 + # in (mapAttrs (n: v: 13 + # let e = tryEval v; 14 + # in if (e.success && (isAttrsOnly v)) then 15 + # (if (any (attr: 16 + # let g = tryEval attr; 17 + # in g.success 18 + # && ((isAttrsOnly attr) || (isList attr) || (isString attr))) 19 + # (attrValues v)) then 20 + # (recursiveUpdateAll' delim v (b.${n} or { })) 21 + # else 22 + # (v // (b.${n} or { }))) 23 + # else if (isList v) then 24 + # (v ++ (b.${n} or [ ])) 25 + # else if ((delim != null) && (isString v)) then 26 + # (if (hasAttr n b) then (v + delim + b.${n}) else v) 27 + # else 28 + # (b.${n} or v)) a) // (builtins.removeAttrs b a-names); 29 + recursiveUpdateAll' = delim: a: b: 30 + let a-names = builtins.attrNames a; 31 + in (builtins.mapAttrs (n: v: 32 + 33 + # TODO: Is this `tryEval' necessary? 34 + let e = builtins.tryEval v; 35 + in if (e.success && (builtins.any (x: x) [ (isAttrsOnly v) ])) then 36 + 37 + # TODO: Need this to merge mkShells 38 + # in if (e.success && ((isAttrsOnly v) || (v ? shellHook))) then 39 + 40 + # (if (any (attr: (isAttrs attr) || (isList attr) || (isString attr)) 41 + # (attrValues v)) then 42 + # (recursiveUpdateAll' delim v (b.${n} or { })) 43 + # else 44 + # (v // (b.${n} or { }))) 45 + (recursiveUpdateAll' delim v (b.${n} or { })) 46 + else if (e.success && (isDerivation v) 47 + && (b.${n}.__append__ or false)) then 48 + (recursiveUpdateAll' delim v 49 + (builtins.removeAttrs b.${n} [ "__append__" ])) 50 + else if (builtins.isList v) then 51 + (v ++ (b.${n} or [ ])) 52 + else if ((delim != null) && (builtins.isString v)) then 53 + (if (builtins.hasAttr n b) then (v + delim + b.${n}) else v) 54 + else 55 + (b.${n} or (if (n == "overridePythonAttrs") then "" else v))) a) 56 + // (builtins.removeAttrs b a-names); 57 + recursiveUpdateAll = recursiveUpdateAll' null; 58 + 59 + # Adapted From: https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix#L40 60 + mergeExtends = f: rattrs: self: 61 + let super = rattrs self; 62 + in (recursiveUpdateAll super (f self super)); 63 + 64 + # Adapted From: https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix#L107 65 + mkMergeExtensibleWithCustomName = extenderName: rattrs: 66 + fix' (self: 67 + (rattrs self) // { 68 + ${extenderName} = f: 69 + mkMergeExtensibleWithCustomName extenderName 70 + (mergeExtends f rattrs); 71 + }); 72 + 73 + # Adapted From: https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix#L89 74 + mkMergeExtensible = mkMergeExtensibleWithCustomName "extend"; 75 + 76 + tracer = items: compose (map (item: builtins.trace item) items); 77 + deepSeqVal = value: builtins.deepSeq value value; 78 + 79 + import = { 80 + can = f: 81 + let fString = toString f; 82 + in ((isString f) || (isPath f)) && ((hasSuffix ".nix" fString) 83 + || ((builtins.readDir fString) ? "default.nix")); 84 + should = f: 85 + let 86 + should_import = silicon.import.can f; 87 + should_return = builtins.isAttrs f || builtins.isFunction f; 88 + in { 89 + success = should_import || should_return; 90 + value = if should_import then 91 + (builtins.import f) 92 + else if should_return then 93 + f 94 + else 95 + false; 96 + }; 97 + # TODO: Use an args set of includes and ignores 98 + all = rec { 99 + named = _dir: 100 + { ignores ? "default", recurse ? false }: 101 + let 102 + dir = toString _dir; 103 + removeNix = removeSuffix ".nix"; 104 + in if (builtins.pathExists dir) then 105 + (if recurse then 106 + (builtins.listToAttrs (map (file: 107 + nameValuePair (builtins.baseNameOf (removeNix file)) 108 + (builtins.import file)) filesystem.listFilesRecursive)) 109 + else 110 + (pipe dir [ 111 + builtins.readDir 112 + (filterAttrs (n: v: 113 + (!(elem (removeNix n) (toList ignores))) 114 + && (!(hasPrefix "_" n)) && (let isDir = v == "directory"; 115 + in (isDir 116 + && ((builtins.readDir "${dir}/${n}") ? "default.nix")) 117 + || (!isDir)))) 118 + (mapAttrs' (n: v: 119 + nameValuePair (removeNix n) (builtins.import "${dir}/${n}"))) 120 + ])) 121 + else 122 + { }; 123 + __functor = self: _dir: ignores: 124 + builtins.attrValues (named _dir ignores); 125 + }; 126 + }; 127 + 128 + intersectArgs = f: with builtins; intersectAttrs (functionArgs f); 129 + 130 + callFunction = f: args: f (intersectArgs f args); 131 + callFunction' = f: args: functionArgs: f (intersectAttrs functionArgs args); 132 + 133 + compose = flip pipe; 134 + 135 + callLib = final: prev: self: super: inheritance: file: 136 + let 137 + args = { 138 + inherit final prev; 139 + self = final.syvl; 140 + super = prev.syvl; 141 + lib = final; 142 + inherit (final) syvl; 143 + inherit silicon; 144 + } // inheritance; 145 + ifile = builtins.import file; 146 + in if (isAttrs file) then 147 + file 148 + else if (isFunction file) then 149 + (callFunction file args) 150 + else if (isAttrs ifile) then 151 + ifile 152 + else 153 + (callFunction ifile args); 154 + 155 + mks = { 156 + call = final: prev: self: super: inheritance: f: 157 + let 158 + apply = callLib final prev self super inheritance; 159 + e = silicon.import.should f; 160 + in if e.success then 161 + (apply e.value) 162 + else if (isList f) then 163 + (map apply f) 164 + else 165 + (map apply (silicon.import.all f { })); 166 + 167 + extend = name: final: prev: inheritance: f: 168 + let 169 + update = silicon: self: super: 170 + let extension = mks.call final prev self super inheritance f; 171 + in if (isAttrs extension) then 172 + (recursiveUpdateAll silicon extension) 173 + else 174 + (foldl' recursiveUpdateAll silicon extension); 175 + in if (hasAttr name prev) then 176 + (prev.${name}.extend (update { })) 177 + else 178 + (mkMergeExtensible (self: update silicon self { })); 179 + 180 + # `final` is the final state of `lib` 181 + # `prev` is the original state of `lib` 182 + # `self` is the final state of `syvl` 183 + # `super` is the original state of `syvl` 184 + lib = name: lib: inheritance: f: 185 + lib.extend 186 + (final: prev: { ${name} = mks.extend name final prev inheritance f; }); 187 + 188 + "${_name}lib" = mks.lib _name; 189 + 190 + libs = lib: inheritances: fs: 191 + lib.extend (final: prev: 192 + mapAttrs 193 + (name: mks.extend name final prev (inheritances.${name} or { })) fs); 194 + 195 + }; 196 + __functor = _: mks.lib _name; 197 + }; 198 + in with silicon; { 199 + ${_name} = 200 + mks.extend _name final prev inheritance (silicon.import.all ./. { }); 201 + }
+282
lib/flake.nix
··· 1 + { lib, prev, silicon, system }: 2 + with lib; 3 + with silicon; rec { 4 + getFlake = args@{ src, ... }: 5 + let 6 + yesFlake = builtins ? getFlake; 7 + flake = if yesFlake then 8 + (builtins.getFlake (toString src)) 9 + else 10 + (let 11 + nodes = if (builtins.pathExists ./flake.lock) then 12 + (builtins.fromJSON (builtins.readFile ./flake.lock)) 13 + else { 14 + root.inputs.flake-compat = "flake-compat"; 15 + flake-compat.locked.rev = "master"; 16 + }; 17 + inherit (nodes.${nodes.root.inputs.flake-compat}) locked; 18 + url = 19 + locked.url or "https://github.com/edolstra/flake-compat/archive/${locked.rev}.tar.gz"; 20 + flake-compat = args.flake-compat or (if yesFlake then 21 + (builtins.getFlake url) 22 + else 23 + (builtins.import (fetchTarball { 24 + inherit url; 25 + ${if (locked ? narHash) then "sha256" else null} = locked.narHash; 26 + }))); 27 + 28 + # builtins.unsafeDiscardStringContext 29 + in flake-compat { inherit src; }).defaultNix; 30 + 31 + in formatOutputs flake; 32 + 33 + isLambda = f: (!(isAttrs f)) && (isFunction f); 34 + isFunctor = f: (isAttrs f) && (isFunction f); 35 + isCoerced = f: (f ? __functionArgs) && (f ? __functor); 36 + isCoercedLambda = f: (isLambda f) || (isCoerced f); 37 + 38 + mk = { 39 + # Adapted From: https://github.com/hercules-ci/flake-parts/blob/4524271976b625a4a605beefd893f270620fd751/lib.nix#L72C5-L125C11 40 + __functor = self: mk.simple; 41 + simple = let 42 + strPath = with types; either str path; 43 + extraLibType = with types; 44 + oneOf [ str path attrs list (functionTo attrs) ]; 45 + in module: 46 + formatOutputs (lib.evalModules { 47 + class = "flake"; 48 + modules = [ 49 + ({ config, options, ... }: { 50 + options = { 51 + src = mkOption { 52 + type = strPath; 53 + default = 54 + dirOf (unsafeGetAttrPos (head (attrNames module)) module).file; 55 + apply = toString; 56 + }; 57 + sources = mkOption { 58 + type = with types; 59 + coercedTo (either strPath (listOf strPath)) (compose [ 60 + toList 61 + (map (src: config.src + "/" + src)) 62 + (filter pathExists) 63 + ]) (listOf strPath); 64 + }; 65 + self = mkOption { 66 + type = types.attrs; 67 + default = config.inputs.self; 68 + }; 69 + inputs = mkOption { 70 + type = types.attrs; 71 + apply = mapAttrs 72 + (n: v: if (isAttrsOnly v) then (formatOutputs v) else v); 73 + }; 74 + ${_name} = mkOption { 75 + type = extraLibType; 76 + default = { }; 77 + }; 78 + lib = mkOption { 79 + type = types.attrs; 80 + default = lib; 81 + apply = lib: 82 + if (config.libs == { }) then 83 + lib 84 + else 85 + (mks.libs lib config.inheritances config.libs); 86 + }; 87 + inheritance = mkOption { 88 + type = types.attrs; 89 + default = { }; 90 + }; 91 + inheritances = mkOption { 92 + type = types.attrs; 93 + default = { }; 94 + }; 95 + libs = mkOption { 96 + type = types.attrsOf extraLibType; 97 + default = { }; 98 + }; 99 + 100 + # TODO: Convert this to a nixpkgs settings submodule, 101 + # using the `functionArgs' of `config.nixpkgs`. 102 + settings = mkOption { 103 + type = with types; 104 + submodule ({ name, config, ... }: { 105 + options = { 106 + config = mkOption { 107 + type = attrs; 108 + default = { }; 109 + }; 110 + overlays = mkOption { 111 + type = attrsOf (functionArgsTo 2 attrs); 112 + default = { }; 113 + }; 114 + }; 115 + }); 116 + }; 117 + nixpkgs = mkOption { 118 + type = types.attrs; 119 + default = let 120 + nixpkgs = attrValues 121 + (filterAttrs (n: v: hasPrefix "nixpkgs" n) config.inputs); 122 + in if (nixpkgs == [ ]) then { } else (head nixpkgs); 123 + }; 124 + 125 + specialArgs = mkOption { type = types.attrs; }; 126 + flake = mkOption { 127 + type = types.attrs; 128 + default = { }; 129 + }; 130 + 131 + # TODO: Make `outputs' a submodule, and everything extra 132 + # will be in a separate attrset that will be merged into the outputs 133 + # at the end. 134 + outputs = mkOption { 135 + type = with types; 136 + let 137 + attrTypes = either attrs (functionTo attrs); 138 + outputTypes = oneOf [ str path attrTypes ]; 139 + in coercedTo (either outputTypes (listOf outputTypes)) 140 + (compose [ 141 + toList 142 + (map (f: 143 + let e = silicon.import.should f; 144 + in syvl.mif.null e.success e.value)) 145 + (remove null) 146 + ]) (listOf attrTypes); 147 + }; 148 + 149 + systems = mkOption { 150 + type = with types; 151 + let systemType = enum lib.systems.flakeExposed; 152 + in coercedTo (either systemType (listOf systemType)) toList 153 + (listOf systemType); 154 + default = [ system ]; 155 + }; 156 + makers = mkOption { 157 + type = with types; attrsOf (optionTypes.functionArgsTo 2 attrs); 158 + }; 159 + maker = mkOption { 160 + type = with types; 161 + either (functionTo (either attrs (functionTo attrs))) 162 + (enum (builtins.attrNames config.makers)); 163 + default = "default"; 164 + }; 165 + }; 166 + _file = toString ./flake.nix; 167 + config = let extraLib = !(elem config.${_name} [ { } [ ] ]); 168 + in { 169 + libs = mkIf extraLib { ${_name} = config.${_name}; }; 170 + inheritances = mkIf extraLib { ${_name} = config.inheritance; }; 171 + 172 + sources = [ "nix/sources.nix" "npins" ]; 173 + inputs = mkMerge (map builtins.import config.sources); 174 + 175 + specialArgs = { 176 + # inherit (config) self inputs lib pkgs; 177 + }; 178 + 179 + outputs = let srcDir = builtins.readDir config.src; 180 + in [ 181 + 182 + (let outputs = config.src + "/outputs.nix"; 183 + in syvl.mif.null 184 + ((srcDir."outputs.nix" or "directory") != "directory") outputs) 185 + 186 + (let outputs = config.src + "/outputs"; 187 + in syvl.mif.null (((srcDir.outputs or "file") == "directory") 188 + && ((builtins.readDir outputs) ? "default.nix")) outputs) 189 + 190 + ]; 191 + 192 + makers = { 193 + default = outputs: inputs: 194 + if (isCoercedLambda outputs) then 195 + (let 196 + functionArgs = 197 + outputs.__functionArgs or (builtins.functionArgs outputs); 198 + in if (functionArgs ? system) then 199 + (mkMerge (map (system: 200 + mapAttrs (n: v: { ${system} = v; }) (callFunction' outputs 201 + (inputs // { 202 + inherit system; 203 + pkgs = import config.nixpkgs 204 + ((removeAttrs config.settings [ "overlays" ]) // { 205 + inherit system; 206 + hostPlatform = system; 207 + overlays = attrValues config.settings.overlays; 208 + }); 209 + }) functionArgs)) config.systems)) 210 + else 211 + (callFunction' outputs inputs functionArgs)) 212 + else 213 + outputs; 214 + flake-parts = outputs: 215 + inputs@{ flake-parts, ... }: 216 + flake-parts.lib.mkFlake { inherit inputs; } 217 + (if (isFunction outputs) then 218 + outputs 219 + else 220 + ({ inherit (config) systems; } // outputs)); 221 + }; 222 + 223 + flake = mkMerge ([{ 224 + inherit config; 225 + simpleflake = true; 226 + }] ++ (map (flip config.makers.${config.maker} ({ 227 + inherit (config) lib; # pkgs; 228 + } // config.inputs)) (unique config.outputs))); 229 + }; 230 + }) 231 + 232 + # Adapted From: https://github.com/NixOS/nixpkgs/blob/df3de70468b743b371a7191ea61d1040fe3bf399/lib/modules.nix#L567-L570 233 + ({ config, ... }: { 234 + imports = let moduleLocation = "${config.src}/flake.nix"; 235 + in [{ 236 + _file = moduleLocation; 237 + _module.args = { inherit moduleLocation; } // config.specialArgs; 238 + imports = [ module ]; 239 + }]; 240 + }) 241 + 242 + ]; 243 + }).config.flake; 244 + }; 245 + 246 + optionTypes.functionArgsTo = argNumber: 247 + compose (replicate argNumber types.functionTo); 248 + 249 + formatOutputs = _flake: 250 + let 251 + systemsList = builtins.attrNames 252 + (_flake.checks or _flake.packages or _flake.apps or _flake.formatter or _flake.devShells or _flake.legacyPackages or { 253 + ${system} = null; 254 + }); 255 + flake = { 256 + lib = lib.genAttrs systemsList 257 + (system: lib.extend (builtins.import ./. { inherit system; })); 258 + } // _flake; 259 + systems = let 260 + allSystems = lib.genAttrs systemsList 261 + (system: lib.mapAttrs (n: v: v.${system} or v) flake); 262 + in allSystems // { currentSystem = allSystems.${system}; }; 263 + in { 264 + inherit systems; 265 + } // (lib.mapAttrs (n: v: 266 + if ((isAttrsOnly v) && (builtins.hasAttr system v)) then 267 + (v // { currentSystem = systems.currentSystem.${n}; }) 268 + else 269 + v) flake) // { 270 + inputs = let 271 + simpleflake = flake.simpleflake or false; 272 + inputs = if simpleflake then 273 + flake.config.inputs 274 + else 275 + (flake.inputs or { }); 276 + in if simpleflake then 277 + inputs 278 + else 279 + (mapAttrs (n: v: if (isAttrsOnly v) then (formatOutputs v) else v) 280 + inputs); 281 + }; 282 + }
+27
lib/optionals.nix
··· 1 + { lib }: 2 + with lib; { 3 + optionalName = condition: name: if condition then name else null; 4 + mif = { 5 + list = optionals; 6 + list' = optional; 7 + attrs = optionalAttrs; 8 + num = condition: value: if condition then value else 0; 9 + null = syvl.optionalName; 10 + str = optionalString; 11 + True = condition: value: if condition then value else true; 12 + False = condition: value: if condition then value else false; 13 + fn = condition: fn: value: if condition then (fn value) else value; 14 + }; 15 + mifNotNull = { 16 + __functor = self: a: b: if (a != null) then a else b; 17 + list = a: optionals (a != null); 18 + list' = a: optional (a != null); 19 + attrs = a: optionalAttrs (a != null); 20 + num = a: b: if (a != null) then b else 0; 21 + null = a: b: if (a != null) then b else null; 22 + nullb = a: b: c: if (a != null) then b else c; 23 + str = a: optionalString (a != null); 24 + True = a: b: if (a != null) then b else true; 25 + False = a: b: if (a != null) then b else false; 26 + }; 27 + }
+11 -11
shell.nix
··· 1 - let siluam = toString ./.; 2 - in with (import siluam).legacyPackages.currentSystem; 3 - mkShell { 4 - buildInputs = [ git just nixfmt ]; 5 - shellHook = '' 6 - nixfmt ${siluam} 7 - git -C ${siluam} add . 8 - nix flake update ${siluam} 9 - exec nix repl -L --show-trace --expr "{ siluam = import ${siluam}; }" 10 - ''; 11 - } 1 + let 2 + inherit (builtins.fromJSON (builtins.readFile ./flake.lock)) nodes; 3 + inherit (nodes.${nodes.root.inputs.flake-compat}) locked; 4 + in if (builtins ? getFlake) then 5 + (builtins.getFlake (toString ./.)) 6 + else 7 + ((import builtins.fetchTarball { 8 + url = 9 + locked.url or "https://github.com/edolstra/flake-compat/archive/${locked.rev}.tar.gz"; 10 + sha256 = locked.narHash; 11 + }) { src = ./.; }).shellNix