diff --git a/format.sh b/format.sh index 1ebd942..00cb9c6 100755 --- a/format.sh +++ b/format.sh @@ -1,4 +1,6 @@ #!/usr/bin/env nix-shell #!nix-shell -i bash -I "nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-24.05.tar.gz" -p nixfmt-rfc-style -nixfmt ${1:-"--verify"} ./**/*.nix +files=$(find . -name "*.nix" -type f) + +nixfmt ${1:-"--verify"} ${files} diff --git a/foundation/src/builders/bash/boot.nix b/foundation/src/builders/bash/boot.nix index 64ab2cc..452a868 100644 --- a/foundation/src/builders/bash/boot.nix +++ b/foundation/src/builders/bash/boot.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; builders = config.aux.foundation.builders; stage0 = config.aux.foundation.stages.stage0; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.builders.bash.boot = { build = lib.options.create { type = lib.types.function lib.types.derivation; @@ -17,61 +16,67 @@ in { config = { aux.foundation.builders.bash.boot = { - build = settings @ { - name, - script, - meta ? {}, - extras ? {}, - env ? {}, - deps ? {}, - ... - }: let - package = builtins.derivation ( - (builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"]) - // env - // { - inherit name system script; + build = + settings@{ + name, + script, + meta ? { }, + extras ? { }, + env ? { }, + deps ? { }, + ... + }: + let + package = builtins.derivation ( + (builtins.removeAttrs settings [ + "meta" + "extras" + "executable" + "env" + "deps" + "script" + ]) + // env + // { + inherit name system script; - passAsFile = ["script"]; + passAsFile = [ "script" ]; - builder = "${stage1.bash.boot.package}/bin/bash"; + builder = "${stage1.bash.boot.package}/bin/bash"; - args = [ - "-e" - (builtins.toFile "bash-builder.sh" '' - export CONFIG_SHELL=$SHELL + args = [ + "-e" + (builtins.toFile "bash-builder.sh" '' + export CONFIG_SHELL=$SHELL - # Normalize the NIX_BUILD_CORES variable. The value might be 0, which - # means that we're supposed to try and auto-detect the number of - # available CPU cores at run-time. We don't have nproc to detect the - # number of available CPU cores so default to 1 if not set. - NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" - if [ $NIX_BUILD_CORES -le 0 ]; then - NIX_BUILD_CORES=1 - fi - export NIX_BUILD_CORES + # Normalize the NIX_BUILD_CORES variable. The value might be 0, which + # means that we're supposed to try and auto-detect the number of + # available CPU cores at run-time. We don't have nproc to detect the + # number of available CPU cores so default to 1 if not set. + NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" + if [ $NIX_BUILD_CORES -le 0 ]; then + NIX_BUILD_CORES=1 + fi + export NIX_BUILD_CORES - bash -eux $scriptPath - '') - ]; + bash -eux $scriptPath + '') + ]; - SHELL = "${stage1.bash.boot.package}/bin/bash"; + SHELL = "${stage1.bash.boot.package}/bin/bash"; - PATH = lib.paths.bin ( - (deps.build.host or []) - ++ [ - stage1.bash.boot.package - stage1.coreutils.boot.package - stage0.mescc-tools-extra.package - ] - ); - } - ); - in - package - // { - inherit meta extras; - }; + PATH = lib.paths.bin ( + (deps.build.host or [ ]) + ++ [ + stage1.bash.boot.package + stage1.coreutils.boot.package + stage0.mescc-tools-extra.package + ] + ); + } + ); + in + package // { inherit meta extras; }; }; }; } diff --git a/foundation/src/builders/bash/default.nix b/foundation/src/builders/bash/default.nix index 0e8ad46..3868f47 100644 --- a/foundation/src/builders/bash/default.nix +++ b/foundation/src/builders/bash/default.nix @@ -1,15 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.builders.bash = { build = lib.options.create { @@ -20,60 +17,66 @@ in { config = { aux.foundation.builders.bash = { - build = settings @ { - name, - script, - meta ? {}, - extras ? {}, - env ? {}, - deps ? {}, - ... - }: let - package = builtins.derivation ( - (builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"]) - // env - // { - inherit name system script; + build = + settings@{ + name, + script, + meta ? { }, + extras ? { }, + env ? { }, + deps ? { }, + ... + }: + let + package = builtins.derivation ( + (builtins.removeAttrs settings [ + "meta" + "extras" + "executable" + "env" + "deps" + "script" + ]) + // env + // { + inherit name system script; - passAsFile = ["script"]; + passAsFile = [ "script" ]; - builder = "${stage1.bash.package}/bin/bash"; + builder = "${stage1.bash.package}/bin/bash"; - args = [ - "-e" - (builtins.toFile "bash-builder.sh" '' - export CONFIG_SHELL=$SHELL + args = [ + "-e" + (builtins.toFile "bash-builder.sh" '' + export CONFIG_SHELL=$SHELL - # Normalize the NIX_BUILD_CORES variable. The value might be 0, which - # means that we're supposed to try and auto-detect the number of - # available CPU cores at run-time. - NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" - if ((NIX_BUILD_CORES <= 0)); then - guess=$(nproc 2>/dev/null || true) - ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) - fi - export NIX_BUILD_CORES + # Normalize the NIX_BUILD_CORES variable. The value might be 0, which + # means that we're supposed to try and auto-detect the number of + # available CPU cores at run-time. + NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" + if ((NIX_BUILD_CORES <= 0)); then + guess=$(nproc 2>/dev/null || true) + ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) + fi + export NIX_BUILD_CORES - bash -eux $scriptPath - '') - ]; + bash -eux $scriptPath + '') + ]; - SHELL = "${stage1.bash.package}/bin/bash"; + SHELL = "${stage1.bash.package}/bin/bash"; - PATH = lib.paths.bin ( - (deps.build.host or []) - ++ [ - stage1.bash.package - stage1.coreutils.package - ] - ); - } - ); - in - package - // { - inherit meta extras; - }; + PATH = lib.paths.bin ( + (deps.build.host or [ ]) + ++ [ + stage1.bash.package + stage1.coreutils.package + ] + ); + } + ); + in + package // { inherit meta extras; }; }; }; } diff --git a/foundation/src/builders/file/text/default.nix b/foundation/src/builders/file/text/default.nix index fc25291..ac34eda 100644 --- a/foundation/src/builders/file/text/default.nix +++ b/foundation/src/builders/file/text/default.nix @@ -1,11 +1,10 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; stage0 = config.aux.foundation.stages.stage0; -in { +in +{ options.aux.foundation.builders.file.text = { build = lib.options.create { type = lib.types.function lib.types.derivation; @@ -15,55 +14,62 @@ in { config = { aux.foundation.builders.file.text = { - build = settings @ { - name, - contents, - isExecutable ? false, - destination ? "", - meta ? {}, - extras ? {}, - ... - }: let - script = - '' - target=''${out}''${destination} - '' - + lib.strings.when (builtins.dirOf destination == ".") '' - mkdir -p ''${out}''${destinationDir} - '' - + '' - cp ''${contentsPath} ''${target} - '' - + lib.strings.when isExecutable '' - chmod 555 ''${target} - ''; - package = builtins.derivation ( - (builtins.removeAttrs settings ["meta" "extras" "executable" "isExecutable"]) - // { - inherit name system destination contents; - destinationDir = builtins.dirOf destination; + build = + settings@{ + name, + contents, + isExecutable ? false, + destination ? "", + meta ? { }, + extras ? { }, + ... + }: + let + script = + '' + target=''${out}''${destination} + '' + + lib.strings.when (builtins.dirOf destination == ".") '' + mkdir -p ''${out}''${destinationDir} + '' + + '' + cp ''${contentsPath} ''${target} + '' + + lib.strings.when isExecutable '' + chmod 555 ''${target} + ''; + package = builtins.derivation ( + (builtins.removeAttrs settings [ + "meta" + "extras" + "executable" + "isExecutable" + ]) + // { + inherit + name + system + destination + contents + ; + destinationDir = builtins.dirOf destination; - passAsFile = ["contents"]; + passAsFile = [ "contents" ]; - builder = "${stage0.kaem.package}/bin/kaem"; + builder = "${stage0.kaem.package}/bin/kaem"; - args = [ - "--verbose" - "--strict" - "--file" - (builtins.toFile "write-text-to-file.kaem" script) - ]; + args = [ + "--verbose" + "--strict" + "--file" + (builtins.toFile "write-text-to-file.kaem" script) + ]; - PATH = lib.paths.bin [ - stage0.mescc-tools-extra.package - ]; - } - ); - in - package - // { - inherit meta extras; - }; + PATH = lib.paths.bin [ stage0.mescc-tools-extra.package ]; + } + ); + in + package // { inherit meta extras; }; }; }; } diff --git a/foundation/src/builders/kaem/default.nix b/foundation/src/builders/kaem/default.nix index a003c50..ab8cc5f 100644 --- a/foundation/src/builders/kaem/default.nix +++ b/foundation/src/builders/kaem/default.nix @@ -1,12 +1,11 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; builders = config.aux.foundation.builders; stage0 = config.aux.foundation.stages.stage0; -in { +in +{ options.aux.foundation.builders.kaem = { build = lib.options.create { type = lib.types.function lib.types.derivation; @@ -16,50 +15,54 @@ in { config = { aux.foundation.builders.kaem = { - build = settings @ { - name, - script, - meta ? {}, - extras ? {}, - env ? {}, - deps ? {}, - ... - }: let - package = builtins.derivation ( - (builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"]) - // env - // { - inherit name system; + build = + settings@{ + name, + script, + meta ? { }, + extras ? { }, + env ? { }, + deps ? { }, + ... + }: + let + package = builtins.derivation ( + (builtins.removeAttrs settings [ + "meta" + "extras" + "executable" + "env" + "deps" + "script" + ]) + // env + // { + inherit name system; - builder = "${stage0.kaem.package}/bin/kaem"; + builder = "${stage0.kaem.package}/bin/kaem"; - args = [ - "--verbose" - "--strict" - "--file" - ( - builders.file.text.build { + args = [ + "--verbose" + "--strict" + "--file" + (builders.file.text.build { name = "${name}-builder"; contents = script; - } - ) - ]; + }) + ]; - PATH = lib.paths.bin ( - (deps.build.host or []) - ++ [ - stage0.kaem.package - stage0.mescc-tools.package - stage0.mescc-tools-extra.package - ] - ); - } - ); - in - package - // { - inherit meta extras; - }; + PATH = lib.paths.bin ( + (deps.build.host or [ ]) + ++ [ + stage0.kaem.package + stage0.mescc-tools.package + stage0.mescc-tools-extra.package + ] + ); + } + ); + in + package // { inherit meta extras; }; }; }; } diff --git a/foundation/src/builders/raw/default.nix b/foundation/src/builders/raw/default.nix index 5ea699b..eb170a8 100644 --- a/foundation/src/builders/raw/default.nix +++ b/foundation/src/builders/raw/default.nix @@ -1,9 +1,8 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; -in { +in +{ options.aux.foundation.builders.raw = { build = lib.options.create { type = lib.types.function lib.types.derivation; @@ -13,30 +12,38 @@ in { config = { aux.foundation.builders.raw = { - build = settings @ { - pname, - version, - executable, - args ? [], - meta ? {}, - extras ? {}, - ... - }: let - package = builtins.derivation ( - (builtins.removeAttrs settings ["meta" "extras" "executable"]) - // { - inherit version pname system args; + build = + settings@{ + pname, + version, + executable, + args ? [ ], + meta ? { }, + extras ? { }, + ... + }: + let + package = builtins.derivation ( + (builtins.removeAttrs settings [ + "meta" + "extras" + "executable" + ]) + // { + inherit + version + pname + system + args + ; - name = "${pname}-${version}"; + name = "${pname}-${version}"; - builder = executable; - } - ); - in - package - // { - inherit meta extras; - }; + builder = executable; + } + ); + in + package // { inherit meta extras; }; }; }; } diff --git a/foundation/src/default.nix b/foundation/src/default.nix index 9e5f4ed..2df67a4 100644 --- a/foundation/src/default.nix +++ b/foundation/src/default.nix @@ -13,4 +13,4 @@ let system = ./system; }; in - modules +modules diff --git a/foundation/src/exports/default.nix b/foundation/src/exports/default.nix index aaabffd..03a0adc 100644 --- a/foundation/src/exports/default.nix +++ b/foundation/src/exports/default.nix @@ -1,20 +1,19 @@ -{ - lib, - config, -}: let +{ lib, config }: +let options = { packages = lib.options.create { - default.value = {}; + default.value = { }; type = lib.types.attrs.of lib.types.derivation; }; extras = lib.options.create { - default.value = {}; + default.value = { }; type = lib.types.attrs.any; }; }; -in { +in +{ options = { exports = { inherit (options) packages extras; @@ -27,19 +26,16 @@ in { config = { exports.resolved = { - packages = - builtins.mapAttrs ( + packages = builtins.mapAttrs ( + name: value: + lib.attrs.filter ( name: value: - lib.attrs.filter - ( - name: value: - if value ? meta && value.meta ? platforms - then builtins.elem config.aux.system value.meta.platforms - else true - ) - value - ) - config.exports.packages; + if value ? meta && value.meta ? platforms then + builtins.elem config.aux.system value.meta.platforms + else + true + ) value + ) config.exports.packages; extras = config.exports.extras; }; diff --git a/foundation/src/mirrors/default.nix b/foundation/src/mirrors/default.nix index 1788c3b..e3dbbfe 100644 --- a/foundation/src/mirrors/default.nix +++ b/foundation/src/mirrors/default.nix @@ -1,4 +1,5 @@ -{lib}: { +{ lib }: +{ options.aux.mirrors = { gnu = lib.options.create { type = lib.types.string; diff --git a/foundation/src/platform/default.nix b/foundation/src/platform/default.nix index d5114f8..cb8c16c 100644 --- a/foundation/src/platform/default.nix +++ b/foundation/src/platform/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; parts = lib.strings.split "-" system; @@ -285,7 +283,8 @@ family = "javascript"; }; }; -in { +in +{ options.aux.platform = { name = lib.options.create { type = lib.types.string; @@ -303,7 +302,10 @@ in { }; endian = lib.options.create { - type = lib.types.enum ["little" "big"]; + type = lib.types.enum [ + "little" + "big" + ]; default.value = "big"; description = "Endianess of the platform"; }; @@ -332,18 +334,13 @@ in { }; config = { - aux.platform = - ( - platforms.${platform} - or (builtins.throw "Unsupported platform: ${system}") - ) - // { - name = platform; + aux.platform = (platforms.${platform} or (builtins.throw "Unsupported platform: ${system}")) // { + name = platform; - # These will only ever have `linux` as the target since we - # do not support darwin bootstrapping. - build = "${platform}-unknown-${target}-gnu"; - host = "${platform}-unknown-${target}-gnu"; - }; + # These will only ever have `linux` as the target since we + # do not support darwin bootstrapping. + build = "${platform}-unknown-${target}-gnu"; + host = "${platform}-unknown-${target}-gnu"; + }; }; } diff --git a/foundation/src/stages/stage0/architecture/default.nix b/foundation/src/stages/stage0/architecture/default.nix index ecb975c..4405d1f 100644 --- a/foundation/src/stages/stage0/architecture/default.nix +++ b/foundation/src/stages/stage0/architecture/default.nix @@ -1,18 +1,18 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; architecture = - if system == "x86_64-linux" - then "AMD64" - else if system == "aarch64-linux" - then "AArch64" - else if system == "i686-linux" - then "x86" - else builtins.throw "Unsupported system for stage0: ${system}"; -in { + if system == "x86_64-linux" then + "AMD64" + else if system == "aarch64-linux" then + "AArch64" + else if system == "i686-linux" then + "x86" + else + builtins.throw "Unsupported system for stage0: ${system}"; +in +{ options.aux.foundation.stages.stage0.architecture = { base = lib.options.create { type = lib.types.string; diff --git a/foundation/src/stages/stage0/default.nix b/foundation/src/stages/stage0/default.nix index aff235a..edd064e 100644 --- a/foundation/src/stages/stage0/default.nix +++ b/foundation/src/stages/stage0/default.nix @@ -1,21 +1,21 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0; system = config.aux.system; builders = config.aux.foundation.builders; architecture = - if system == "x86_64-linux" - then "AMD64" - else if system == "aarch64-linux" - then "AArch64" - else if system == "i686-linux" - then "x86" - else builtins.throw "Unsupported system for stage0: ${system}"; -in { + if system == "x86_64-linux" then + "AMD64" + else if system == "aarch64-linux" then + "AArch64" + else if system == "i686-linux" then + "x86" + else + builtins.throw "Unsupported system for stage0: ${system}"; +in +{ includes = [ ./sources ./architecture diff --git a/foundation/src/stages/stage0/kaem/default.nix b/foundation/src/stages/stage0/kaem/default.nix index 3328fff..acd1105 100644 --- a/foundation/src/stages/stage0/kaem/default.nix +++ b/foundation/src/stages/stage0/kaem/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.kaem; system = config.aux.system; @@ -10,7 +8,8 @@ kaem-unwrapped = config.aux.foundation.stages.stage0.kaem-unwrapped; mescc-tools = config.aux.foundation.stages.stage0.mescc-tools; mescc-tools-extra = config.aux.foundation.stages.stage0.mescc-tools-extra; -in { +in +{ options.aux.foundation.stages.stage0.kaem = { meta = { description = lib.options.create { @@ -35,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -47,24 +46,26 @@ in { config = { aux.foundation.stages.stage0.kaem = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "kaem"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "kaem"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = kaem-unwrapped.package; + executable = kaem-unwrapped.package; - args = [ - "--verbose" - "--strict" - "--file" - ./build.kaem - ]; + args = [ + "--verbose" + "--strict" + "--file" + ./build.kaem + ]; - kaemUnwrapped = kaem-unwrapped.package; - PATH = lib.paths.bin [mescc-tools-extra.package]; - }); + kaemUnwrapped = kaem-unwrapped.package; + PATH = lib.paths.bin [ mescc-tools-extra.package ]; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/mescc-tools-extra/default.nix b/foundation/src/stages/stage0/mescc-tools-extra/default.nix index 0785636..253be54 100644 --- a/foundation/src/stages/stage0/mescc-tools-extra/default.nix +++ b/foundation/src/stages/stage0/mescc-tools-extra/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.mescc-tools-extra; hex0 = config.aux.foundation.stages.stage0.hex0; catm = config.aux.foundation.stages.stage0.catm; @@ -18,7 +16,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.mescc-tools-extra = { meta = { description = lib.options.create { @@ -43,7 +42,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -55,27 +54,29 @@ in { config = { aux.foundation.stages.stage0.mescc-tools-extra = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "mescc-tools-tools"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "mescc-tools-tools"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = kaem-unwrapped.package; + executable = kaem-unwrapped.package; - args = [ - "--verbose" - "--strict" - "--file" - ./build.kaem - ]; + args = [ + "--verbose" + "--strict" + "--file" + ./build.kaem + ]; - src = sources.mescc-tools-extra; + src = sources.mescc-tools-extra; - m2libcOS = "linux"; - m2libcArch = architecture.m2libc; - mesccTools = mescc-tools.package; - }); + m2libcOS = "linux"; + m2libcArch = architecture.m2libc; + mesccTools = mescc-tools.package; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/mescc-tools/default.nix b/foundation/src/stages/stage0/mescc-tools/default.nix index 1855b95..ce15baa 100644 --- a/foundation/src/stages/stage0/mescc-tools/default.nix +++ b/foundation/src/stages/stage0/mescc-tools/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.mescc-tools; hex0 = config.aux.foundation.stages.stage0.hex0; catm = config.aux.foundation.stages.stage0.catm; @@ -18,60 +16,57 @@ sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; - bloodFlag = - if config.aux.platform.bits == 64 - then "--64" - else " "; - endianFlag = - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian"; + bloodFlag = if config.aux.platform.bits == 64 then "--64" else " "; + endianFlag = if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian"; baseAddress = - if config.aux.system == "x86_64-linux" - then "0x00600000" - else if config.aux.system == "aarch64-linux" - then "0x00600000" - else if config.aux.system == "i686-linux" - then "0x08048000" - else builtins.throw "Unsupported system: ${config.aux.system}"; + if config.aux.system == "x86_64-linux" then + "0x00600000" + else if config.aux.system == "aarch64-linux" then + "0x00600000" + else if config.aux.system == "i686-linux" then + "0x08048000" + else + builtins.throw "Unsupported system: ${config.aux.system}"; - getExtraUtil = name: let - script = builtins.toFile "build-${name}.kaem" '' - ''${M2} --architecture ${architecture.m2libc} \ - -f ''${m2libc}/sys/types.h \ - -f ''${m2libc}/stddef.h \ - -f ''${m2libc}/${architecture.m2libc}/linux/fcntl.c \ - -f ''${m2libc}/fcntl.c \ - -f ''${m2libc}/${architecture.m2libc}/linux/unistd.c \ - -f ''${m2libc}/${architecture.m2libc}/linux/sys/stat.c \ - -f ''${m2libc}/stdlib.c \ - -f ''${m2libc}/stdio.h \ - -f ''${m2libc}/stdio.c \ - -f ''${m2libc}/string.c \ - -f ''${m2libc}/bootstrappable.c \ - -f ''${mesccToolsExtra}/${name}.c \ - --debug \ - -o ${name}.M1 + getExtraUtil = + name: + let + script = builtins.toFile "build-${name}.kaem" '' + ''${M2} --architecture ${architecture.m2libc} \ + -f ''${m2libc}/sys/types.h \ + -f ''${m2libc}/stddef.h \ + -f ''${m2libc}/${architecture.m2libc}/linux/fcntl.c \ + -f ''${m2libc}/fcntl.c \ + -f ''${m2libc}/${architecture.m2libc}/linux/unistd.c \ + -f ''${m2libc}/${architecture.m2libc}/linux/sys/stat.c \ + -f ''${m2libc}/stdlib.c \ + -f ''${m2libc}/stdio.h \ + -f ''${m2libc}/stdio.c \ + -f ''${m2libc}/string.c \ + -f ''${m2libc}/bootstrappable.c \ + -f ''${mesccToolsExtra}/${name}.c \ + --debug \ + -o ${name}.M1 - ''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1 + ''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1 - ''${M1} --architecture ${architecture.m2libc} \ - ${endianFlag} \ - -f ''${m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1 \ - -f ''${m2libc}/${architecture.m2libc}/libc-full.M1 \ - -f ${name}.M1 \ - -f ${name}-footer.M1 \ - -o ${name}.hex2 + ''${M1} --architecture ${architecture.m2libc} \ + ${endianFlag} \ + -f ''${m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1 \ + -f ''${m2libc}/${architecture.m2libc}/libc-full.M1 \ + -f ${name}.M1 \ + -f ${name}-footer.M1 \ + -o ${name}.hex2 - ''${hex2} --architecture ${architecture.m2libc} \ - ${endianFlag} \ - -f ''${m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2 \ - -f ${name}.hex2 \ - --base-address ${baseAddress} \ - -o ''${out} + ''${hex2} --architecture ${architecture.m2libc} \ + ${endianFlag} \ + -f ''${m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2 \ + -f ${name}.hex2 \ + --base-address ${baseAddress} \ + -o ''${out} - ''; - in + ''; + in builders.raw.build { pname = "mescc-tools-extra-${name}"; version = "1.6.0"; @@ -104,7 +99,8 @@ endianFlag = endianFlag; baseAddress = baseAddress; }; -in { +in +{ options.aux.foundation.stages.stage0.mescc-tools = { meta = { description = lib.options.create { @@ -129,7 +125,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -141,42 +137,44 @@ in { config = { aux.foundation.stages.stage0.mescc-tools = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "mescc-tools"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "mescc-tools"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = kaem-unwrapped.package; + executable = kaem-unwrapped.package; - args = [ - "--verbose" - "--strict" - "--file" - ./build.kaem - ]; + args = [ + "--verbose" + "--strict" + "--file" + ./build.kaem + ]; - M1 = M1.package; - M2 = M2.package; - blood-elf-0 = blood-elf.package; - hex2 = hex2.package; + M1 = M1.package; + M2 = M2.package; + blood-elf-0 = blood-elf.package; + hex2 = hex2.package; - m2libc = sources.m2libc; - m2libcArch = architecture.m2libc; - m2planet = sources.m2planet; - m2mesoplanet = sources.m2mesoplanet; - mesccTools = sources.mescc-tools; - mesccToolsExtra = sources.mescc-tools-extra; + m2libc = sources.m2libc; + m2libcArch = architecture.m2libc; + m2planet = sources.m2planet; + m2mesoplanet = sources.m2mesoplanet; + mesccTools = sources.mescc-tools; + mesccToolsExtra = sources.mescc-tools-extra; - bloodFlag = bloodFlag; - endianFlag = endianFlag; - baseAddress = baseAddress; + bloodFlag = bloodFlag; + endianFlag = endianFlag; + baseAddress = baseAddress; - mkdir = getExtraUtil "mkdir"; - cp = getExtraUtil "cp"; - chmod = getExtraUtil "chmod"; - replace = getExtraUtil "replace"; - }); + mkdir = getExtraUtil "mkdir"; + cp = getExtraUtil "cp"; + chmod = getExtraUtil "chmod"; + replace = getExtraUtil "replace"; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase00.nix b/foundation/src/stages/stage0/phases/phase00.nix index 8861c64..7ce452d 100644 --- a/foundation/src/stages/stage0/phases/phase00.nix +++ b/foundation/src/stages/stage0/phases/phase00.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.hex0; system = config.aux.system; @@ -9,14 +7,16 @@ sources = config.aux.foundation.stages.stage0.sources; architecture = - if system == "x86_64-linux" - then "AMD64" - else if system == "aarch64-linux" - then "AArch64" - else if system == "i686-linux" - then "x86" - else builtins.throw "Unsupported system for stage0: ${system}"; -in { + if system == "x86_64-linux" then + "AMD64" + else if system == "aarch64-linux" then + "AArch64" + else if system == "i686-linux" then + "x86" + else + builtins.throw "Unsupported system for stage0: ${system}"; +in +{ options.aux.foundation.stages.stage0.hex0 = { meta = { description = lib.options.create { @@ -41,7 +41,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -66,40 +66,45 @@ in { config = { aux.foundation.stages.stage0.hex0 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "hex0"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "hex0"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = cfg.executable; + executable = cfg.executable; - args = [ - "${sources.base}/hex0_${architecture}.hex0" - (builtins.placeholder "out") - ]; + args = [ + "${sources.base}/hex0_${architecture}.hex0" + (builtins.placeholder "out") + ]; - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; - outputHash = cfg.hash; - }); - - hash = lib.modules.overrides.default ( - if system == "x86_64-linux" - then "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY=" - else if system == "aarch64-linux" - then "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo=" - else if system == "i686-linux" - then "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8=" - else null + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = cfg.hash; + } ); - executable = lib.modules.overrides.default (import { - name = "hex0-seed"; - url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${architecture}/hex0-seed"; - executable = true; - hash = cfg.hash; - }); + hash = lib.modules.overrides.default ( + if system == "x86_64-linux" then + "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY=" + else if system == "aarch64-linux" then + "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo=" + else if system == "i686-linux" then + "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8=" + else + null + ); + + executable = lib.modules.overrides.default ( + import { + name = "hex0-seed"; + url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${architecture}/hex0-seed"; + executable = true; + hash = cfg.hash; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase01.nix b/foundation/src/stages/stage0/phases/phase01.nix index e820985..28a856c 100644 --- a/foundation/src/stages/stage0/phases/phase01.nix +++ b/foundation/src/stages/stage0/phases/phase01.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.hex1; hex0 = config.aux.foundation.stages.stage0.hex0; @@ -9,7 +7,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.hex1 = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -46,19 +45,21 @@ in { config = { aux.foundation.stages.stage0.hex1 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "hex1"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "hex1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex0.package; + executable = hex0.package; - args = [ - "${sources.base}/hex1_${architecture.base}.hex0" - (builtins.placeholder "out") - ]; - }); + args = [ + "${sources.base}/hex1_${architecture.base}.hex0" + (builtins.placeholder "out") + ]; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase02.nix b/foundation/src/stages/stage0/phases/phase02.nix index 3735002..fb3f1b2 100644 --- a/foundation/src/stages/stage0/phases/phase02.nix +++ b/foundation/src/stages/stage0/phases/phase02.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.hex2-0; hex0 = config.aux.foundation.stages.stage0.hex0; hex1 = config.aux.foundation.stages.stage0.hex1; @@ -10,7 +8,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.hex2-0 = { meta = { description = lib.options.create { @@ -35,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -47,19 +46,21 @@ in { config = { aux.foundation.stages.stage0.hex2-0 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "hex2-0"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "hex2-0"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex1.package; + executable = hex1.package; - args = [ - "${sources.base}/hex2_${architecture.base}.hex1" - (builtins.placeholder "out") - ]; - }); + args = [ + "${sources.base}/hex2_${architecture.base}.hex1" + (builtins.placeholder "out") + ]; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase03.nix b/foundation/src/stages/stage0/phases/phase03.nix index bc7c345..f446684 100644 --- a/foundation/src/stages/stage0/phases/phase03.nix +++ b/foundation/src/stages/stage0/phases/phase03.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.catm; hex0 = config.aux.foundation.stages.stage0.hex0; hex1 = config.aux.foundation.stages.stage0.hex1; @@ -11,7 +9,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.catm = { meta = { description = lib.options.create { @@ -36,7 +35,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -48,28 +47,28 @@ in { config = { aux.foundation.stages.stage0.catm = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "catm"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "catm"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = - if architecture.base == "AArch64" - then hex1.package - else hex2-0.package; + executable = if architecture.base == "AArch64" then hex1.package else hex2-0.package; - args = - if architecture.base == "AArch64" - then [ - "${sources.base}/catm_${architecture.base}.hex1" - (builtins.placeholder "out") - ] - else [ - "${sources.base}/catm_${architecture.base}.hex2" - (builtins.placeholder "out") - ]; - }); + args = + if architecture.base == "AArch64" then + [ + "${sources.base}/catm_${architecture.base}.hex1" + (builtins.placeholder "out") + ] + else + [ + "${sources.base}/catm_${architecture.base}.hex2" + (builtins.placeholder "out") + ]; + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase04.nix b/foundation/src/stages/stage0/phases/phase04.nix index eea5e29..53da830 100644 --- a/foundation/src/stages/stage0/phases/phase04.nix +++ b/foundation/src/stages/stage0/phases/phase04.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.M0; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -11,7 +9,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.M0 = { meta = { description = lib.options.create { @@ -36,7 +35,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -48,34 +47,38 @@ in { config = { aux.foundation.stages.stage0.M0 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "M0"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "M0"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-0.package; + executable = hex2-0.package; - args = let - M0_hex2-0 = builders.raw.build { - pname = "M0_hex2-0"; - version = "1.6.0"; + args = + let + M0_hex2-0 = builders.raw.build { + pname = "M0_hex2-0"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = catm.package; + executable = catm.package; - args = [ + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" + "${sources.base}/M0_${architecture.base}.hex2" + ]; + }; + in + [ + M0_hex2-0 (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" - "${sources.base}/M0_${architecture.base}.hex2" ]; - }; - in [ - M0_hex2-0 - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase05.nix b/foundation/src/stages/stage0/phases/phase05.nix index 84c4548..fe4e046 100644 --- a/foundation/src/stages/stage0/phases/phase05.nix +++ b/foundation/src/stages/stage0/phases/phase05.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.cc_arch; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -12,7 +10,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.cc_arch = { meta = { description = lib.options.create { @@ -37,7 +36,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -49,47 +48,51 @@ in { config = { aux.foundation.stages.stage0.cc_arch = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "cc_arch"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "cc_arch"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-0.package; + executable = hex2-0.package; - args = let - cc_arch0_hex2-0 = builders.raw.build { - pname = "cc_arch0_hex2-0"; - version = "1.6.0"; + args = + let + cc_arch0_hex2-0 = builders.raw.build { + pname = "cc_arch0_hex2-0"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M0.package; + executable = M0.package; - args = [ - "${sources.base}/cc_${architecture.m2libc}.M1" + args = [ + "${sources.base}/cc_${architecture.m2libc}.M1" + (builtins.placeholder "out") + ]; + }; + cc_arch1_hex2-0 = builders.raw.build { + pname = "cc_arch1_hex2-0"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" + cc_arch0_hex2-0 + ]; + }; + in + [ + cc_arch1_hex2-0 (builtins.placeholder "out") ]; - }; - cc_arch1_hex2-0 = builders.raw.build { - pname = "cc_arch1_hex2-0"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" - cc_arch0_hex2-0 - ]; - }; - in [ - cc_arch1_hex2-0 - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase06.nix b/foundation/src/stages/stage0/phases/phase06.nix index 2ff8954..a5dee9f 100644 --- a/foundation/src/stages/stage0/phases/phase06.nix +++ b/foundation/src/stages/stage0/phases/phase06.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.M2; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -13,7 +11,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.M2 = { meta = { description = lib.options.create { @@ -38,7 +37,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -50,97 +49,101 @@ in { config = { aux.foundation.stages.stage0.M2 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "M2"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "M2"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-0.package; + executable = hex2-0.package; - args = let - M2_c = builders.raw.build { - pname = "M2_c"; - version = "1.6.0"; + args = + let + M2_c = builders.raw.build { + pname = "M2_c"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = catm.package; + executable = catm.package; - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c" - "${sources.m2planet}/cc.h" - "${sources.m2libc}/bootstrappable.c" - "${sources.m2planet}/cc_globals.c" - "${sources.m2planet}/cc_reader.c" - "${sources.m2planet}/cc_strings.c" - "${sources.m2planet}/cc_types.c" - "${sources.m2planet}/cc_core.c" - "${sources.m2planet}/cc_macro.c" - "${sources.m2planet}/cc.c" - ]; - }; - M2_M1 = builders.raw.build { - pname = "M2_M1"; - version = "1.6.0"; + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c" + "${sources.m2planet}/cc.h" + "${sources.m2libc}/bootstrappable.c" + "${sources.m2planet}/cc_globals.c" + "${sources.m2planet}/cc_reader.c" + "${sources.m2planet}/cc_strings.c" + "${sources.m2planet}/cc_types.c" + "${sources.m2planet}/cc_core.c" + "${sources.m2planet}/cc_macro.c" + "${sources.m2planet}/cc.c" + ]; + }; + M2_M1 = builders.raw.build { + pname = "M2_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = cc_arch.package; + executable = cc_arch.package; - args = [ - M2_c + args = [ + M2_c + (builtins.placeholder "out") + ]; + }; + M2_M1' = builders.raw.build { + pname = "M2_M1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "${sources.m2libc}/${architecture.m2libc}/libc-core.M1" + M2_M1 + ]; + }; + M2_hex2-0 = builders.raw.build { + pname = "M2_hex2-0"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M0.package; + + args = [ + M2_M1' + (builtins.placeholder "out") + ]; + }; + M2_hex2-0' = builders.raw.build { + pname = "M2_hex2-0"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" + M2_hex2-0 + ]; + }; + in + [ + M2_hex2-0' (builtins.placeholder "out") ]; - }; - M2_M1' = builders.raw.build { - pname = "M2_M1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" - "${sources.m2libc}/${architecture.m2libc}/libc-core.M1" - M2_M1 - ]; - }; - M2_hex2-0 = builders.raw.build { - pname = "M2_hex2-0"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M0.package; - - args = [ - M2_M1' - (builtins.placeholder "out") - ]; - }; - M2_hex2-0' = builders.raw.build { - pname = "M2_hex2-0"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" - M2_hex2-0 - ]; - }; - in [ - M2_hex2-0' - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase07.nix b/foundation/src/stages/stage0/phases/phase07.nix index dafba6a..7829828 100644 --- a/foundation/src/stages/stage0/phases/phase07.nix +++ b/foundation/src/stages/stage0/phases/phase07.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.blood-elf; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -14,7 +12,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.blood-elf = { meta = { description = lib.options.create { @@ -39,7 +38,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -51,86 +50,90 @@ in { config = { aux.foundation.stages.stage0.blood-elf = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "blood-elf"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "blood-elf"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-0.package; + executable = hex2-0.package; - args = let - blood-elf_M1 = builders.raw.build { - pname = "blood-elf_M1"; - version = "1.6.0"; + args = + let + blood-elf_M1 = builders.raw.build { + pname = "blood-elf_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M2.package; + executable = M2.package; - args = [ - "--architecture" - architecture.m2libc - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c" - "-f" - "${sources.m2libc}/bootstrappable.c" - "-f" - "${sources.mescc-tools}/stringify.c" - "-f" - "${sources.mescc-tools}/blood-elf.c" - "--bootstrap-mode" - "-o" + args = [ + "--architecture" + architecture.m2libc + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c" + "-f" + "${sources.m2libc}/bootstrappable.c" + "-f" + "${sources.mescc-tools}/stringify.c" + "-f" + "${sources.mescc-tools}/blood-elf.c" + "--bootstrap-mode" + "-o" + (builtins.placeholder "out") + ]; + }; + blood-elf_M1' = builders.raw.build { + pname = "blood-elf_M1-1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "${sources.m2libc}/${architecture.m2libc}/libc-core.M1" + blood-elf_M1 + ]; + }; + blood-elf_hex2-0 = builders.raw.build { + pname = "blood-elf_hex2-0"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M0.package; + + args = [ + blood-elf_M1' + (builtins.placeholder "out") + ]; + }; + blood-elf_hex2-0' = builders.raw.build { + pname = "blood-elf_hex2-0-1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" + blood-elf_hex2-0 + ]; + }; + in + [ + blood-elf_hex2-0' (builtins.placeholder "out") ]; - }; - blood-elf_M1' = builders.raw.build { - pname = "blood-elf_M1-1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" - "${sources.m2libc}/${architecture.m2libc}/libc-core.M1" - blood-elf_M1 - ]; - }; - blood-elf_hex2-0 = builders.raw.build { - pname = "blood-elf_hex2-0"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M0.package; - - args = [ - blood-elf_M1' - (builtins.placeholder "out") - ]; - }; - blood-elf_hex2-0' = builders.raw.build { - pname = "blood-elf_hex2-0-1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2" - blood-elf_hex2-0 - ]; - }; - in [ - blood-elf_hex2-0' - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase08.nix b/foundation/src/stages/stage0/phases/phase08.nix index ac1d888..0656675 100644 --- a/foundation/src/stages/stage0/phases/phase08.nix +++ b/foundation/src/stages/stage0/phases/phase08.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.M1-0; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -15,7 +13,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.M1-0 = { meta = { description = lib.options.create { @@ -40,7 +39,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -52,110 +51,108 @@ in { config = { aux.foundation.stages.stage0.M1-0 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "M1-0"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "M1-0"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-0.package; + executable = hex2-0.package; - args = let - M1-macro-0_M1 = builders.raw.build { - pname = "M1-macro-0_M1"; - version = "1.6.0"; + args = + let + M1-macro-0_M1 = builders.raw.build { + pname = "M1-macro-0_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M2.package; + executable = M2.package; - args = [ - "--architecture" - architecture.m2libc - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c" - "-f" - "${sources.m2libc}/bootstrappable.c" - "-f" - "${sources.mescc-tools}/stringify.c" - "-f" - "${sources.mescc-tools}/M1-macro.c" - "--bootstrap-mode" - "--debug" - "-o" + args = [ + "--architecture" + architecture.m2libc + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c" + "-f" + "${sources.m2libc}/bootstrappable.c" + "-f" + "${sources.mescc-tools}/stringify.c" + "-f" + "${sources.mescc-tools}/M1-macro.c" + "--bootstrap-mode" + "--debug" + "-o" + (builtins.placeholder "out") + ]; + }; + M1-macro-0-footer_M1 = builders.raw.build { + pname = "M1-macro-0-footer_M1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = blood-elf.package; + + args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [ + "-f" + M1-macro-0_M1 + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-o" + (builtins.placeholder "out") + ]; + }; + M1-macro-0_M1' = builders.raw.build { + pname = "M1-macro-0_M1-1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "${sources.m2libc}/${architecture.m2libc}/libc-core.M1" + M1-macro-0_M1 + M1-macro-0-footer_M1 + ]; + }; + M1-macro-0_hex2-0 = builders.raw.build { + pname = "M1-macro-0_hex2-0"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M0.package; + + args = [ + M1-macro-0_M1' + (builtins.placeholder "out") + ]; + }; + M1-macro-0_hex2-0' = builders.raw.build { + pname = "M1-macro-0_hex2-0-1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" + M1-macro-0_hex2-0 + ]; + }; + in + [ + M1-macro-0_hex2-0' (builtins.placeholder "out") ]; - }; - M1-macro-0-footer_M1 = builders.raw.build { - pname = "M1-macro-0-footer_M1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = blood-elf.package; - - args = - (lib.lists.when (config.aux.platform.bits == 64) "--64") - ++ [ - "-f" - M1-macro-0_M1 - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "-o" - (builtins.placeholder "out") - ]; - }; - M1-macro-0_M1' = builders.raw.build { - pname = "M1-macro-0_M1-1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" - "${sources.m2libc}/${architecture.m2libc}/libc-core.M1" - M1-macro-0_M1 - M1-macro-0-footer_M1 - ]; - }; - M1-macro-0_hex2-0 = builders.raw.build { - pname = "M1-macro-0_hex2-0"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M0.package; - - args = [ - M1-macro-0_M1' - (builtins.placeholder "out") - ]; - }; - M1-macro-0_hex2-0' = builders.raw.build { - pname = "M1-macro-0_hex2-0-1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" - M1-macro-0_hex2-0 - ]; - }; - in [ - M1-macro-0_hex2-0' - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase09.nix b/foundation/src/stages/stage0/phases/phase09.nix index 000fb72..c3fe96d 100644 --- a/foundation/src/stages/stage0/phases/phase09.nix +++ b/foundation/src/stages/stage0/phases/phase09.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.hex2-1; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -16,7 +14,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.hex2-1 = { meta = { description = lib.options.create { @@ -41,7 +40,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -53,128 +52,122 @@ in { config = { aux.foundation.stages.stage0.hex2-1 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "hex2-1"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "hex2-1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-0.package; + executable = hex2-0.package; - args = let - hex2_linker_M1 = builders.raw.build { - pname = "hex2_linker_M1"; - version = "1.6.0"; + args = + let + hex2_linker_M1 = builders.raw.build { + pname = "hex2_linker_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M2.package; + executable = M2.package; - args = [ - "--architecture" - architecture.m2libc - "-f" - "${sources.m2libc}/sys/types.h" - "-f" - "${sources.m2libc}/stddef.h" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" - "-f" - "${sources.m2libc}/fcntl.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" - "-f" - "${sources.m2libc}/stdlib.c" - "-f" - "${sources.m2libc}/stdio.h" - "-f" - "${sources.m2libc}/stdio.c" - "-f" - "${sources.m2libc}/bootstrappable.c" - "-f" - "${sources.mescc-tools}/hex2.h" - "-f" - "${sources.mescc-tools}/hex2_linker.c" - "-f" - "${sources.mescc-tools}/hex2_word.c" - "-f" - "${sources.mescc-tools}/hex2.c" - "--debug" - "-o" + args = [ + "--architecture" + architecture.m2libc + "-f" + "${sources.m2libc}/sys/types.h" + "-f" + "${sources.m2libc}/stddef.h" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" + "-f" + "${sources.m2libc}/fcntl.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" + "-f" + "${sources.m2libc}/stdlib.c" + "-f" + "${sources.m2libc}/stdio.h" + "-f" + "${sources.m2libc}/stdio.c" + "-f" + "${sources.m2libc}/bootstrappable.c" + "-f" + "${sources.mescc-tools}/hex2.h" + "-f" + "${sources.mescc-tools}/hex2_linker.c" + "-f" + "${sources.mescc-tools}/hex2_word.c" + "-f" + "${sources.mescc-tools}/hex2.c" + "--debug" + "-o" + (builtins.placeholder "out") + ]; + }; + hex2_linker-footer_M1 = builders.raw.build { + pname = "hex2_linker-footer_M1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = blood-elf.package; + + args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [ + "-f" + hex2_linker_M1 + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-o" + (builtins.placeholder "out") + ]; + }; + hex2_linker_hex2 = builders.raw.build { + pname = "hex2_linker_hex2"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M1-0.package; + + args = [ + "--architecture" + architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-f" + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "-f" + "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" + "-f" + hex2_linker_M1 + "-f" + hex2_linker-footer_M1 + "-o" + (builtins.placeholder "out") + ]; + }; + hex2_linker_hex2' = builders.raw.build { + pname = "hex2_linker_hex2-1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = catm.package; + + args = [ + (builtins.placeholder "out") + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" + hex2_linker_hex2 + ]; + }; + in + [ + hex2_linker_hex2' (builtins.placeholder "out") ]; - }; - hex2_linker-footer_M1 = builders.raw.build { - pname = "hex2_linker-footer_M1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = blood-elf.package; - - args = - (lib.lists.when (config.aux.platform.bits == 64) "--64") - ++ [ - "-f" - hex2_linker_M1 - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "-o" - (builtins.placeholder "out") - ]; - }; - hex2_linker_hex2 = builders.raw.build { - pname = "hex2_linker_hex2"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M1-0.package; - - args = [ - "--architecture" - architecture.m2libc - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "-f" - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" - "-f" - "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" - "-f" - hex2_linker_M1 - "-f" - hex2_linker-footer_M1 - "-o" - (builtins.placeholder "out") - ]; - }; - hex2_linker_hex2' = builders.raw.build { - pname = "hex2_linker_hex2-1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = catm.package; - - args = [ - (builtins.placeholder "out") - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" - hex2_linker_hex2 - ]; - }; - in [ - hex2_linker_hex2' - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase10.nix b/foundation/src/stages/stage0/phases/phase10.nix index 567713d..67dac35 100644 --- a/foundation/src/stages/stage0/phases/phase10.nix +++ b/foundation/src/stages/stage0/phases/phase10.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.M1; hex0 = config.aux.foundation.stages.stage0.hex0; hex2-0 = config.aux.foundation.stages.stage0.hex2-0; @@ -17,7 +15,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.M1 = { meta = { description = lib.options.create { @@ -42,7 +41,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -54,133 +53,124 @@ in { config = { aux.foundation.stages.stage0.M1 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "M1"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-1.package; + executable = hex2-1.package; - args = let - M1-macro_M1 = builders.raw.build { - pname = "M1-macro_M1"; - version = "1.6.0"; + args = + let + M1-macro_M1 = builders.raw.build { + pname = "M1-macro_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M2.package; + executable = M2.package; - args = [ - "--architecture" - architecture.m2libc - "-f" - "${sources.m2libc}/sys/types.h" - "-f" - "${sources.m2libc}/stddef.h" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" - "-f" - "${sources.m2libc}/fcntl.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" - "-f" - "${sources.m2libc}/string.c" - "-f" - "${sources.m2libc}/stdlib.c" - "-f" - "${sources.m2libc}/stdio.h" - "-f" - "${sources.m2libc}/stdio.c" - "-f" - "${sources.m2libc}/bootstrappable.c" - "-f" - "${sources.mescc-tools}/stringify.c" - "-f" - "${sources.mescc-tools}/M1-macro.c" - "--debug" - "-o" - (builtins.placeholder "out") - ]; - }; - M1-macro-footer_M1 = builders.raw.build { - pname = "M1-macro-footer_M1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = blood-elf.package; - - args = - (lib.lists.when (config.aux.platform.bits == 64) "--64") - ++ [ - "-f" - M1-macro_M1 - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "-o" - (builtins.placeholder "out") - ]; - }; - M1-macro_hex2 = builders.raw.build { - pname = "M1-macro_hex2"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M1-0.package; - - args = [ + args = [ + "--architecture" + architecture.m2libc + "-f" + "${sources.m2libc}/sys/types.h" + "-f" + "${sources.m2libc}/stddef.h" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" + "-f" + "${sources.m2libc}/fcntl.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" + "-f" + "${sources.m2libc}/string.c" + "-f" + "${sources.m2libc}/stdlib.c" + "-f" + "${sources.m2libc}/stdio.h" + "-f" + "${sources.m2libc}/stdio.c" + "-f" + "${sources.m2libc}/bootstrappable.c" + "-f" + "${sources.mescc-tools}/stringify.c" + "-f" + "${sources.mescc-tools}/M1-macro.c" + "--debug" + "-o" + (builtins.placeholder "out") + ]; + }; + M1-macro-footer_M1 = builders.raw.build { + pname = "M1-macro-footer_M1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = blood-elf.package; + + args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [ + "-f" + M1-macro_M1 + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-o" + (builtins.placeholder "out") + ]; + }; + M1-macro_hex2 = builders.raw.build { + pname = "M1-macro_hex2"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M1-0.package; + + args = [ + "--architecture" + architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-f" + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "-f" + "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" + "-f" + M1-macro_M1 + "-f" + M1-macro-footer_M1 + "-o" + (builtins.placeholder "out") + ]; + }; + in + [ "--architecture" architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "--base-address" ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" + if config.aux.system == "x86_64-linux" then + "0x00600000" + else if config.aux.system == "aarch64-linux" then + "0x00600000" + else if config.aux.system == "i686-linux" then + "0x08048000" + else + builtins.throw "Unsupported system: ${config.aux.system}" ) "-f" - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" "-f" - "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" - "-f" - M1-macro_M1 - "-f" - M1-macro-footer_M1 + M1-macro_hex2 "-o" (builtins.placeholder "out") ]; - }; - in [ - "--architecture" - architecture.m2libc - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "--base-address" - ( - if config.aux.system == "x86_64-linux" - then "0x00600000" - else if config.aux.system == "aarch64-linux" - then "0x00600000" - else if config.aux.system == "i686-linux" - then "0x08048000" - else builtins.throw "Unsupported system: ${config.aux.system}" - ) - "-f" - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" - "-f" - M1-macro_hex2 - "-o" - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase11.nix b/foundation/src/stages/stage0/phases/phase11.nix index 9c5ef9f..8873ae0 100644 --- a/foundation/src/stages/stage0/phases/phase11.nix +++ b/foundation/src/stages/stage0/phases/phase11.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.hex2; hex0 = config.aux.foundation.stages.stage0.hex0; catm = config.aux.foundation.stages.stage0.catm; @@ -16,7 +14,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.hex2 = { meta = { description = lib.options.create { @@ -41,7 +40,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -53,135 +52,126 @@ in { config = { aux.foundation.stages.stage0.hex2 = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "hex2"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "hex2"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2-1.package; + executable = hex2-1.package; - args = let - hex2_linker_M1 = builders.raw.build { - pname = "hex2_linker_M1"; - version = "1.6.0"; + args = + let + hex2_linker_M1 = builders.raw.build { + pname = "hex2_linker_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M2.package; + executable = M2.package; - args = [ - "--architecture" - architecture.m2libc - "-f" - "${sources.m2libc}/sys/types.h" - "-f" - "${sources.m2libc}/stddef.h" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" - "-f" - "${sources.m2libc}/fcntl.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" - "-f" - "${sources.m2libc}/stdlib.c" - "-f" - "${sources.m2libc}/stdio.h" - "-f" - "${sources.m2libc}/stdio.c" - "-f" - "${sources.m2libc}/bootstrappable.c" - "-f" - "${sources.mescc-tools}/hex2.h" - "-f" - "${sources.mescc-tools}/hex2_linker.c" - "-f" - "${sources.mescc-tools}/hex2_word.c" - "-f" - "${sources.mescc-tools}/hex2.c" - "--debug" - "-o" - (builtins.placeholder "out") - ]; - }; - hex2_linker-footer_M1 = builders.raw.build { - pname = "hex2_linker-footer_M1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = blood-elf.package; - - args = - (lib.lists.when (config.aux.platform.bits == 64) "--64") - ++ [ - "-f" - hex2_linker_M1 - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "-o" - (builtins.placeholder "out") - ]; - }; - hex2_linker_hex2 = builders.raw.build { - pname = "hex2_linker_hex2"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M1.package; - - args = [ + args = [ + "--architecture" + architecture.m2libc + "-f" + "${sources.m2libc}/sys/types.h" + "-f" + "${sources.m2libc}/stddef.h" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" + "-f" + "${sources.m2libc}/fcntl.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" + "-f" + "${sources.m2libc}/stdlib.c" + "-f" + "${sources.m2libc}/stdio.h" + "-f" + "${sources.m2libc}/stdio.c" + "-f" + "${sources.m2libc}/bootstrappable.c" + "-f" + "${sources.mescc-tools}/hex2.h" + "-f" + "${sources.mescc-tools}/hex2_linker.c" + "-f" + "${sources.mescc-tools}/hex2_word.c" + "-f" + "${sources.mescc-tools}/hex2.c" + "--debug" + "-o" + (builtins.placeholder "out") + ]; + }; + hex2_linker-footer_M1 = builders.raw.build { + pname = "hex2_linker-footer_M1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = blood-elf.package; + + args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [ + "-f" + hex2_linker_M1 + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-o" + (builtins.placeholder "out") + ]; + }; + hex2_linker_hex2 = builders.raw.build { + pname = "hex2_linker_hex2"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M1.package; + + args = [ + "--architecture" + architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-f" + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "-f" + "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" + "-f" + hex2_linker_M1 + "-f" + hex2_linker-footer_M1 + "-o" + (builtins.placeholder "out") + ]; + }; + in + [ "--architecture" architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "--base-address" ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" + if config.aux.system == "x86_64-linux" then + "0x00600000" + else if config.aux.system == "aarch64-linux" then + "0x00600000" + else if config.aux.system == "i686-linux" then + "0x08048000" + else + builtins.throw "Unsupported system: ${config.aux.system}" ) "-f" - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" "-f" - "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" - "-f" - hex2_linker_M1 - "-f" - hex2_linker-footer_M1 + hex2_linker_hex2 "-o" (builtins.placeholder "out") ]; - }; - in [ - "--architecture" - architecture.m2libc - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "--base-address" - ( - if config.aux.system == "x86_64-linux" - then "0x00600000" - else if config.aux.system == "aarch64-linux" - then "0x00600000" - else if config.aux.system == "i686-linux" - then "0x08048000" - else builtins.throw "Unsupported system: ${config.aux.system}" - ) - "-f" - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" - "-f" - hex2_linker_hex2 - "-o" - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/phases/phase12.nix b/foundation/src/stages/stage0/phases/phase12.nix index f241d84..c7634a7 100644 --- a/foundation/src/stages/stage0/phases/phase12.nix +++ b/foundation/src/stages/stage0/phases/phase12.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage0.kaem-unwrapped; hex0 = config.aux.foundation.stages.stage0.hex0; catm = config.aux.foundation.stages.stage0.catm; @@ -16,7 +14,8 @@ builders = config.aux.foundation.builders; sources = config.aux.foundation.stages.stage0.sources; architecture = config.aux.foundation.stages.stage0.architecture; -in { +in +{ options.aux.foundation.stages.stage0.kaem-unwrapped = { meta = { description = lib.options.create { @@ -41,7 +40,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -53,137 +52,128 @@ in { config = { aux.foundation.stages.stage0.kaem-unwrapped = { - package = lib.modules.overrides.default (builders.raw.build { - pname = "kaem-unwrapped"; - version = "1.6.0"; + package = lib.modules.overrides.default ( + builders.raw.build { + pname = "kaem-unwrapped"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = hex2.package; + executable = hex2.package; - args = let - kaem_M1 = builders.raw.build { - pname = "kaem_M1"; - version = "1.6.0"; + args = + let + kaem_M1 = builders.raw.build { + pname = "kaem_M1"; + version = "1.6.0"; - meta = cfg.meta; + meta = cfg.meta; - executable = M2.package; + executable = M2.package; - args = [ - "--architecture" - architecture.m2libc - "-f" - "${sources.m2libc}/sys/types.h" - "-f" - "${sources.m2libc}/stddef.h" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" - "-f" - "${sources.m2libc}/fcntl.c" - "-f" - "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" - "-f" - "${sources.m2libc}/string.c" - "-f" - "${sources.m2libc}/stdlib.c" - "-f" - "${sources.m2libc}/stdio.h" - "-f" - "${sources.m2libc}/stdio.c" - "-f" - "${sources.m2libc}/bootstrappable.c" - "-f" - "${sources.mescc-tools}/Kaem/kaem.h" - "-f" - "${sources.mescc-tools}/Kaem/variable.c" - "-f" - "${sources.mescc-tools}/Kaem/kaem_globals.c" - "-f" - "${sources.mescc-tools}/Kaem/kaem.c" - "--debug" - "-o" - (builtins.placeholder "out") - ]; - }; - kaem-footer_M1 = builders.raw.build { - pname = "kaem-footer_M1"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = blood-elf.package; - - args = - (lib.lists.when (config.aux.platform.bits == 64) "--64") - ++ [ - "-f" - kaem_M1 - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "-o" - (builtins.placeholder "out") - ]; - }; - kaem_hex2 = builders.raw.build { - pname = "kaem_hex2"; - version = "1.6.0"; - - meta = cfg.meta; - - executable = M1.package; - - args = [ + args = [ + "--architecture" + architecture.m2libc + "-f" + "${sources.m2libc}/sys/types.h" + "-f" + "${sources.m2libc}/stddef.h" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/unistd.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c" + "-f" + "${sources.m2libc}/fcntl.c" + "-f" + "${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c" + "-f" + "${sources.m2libc}/string.c" + "-f" + "${sources.m2libc}/stdlib.c" + "-f" + "${sources.m2libc}/stdio.h" + "-f" + "${sources.m2libc}/stdio.c" + "-f" + "${sources.m2libc}/bootstrappable.c" + "-f" + "${sources.mescc-tools}/Kaem/kaem.h" + "-f" + "${sources.mescc-tools}/Kaem/variable.c" + "-f" + "${sources.mescc-tools}/Kaem/kaem_globals.c" + "-f" + "${sources.mescc-tools}/Kaem/kaem.c" + "--debug" + "-o" + (builtins.placeholder "out") + ]; + }; + kaem-footer_M1 = builders.raw.build { + pname = "kaem-footer_M1"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = blood-elf.package; + + args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [ + "-f" + kaem_M1 + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-o" + (builtins.placeholder "out") + ]; + }; + kaem_hex2 = builders.raw.build { + pname = "kaem_hex2"; + version = "1.6.0"; + + meta = cfg.meta; + + executable = M1.package; + + args = [ + "--architecture" + architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "-f" + "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "-f" + "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" + "-f" + kaem_M1 + "-f" + kaem-footer_M1 + "-o" + (builtins.placeholder "out") + ]; + }; + in + [ "--architecture" architecture.m2libc + (if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian") + "--base-address" ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" + if config.aux.system == "x86_64-linux" then + "0x00600000" + else if config.aux.system == "aarch64-linux" then + "0x00600000" + else if config.aux.system == "i686-linux" then + "0x08048000" + else + builtins.throw "Unsupported system: ${config.aux.system}" ) "-f" - "${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1" + "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" "-f" - "${sources.m2libc}/${architecture.m2libc}/libc-full.M1" - "-f" - kaem_M1 - "-f" - kaem-footer_M1 + kaem_hex2 "-o" (builtins.placeholder "out") ]; - }; - in [ - "--architecture" - architecture.m2libc - ( - if config.aux.platform.endian == "little" - then "--little-endian" - else "--big-endian" - ) - "--base-address" - ( - if config.aux.system == "x86_64-linux" - then "0x00600000" - else if config.aux.system == "aarch64-linux" - then "0x00600000" - else if config.aux.system == "i686-linux" - then "0x08048000" - else builtins.throw "Unsupported system: ${config.aux.system}" - ) - "-f" - "${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2" - "-f" - kaem_hex2 - "-o" - (builtins.placeholder "out") - ]; - }); + } + ); }; }; } diff --git a/foundation/src/stages/stage0/sources/default.nix b/foundation/src/stages/stage0/sources/default.nix index af9d52b..c6406c0 100644 --- a/foundation/src/stages/stage0/sources/default.nix +++ b/foundation/src/stages/stage0/sources/default.nix @@ -1,11 +1,10 @@ -{ - lib, - config, -}: let +{ lib, config }: +let system = config.aux.system; architecture = config.aux.foundation.stages.stage0.architecture.base; -in { +in +{ options.aux.foundation.stages.stage0.sources = { base = lib.options.create { type = lib.types.string; @@ -44,27 +43,25 @@ in { # fetching that, we are instead fetching each submodule directly. The central repository is located # here: https://github.com/oriansj/stage0-posix base = - if architecture == "AMD64" - then + if architecture == "AMD64" then builtins.fetchTarball { url = "https://github.com/oriansj/stage0-posix-amd64/archive/93fbe4c08772d8df1412e2554668e24cf604088c.tar.gz"; sha256 = "10d1xnjzqplpfip3pm89bydd501x1bcgkg7lkkadyq5bqpad5flp"; } - else if architecture == "AArch64" - then + else if architecture == "AArch64" then # FIXME: We may need to patch the aarch64 variant. # https://github.com/oriansj/M2libc/pull/17 builtins.fetchTarball { url = "https://github.com/oriansj/stage0-posix-aarch64/archive/39a43f803d572b53f95d42507202152eeda18361.tar.gz"; sha256 = "1x607hr3n5j89394d156r23igpx8hifjd14ygksx7902rlwrrry2"; } - else if architecture == "x86" - then + else if architecture == "x86" then builtins.fetchTarball { url = "https://github.com/oriansj/stage0-posix-x86/archive/e86bf7d304bae5ce5ccc88454bb60cf0837e941f.tar.gz"; sha256 = "1c1fk793yzq8zbg60n2zd22fsmirc3zr26fj0iskap456g84nxv8"; } - else builtins.throw "Unsupported architecture for stage0: ${architecture}"; + else + builtins.throw "Unsupported architecture for stage0: ${architecture}"; m2libc = builtins.fetchTarball { url = "https://github.com/oriansj/M2libc/archive/de7c75f144176c3b9be77695d9bf94440445aeae.tar.gz"; diff --git a/foundation/src/stages/stage1/bash/boot.nix b/foundation/src/stages/stage1/bash/boot.nix index 1403422..d5c7035 100644 --- a/foundation/src/stages/stage1/bash/boot.nix +++ b/foundation/src/stages/stage1/bash/boot.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.bash.boot; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.bash.boot = { meta = { description = lib.options.create { @@ -32,7 +31,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -61,55 +60,56 @@ in { sha256 = "1r1z2qdw3rz668nxrzwa14vk2zcn00hw7mpjn384picck49d80xs"; }; - package = let - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b/bash-2.05b.kaem - liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b"; + package = + let + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b/bash-2.05b.kaem + liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b"; - main_mk = builtins.fetchurl { - url = "${liveBootstrap}/mk/main.mk"; - sha256 = "0hj29q3pq3370p18sxkpvv9flb7yvx2fs96xxlxqlwa8lkimd0j4"; - }; + main_mk = builtins.fetchurl { + url = "${liveBootstrap}/mk/main.mk"; + sha256 = "0hj29q3pq3370p18sxkpvv9flb7yvx2fs96xxlxqlwa8lkimd0j4"; + }; - common_mk = builtins.fetchurl { - url = "${liveBootstrap}/mk/common.mk"; - sha256 = "09rigxxf85p2ybnq248sai1gdx95yykc8jmwi4yjx389zh09mcr8"; - }; + common_mk = builtins.fetchurl { + url = "${liveBootstrap}/mk/common.mk"; + sha256 = "09rigxxf85p2ybnq248sai1gdx95yykc8jmwi4yjx389zh09mcr8"; + }; - builtins_mk = builtins.fetchurl { - url = "${liveBootstrap}/mk/builtins.mk"; - sha256 = "0939dy5by1xhfmsjj6w63nlgk509fjrhpb2crics3dpcv7prl8lj"; - }; + builtins_mk = builtins.fetchurl { + url = "${liveBootstrap}/mk/builtins.mk"; + sha256 = "0939dy5by1xhfmsjj6w63nlgk509fjrhpb2crics3dpcv7prl8lj"; + }; - patches = [ - # mes libc does not have locale support - (builtins.fetchurl { - url = "${liveBootstrap}/patches/mes-libc.patch"; - sha256 = "0zksdjf6zbb3p4hqg6plq631y76hhhgab7kdvf7cnpk8bcykn12z"; - }) - # int name, namelen; is wrong for mes libc, it is char* name, so we modify tinycc - # to reflect this. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/tinycc.patch"; - sha256 = "042d2kr4a8klazk1hlvphxr6frn4mr53k957aq3apf6lbvrjgcj2"; - }) - # add ifdef's for features we don't want - (builtins.fetchurl { - url = "${liveBootstrap}/patches/missing-defines.patch"; - sha256 = "1q0k1kj5mrvjkqqly7ki5575a5b3hy1ywnmvhrln318yh67qnkj4"; - }) - # mes libc + setting locale = not worky - (builtins.fetchurl { - url = "${liveBootstrap}/patches/locale.patch"; - sha256 = "1p1q1slhafsgj8x4k0dpn9h6ryq5fwfx7dicbbxhldbw7zvnnbx9"; - }) - # We do not have /dev at this stage of the bootstrap, including /dev/tty - (builtins.fetchurl { - url = "${liveBootstrap}/patches/dev-tty.patch"; - sha256 = "1315slv5f7ziajqyxg4jlyanf1xwd06xw14y6pq7xpm3jzjk55j9"; - }) - ]; - in + patches = [ + # mes libc does not have locale support + (builtins.fetchurl { + url = "${liveBootstrap}/patches/mes-libc.patch"; + sha256 = "0zksdjf6zbb3p4hqg6plq631y76hhhgab7kdvf7cnpk8bcykn12z"; + }) + # int name, namelen; is wrong for mes libc, it is char* name, so we modify tinycc + # to reflect this. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/tinycc.patch"; + sha256 = "042d2kr4a8klazk1hlvphxr6frn4mr53k957aq3apf6lbvrjgcj2"; + }) + # add ifdef's for features we don't want + (builtins.fetchurl { + url = "${liveBootstrap}/patches/missing-defines.patch"; + sha256 = "1q0k1kj5mrvjkqqly7ki5575a5b3hy1ywnmvhrln318yh67qnkj4"; + }) + # mes libc + setting locale = not worky + (builtins.fetchurl { + url = "${liveBootstrap}/patches/locale.patch"; + sha256 = "1p1q1slhafsgj8x4k0dpn9h6ryq5fwfx7dicbbxhldbw7zvnnbx9"; + }) + # We do not have /dev at this stage of the bootstrap, including /dev/tty + (builtins.fetchurl { + url = "${liveBootstrap}/patches/dev-tty.patch"; + sha256 = "1315slv5f7ziajqyxg4jlyanf1xwd06xw14y6pq7xpm3jzjk55j9"; + }) + ]; + in builders.kaem.build { name = "bash-${cfg.version}"; diff --git a/foundation/src/stages/stage1/bash/default.nix b/foundation/src/stages/stage1/bash/default.nix index 38952c0..2e0b319 100644 --- a/foundation/src/stages/stage1/bash/default.nix +++ b/foundation/src/stages/stage1/bash/default.nix @@ -1,17 +1,14 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.bash; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.stages.stage1.bash = { meta = { @@ -37,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { @@ -72,12 +69,13 @@ in { sha256 = "132qng0jy600mv1fs95ylnlisx2wavkkgpb19c6kmz7lnmjhjwhk"; }; - package = let - patches = [ - # flush output for generated code - ./patches/mksignames-flush.patch - ]; - in + package = + let + patches = [ + # flush output for generated code + ./patches/mksignames-flush.patch + ]; + in builders.bash.boot.build { name = "bash-${cfg.version}"; diff --git a/foundation/src/stages/stage1/binutils/default.nix b/foundation/src/stages/stage1/binutils/default.nix index 9e93240..cbe9333 100644 --- a/foundation/src/stages/stage1/binutils/default.nix +++ b/foundation/src/stages/stage1/binutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.binutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.binutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -62,32 +61,33 @@ in { sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA="; }; - package = let - patches = [ - # Make binutils output deterministic by default. - ./patches/deterministic.patch - ]; + package = + let + patches = [ + # Make binutils output deterministic by default. + ./patches/deterministic.patch + ]; - configureFlags = [ - "--prefix=${builtins.placeholder "out"}" - "--build=${platform.build}" - "--host=${platform.host}" - "--with-sysroot=/" - "--enable-deterministic-archives" - # depends on bison - "--disable-gprofng" + configureFlags = [ + "--prefix=${builtins.placeholder "out"}" + "--build=${platform.build}" + "--host=${platform.host}" + "--with-sysroot=/" + "--enable-deterministic-archives" + # depends on bison + "--disable-gprofng" - # Turn on --enable-new-dtags by default to make the linker set - # RUNPATH instead of RPATH on binaries. This is important because - # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. - "--enable-new-dtags" + # Turn on --enable-new-dtags by default to make the linker set + # RUNPATH instead of RPATH on binaries. This is important because + # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. + "--enable-new-dtags" - # By default binutils searches $libdir for libraries. This brings in - # libbfd and libopcodes into a default visibility. Drop default lib - # path to force users to declare their use of these libraries. - "--with-lib-path=:" - ]; - in + # By default binutils searches $libdir for libraries. This brings in + # libbfd and libopcodes into a default visibility. Drop default lib + # path to force users to declare their use of these libraries. + "--with-lib-path=:" + ]; + in builders.bash.boot.build { name = "binutils-${cfg.version}"; diff --git a/foundation/src/stages/stage1/bison/default.nix b/foundation/src/stages/stage1/bison/default.nix index 0adedf3..711f85e 100644 --- a/foundation/src/stages/stage1/bison/default.nix +++ b/foundation/src/stages/stage1/bison/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.bison; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.bison = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/bzip2/default.nix b/foundation/src/stages/stage1/bzip2/default.nix index 54edfad..5435bcb 100644 --- a/foundation/src/stages/stage1/bzip2/default.nix +++ b/foundation/src/stages/stage1/bzip2/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.bzip2; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.bzip2 = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; # TODO: Support more platforms. - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/coreutils/boot.nix b/foundation/src/stages/stage1/coreutils/boot.nix index d49209b..46ccba7 100644 --- a/foundation/src/stages/stage1/coreutils/boot.nix +++ b/foundation/src/stages/stage1/coreutils/boot.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.coreutils.boot; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.coreutils.boot = { package = lib.options.create { type = lib.types.derivation; @@ -34,63 +33,64 @@ in { sha256 = "10wq6k66i8adr4k08p0xmg87ff4ypiazvwzlmi7myib27xgffz62"; }; - package = let - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0/coreutils-5.0.kaem - liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0"; + package = + let + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0/coreutils-5.0.kaem + liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0"; - makefile = builtins.fetchurl { - url = "${liveBootstrap}/mk/main.mk"; - sha256 = "0njg4xccxfqrslrmlb8ls7h6hlnfmdx42nvxwmca8flvczwrplfd"; - }; + makefile = builtins.fetchurl { + url = "${liveBootstrap}/mk/main.mk"; + sha256 = "0njg4xccxfqrslrmlb8ls7h6hlnfmdx42nvxwmca8flvczwrplfd"; + }; - patches = [ - # modechange.h uses functions defined in sys/stat.h, so we need to move it to - # after sys/stat.h include. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/modechange.patch"; - sha256 = "04xa4a5w2syjs3xs6qhh8kdzqavxnrxpxwyhc3qqykpk699p3ms5"; - }) - # mbstate_t is a struct that is required. However, it is not defined by mes libc. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/mbstate.patch"; - sha256 = "0rz3c0sflgxjv445xs87b83i7gmjpl2l78jzp6nm3khdbpcc53vy"; - }) - # strcoll() does not exist in mes libc, change it to strcmp. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/ls-strcmp.patch"; - sha256 = "0lx8rz4sxq3bvncbbr6jf0kyn5bqwlfv9gxyafp0541dld6l55p6"; - }) - # getdate.c is pre-compiled from getdate.y - # At this point we don't have bison yet and in any case getdate.y does not - # compile when generated with modern bison. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/touch-getdate.patch"; - sha256 = "1xd3z57lvkj7r8vs5n0hb9cxzlyp58pji7d335snajbxzwy144ma"; - }) - # touch: add -h to change symlink timestamps, where supported - (builtins.fetchurl { - url = "${liveBootstrap}/patches/touch-dereference.patch"; - sha256 = "0wky5r3k028xwyf6g6ycwqxzc7cscgmbymncjg948vv4qxsxlfda"; - }) - # strcoll() does not exist in mes libc, change it to strcmp. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/expr-strcmp.patch"; - sha256 = "19f31lfsm1iwqzvp2fyv97lmqg4730prfygz9zip58651jf739a9"; - }) - # strcoll() does not exist in mes libc, change it to strcmp. - # hard_LC_COLLATE is used but not declared when HAVE_SETLOCALE is unset. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/sort-locale.patch"; - sha256 = "0bdch18mpyyxyl6gyqfs0wb4pap9flr11izqdyxccx1hhz0a2i6c"; - }) - # don't assume fopen cannot return stdin or stdout. - (builtins.fetchurl { - url = "${liveBootstrap}/patches/uniq-fopen.patch"; - sha256 = "0qs6shyxl9j4h34v5j5sgpxrr4gjfljd2hxzw416ghwc3xzv63fp"; - }) - ]; - in + patches = [ + # modechange.h uses functions defined in sys/stat.h, so we need to move it to + # after sys/stat.h include. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/modechange.patch"; + sha256 = "04xa4a5w2syjs3xs6qhh8kdzqavxnrxpxwyhc3qqykpk699p3ms5"; + }) + # mbstate_t is a struct that is required. However, it is not defined by mes libc. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/mbstate.patch"; + sha256 = "0rz3c0sflgxjv445xs87b83i7gmjpl2l78jzp6nm3khdbpcc53vy"; + }) + # strcoll() does not exist in mes libc, change it to strcmp. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/ls-strcmp.patch"; + sha256 = "0lx8rz4sxq3bvncbbr6jf0kyn5bqwlfv9gxyafp0541dld6l55p6"; + }) + # getdate.c is pre-compiled from getdate.y + # At this point we don't have bison yet and in any case getdate.y does not + # compile when generated with modern bison. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/touch-getdate.patch"; + sha256 = "1xd3z57lvkj7r8vs5n0hb9cxzlyp58pji7d335snajbxzwy144ma"; + }) + # touch: add -h to change symlink timestamps, where supported + (builtins.fetchurl { + url = "${liveBootstrap}/patches/touch-dereference.patch"; + sha256 = "0wky5r3k028xwyf6g6ycwqxzc7cscgmbymncjg948vv4qxsxlfda"; + }) + # strcoll() does not exist in mes libc, change it to strcmp. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/expr-strcmp.patch"; + sha256 = "19f31lfsm1iwqzvp2fyv97lmqg4730prfygz9zip58651jf739a9"; + }) + # strcoll() does not exist in mes libc, change it to strcmp. + # hard_LC_COLLATE is used but not declared when HAVE_SETLOCALE is unset. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/sort-locale.patch"; + sha256 = "0bdch18mpyyxyl6gyqfs0wb4pap9flr11izqdyxccx1hhz0a2i6c"; + }) + # don't assume fopen cannot return stdin or stdout. + (builtins.fetchurl { + url = "${liveBootstrap}/patches/uniq-fopen.patch"; + sha256 = "0qs6shyxl9j4h34v5j5sgpxrr4gjfljd2hxzw416ghwc3xzv63fp"; + }) + ]; + in builders.kaem.build { name = "coreutils-boot-${cfg.version}"; diff --git a/foundation/src/stages/stage1/coreutils/default.nix b/foundation/src/stages/stage1/coreutils/default.nix index a995064..a3390e7 100644 --- a/foundation/src/stages/stage1/coreutils/default.nix +++ b/foundation/src/stages/stage1/coreutils/default.nix @@ -1,17 +1,14 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.coreutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.stages.stage1.coreutils = { meta = { @@ -37,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -66,17 +63,18 @@ in { sha256 = "X2ANkJOXOwr+JTk9m8GMRPIjJlf0yg2V6jHHAutmtzk="; }; - package = let - configureFlags = [ - "--prefix=${builtins.placeholder "out"}" - "--build=${platform.build}" - "--host=${platform.host}" - # musl 1.1.x doesn't use 64bit time_t - "--disable-year2038" - # libstdbuf.so fails in static builds - "--enable-no-install-program=stdbuf" - ]; - in + package = + let + configureFlags = [ + "--prefix=${builtins.placeholder "out"}" + "--build=${platform.build}" + "--host=${platform.host}" + # musl 1.1.x doesn't use 64bit time_t + "--disable-year2038" + # libstdbuf.so fails in static builds + "--enable-no-install-program=stdbuf" + ]; + in builders.bash.boot.build { name = "coreutils-${cfg.version}"; diff --git a/foundation/src/stages/stage1/default.nix b/foundation/src/stages/stage1/default.nix index 6505edb..6bc94f8 100644 --- a/foundation/src/stages/stage1/default.nix +++ b/foundation/src/stages/stage1/default.nix @@ -1,11 +1,10 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ includes = [ ./nyacc ./mes diff --git a/foundation/src/stages/stage1/diffutils/default.nix b/foundation/src/stages/stage1/diffutils/default.nix index 67d6ee7..c3903ea 100644 --- a/foundation/src/stages/stage1/diffutils/default.nix +++ b/foundation/src/stages/stage1/diffutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.diffutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.diffutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/findutils/default.nix b/foundation/src/stages/stage1/findutils/default.nix index dc62440..30eb797 100644 --- a/foundation/src/stages/stage1/findutils/default.nix +++ b/foundation/src/stages/stage1/findutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.findutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.findutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/gawk/boot.nix b/foundation/src/stages/stage1/gawk/boot.nix index 165ab89..bd0abd8 100644 --- a/foundation/src/stages/stage1/gawk/boot.nix +++ b/foundation/src/stages/stage1/gawk/boot.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gawk.boot; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gawk.boot = { package = lib.options.create { type = lib.types.derivation; @@ -35,12 +34,13 @@ in { sha256 = "1z4bibjm7ldvjwq3hmyifyb429rs2d9bdwkvs0r171vv1khpdwmb"; }; - package = let - patches = [ - # for reproducibility don't generate date stamp - ./patches/no-stamp.patch - ]; - in + package = + let + patches = [ + # for reproducibility don't generate date stamp + ./patches/no-stamp.patch + ]; + in builders.bash.boot.build { name = "gawk-boot-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gawk/default.nix b/foundation/src/stages/stage1/gawk/default.nix index df8b03f..0ac0583 100644 --- a/foundation/src/stages/stage1/gawk/default.nix +++ b/foundation/src/stages/stage1/gawk/default.nix @@ -1,17 +1,14 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gawk; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.stages.stage1.gawk = { meta = { @@ -37,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage1/gcc/default.nix b/foundation/src/stages/stage1/gcc/default.nix index 94eac78..93f91d9 100644 --- a/foundation/src/stages/stage1/gcc/default.nix +++ b/foundation/src/stages/stage1/gcc/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gcc; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ includes = [ ./v4.6.nix ./v4.6.cxx.nix @@ -39,7 +38,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/gcc/v4.6.cxx.nix b/foundation/src/stages/stage1/gcc/v4.6.cxx.nix index bc4835b..459fde6 100644 --- a/foundation/src/stages/stage1/gcc/v4.6.cxx.nix +++ b/foundation/src/stages/stage1/gcc/v4.6.cxx.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gcc.v46.cxx; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gcc.v46.cxx = { package = lib.options.create { type = lib.types.derivation; @@ -112,12 +111,13 @@ in { }; }; - package = let - patches = [ - # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR - ./patches/no-system-headers.patch - ]; - in + package = + let + patches = [ + # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR + ./patches/no-system-headers.patch + ]; + in builders.bash.build { name = "gcc-cxx-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gcc/v4.6.nix b/foundation/src/stages/stage1/gcc/v4.6.nix index c47df89..5568ac3 100644 --- a/foundation/src/stages/stage1/gcc/v4.6.nix +++ b/foundation/src/stages/stage1/gcc/v4.6.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gcc.v46; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gcc.v46 = { package = lib.options.create { type = lib.types.derivation; @@ -112,12 +111,13 @@ in { }; }; - package = let - patches = [ - # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR - ./patches/no-system-headers.patch - ]; - in + package = + let + patches = [ + # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR + ./patches/no-system-headers.patch + ]; + in builders.bash.build { name = "gcc-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gcc/v8.nix b/foundation/src/stages/stage1/gcc/v8.nix index 6188475..c738289 100644 --- a/foundation/src/stages/stage1/gcc/v8.nix +++ b/foundation/src/stages/stage1/gcc/v8.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gcc.v8; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gcc.v8 = { package = lib.options.create { type = lib.types.derivation; diff --git a/foundation/src/stages/stage1/gnugrep/default.nix b/foundation/src/stages/stage1/gnugrep/default.nix index 502bdb1..f5150fb 100644 --- a/foundation/src/stages/stage1/gnugrep/default.nix +++ b/foundation/src/stages/stage1/gnugrep/default.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnugrep; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnugrep = { meta = { description = lib.options.create { @@ -32,7 +31,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { @@ -67,14 +66,15 @@ in { sha256 = "05iayw5sfclc476vpviz67hdy03na0pz2kb5csa50232nfx34853"; }; - package = let - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4 - makefile = builtins.fetchurl { - url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4/mk/main.mk"; - sha256 = "08an9ljlqry3p15w28hahm6swnd3jxizsd2188przvvsj093j91k"; - }; - in + package = + let + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4 + makefile = builtins.fetchurl { + url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4/mk/main.mk"; + sha256 = "08an9ljlqry3p15w28hahm6swnd3jxizsd2188przvvsj093j91k"; + }; + in builders.bash.boot.build { name = "gnugrep-${cfg.version}"; meta = cfg.meta; diff --git a/foundation/src/stages/stage1/gnum4/default.nix b/foundation/src/stages/stage1/gnum4/default.nix index 1e7e9c3..35482a7 100644 --- a/foundation/src/stages/stage1/gnum4/default.nix +++ b/foundation/src/stages/stage1/gnum4/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnum4; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnum4 = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/gnumake/boot.nix b/foundation/src/stages/stage1/gnumake/boot.nix index 8cc0a1f..3518268 100644 --- a/foundation/src/stages/stage1/gnumake/boot.nix +++ b/foundation/src/stages/stage1/gnumake/boot.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnumake.boot; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnumake.boot = { package = lib.options.create { type = lib.types.derivation; @@ -34,88 +33,88 @@ in { sha256 = "1cwgcmwdn7gqn5da2ia91gkyiqs9birr10sy5ykpkaxzcwfzn5nx"; }; - package = let - patches = [ - # Replaces /bin/sh with sh, see patch file for reasoning - ./patches/0001-No-impure-bin-sh.patch - # Purity: don't look for library dependencies (of the form `-lfoo') in /lib - # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for - # included Makefiles, don't look in /usr/include and friends. - ./patches/0002-remove-impure-dirs.patch - # Fixes for tinycc. See comments in patch file for reasoning - ./patches/0003-tinycc-support.patch - ]; + package = + let + patches = [ + # Replaces /bin/sh with sh, see patch file for reasoning + ./patches/0001-No-impure-bin-sh.patch + # Purity: don't look for library dependencies (of the form `-lfoo') in /lib + # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for + # included Makefiles, don't look in /usr/include and friends. + ./patches/0002-remove-impure-dirs.patch + # Fixes for tinycc. See comments in patch file for reasoning + ./patches/0003-tinycc-support.patch + ]; - /* - Maintenance notes: + /* + Maintenance notes: - Generated by - ./configure \ - --build i686-pc-linux-gnu \ - --host i686-pc-linux-gnu \ - CC="${tinycc.compiler}/bin/tcc -B ${tinycc.libs}/lib" \ - ac_cv_func_dup=no - - `ac_cv_func_dup` disabled as mes-libc doesn't implement tmpfile() + Generated by + ./configure \ + --build i686-pc-linux-gnu \ + --host i686-pc-linux-gnu \ + CC="${tinycc.compiler}/bin/tcc -B ${tinycc.libs}/lib" \ + ac_cv_func_dup=no + - `ac_cv_func_dup` disabled as mes-libc doesn't implement tmpfile() - The output src/config.h was then manually filtered, removing definitions that - didn't have uses in the source code - */ - config = [ - "-DFILE_TIMESTAMP_HI_RES=0" - "-DHAVE_ALLOCA" - "-DHAVE_ALLOCA_H" - "-DHAVE_ATEXIT" - "-DHAVE_DECL_BSD_SIGNAL=0" - "-DHAVE_DECL_GETLOADAVG=0" - "-DHAVE_DECL_SYS_SIGLIST=0" - "-DHAVE_DECL__SYS_SIGLIST=0" - "-DHAVE_DECL___SYS_SIGLIST=0" - "-DHAVE_DIRENT_H" - "-DHAVE_DUP2" - "-DHAVE_FCNTL_H" - "-DHAVE_FDOPEN" - "-DHAVE_GETCWD" - "-DHAVE_GETTIMEOFDAY" - "-DHAVE_INTTYPES_H" - "-DHAVE_ISATTY" - "-DHAVE_LIMITS_H" - "-DHAVE_LOCALE_H" - "-DHAVE_MEMORY_H" - "-DHAVE_MKTEMP" - "-DHAVE_SA_RESTART" - "-DHAVE_SETVBUF" - "-DHAVE_SIGACTION" - "-DHAVE_SIGSETMASK" - "-DHAVE_STDINT_H" - "-DHAVE_STDLIB_H" - "-DHAVE_STRDUP" - "-DHAVE_STRERROR" - "-DHAVE_STRINGS_H" - "-DHAVE_STRING_H" - "-DHAVE_STRTOLL" - "-DHAVE_SYS_FILE_H" - "-DHAVE_SYS_PARAM_H" - "-DHAVE_SYS_RESOURCE_H" - "-DHAVE_SYS_SELECT_H" - "-DHAVE_SYS_STAT_H" - "-DHAVE_SYS_TIMEB_H" - "-DHAVE_SYS_TIME_H" - "-DHAVE_SYS_WAIT_H" - "-DHAVE_TTYNAME" - "-DHAVE_UMASK" - "-DHAVE_UNISTD_H" - "-DHAVE_WAITPID" - "-DMAKE_JOBSERVER" - "-DMAKE_SYMLINKS" - "-DPATH_SEPARATOR_CHAR=':'" - "-DSCCS_GET=\\\"get\\\"" - "-DSTDC_HEADERS" - "-Dsig_atomic_t=int" - "-Dvfork=fork" - ]; + The output src/config.h was then manually filtered, removing definitions that + didn't have uses in the source code + */ + config = [ + "-DFILE_TIMESTAMP_HI_RES=0" + "-DHAVE_ALLOCA" + "-DHAVE_ALLOCA_H" + "-DHAVE_ATEXIT" + "-DHAVE_DECL_BSD_SIGNAL=0" + "-DHAVE_DECL_GETLOADAVG=0" + "-DHAVE_DECL_SYS_SIGLIST=0" + "-DHAVE_DECL__SYS_SIGLIST=0" + "-DHAVE_DECL___SYS_SIGLIST=0" + "-DHAVE_DIRENT_H" + "-DHAVE_DUP2" + "-DHAVE_FCNTL_H" + "-DHAVE_FDOPEN" + "-DHAVE_GETCWD" + "-DHAVE_GETTIMEOFDAY" + "-DHAVE_INTTYPES_H" + "-DHAVE_ISATTY" + "-DHAVE_LIMITS_H" + "-DHAVE_LOCALE_H" + "-DHAVE_MEMORY_H" + "-DHAVE_MKTEMP" + "-DHAVE_SA_RESTART" + "-DHAVE_SETVBUF" + "-DHAVE_SIGACTION" + "-DHAVE_SIGSETMASK" + "-DHAVE_STDINT_H" + "-DHAVE_STDLIB_H" + "-DHAVE_STRDUP" + "-DHAVE_STRERROR" + "-DHAVE_STRINGS_H" + "-DHAVE_STRING_H" + "-DHAVE_STRTOLL" + "-DHAVE_SYS_FILE_H" + "-DHAVE_SYS_PARAM_H" + "-DHAVE_SYS_RESOURCE_H" + "-DHAVE_SYS_SELECT_H" + "-DHAVE_SYS_STAT_H" + "-DHAVE_SYS_TIMEB_H" + "-DHAVE_SYS_TIME_H" + "-DHAVE_SYS_WAIT_H" + "-DHAVE_TTYNAME" + "-DHAVE_UMASK" + "-DHAVE_UNISTD_H" + "-DHAVE_WAITPID" + "-DMAKE_JOBSERVER" + "-DMAKE_SYMLINKS" + "-DPATH_SEPARATOR_CHAR=':'" + "-DSCCS_GET=\\\"get\\\"" + "-DSTDC_HEADERS" + "-Dsig_atomic_t=int" + "-Dvfork=fork" + ]; - cflags = - [ + cflags = [ "-I./src" "-I./lib" "-DHAVE_CONFIG_H" @@ -127,67 +126,53 @@ in { "-DNO_OUTPUT_SYNC=1" # mes-libc doesn't define O_TMPFILE "-DO_TMPFILE=020000000" - ] - ++ config; + ] ++ config; - sources = { - # Maintenance note: list of source files derived from Basic.mk - make = [ - "src/ar.c" - "src/arscan.c" - "src/commands.c" - "src/default.c" - "src/dir.c" - "src/expand.c" - "src/file.c" - "src/function.c" - "src/getopt.c" - "src/getopt1.c" - "src/guile.c" - "src/hash.c" - "src/implicit.c" - "src/job.c" - "src/load.c" - "src/loadapi.c" - "src/main.c" - "src/misc.c" - "src/output.c" - "src/read.c" - "src/remake.c" - "src/rule.c" - "src/shuffle.c" - "src/signame.c" - "src/strcache.c" - "src/variable.c" - "src/version.c" - "src/vpath.c" - ]; - glob = [ - "lib/fnmatch.c" - "lib/glob.c" - ]; - remote = [ - "src/remote-stub.c" - ]; - }; + sources = { + # Maintenance note: list of source files derived from Basic.mk + make = [ + "src/ar.c" + "src/arscan.c" + "src/commands.c" + "src/default.c" + "src/dir.c" + "src/expand.c" + "src/file.c" + "src/function.c" + "src/getopt.c" + "src/getopt1.c" + "src/guile.c" + "src/hash.c" + "src/implicit.c" + "src/job.c" + "src/load.c" + "src/loadapi.c" + "src/main.c" + "src/misc.c" + "src/output.c" + "src/read.c" + "src/remake.c" + "src/rule.c" + "src/shuffle.c" + "src/signame.c" + "src/strcache.c" + "src/variable.c" + "src/version.c" + "src/vpath.c" + ]; + glob = [ + "lib/fnmatch.c" + "lib/glob.c" + ]; + remote = [ "src/remote-stub.c" ]; + }; - files = - sources.make - ++ sources.glob - ++ sources.remote - ++ [ - "src/posixos.c" - ]; + files = sources.make ++ sources.glob ++ sources.remote ++ [ "src/posixos.c" ]; - objects = - builtins.map - ( - value: - builtins.replaceStrings [".c"] [".o"] - (builtins.baseNameOf value) - ) - files; - in + objects = builtins.map ( + value: builtins.replaceStrings [ ".c" ] [ ".o" ] (builtins.baseNameOf value) + ) files; + in builders.kaem.build { name = "gnumake-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gnumake/default.nix b/foundation/src/stages/stage1/gnumake/default.nix index 09c3da0..94b018b 100644 --- a/foundation/src/stages/stage1/gnumake/default.nix +++ b/foundation/src/stages/stage1/gnumake/default.nix @@ -1,17 +1,14 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnumake; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.stages.stage1.gnumake = { meta = { @@ -37,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -66,16 +63,17 @@ in { sha256 = "3Rb7HWe/q3mnL16DkHNcSePo5wtJRaFasfgd23hlj7M="; }; - package = let - patches = [ - # Replaces /bin/sh with sh, see patch file for reasoning - ./patches/0001-No-impure-bin-sh.patch - # Purity: don't look for library dependencies (of the form `-lfoo') in /lib - # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for - # included Makefiles, don't look in /usr/include and friends. - ./patches/0002-remove-impure-dirs.patch - ]; - in + package = + let + patches = [ + # Replaces /bin/sh with sh, see patch file for reasoning + ./patches/0001-No-impure-bin-sh.patch + # Purity: don't look for library dependencies (of the form `-lfoo') in /lib + # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for + # included Makefiles, don't look in /usr/include and friends. + ./patches/0002-remove-impure-dirs.patch + ]; + in builders.bash.boot.build { name = "gnumake-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gnupatch/default.nix b/foundation/src/stages/stage1/gnupatch/default.nix index fcd53b7..af02e78 100644 --- a/foundation/src/stages/stage1/gnupatch/default.nix +++ b/foundation/src/stages/stage1/gnupatch/default.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnupatch; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnupatch = { meta = { description = lib.options.create { @@ -32,7 +31,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -61,82 +60,72 @@ in { sha256 = "12nv7jx3gxfp50y11nxzlnmqqrpicjggw6pcsq0wyavkkm3cddgc"; }; - package = let - # Thanks to the live-bootstrap project! - # https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/patch-2.5.9/mk/main.mk - cflags = [ - "-I." - "-DHAVE_DECL_GETENV" - "-DHAVE_DECL_MALLOC" - "-DHAVE_DIRENT_H" - "-DHAVE_LIMITS_H" - "-DHAVE_GETEUID" - "-DHAVE_MKTEMP" - "-DPACKAGE_BUGREPORT=" - "-Ded_PROGRAM=\\\"/nullop\\\"" - "-Dmbstate_t=int" # When HAVE_MBRTOWC is not enabled uses of mbstate_t are always a no-op - "-DRETSIGTYPE=int" - "-DHAVE_MKDIR" - "-DHAVE_RMDIR" - "-DHAVE_FCNTL_H" - "-DPACKAGE_NAME=\\\"patch\\\"" - "-DPACKAGE_VERSION=\\\"${cfg.version}\\\"" - "-DHAVE_MALLOC" - "-DHAVE_REALLOC" - "-DSTDC_HEADERS" - "-DHAVE_STRING_H" - "-DHAVE_STDLIB_H" - ]; + package = + let + # Thanks to the live-bootstrap project! + # https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/patch-2.5.9/mk/main.mk + cflags = [ + "-I." + "-DHAVE_DECL_GETENV" + "-DHAVE_DECL_MALLOC" + "-DHAVE_DIRENT_H" + "-DHAVE_LIMITS_H" + "-DHAVE_GETEUID" + "-DHAVE_MKTEMP" + "-DPACKAGE_BUGREPORT=" + "-Ded_PROGRAM=\\\"/nullop\\\"" + "-Dmbstate_t=int" # When HAVE_MBRTOWC is not enabled uses of mbstate_t are always a no-op + "-DRETSIGTYPE=int" + "-DHAVE_MKDIR" + "-DHAVE_RMDIR" + "-DHAVE_FCNTL_H" + "-DPACKAGE_NAME=\\\"patch\\\"" + "-DPACKAGE_VERSION=\\\"${cfg.version}\\\"" + "-DHAVE_MALLOC" + "-DHAVE_REALLOC" + "-DSTDC_HEADERS" + "-DHAVE_STRING_H" + "-DHAVE_STDLIB_H" + ]; - # Maintenance note: List of sources from Makefile.in - files = [ - "addext.c" - "argmatch.c" - "backupfile.c" - "basename.c" - "dirname.c" - "getopt.c" - "getopt1.c" - "inp.c" - "maketime.c" - "partime.c" - "patch.c" - "pch.c" - "quote.c" - "quotearg.c" - "quotesys.c" - "util.c" - "version.c" - "xmalloc.c" - ]; + # Maintenance note: List of sources from Makefile.in + files = [ + "addext.c" + "argmatch.c" + "backupfile.c" + "basename.c" + "dirname.c" + "getopt.c" + "getopt1.c" + "inp.c" + "maketime.c" + "partime.c" + "patch.c" + "pch.c" + "quote.c" + "quotearg.c" + "quotesys.c" + "util.c" + "version.c" + "xmalloc.c" + ]; - sources = - files - ++ [ + sources = files ++ [ # mes-libc doesn't implement `error()` "error.c" ]; - objects = - builtins.map - ( - value: - builtins.replaceStrings - [".c"] - [".o"] - (builtins.baseNameOf value) - ) - sources; - in + objects = builtins.map ( + value: builtins.replaceStrings [ ".c" ] [ ".o" ] (builtins.baseNameOf value) + ) sources; + in builders.kaem.build { name = "gnupatch-${cfg.version}"; meta = cfg.meta; src = cfg.src; - deps.build.host = [ - stage1.tinycc.mes.compiler.package - ]; + deps.build.host = [ stage1.tinycc.mes.compiler.package ]; script = '' # Unpack diff --git a/foundation/src/stages/stage1/gnused/boot.nix b/foundation/src/stages/stage1/gnused/boot.nix index 0f28085..5299386 100644 --- a/foundation/src/stages/stage1/gnused/boot.nix +++ b/foundation/src/stages/stage1/gnused/boot.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnused.boot; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnused.boot = { package = lib.options.create { type = lib.types.derivation; @@ -34,14 +33,15 @@ in { sha256 = "0006gk1dw2582xsvgx6y6rzs9zw8b36rhafjwm288zqqji3qfrf3"; }; - package = let - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem - makefile = builtins.fetchurl { - url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/mk/main.mk"; - sha256 = "0w1f5ri0g5zla31m6l6xyzbqwdvandqfnzrsw90dd6ak126w3mya"; - }; - in + package = + let + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem + makefile = builtins.fetchurl { + url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/mk/main.mk"; + sha256 = "0w1f5ri0g5zla31m6l6xyzbqwdvandqfnzrsw90dd6ak126w3mya"; + }; + in builders.bash.boot.build { name = "gnused-boot-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gnused/default.nix b/foundation/src/stages/stage1/gnused/default.nix index 74d804a..3c4418f 100644 --- a/foundation/src/stages/stage1/gnused/default.nix +++ b/foundation/src/stages/stage1/gnused/default.nix @@ -1,17 +1,14 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnused; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.stages.stage1.gnused = { meta = { @@ -37,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage1/gnutar/boot.nix b/foundation/src/stages/stage1/gnutar/boot.nix index 178e2dc..df5d8a1 100644 --- a/foundation/src/stages/stage1/gnutar/boot.nix +++ b/foundation/src/stages/stage1/gnutar/boot.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnutar.boot; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnutar.boot = { package = lib.options.create { type = lib.types.derivation; @@ -35,8 +34,9 @@ in { sha256 = "02m6gajm647n8l9a5bnld6fnbgdpyi4i3i83p7xcwv0kif47xhy6"; }; - package = let - in + package = + let + in builders.bash.boot.build { name = "gnutar-boot-${cfg.version}"; diff --git a/foundation/src/stages/stage1/gnutar/default.nix b/foundation/src/stages/stage1/gnutar/default.nix index 1c69b74..ba25738 100644 --- a/foundation/src/stages/stage1/gnutar/default.nix +++ b/foundation/src/stages/stage1/gnutar/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnutar; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ includes = [ ./boot.nix ./musl.nix @@ -38,7 +37,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage1/gnutar/musl.nix b/foundation/src/stages/stage1/gnutar/musl.nix index ea02d70..b968384 100644 --- a/foundation/src/stages/stage1/gnutar/musl.nix +++ b/foundation/src/stages/stage1/gnutar/musl.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gnutar.musl; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gnutar.musl = { package = lib.options.create { type = lib.types.derivation; diff --git a/foundation/src/stages/stage1/gzip/default.nix b/foundation/src/stages/stage1/gzip/default.nix index 88bd6ce..a59b251 100644 --- a/foundation/src/stages/stage1/gzip/default.nix +++ b/foundation/src/stages/stage1/gzip/default.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.gzip; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.gzip = { meta = { description = lib.options.create { @@ -32,7 +31,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -61,8 +60,9 @@ in { sha256 = "0ryr5b00qz3xcdcv03qwjdfji8pasp0007ay3ppmk71wl8c1i90w"; }; - package = let - in + package = + let + in builders.bash.boot.build { name = "gzip-${cfg.version}"; meta = cfg.meta; diff --git a/foundation/src/stages/stage1/heirloom/default.nix b/foundation/src/stages/stage1/heirloom/default.nix index 57bb742..63f79cf 100644 --- a/foundation/src/stages/stage1/heirloom/default.nix +++ b/foundation/src/stages/stage1/heirloom/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.heirloom; platform = config.aux.platform; @@ -9,10 +7,9 @@ stage1 = config.aux.foundation.stages.stage1; stage2 = config.aux.foundation.stages.stage2; -in { - includes = [ - ./devtools.nix - ]; +in +{ + includes = [ ./devtools.nix ]; options.aux.foundation.stages.stage1.heirloom = { meta = { @@ -48,7 +45,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -77,61 +74,62 @@ in { sha256 = "6zP3C8wBmx0OCkHx11UtRcV6FicuThxIY07D5ESWow8="; }; - package = let - patches = [ - # we pre-generate nawk's proctab.c as meslibc is not capable of running maketab - # during build time (insufficient sscanf support) - ./patches/proctab.patch + package = + let + patches = [ + # we pre-generate nawk's proctab.c as meslibc is not capable of running maketab + # during build time (insufficient sscanf support) + ./patches/proctab.patch - # disable utilities that don't build successfully - ./patches/disable-programs.patch + # disable utilities that don't build successfully + ./patches/disable-programs.patch - # "tcc -ar" doesn't support creating empty archives - ./patches/tcc-empty-ar.patch - # meslibc doesn't have seperate libm - ./patches/dont-link-lm.patch - # meslibc's vprintf doesn't support %ll - ./patches/vprintf.patch - # meslibc doesn't support sysconf() - ./patches/sysconf.patch - # meslibc doesn't support locale - ./patches/strcoll.patch - # meslibc doesn't support termios.h - ./patches/termios.patch - # meslibc doesn't support utime.h - ./patches/utime.patch - # meslibc doesn't support langinfo.h - ./patches/langinfo.patch - # support building with meslibc - ./patches/meslibc-support.patch - # remove socket functionality as unsupported by meslibc - ./patches/cp-no-socket.patch - ]; + # "tcc -ar" doesn't support creating empty archives + ./patches/tcc-empty-ar.patch + # meslibc doesn't have seperate libm + ./patches/dont-link-lm.patch + # meslibc's vprintf doesn't support %ll + ./patches/vprintf.patch + # meslibc doesn't support sysconf() + ./patches/sysconf.patch + # meslibc doesn't support locale + ./patches/strcoll.patch + # meslibc doesn't support termios.h + ./patches/termios.patch + # meslibc doesn't support utime.h + ./patches/utime.patch + # meslibc doesn't support langinfo.h + ./patches/langinfo.patch + # support building with meslibc + ./patches/meslibc-support.patch + # remove socket functionality as unsupported by meslibc + ./patches/cp-no-socket.patch + ]; - makeFlags = [ - # mk.config build options - "CC='tcc -B ${stage1.tinycc.mes.libs.package}/lib -include ${./stubs.h} -include ${./musl.h}'" - "AR='tcc -ar'" - "RANLIB=true" - "STRIP=true" - "SHELL=${stage1.bash.package}/bin/sh" - "POSIX_SHELL=${stage1.bash.package}/bin/sh" - "DEFBIN=/bin" - "SV3BIN=/5bin" - "S42BIN=/5bin/s42" - "SUSBIN=/bin" - "SU3BIN=/5bin/posix2001" - "UCBBIN=/ucb" - "CCSBIN=/ccs/bin" - "DEFLIB=/lib" - "DEFSBIN=/bin" - "MANDIR=/share/man" - "LCURS=" # disable ncurses - "USE_ZLIB=0" # disable zlib - "IWCHAR='-I../libwchar'" - "LWCHAR='-L../libwchar -lwchar'" - ]; - in + makeFlags = [ + # mk.config build options + "CC='tcc -B ${stage1.tinycc.mes.libs.package}/lib -include ${./stubs.h} -include ${./musl.h}'" + "AR='tcc -ar'" + "RANLIB=true" + "STRIP=true" + "SHELL=${stage1.bash.package}/bin/sh" + "POSIX_SHELL=${stage1.bash.package}/bin/sh" + "DEFBIN=/bin" + "SV3BIN=/5bin" + "S42BIN=/5bin/s42" + "SUSBIN=/bin" + "SU3BIN=/5bin/posix2001" + "UCBBIN=/ucb" + "CCSBIN=/ccs/bin" + "DEFLIB=/lib" + "DEFSBIN=/bin" + "MANDIR=/share/man" + "LCURS=" # disable ncurses + "USE_ZLIB=0" # disable zlib + "IWCHAR='-I../libwchar'" + "LWCHAR='-L../libwchar -lwchar'" + ]; + in builders.bash.boot.build { name = "heirloom-${cfg.version}"; meta = cfg.meta; diff --git a/foundation/src/stages/stage1/heirloom/devtools.nix b/foundation/src/stages/stage1/heirloom/devtools.nix index affce51..87b9243 100644 --- a/foundation/src/stages/stage1/heirloom/devtools.nix +++ b/foundation/src/stages/stage1/heirloom/devtools.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.heirloom.devtools; platform = config.aux.platform; @@ -10,7 +8,8 @@ stage0 = config.aux.foundation.stages.stage0; stage1 = config.aux.foundation.stages.stage1; stage2 = config.aux.foundation.stages.stage2; -in { +in +{ options.aux.foundation.stages.stage1.heirloom.devtools = { package = lib.options.create { type = lib.types.derivation; @@ -54,7 +53,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; }; @@ -68,24 +67,25 @@ in { sha256 = "9f233d8b78e4351fe9dd2d50d83958a0e5af36f54e9818521458a08e058691ba"; }; - package = let - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527/heirloom-devtools-070527.kaem - liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527"; + package = + let + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527/heirloom-devtools-070527.kaem + liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527"; - patches = [ - # Remove all kinds of wchar support. Mes Libc does not support wchar in any form - (builtins.fetchurl { - url = "${liveBootstrap}/patches/yacc_remove_wchar.patch"; - sha256 = "0wgiz02bb7xzjy2gnbjp8y31qy6rc4b29v01zi32zh9lw54j68hc"; - }) - # Similarly to yacc, remove wchar. See yacc patch for further information - (builtins.fetchurl { - url = "${liveBootstrap}/patches/lex_remove_wchar.patch"; - sha256 = "168dfngi51ljjqgd55wbvmffaq61gk48gak50ymnl1br92qkp4zh"; - }) - ]; - in + patches = [ + # Remove all kinds of wchar support. Mes Libc does not support wchar in any form + (builtins.fetchurl { + url = "${liveBootstrap}/patches/yacc_remove_wchar.patch"; + sha256 = "0wgiz02bb7xzjy2gnbjp8y31qy6rc4b29v01zi32zh9lw54j68hc"; + }) + # Similarly to yacc, remove wchar. See yacc patch for further information + (builtins.fetchurl { + url = "${liveBootstrap}/patches/lex_remove_wchar.patch"; + sha256 = "168dfngi51ljjqgd55wbvmffaq61gk48gak50ymnl1br92qkp4zh"; + }) + ]; + in builders.kaem.build { name = "heirloom-${cfg.version}"; meta = cfg.meta; diff --git a/foundation/src/stages/stage1/linux-headers/default.nix b/foundation/src/stages/stage1/linux-headers/default.nix index fc496fe..c999611 100644 --- a/foundation/src/stages/stage1/linux-headers/default.nix +++ b/foundation/src/stages/stage1/linux-headers/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.linux-headers; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.linux-headers = { meta = { description = lib.options.create { @@ -27,7 +26,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/ln-boot/default.nix b/foundation/src/stages/stage1/ln-boot/default.nix index 833cba3..7b98c20 100644 --- a/foundation/src/stages/stage1/ln-boot/default.nix +++ b/foundation/src/stages/stage1/ln-boot/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.ln-boot; builders = config.aux.foundation.builders; stage0 = config.aux.foundation.stages.stage0; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.ln-boot = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/mes/compiler.nix b/foundation/src/stages/stage1/mes/compiler.nix index a6e8974..e45e0e2 100644 --- a/foundation/src/stages/stage1/mes/compiler.nix +++ b/foundation/src/stages/stage1/mes/compiler.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.mes.compiler; system = config.aux.system; @@ -9,7 +7,8 @@ stage0 = config.aux.foundation.stages.stage0; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.mes.compiler = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -46,45 +45,46 @@ in { config = { aux.foundation.stages.stage1.mes.compiler = { - package = let - compile = path: let - file = builtins.baseNameOf path; - fileWithoutExtension = builtins.replaceStrings [".c"] [""] file; + package = + let + compile = + path: + let + file = builtins.baseNameOf path; + fileWithoutExtension = builtins.replaceStrings [ ".c" ] [ "" ] file; - cc = builtins.concatStringsSep " " [ - "${stage1.mes.libs.src.bin}/bin/mes-m2" - "-e" - "main" - "${stage1.mes.libs.src.bin}/bin/mescc.scm" - "--" - "-D" - "HAVE_CONFIG_H=1" - "-I" - "${stage1.mes.libs.prefix}/include" - "-I" - "${stage1.mes.libs.prefix}/include/linux/x86" - ]; + cc = builtins.concatStringsSep " " [ + "${stage1.mes.libs.src.bin}/bin/mes-m2" + "-e" + "main" + "${stage1.mes.libs.src.bin}/bin/mescc.scm" + "--" + "-D" + "HAVE_CONFIG_H=1" + "-I" + "${stage1.mes.libs.prefix}/include" + "-I" + "${stage1.mes.libs.prefix}/include/linux/x86" + ]; + in + builders.kaem.build { + name = fileWithoutExtension; + + script = '' + mkdir ''${out} + cd ''${out} + ${cc} -c ${stage1.mes.libs.prefix}/${path} + ''; + }; + + getSourcePath = suffix: source: "${source}/${source.name}${suffix}"; + + sources = import ./sources.nix; + + files = lib.strings.concatMapSep " " (getSourcePath ".o") ( + builtins.map compile sources.x86.linux.mescc.mes + ); in - builders.kaem.build { - name = fileWithoutExtension; - - script = '' - mkdir ''${out} - cd ''${out} - ${cc} -c ${stage1.mes.libs.prefix}/${path} - ''; - }; - - getSourcePath = suffix: source: "${source}/${source.name}${suffix}"; - - sources = import ./sources.nix; - - files = - lib.strings.concatMapSep - " " - (getSourcePath ".o") - (builtins.map compile sources.x86.linux.mescc.mes); - in builders.kaem.build { name = "mes-${stage1.mes.version}"; diff --git a/foundation/src/stages/stage1/mes/default.nix b/foundation/src/stages/stage1/mes/default.nix index b3d9c98..008e3ae 100644 --- a/foundation/src/stages/stage1/mes/default.nix +++ b/foundation/src/stages/stage1/mes/default.nix @@ -1,12 +1,11 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.mes; system = config.aux.system; builders = config.aux.foundation.builders; -in { +in +{ includes = [ ./compiler.nix ./libs.nix diff --git a/foundation/src/stages/stage1/mes/libc.nix b/foundation/src/stages/stage1/mes/libc.nix index ecf2fd6..97a07de 100644 --- a/foundation/src/stages/stage1/mes/libc.nix +++ b/foundation/src/stages/stage1/mes/libc.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.mes.libc; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.mes.libc = { meta = { description = lib.options.create { @@ -32,7 +31,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -44,22 +43,21 @@ in { config = { aux.foundation.stages.stage1.mes.libc = { - package = let - sources = import ./sources.nix; + package = + let + sources = import ./sources.nix; - libtcc1 = sources.x86.linux.gcc.libtcc1; + libtcc1 = sources.x86.linux.gcc.libtcc1; - first = lib.lists.take 100 sources.x86.linux.gcc.libc_gnu; - last = lib.lists.drop 100 sources.x86.linux.gcc.libc_gnu; - in + first = lib.lists.take 100 sources.x86.linux.gcc.libc_gnu; + last = lib.lists.drop 100 sources.x86.linux.gcc.libc_gnu; + in builders.kaem.build { name = "mes-libc-${stage1.mes.version}"; meta = cfg.meta; - deps.build.host = [ - stage1.ln-boot.package - ]; + deps.build.host = [ stage1.ln-boot.package ]; script = '' cd ${stage1.mes.libs.prefix} diff --git a/foundation/src/stages/stage1/mes/libs.nix b/foundation/src/stages/stage1/mes/libs.nix index 3154f93..aa75bd7 100644 --- a/foundation/src/stages/stage1/mes/libs.nix +++ b/foundation/src/stages/stage1/mes/libs.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.mes.libs; system = config.aux.system; @@ -9,7 +7,8 @@ stage0 = config.aux.foundation.stages.stage0; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.mes.libs = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -58,12 +57,13 @@ in { aux.foundation.stages.stage1.mes.libs = { prefix = "${cfg.src.out}/mes-${stage1.mes.version}"; - src = let - config_h = builtins.toFile "config.h" '' - #undef SYSTEM_LIBC - #define MES_VERSION "${stage1.mes.version}" - ''; - in + src = + let + config_h = builtins.toFile "config.h" '' + #undef SYSTEM_LIBC + #define MES_VERSION "${stage1.mes.version}" + ''; + in builders.kaem.build { name = "mes-src-${stage1.mes.version}"; @@ -140,71 +140,82 @@ in { ''; }; - package = let - compile = path: let - file = builtins.baseNameOf path; - fileWithoutExtension = builtins.replaceStrings [".c"] [""] file; + package = + let + compile = + path: + let + file = builtins.baseNameOf path; + fileWithoutExtension = builtins.replaceStrings [ ".c" ] [ "" ] file; - cc = builtins.concatStringsSep " " [ - "${cfg.src.bin}/bin/mes-m2" - "-e" - "main" - "${cfg.src.bin}/bin/mescc.scm" - "--" - "-D" - "HAVE_CONFIG_H=1" - "-I" - "${cfg.prefix}/include" - "-I" - "${cfg.prefix}/include/linux/x86" - ]; + cc = builtins.concatStringsSep " " [ + "${cfg.src.bin}/bin/mes-m2" + "-e" + "main" + "${cfg.src.bin}/bin/mescc.scm" + "--" + "-D" + "HAVE_CONFIG_H=1" + "-I" + "${cfg.prefix}/include" + "-I" + "${cfg.prefix}/include/linux/x86" + ]; + in + builders.kaem.build { + name = fileWithoutExtension; + + script = '' + mkdir ''${out} + cd ''${out} + ${cc} -c ${cfg.prefix}/${path} + ''; + }; + + getSourcePath = suffix: source: "${source}/${source.name}${suffix}"; + + archive = + destination: sources: + "catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".o") sources}"; + source = + destination: sources: + "catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".s") sources}"; + + createLib = + name: sources: + let + compiled = builtins.map compile sources; + in + builders.kaem.build { + name = "mes-${name}-${stage1.mes.version}"; + + meta = cfg.meta; + + script = '' + LIBDIR=''${out}/lib + mkdir -p ''${LIBDIR} + cd ''${LIBDIR} + + ${archive "${name}.a" compiled} + ${source "${name}.s" compiled} + + ''; + }; + + sources = import ./sources.nix; + + crt1 = compile "lib/linux/x86-mes-mescc/crt1.c"; + libc-mini = createLib "libc-mini" sources.x86.linux.mescc.libc_mini; + libmescc = createLib "libmescc" sources.x86.linux.mescc.libmescc; + libc = createLib "libc" sources.x86.linux.mescc.libc; + libc_tcc = createLib "libc+tcc" ( + sources.x86.linux.mescc.libc_tcc + ++ [ + # We need `symlink` support for `ln-boot` to work. + "lib/linux/symlink.c" + ] + ); in - builders.kaem.build { - name = fileWithoutExtension; - - script = '' - mkdir ''${out} - cd ''${out} - ${cc} -c ${cfg.prefix}/${path} - ''; - }; - - getSourcePath = suffix: source: "${source}/${source.name}${suffix}"; - - archive = destination: sources: "catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".o") sources}"; - source = destination: sources: "catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".s") sources}"; - - createLib = name: sources: let - compiled = builtins.map compile sources; - in - builders.kaem.build { - name = "mes-${name}-${stage1.mes.version}"; - - meta = cfg.meta; - - script = '' - LIBDIR=''${out}/lib - mkdir -p ''${LIBDIR} - cd ''${LIBDIR} - - ${archive "${name}.a" compiled} - ${source "${name}.s" compiled} - - ''; - }; - - sources = import ./sources.nix; - - crt1 = compile "lib/linux/x86-mes-mescc/crt1.c"; - libc-mini = createLib "libc-mini" sources.x86.linux.mescc.libc_mini; - libmescc = createLib "libmescc" sources.x86.linux.mescc.libmescc; - libc = createLib "libc" sources.x86.linux.mescc.libc; - libc_tcc = createLib "libc+tcc" (sources.x86.linux.mescc.libc_tcc - ++ [ - # We need `symlink` support for `ln-boot` to work. - "lib/linux/symlink.c" - ]); - in builders.kaem.build { name = "mes-m2-libs-${stage1.mes.version}"; diff --git a/foundation/src/stages/stage1/mes/sources.nix b/foundation/src/stages/stage1/mes/sources.nix index 5c247c3..ef8c2b7 100644 --- a/foundation/src/stages/stage1/mes/sources.nix +++ b/foundation/src/stages/stage1/mes/sources.nix @@ -18,9 +18,7 @@ "lib/mes/globals.c" "lib/linux/x86-mes-mescc/syscall-internal.c" ]; - libtcc1 = [ - "lib/libtcc1.c" - ]; + libtcc1 = [ "lib/libtcc1.c" ]; libc = [ "lib/mes/__init_io.c" "lib/mes/eputs.c" @@ -546,9 +544,7 @@ "lib/mes/globals.c" "lib/linux/x86-mes-gcc/syscall-internal.c" ]; - libtcc1 = [ - "lib/libtcc1.c" - ]; + libtcc1 = [ "lib/libtcc1.c" ]; libc = [ "lib/mes/__init_io.c" "lib/mes/eputs.c" diff --git a/foundation/src/stages/stage1/musl/boot.nix b/foundation/src/stages/stage1/musl/boot.nix index ad8892d..4b1e2fa 100644 --- a/foundation/src/stages/stage1/musl/boot.nix +++ b/foundation/src/stages/stage1/musl/boot.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.musl.boot; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.musl.boot = { package = lib.options.create { type = lib.types.derivation; @@ -35,52 +34,53 @@ in { sha256 = "E3DJqBKyzyp9koAlEMygBYzDfmanvt1wBR8KNAFQIqM="; }; - package = let - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24/musl-1.1.24.sh - liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24"; - patches = [ - (builtins.fetchurl { - url = "${liveBootstrap}/patches/avoid_set_thread_area.patch"; - sha256 = "TsbBZXk4/KMZG9EKi7cF+sullVXrxlizLNH0UHGXsPs="; - }) - (builtins.fetchurl { - url = "${liveBootstrap}/patches/avoid_sys_clone.patch"; - sha256 = "/ZmH64J57MmbxdfQ4RNjamAiBdkImMTlHsHdgV4gMj4="; - }) - (builtins.fetchurl { - url = "${liveBootstrap}/patches/fenv.patch"; - sha256 = "vMVGjoN4deAJW5gsSqA207SJqAbvhrnOsGK49DdEiTI="; - }) - (builtins.fetchurl { - url = "${liveBootstrap}/patches/makefile.patch"; - sha256 = "03iYBAUnsrEdLIIhhhq5mM6BGnPn2EfUmIHu51opxbw="; - }) - (builtins.fetchurl { - url = "${liveBootstrap}/patches/musl_weak_symbols.patch"; - sha256 = "/d9a2eUkpe9uyi1ye6T4CiYc9MR3FZ9na0Gb90+g4v0="; - }) - (builtins.fetchurl { - url = "${liveBootstrap}/patches/set_thread_area.patch"; - sha256 = "RIZYqbbRSx4X/0iFUhriwwBRmoXVR295GNBUjf2UrM0="; - }) - (builtins.fetchurl { - url = "${liveBootstrap}/patches/sigsetjmp.patch"; - sha256 = "wd2Aev1zPJXy3q933aiup5p1IMKzVJBquAyl3gbK4PU="; - }) - # FIXME: this patch causes the build to fail - # (builtins.fetchurl { - # url = "${liveBootstrap}/patches/stdio_flush_on_exit.patch"; - # sha256 = "/z5ze3h3QTysay8nRvyvwPv3pmTcKptdkBIaMCoeLDg="; - # }) - # HACK: always flush stdio immediately - ./patches/always-flush.patch - (builtins.fetchurl { - url = "${liveBootstrap}/patches/va_list.patch"; - sha256 = "UmcMIl+YCi3wIeVvjbsCyqFlkyYsM4ECNwTfXP+s7vg="; - }) - ]; - in + package = + let + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24/musl-1.1.24.sh + liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24"; + patches = [ + (builtins.fetchurl { + url = "${liveBootstrap}/patches/avoid_set_thread_area.patch"; + sha256 = "TsbBZXk4/KMZG9EKi7cF+sullVXrxlizLNH0UHGXsPs="; + }) + (builtins.fetchurl { + url = "${liveBootstrap}/patches/avoid_sys_clone.patch"; + sha256 = "/ZmH64J57MmbxdfQ4RNjamAiBdkImMTlHsHdgV4gMj4="; + }) + (builtins.fetchurl { + url = "${liveBootstrap}/patches/fenv.patch"; + sha256 = "vMVGjoN4deAJW5gsSqA207SJqAbvhrnOsGK49DdEiTI="; + }) + (builtins.fetchurl { + url = "${liveBootstrap}/patches/makefile.patch"; + sha256 = "03iYBAUnsrEdLIIhhhq5mM6BGnPn2EfUmIHu51opxbw="; + }) + (builtins.fetchurl { + url = "${liveBootstrap}/patches/musl_weak_symbols.patch"; + sha256 = "/d9a2eUkpe9uyi1ye6T4CiYc9MR3FZ9na0Gb90+g4v0="; + }) + (builtins.fetchurl { + url = "${liveBootstrap}/patches/set_thread_area.patch"; + sha256 = "RIZYqbbRSx4X/0iFUhriwwBRmoXVR295GNBUjf2UrM0="; + }) + (builtins.fetchurl { + url = "${liveBootstrap}/patches/sigsetjmp.patch"; + sha256 = "wd2Aev1zPJXy3q933aiup5p1IMKzVJBquAyl3gbK4PU="; + }) + # FIXME: this patch causes the build to fail + # (builtins.fetchurl { + # url = "${liveBootstrap}/patches/stdio_flush_on_exit.patch"; + # sha256 = "/z5ze3h3QTysay8nRvyvwPv3pmTcKptdkBIaMCoeLDg="; + # }) + # HACK: always flush stdio immediately + ./patches/always-flush.patch + (builtins.fetchurl { + url = "${liveBootstrap}/patches/va_list.patch"; + sha256 = "UmcMIl+YCi3wIeVvjbsCyqFlkyYsM4ECNwTfXP+s7vg="; + }) + ]; + in builders.bash.boot.build { name = "musl-boot-${cfg.version}"; diff --git a/foundation/src/stages/stage1/musl/default.nix b/foundation/src/stages/stage1/musl/default.nix index 3b36ff5..89e245e 100644 --- a/foundation/src/stages/stage1/musl/default.nix +++ b/foundation/src/stages/stage1/musl/default.nix @@ -1,17 +1,14 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.musl; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { - includes = [ - ./boot.nix - ]; +in +{ + includes = [ ./boot.nix ]; options.aux.foundation.stages.stage1.musl = { meta = { @@ -38,7 +35,7 @@ in { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; # TODO: Support more platforms. - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/nyacc/default.nix b/foundation/src/stages/stage1/nyacc/default.nix index 64d8b2f..799b361 100644 --- a/foundation/src/stages/stage1/nyacc/default.nix +++ b/foundation/src/stages/stage1/nyacc/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.nyacc; builders = config.aux.foundation.builders; @@ -10,7 +8,8 @@ pname = "nyacc"; version = "1.00.2"; -in { +in +{ options.aux.foundation.stages.stage1.nyacc = { meta = { description = lib.options.create { @@ -35,7 +34,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/python/default.nix b/foundation/src/stages/stage1/python/default.nix index 9297b03..f730cb5 100644 --- a/foundation/src/stages/stage1/python/default.nix +++ b/foundation/src/stages/stage1/python/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.python; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.python = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -62,16 +61,17 @@ in { sha256 = "eVw09E30Wg6blxDIxxwVxnGHFSTNQSyhTe8hLozLFV0="; }; - package = let - patches = [ - # Disable the use of ldconfig in ctypes.util.find_library (since - # ldconfig doesn't work on NixOS), and don't use - # ctypes.util.find_library during the loading of the uuid module - # (since it will do a futile invocation of gcc (!) to find - # libuuid, slowing down program startup a lot). - ./patches/no-ldconfig.patch - ]; - in + package = + let + patches = [ + # Disable the use of ldconfig in ctypes.util.find_library (since + # ldconfig doesn't work on NixOS), and don't use + # ctypes.util.find_library during the loading of the uuid module + # (since it will do a futile invocation of gcc (!) to find + # libuuid, slowing down program startup a lot). + ./patches/no-ldconfig.patch + ]; + in builders.bash.build { name = "python-${cfg.version}"; meta = cfg.meta; diff --git a/foundation/src/stages/stage1/tinycc/boot.nix b/foundation/src/stages/stage1/tinycc/boot.nix index e1979e3..9e139e4 100644 --- a/foundation/src/stages/stage1/tinycc/boot.nix +++ b/foundation/src/stages/stage1/tinycc/boot.nix @@ -1,7 +1,5 @@ -args @ { - lib, - config, -}: let +args@{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.tinycc.boot; builders = config.aux.foundation.builders; @@ -11,7 +9,8 @@ args @ { pname = "tinycc-boot"; helpers = lib.fp.withDynamicArgs (import ./helpers.nix) args; -in { +in +{ options.aux.foundation.stages.stage1.tinycc.boot = { meta = { description = lib.options.create { @@ -36,7 +35,10 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["x86_64-linux" "i686-linux"]; + default.value = [ + "x86_64-linux" + "i686-linux" + ]; }; }; @@ -66,129 +68,130 @@ in { }; config = { - aux.foundation.stages.stage1.tinycc.boot = let - tinycc-boot = let - tinycc-mes-bootstrappable = helpers.createBoot { - pname = "tinycc-mes-bootstrappable"; - version = stage1.tinycc.version; - src = cfg.src; - }; + aux.foundation.stages.stage1.tinycc.boot = + let + tinycc-boot = + let + tinycc-mes-bootstrappable = helpers.createBoot { + pname = "tinycc-mes-bootstrappable"; + version = stage1.tinycc.version; + src = cfg.src; + }; - tinycc-boot0 = helpers.createTinyccMes { - pname = "tinycc-boot0"; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-D HAVE_LONG_LONG_STUB=1" - "-D HAVE_SETJMP=1" - ]; - lib.args = [ - "-D HAVE_LONG_LONG_STUB=1" - ]; - boot = tinycc-mes-bootstrappable; - meta = cfg.meta; - }; + tinycc-boot0 = helpers.createTinyccMes { + pname = "tinycc-boot0"; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-D HAVE_LONG_LONG_STUB=1" + "-D HAVE_SETJMP=1" + ]; + lib.args = [ "-D HAVE_LONG_LONG_STUB=1" ]; + boot = tinycc-mes-bootstrappable; + meta = cfg.meta; + }; - tinycc-boot1 = helpers.createTinyccMes { - pname = "tinycc-boot1"; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-D HAVE_BITFIELD=1" - "-D HAVE_LONG_LONG=1" - "-D HAVE_SETJMP=1" - ]; - lib.args = [ - "-D HAVE_LONG_LONG=1" - ]; - boot = tinycc-boot0; - meta = cfg.meta; - }; + tinycc-boot1 = helpers.createTinyccMes { + pname = "tinycc-boot1"; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-D HAVE_BITFIELD=1" + "-D HAVE_LONG_LONG=1" + "-D HAVE_SETJMP=1" + ]; + lib.args = [ "-D HAVE_LONG_LONG=1" ]; + boot = tinycc-boot0; + meta = cfg.meta; + }; - tinycc-boot2 = helpers.createTinyccMes { - pname = "tinycc-boot2"; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-D HAVE_BITFIELD=1" - "-D HAVE_FLOAT_STUB=1" - "-D HAVE_LONG_LONG=1" - "-D HAVE_SETJMP=1" - ]; - lib.args = [ - "-D HAVE_FLOAT_STUB=1" - "-D HAVE_LONG_LONG=1" - ]; - boot = tinycc-boot1; - meta = cfg.meta; - }; + tinycc-boot2 = helpers.createTinyccMes { + pname = "tinycc-boot2"; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-D HAVE_BITFIELD=1" + "-D HAVE_FLOAT_STUB=1" + "-D HAVE_LONG_LONG=1" + "-D HAVE_SETJMP=1" + ]; + lib.args = [ + "-D HAVE_FLOAT_STUB=1" + "-D HAVE_LONG_LONG=1" + ]; + boot = tinycc-boot1; + meta = cfg.meta; + }; - tinycc-boot3 = helpers.createTinyccMes { - pname = "tinycc-boot3"; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-D HAVE_BITFIELD=1" - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - "-D HAVE_SETJMP=1" - ]; - lib.args = [ - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - ]; - boot = tinycc-boot2; - meta = cfg.meta; - }; + tinycc-boot3 = helpers.createTinyccMes { + pname = "tinycc-boot3"; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-D HAVE_BITFIELD=1" + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + "-D HAVE_SETJMP=1" + ]; + lib.args = [ + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + ]; + boot = tinycc-boot2; + meta = cfg.meta; + }; + in + helpers.createTinyccMes { + pname = "tinycc-boot"; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-D HAVE_BITFIELD=1" + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + "-D HAVE_SETJMP=1" + ]; + lib.args = [ + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + ]; + boot = tinycc-boot3; + meta = cfg.meta; + }; in - helpers.createTinyccMes { - pname = "tinycc-boot"; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-D HAVE_BITFIELD=1" - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - "-D HAVE_SETJMP=1" - ]; - lib.args = [ - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - ]; - boot = tinycc-boot3; - meta = cfg.meta; - }; - in { - revision = "80114c4da6b17fbaabb399cc29f427e368309bc8"; + { + revision = "80114c4da6b17fbaabb399cc29f427e368309bc8"; - libs.package = tinycc-boot.libs; - compiler.package = tinycc-boot.compiler; + libs.package = tinycc-boot.libs; + compiler.package = tinycc-boot.compiler; - src = let - tarball = builtins.fetchurl { - url = "https://gitlab.com/janneke/tinycc/-/archive/${cfg.revision}/tinycc-${cfg.revision}.tar.gz"; - sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq"; - }; + src = + let + tarball = builtins.fetchurl { + url = "https://gitlab.com/janneke/tinycc/-/archive/${cfg.revision}/tinycc-${cfg.revision}.tar.gz"; + sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq"; + }; - patched = builders.kaem.build { - name = "${pname}-src"; + patched = builders.kaem.build { + name = "${pname}-src"; - meta = stage1.tinycc.meta; + meta = stage1.tinycc.meta; - script = '' - ungz --file ${tarball} --output tinycc.tar - mkdir -p ''${out} - cd ''${out} - untar --file ''${NIX_BUILD_TOP}/tinycc.tar + script = '' + ungz --file ${tarball} --output tinycc.tar + mkdir -p ''${out} + cd ''${out} + untar --file ''${NIX_BUILD_TOP}/tinycc.tar - # Patch - cd tinycc-${cfg.revision} + # Patch + cd tinycc-${cfg.revision} - # Static link by default - replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;" - ''; - }; - in "${patched}/tinycc-${cfg.revision}"; - }; + # Static link by default + replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;" + ''; + }; + in + "${patched}/tinycc-${cfg.revision}"; + }; }; } diff --git a/foundation/src/stages/stage1/tinycc/default.nix b/foundation/src/stages/stage1/tinycc/default.nix index 1e3168a..b599aab 100644 --- a/foundation/src/stages/stage1/tinycc/default.nix +++ b/foundation/src/stages/stage1/tinycc/default.nix @@ -1,13 +1,12 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.tinycc; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ includes = [ ./boot.nix ./mes.nix @@ -38,7 +37,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/tinycc/helpers.nix b/foundation/src/stages/stage1/tinycc/helpers.nix index c2450ce..7fac9fa 100644 --- a/foundation/src/stages/stage1/tinycc/helpers.nix +++ b/foundation/src/stages/stage1/tinycc/helpers.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.tinycc.boot; builders = config.aux.foundation.builders; @@ -9,151 +7,163 @@ stage1 = config.aux.foundation.stages.stage1; cflags = stage1.mes.libc.package.extras.CFLAGS; - createBoot = { - pname, - version, - src, - }: let - compiler = builders.kaem.build { - name = "${pname}-${version}"; - - script = '' - catm config.h - ${stage1.mes.compiler.package}/bin/mes --no-auto-compile -e main ${stage1.mes.libs.src.bin}/bin/mescc.scm -- \ - -S \ - -o tcc.s \ - -I . \ - -D BOOTSTRAP=1 \ - -I ${src} \ - -D TCC_TARGET_I386=1 \ - -D inline= \ - -D CONFIG_TCCDIR=\"\" \ - -D CONFIG_SYSROOT=\"\" \ - -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ - -D CONFIG_TCC_ELFINTERP=\"/mes/loader\" \ - -D CONFIG_TCC_LIBPATHS=\"{B}\" \ - -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.mes.libc.package}/include\" \ - -D TCC_LIBGCC=\"${stage1.mes.libc.package}/lib/x86-mes/libc.a\" \ - -D CONFIG_TCC_LIBTCC1_MES=0 \ - -D CONFIG_TCCBOOT=1 \ - -D CONFIG_TCC_STATIC=1 \ - -D CONFIG_USE_LIBGCC=1 \ - -D TCC_MES_LIBC=1 \ - -D TCC_VERSION=\"${version}\" \ - -D ONE_SOURCE=1 \ - ${src}/tcc.c - mkdir -p ''${out}/bin - ${stage1.mes.compiler.package}/bin/mes --no-auto-compile -e main ${stage1.mes.libs.src.bin}/bin/mescc.scm -- \ - -L ${stage1.mes.libs.package}/lib \ - -l c+tcc \ - -o ''${out}/bin/tcc \ - tcc.s - ''; - }; - - libs = createLibc { - inherit pname version; - src = stage1.mes.libc.package; - args = cflags; - tinycc = compiler; - }; - in {inherit compiler libs;}; - - createTinyccMes = { - pname, - version, - src, - args, - boot, - lib ? {}, - meta, - }: let - compiler = builders.kaem.build { - name = "${pname}-${version}"; - - inherit meta; - - # - script = '' - catm config.h - mkdir -p ''${out}/bin - ${boot.compiler}/bin/tcc \ - -B ${boot.libs}/lib \ - -g \ - -v \ - -o ''${out}/bin/tcc \ - -D BOOTSTRAP=1 \ - ${builtins.concatStringsSep " " args} \ - -I . \ - -I ${src} \ - -D TCC_TARGET_I386=1 \ - -D CONFIG_TCCDIR=\"\" \ - -D CONFIG_SYSROOT=\"\" \ - -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ - -D CONFIG_TCC_ELFINTERP=\"\" \ - -D CONFIG_TCC_LIBPATHS=\"{B}\" \ - -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.mes.libc.package}/include\" \ - -D TCC_LIBGCC=\"libc.a\" \ - -D TCC_LIBTCC1=\"libtcc1.a\" \ - -D CONFIG_TCCBOOT=1 \ - -D CONFIG_TCC_STATIC=1 \ - -D CONFIG_USE_LIBGCC=1 \ - -D TCC_MES_LIBC=1 \ - -D TCC_VERSION=\"${version}\" \ - -D ONE_SOURCE=1 \ - ${src}/tcc.c - ''; - }; - - libs = createLibc { - inherit pname version src; - - args = - builtins.concatStringsSep - " " - ( - ["-c" "-D" "TCC_TARGET_I386=1"] - ++ (lib.args or []) - ); - - tinycc = compiler; - }; - in { - inherit compiler libs boot; - }; - - createLibc = { - pname, - version, - src, - args, - tinycc, - }: let - createLibrary = name: args: source: - builders.kaem.build { - name = "${name}.a"; + createBoot = + { + pname, + version, + src, + }: + let + compiler = builders.kaem.build { + name = "${pname}-${version}"; script = '' - ${tinycc}/bin/tcc ${args} -c -o ${name}.o ${source} - ${tinycc}/bin/tcc -ar cr ''${out} ${name}.o + catm config.h + ${stage1.mes.compiler.package}/bin/mes --no-auto-compile -e main ${stage1.mes.libs.src.bin}/bin/mescc.scm -- \ + -S \ + -o tcc.s \ + -I . \ + -D BOOTSTRAP=1 \ + -I ${src} \ + -D TCC_TARGET_I386=1 \ + -D inline= \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_SYSROOT=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/mes/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.mes.libc.package}/include\" \ + -D TCC_LIBGCC=\"${stage1.mes.libc.package}/lib/x86-mes/libc.a\" \ + -D CONFIG_TCC_LIBTCC1_MES=0 \ + -D CONFIG_TCCBOOT=1 \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_MES_LIBC=1 \ + -D TCC_VERSION=\"${version}\" \ + -D ONE_SOURCE=1 \ + ${src}/tcc.c + mkdir -p ''${out}/bin + ${stage1.mes.compiler.package}/bin/mes --no-auto-compile -e main ${stage1.mes.libs.src.bin}/bin/mescc.scm -- \ + -L ${stage1.mes.libs.package}/lib \ + -l c+tcc \ + -o ''${out}/bin/tcc \ + tcc.s ''; }; - crt = builders.kaem.build { - name = "crt"; - - script = '' - mkdir -p ''${out}/lib - ${tinycc}/bin/tcc ${cflags} -c -o ''${out}/lib/crt1.o ${stage1.mes.libc.package}/lib/crt1.c - ${tinycc}/bin/tcc ${cflags} -c -o ''${out}/lib/crtn.o ${stage1.mes.libc.package}/lib/crtn.c - ${tinycc}/bin/tcc ${cflags} -c -o ''${out}/lib/crti.o ${stage1.mes.libc.package}/lib/crti.c - ''; + libs = createLibc { + inherit pname version; + src = stage1.mes.libc.package; + args = cflags; + tinycc = compiler; + }; + in + { + inherit compiler libs; }; - libtcc1 = createLibrary "libtcc1" args "${src}/lib/libtcc1.c"; - libc = createLibrary "libc" cflags "${stage1.mes.libc.package}/lib/libc.c"; - libgetopt = createLibrary "libgetopt" cflags "${stage1.mes.libc.package}/lib/libgetopt.c"; - in + createTinyccMes = + { + pname, + version, + src, + args, + boot, + lib ? { }, + meta, + }: + let + compiler = builders.kaem.build { + name = "${pname}-${version}"; + + inherit meta; + + # + script = '' + catm config.h + mkdir -p ''${out}/bin + ${boot.compiler}/bin/tcc \ + -B ${boot.libs}/lib \ + -g \ + -v \ + -o ''${out}/bin/tcc \ + -D BOOTSTRAP=1 \ + ${builtins.concatStringsSep " " args} \ + -I . \ + -I ${src} \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_SYSROOT=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.mes.libc.package}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCCBOOT=1 \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_MES_LIBC=1 \ + -D TCC_VERSION=\"${version}\" \ + -D ONE_SOURCE=1 \ + ${src}/tcc.c + ''; + }; + + libs = createLibc { + inherit pname version src; + + args = builtins.concatStringsSep " " ( + [ + "-c" + "-D" + "TCC_TARGET_I386=1" + ] + ++ (lib.args or [ ]) + ); + + tinycc = compiler; + }; + in + { + inherit compiler libs boot; + }; + + createLibc = + { + pname, + version, + src, + args, + tinycc, + }: + let + createLibrary = + name: args: source: + builders.kaem.build { + name = "${name}.a"; + + script = '' + ${tinycc}/bin/tcc ${args} -c -o ${name}.o ${source} + ${tinycc}/bin/tcc -ar cr ''${out} ${name}.o + ''; + }; + + crt = builders.kaem.build { + name = "crt"; + + script = '' + mkdir -p ''${out}/lib + ${tinycc}/bin/tcc ${cflags} -c -o ''${out}/lib/crt1.o ${stage1.mes.libc.package}/lib/crt1.c + ${tinycc}/bin/tcc ${cflags} -c -o ''${out}/lib/crtn.o ${stage1.mes.libc.package}/lib/crtn.c + ${tinycc}/bin/tcc ${cflags} -c -o ''${out}/lib/crti.o ${stage1.mes.libc.package}/lib/crti.c + ''; + }; + + libtcc1 = createLibrary "libtcc1" args "${src}/lib/libtcc1.c"; + libc = createLibrary "libc" cflags "${stage1.mes.libc.package}/lib/libc.c"; + libgetopt = createLibrary "libgetopt" cflags "${stage1.mes.libc.package}/lib/libgetopt.c"; + in builders.kaem.build { name = "${pname}-libs-${version}"; @@ -167,10 +177,7 @@ cp ${libgetopt} ''${out}/lib/libgetopt.a ''; }; -in { - inherit - createBoot - createTinyccMes - createLibc - ; +in +{ + inherit createBoot createTinyccMes createLibc; } diff --git a/foundation/src/stages/stage1/tinycc/mes.nix b/foundation/src/stages/stage1/tinycc/mes.nix index 2f298af..c42603f 100644 --- a/foundation/src/stages/stage1/tinycc/mes.nix +++ b/foundation/src/stages/stage1/tinycc/mes.nix @@ -1,7 +1,5 @@ -args @ { - lib, - config, -}: let +args@{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.tinycc.mes; builders = config.aux.foundation.builders; @@ -11,7 +9,8 @@ args @ { pname = "tinycc-mes"; helpers = lib.fp.withDynamicArgs (import ./helpers.nix) args; -in { +in +{ options.aux.foundation.stages.stage1.tinycc.mes = { compiler = { package = lib.options.create { @@ -39,104 +38,109 @@ in { }; config = { - aux.foundation.stages.stage1.tinycc.mes = let - tinycc-mes = let - tccdefs = builders.kaem.build { - name = "tccdefs-${stage1.tinycc.version}"; + aux.foundation.stages.stage1.tinycc.mes = + let + tinycc-mes = + let + tccdefs = builders.kaem.build { + name = "tccdefs-${stage1.tinycc.version}"; - script = '' - mkdir ''${out} - ${stage1.tinycc.boot.compiler.package}/bin/tcc \ - -B ${stage1.tinycc.boot.libs.package}/lib \ - -DC2STR \ - -o c2str \ - ${cfg.src}/conftest.c - ./c2str ${cfg.src}/include/tccdefs.h ''${out}/tccdefs_.h - ''; - }; + script = '' + mkdir ''${out} + ${stage1.tinycc.boot.compiler.package}/bin/tcc \ + -B ${stage1.tinycc.boot.libs.package}/lib \ + -DC2STR \ + -o c2str \ + ${cfg.src}/conftest.c + ./c2str ${cfg.src}/include/tccdefs.h ''${out}/tccdefs_.h + ''; + }; - tinycc-mes-boot = helpers.createTinyccMes { - pname = "${pname}-boot"; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-D HAVE_BITFIELD=1" - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - "-D HAVE_SETJMP=1" - "-D CONFIG_TCC_PREDEFS=1" - "-I ${tccdefs}" - "-D CONFIG_TCC_SEMLOCK=0" - ]; - lib.args = [ - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - "-D CONFIG_TCC_PREDEFS=1" - "-I ${tccdefs}" - "-D CONFIG_TCC_SEMLOCK=0" - ]; - boot = { - libs = stage1.tinycc.boot.libs.package; - compiler = stage1.tinycc.boot.compiler.package; + tinycc-mes-boot = helpers.createTinyccMes { + pname = "${pname}-boot"; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-D HAVE_BITFIELD=1" + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + "-D HAVE_SETJMP=1" + "-D CONFIG_TCC_PREDEFS=1" + "-I ${tccdefs}" + "-D CONFIG_TCC_SEMLOCK=0" + ]; + lib.args = [ + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + "-D CONFIG_TCC_PREDEFS=1" + "-I ${tccdefs}" + "-D CONFIG_TCC_SEMLOCK=0" + ]; + boot = { + libs = stage1.tinycc.boot.libs.package; + compiler = stage1.tinycc.boot.compiler.package; + }; + meta = stage1.tinycc.meta; + }; + in + helpers.createTinyccMes { + inherit pname; + version = stage1.tinycc.version; + src = cfg.src; + args = [ + "-std=c99" + "-D HAVE_BITFIELD=1" + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + "-D HAVE_SETJMP=1" + "-D CONFIG_TCC_PREDEFS=1" + "-I ${tccdefs}" + "-D CONFIG_TCC_SEMLOCK=0" + ]; + lib.args = [ + "-D HAVE_FLOAT=1" + "-D HAVE_LONG_LONG=1" + "-D CONFIG_TCC_PREDEFS=1" + "-I ${tccdefs}" + "-D CONFIG_TCC_SEMLOCK=0" + ]; + boot = tinycc-mes-boot; + meta = stage1.tinycc.meta; }; - meta = stage1.tinycc.meta; - }; in - helpers.createTinyccMes { - inherit pname; - version = stage1.tinycc.version; - src = cfg.src; - args = [ - "-std=c99" - "-D HAVE_BITFIELD=1" - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - "-D HAVE_SETJMP=1" - "-D CONFIG_TCC_PREDEFS=1" - "-I ${tccdefs}" - "-D CONFIG_TCC_SEMLOCK=0" - ]; - lib.args = [ - "-D HAVE_FLOAT=1" - "-D HAVE_LONG_LONG=1" - "-D CONFIG_TCC_PREDEFS=1" - "-I ${tccdefs}" - "-D CONFIG_TCC_SEMLOCK=0" - ]; - boot = tinycc-mes-boot; - meta = stage1.tinycc.meta; - }; - in { - revision = "86f3d8e33105435946383aee52487b5ddf918140"; + { + revision = "86f3d8e33105435946383aee52487b5ddf918140"; - libs.package = tinycc-mes.libs; - compiler.package = tinycc-mes.compiler; + libs.package = tinycc-mes.libs; + compiler.package = tinycc-mes.compiler; - src = let - tarball = builtins.fetchurl { - url = "https://repo.or.cz/tinycc.git/snapshot/${cfg.revision}.tar.gz"; - sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap"; - }; + src = + let + tarball = builtins.fetchurl { + url = "https://repo.or.cz/tinycc.git/snapshot/${cfg.revision}.tar.gz"; + sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap"; + }; - patched = builders.kaem.build { - name = "${pname}-src"; + patched = builders.kaem.build { + name = "${pname}-src"; - meta = stage1.tinycc.meta; + meta = stage1.tinycc.meta; - script = '' - ungz --file ${tarball} --output tinycc.tar - mkdir -p ''${out} - cd ''${out} - untar --file ''${NIX_BUILD_TOP}/tinycc.tar + script = '' + ungz --file ${tarball} --output tinycc.tar + mkdir -p ''${out} + cd ''${out} + untar --file ''${NIX_BUILD_TOP}/tinycc.tar - # Patch - cd tinycc-${builtins.substring 0 7 cfg.revision} + # Patch + cd tinycc-${builtins.substring 0 7 cfg.revision} - # Static link by default - replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;" - ''; - }; - in "${patched}/tinycc-${builtins.substring 0 7 cfg.revision}"; - }; + # Static link by default + replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;" + ''; + }; + in + "${patched}/tinycc-${builtins.substring 0 7 cfg.revision}"; + }; }; } diff --git a/foundation/src/stages/stage1/tinycc/musl.nix b/foundation/src/stages/stage1/tinycc/musl.nix index 6c894a6..006921b 100644 --- a/foundation/src/stages/stage1/tinycc/musl.nix +++ b/foundation/src/stages/stage1/tinycc/musl.nix @@ -1,7 +1,5 @@ -args @ { - lib, - config, -}: let +args@{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.tinycc.musl; builders = config.aux.foundation.builders; @@ -11,7 +9,8 @@ args @ { pname = "tinycc-musl"; helpers = lib.fp.withDynamicArgs (import ./helpers.nix) args; -in { +in +{ options.aux.foundation.stages.stage1.tinycc.musl = { compiler = { package = lib.options.create { @@ -39,139 +38,141 @@ in { }; config = { - aux.foundation.stages.stage1.tinycc.musl = let - patches = [ - ./patches/ignore-duplicate-symbols.patch - ./patches/ignore-static-inside-array.patch - ./patches/static-link.patch - ]; - - tinycc-musl = builders.bash.boot.build { - name = "${pname}-${stage1.tinycc.version}"; - - meta = stage1.tinycc.meta; - - deps.build.host = [ - stage1.tinycc.boot.compiler.package - stage1.gnupatch.package - stage1.gnutar.boot.package - stage1.gzip.package + aux.foundation.stages.stage1.tinycc.musl = + let + patches = [ + ./patches/ignore-duplicate-symbols.patch + ./patches/ignore-static-inside-array.patch + ./patches/static-link.patch ]; - script = '' - # Unpack - tar xzf ${cfg.src} - cd tinycc-${builtins.substring 0 7 cfg.revision} + tinycc-musl = builders.bash.boot.build { + name = "${pname}-${stage1.tinycc.version}"; - # Patch - ${lib.strings.concatMapSep "\n" (file: "patch -Np0 -i ${file}") patches} + meta = stage1.tinycc.meta; - # Configure - touch config.h + deps.build.host = [ + stage1.tinycc.boot.compiler.package + stage1.gnupatch.package + stage1.gnutar.boot.package + stage1.gzip.package + ]; - # Build - # We first have to recompile using tcc-0.9.26 as tcc-0.9.27 is not self-hosting, - # but when linked with musl it is. - ln -s ${stage1.musl.boot.package}/lib/libtcc1.a ./libtcc1.a + script = '' + # Unpack + tar xzf ${cfg.src} + cd tinycc-${builtins.substring 0 7 cfg.revision} - tcc \ - -B ${stage1.tinycc.boot.libs.package}/lib \ - -DC2STR \ - -o c2str \ - conftest.c - ./c2str include/tccdefs.h tccdefs_.h + # Patch + ${lib.strings.concatMapSep "\n" (file: "patch -Np0 -i ${file}") patches} - tcc -v \ - -static \ - -o tcc-musl \ - -D TCC_TARGET_I386=1 \ - -D CONFIG_TCCDIR=\"\" \ - -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ - -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ - -D CONFIG_TCC_LIBPATHS=\"{B}\" \ - -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.musl.boot.package}/include\" \ - -D TCC_LIBGCC=\"libc.a\" \ - -D TCC_LIBTCC1=\"libtcc1.a\" \ - -D CONFIG_TCC_STATIC=1 \ - -D CONFIG_USE_LIBGCC=1 \ - -D TCC_VERSION=\"0.9.27\" \ - -D ONE_SOURCE=1 \ - -D TCC_MUSL=1 \ - -D CONFIG_TCC_PREDEFS=1 \ - -D CONFIG_TCC_SEMLOCK=0 \ - -B . \ - -B ${stage1.tinycc.boot.libs.package}/lib \ - tcc.c - # libtcc1.a - rm -f libtcc1.a - tcc -c -D HAVE_CONFIG_H=1 lib/libtcc1.c - tcc -ar cr libtcc1.a libtcc1.o + # Configure + touch config.h - # Rebuild tcc-musl with itself - ./tcc-musl \ - -v \ - -static \ - -o tcc-musl \ - -D TCC_TARGET_I386=1 \ - -D CONFIG_TCCDIR=\"\" \ - -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ - -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ - -D CONFIG_TCC_LIBPATHS=\"{B}\" \ - -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.musl.boot.package}/include\" \ - -D TCC_LIBGCC=\"libc.a\" \ - -D TCC_LIBTCC1=\"libtcc1.a\" \ - -D CONFIG_TCC_STATIC=1 \ - -D CONFIG_USE_LIBGCC=1 \ - -D TCC_VERSION=\"0.9.27\" \ - -D ONE_SOURCE=1 \ - -D TCC_MUSL=1 \ - -D CONFIG_TCC_PREDEFS=1 \ - -D CONFIG_TCC_SEMLOCK=0 \ - -B . \ - -B ${stage1.musl.boot.package}/lib \ - tcc.c - # libtcc1.a - rm -f libtcc1.a - ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/libtcc1.c - ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/alloca.S - ./tcc-musl -ar cr libtcc1.a libtcc1.o alloca.o + # Build + # We first have to recompile using tcc-0.9.26 as tcc-0.9.27 is not self-hosting, + # but when linked with musl it is. + ln -s ${stage1.musl.boot.package}/lib/libtcc1.a ./libtcc1.a - # Install - install -D tcc-musl $out/bin/tcc - install -Dm444 libtcc1.a $out/lib/libtcc1.a - ''; + tcc \ + -B ${stage1.tinycc.boot.libs.package}/lib \ + -DC2STR \ + -o c2str \ + conftest.c + ./c2str include/tccdefs.h tccdefs_.h + + tcc -v \ + -static \ + -o tcc-musl \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.musl.boot.package}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_VERSION=\"0.9.27\" \ + -D ONE_SOURCE=1 \ + -D TCC_MUSL=1 \ + -D CONFIG_TCC_PREDEFS=1 \ + -D CONFIG_TCC_SEMLOCK=0 \ + -B . \ + -B ${stage1.tinycc.boot.libs.package}/lib \ + tcc.c + # libtcc1.a + rm -f libtcc1.a + tcc -c -D HAVE_CONFIG_H=1 lib/libtcc1.c + tcc -ar cr libtcc1.a libtcc1.o + + # Rebuild tcc-musl with itself + ./tcc-musl \ + -v \ + -static \ + -o tcc-musl \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${stage1.musl.boot.package}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_VERSION=\"0.9.27\" \ + -D ONE_SOURCE=1 \ + -D TCC_MUSL=1 \ + -D CONFIG_TCC_PREDEFS=1 \ + -D CONFIG_TCC_SEMLOCK=0 \ + -B . \ + -B ${stage1.musl.boot.package}/lib \ + tcc.c + # libtcc1.a + rm -f libtcc1.a + ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/libtcc1.c + ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/alloca.S + ./tcc-musl -ar cr libtcc1.a libtcc1.o alloca.o + + # Install + install -D tcc-musl $out/bin/tcc + install -Dm444 libtcc1.a $out/lib/libtcc1.a + ''; + }; + in + { + revision = "fd6d2180c5c801bb0b4c5dde27d61503059fc97d"; + + src = builtins.fetchurl { + url = "https://repo.or.cz/tinycc.git/snapshot/${cfg.revision}.tar.gz"; + sha256 = "R81SNbEmh4s9FNQxCWZwUiMCYRkkwOHAdRf0aMnnRiA="; + }; + + compiler.package = builders.bash.boot.build { + name = "${pname}-${stage1.tinycc.version}-compiler"; + + meta = stage1.tinycc.meta; + + script = '' + install -D ${tinycc-musl}/bin/tcc $out/bin/tcc + ''; + }; + + libs.package = builders.bash.boot.build { + name = "${pname}-${stage1.tinycc.version}-libs"; + + meta = stage1.tinycc.meta; + + script = '' + mkdir $out + cp -r ${stage1.musl.boot.package}/* $out + chmod +w $out/lib/libtcc1.a + cp ${tinycc-musl}/lib/libtcc1.a $out/lib/libtcc1.a + + ''; + }; }; - in { - revision = "fd6d2180c5c801bb0b4c5dde27d61503059fc97d"; - - src = builtins.fetchurl { - url = "https://repo.or.cz/tinycc.git/snapshot/${cfg.revision}.tar.gz"; - sha256 = "R81SNbEmh4s9FNQxCWZwUiMCYRkkwOHAdRf0aMnnRiA="; - }; - - compiler.package = builders.bash.boot.build { - name = "${pname}-${stage1.tinycc.version}-compiler"; - - meta = stage1.tinycc.meta; - - script = '' - install -D ${tinycc-musl}/bin/tcc $out/bin/tcc - ''; - }; - - libs.package = builders.bash.boot.build { - name = "${pname}-${stage1.tinycc.version}-libs"; - - meta = stage1.tinycc.meta; - - script = '' - mkdir $out - cp -r ${stage1.musl.boot.package}/* $out - chmod +w $out/lib/libtcc1.a - cp ${tinycc-musl}/lib/libtcc1.a $out/lib/libtcc1.a - - ''; - }; - }; }; } diff --git a/foundation/src/stages/stage1/xz/default.nix b/foundation/src/stages/stage1/xz/default.nix index 3857a63..867f600 100644 --- a/foundation/src/stages/stage1/xz/default.nix +++ b/foundation/src/stages/stage1/xz/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.xz; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.xz = { meta = { description = lib.options.create { @@ -36,7 +35,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage1/zlib/default.nix b/foundation/src/stages/stage1/zlib/default.nix index 39c5a04..ba9e018 100644 --- a/foundation/src/stages/stage1/zlib/default.nix +++ b/foundation/src/stages/stage1/zlib/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage1.zlib; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage1.zlib = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/bash/default.nix b/foundation/src/stages/stage2/bash/default.nix index 4ea4295..ebdada0 100644 --- a/foundation/src/stages/stage2/bash/default.nix +++ b/foundation/src/stages/stage2/bash/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.bash; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.bash = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage2/binutils/default.nix b/foundation/src/stages/stage2/binutils/default.nix index 27a4fcb..31af117 100644 --- a/foundation/src/stages/stage2/binutils/default.nix +++ b/foundation/src/stages/stage2/binutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.binutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.binutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -62,35 +61,36 @@ in { sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA="; }; - package = let - patches = [ - # Make binutils output deterministic by default. - ./patches/deterministic.patch - ]; + package = + let + patches = [ + # Make binutils output deterministic by default. + ./patches/deterministic.patch + ]; - configureFlags = [ - "CC=musl-gcc" - "LDFLAGS=--static" - "--prefix=${builtins.placeholder "out"}" - "--build=${platform.build}" - "--host=${platform.host}" + configureFlags = [ + "CC=musl-gcc" + "LDFLAGS=--static" + "--prefix=${builtins.placeholder "out"}" + "--build=${platform.build}" + "--host=${platform.host}" - "--with-sysroot=/" - "--enable-deterministic-archives" - # depends on bison - "--disable-gprofng" + "--with-sysroot=/" + "--enable-deterministic-archives" + # depends on bison + "--disable-gprofng" - # Turn on --enable-new-dtags by default to make the linker set - # RUNPATH instead of RPATH on binaries. This is important because - # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. - "--enable-new-dtags" + # Turn on --enable-new-dtags by default to make the linker set + # RUNPATH instead of RPATH on binaries. This is important because + # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. + "--enable-new-dtags" - # By default binutils searches $libdir for libraries. This brings in - # libbfd and libopcodes into a default visibility. Drop default lib - # path to force users to declare their use of these libraries. - "--with-lib-path=:" - ]; - in + # By default binutils searches $libdir for libraries. This brings in + # libbfd and libopcodes into a default visibility. Drop default lib + # path to force users to declare their use of these libraries. + "--with-lib-path=:" + ]; + in builders.bash.build { name = "binutils-static-${cfg.version}"; diff --git a/foundation/src/stages/stage2/busybox/default.nix b/foundation/src/stages/stage2/busybox/default.nix index bdef1f2..8d50e48 100644 --- a/foundation/src/stages/stage2/busybox/default.nix +++ b/foundation/src/stages/stage2/busybox/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.busybox; platform = config.aux.platform; @@ -9,7 +7,8 @@ stage1 = config.aux.foundation.stages.stage1; stage2 = config.aux.foundation.stages.stage2; -in { +in +{ options.aux.foundation.stages.stage2.busybox = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -63,20 +62,19 @@ in { sha256 = "uMwkyVdNgJ5yecO+NJeVxdXOtv3xnKcJ+AzeUOR94xQ="; }; - package = let - patches = [ - ./patches/busybox-in-store.patch - ]; + package = + let + patches = [ ./patches/busybox-in-store.patch ]; - busyboxConfig = [ - "CC=musl-gcc" - "HOSTCC=musl-gcc" - "CFLAGS=-I${stage1.linux-headers.package}/include" - "KCONFIG_NOTIMESTAMP=y" - "CONFIG_PREFIX=${builtins.placeholder "out"}" - "CONFIG_STATIC=y" - ]; - in + busyboxConfig = [ + "CC=musl-gcc" + "HOSTCC=musl-gcc" + "CFLAGS=-I${stage1.linux-headers.package}/include" + "KCONFIG_NOTIMESTAMP=y" + "CONFIG_PREFIX=${builtins.placeholder "out"}" + "CONFIG_STATIC=y" + ]; + in builders.bash.build { name = "busybox-static-${cfg.version}"; meta = cfg.meta; diff --git a/foundation/src/stages/stage2/bzip2/default.nix b/foundation/src/stages/stage2/bzip2/default.nix index ba1ab7b..e503604 100644 --- a/foundation/src/stages/stage2/bzip2/default.nix +++ b/foundation/src/stages/stage2/bzip2/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.bzip2; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.bzip2 = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; # TODO: Support more platforms. - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/coreutils/default.nix b/foundation/src/stages/stage2/coreutils/default.nix index 4d9ec19..734fbcc 100644 --- a/foundation/src/stages/stage2/coreutils/default.nix +++ b/foundation/src/stages/stage2/coreutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.coreutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.coreutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -62,18 +61,19 @@ in { sha256 = "X2ANkJOXOwr+JTk9m8GMRPIjJlf0yg2V6jHHAutmtzk="; }; - package = let - configureFlags = [ - "--prefix=${builtins.placeholder "out"}" - "--build=${platform.build}" - "--host=${platform.host}" - # libstdbuf.so fails in static builds - "--enable-no-install-program=stdbuf" - "--enable-single-binary=symlinks" - "CC=musl-gcc" - "CFLAGS=-static" - ]; - in + package = + let + configureFlags = [ + "--prefix=${builtins.placeholder "out"}" + "--build=${platform.build}" + "--host=${platform.host}" + # libstdbuf.so fails in static builds + "--enable-no-install-program=stdbuf" + "--enable-single-binary=symlinks" + "CC=musl-gcc" + "CFLAGS=-static" + ]; + in builders.bash.build { name = "coreutils-${cfg.version}"; diff --git a/foundation/src/stages/stage2/default.nix b/foundation/src/stages/stage2/default.nix index 05f9368..e55f9f0 100644 --- a/foundation/src/stages/stage2/default.nix +++ b/foundation/src/stages/stage2/default.nix @@ -1,9 +1,8 @@ -{ - lib, - config, -}: let +{ lib, config }: +let stage2 = config.aux.foundation.stages.stage2; -in { +in +{ includes = [ ./bash ./binutils diff --git a/foundation/src/stages/stage2/diffutils/default.nix b/foundation/src/stages/stage2/diffutils/default.nix index 90c8747..92d193b 100644 --- a/foundation/src/stages/stage2/diffutils/default.nix +++ b/foundation/src/stages/stage2/diffutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.diffutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.diffutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/findutils/default.nix b/foundation/src/stages/stage2/findutils/default.nix index 201b530..2ee6280 100644 --- a/foundation/src/stages/stage2/findutils/default.nix +++ b/foundation/src/stages/stage2/findutils/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.findutils; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.findutils = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/gawk/default.nix b/foundation/src/stages/stage2/gawk/default.nix index dd7f269..1a85835 100644 --- a/foundation/src/stages/stage2/gawk/default.nix +++ b/foundation/src/stages/stage2/gawk/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gawk; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gawk = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage2/gcc/default.nix b/foundation/src/stages/stage2/gcc/default.nix index 51da8ea..8e9b7da 100644 --- a/foundation/src/stages/stage2/gcc/default.nix +++ b/foundation/src/stages/stage2/gcc/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gcc; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gcc = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/glibc/default.nix b/foundation/src/stages/stage2/glibc/default.nix index 2e76ebb..9167d48 100644 --- a/foundation/src/stages/stage2/glibc/default.nix +++ b/foundation/src/stages/stage2/glibc/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.glibc; platform = config.aux.platform; @@ -9,7 +7,8 @@ stage1 = config.aux.foundation.stages.stage1; stage2 = config.aux.foundation.stages.stage2; -in { +in +{ options.aux.foundation.stages.stage2.glibc = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/gnugrep/default.nix b/foundation/src/stages/stage2/gnugrep/default.nix index 1ecd5ec..b304cd6 100644 --- a/foundation/src/stages/stage2/gnugrep/default.nix +++ b/foundation/src/stages/stage2/gnugrep/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gnugrep; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gnugrep = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage2/gnumake/default.nix b/foundation/src/stages/stage2/gnumake/default.nix index f43c46a..cee3398 100644 --- a/foundation/src/stages/stage2/gnumake/default.nix +++ b/foundation/src/stages/stage2/gnumake/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gnumake; platform = config.aux.platform; @@ -9,7 +7,8 @@ stage1 = config.aux.foundation.stages.stage1; stage2 = config.aux.foundation.stages.stage2; -in { +in +{ options.aux.foundation.stages.stage2.gnumake = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; @@ -63,16 +62,17 @@ in { sha256 = "3Rb7HWe/q3mnL16DkHNcSePo5wtJRaFasfgd23hlj7M="; }; - package = let - patches = [ - # Replaces /bin/sh with sh, see patch file for reasoning - ./patches/0001-No-impure-bin-sh.patch - # Purity: don't look for library dependencies (of the form `-lfoo') in /lib - # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for - # included Makefiles, don't look in /usr/include and friends. - ./patches/0002-remove-impure-dirs.patch - ]; - in + package = + let + patches = [ + # Replaces /bin/sh with sh, see patch file for reasoning + ./patches/0001-No-impure-bin-sh.patch + # Purity: don't look for library dependencies (of the form `-lfoo') in /lib + # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for + # included Makefiles, don't look in /usr/include and friends. + ./patches/0002-remove-impure-dirs.patch + ]; + in builders.bash.boot.build { name = "gnumake-static-${cfg.version}"; diff --git a/foundation/src/stages/stage2/gnupatch/default.nix b/foundation/src/stages/stage2/gnupatch/default.nix index e5520f1..12519d4 100644 --- a/foundation/src/stages/stage2/gnupatch/default.nix +++ b/foundation/src/stages/stage2/gnupatch/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gnupatch; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gnupatch = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/gnused/default.nix b/foundation/src/stages/stage2/gnused/default.nix index 3b1c564..d4a9942 100644 --- a/foundation/src/stages/stage2/gnused/default.nix +++ b/foundation/src/stages/stage2/gnused/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gnused; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gnused = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage2/gnutar/default.nix b/foundation/src/stages/stage2/gnutar/default.nix index 9dd33f6..2423b09 100644 --- a/foundation/src/stages/stage2/gnutar/default.nix +++ b/foundation/src/stages/stage2/gnutar/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gnutar; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gnutar = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; mainProgram = lib.options.create { diff --git a/foundation/src/stages/stage2/gzip/default.nix b/foundation/src/stages/stage2/gzip/default.nix index a3babb9..dc9316a 100644 --- a/foundation/src/stages/stage2/gzip/default.nix +++ b/foundation/src/stages/stage2/gzip/default.nix @@ -1,14 +1,13 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.gzip; platform = config.aux.platform; builders = config.aux.foundation.builders; stage1 = config.aux.foundation.stages.stage1; -in { +in +{ options.aux.foundation.stages.stage2.gzip = { meta = { description = lib.options.create { @@ -33,7 +32,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/stages/stage2/patchelf/default.nix b/foundation/src/stages/stage2/patchelf/default.nix index 40c9fbe..01868cb 100644 --- a/foundation/src/stages/stage2/patchelf/default.nix +++ b/foundation/src/stages/stage2/patchelf/default.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.aux.foundation.stages.stage2.patchelf; platform = config.aux.platform; @@ -9,7 +7,8 @@ stage1 = config.aux.foundation.stages.stage1; stage2 = config.aux.foundation.stages.stage2; -in { +in +{ options.aux.foundation.stages.stage2.patchelf = { meta = { description = lib.options.create { @@ -34,7 +33,7 @@ in { platforms = lib.options.create { type = lib.types.list.of lib.types.string; description = "Platforms the package supports."; - default.value = ["i686-linux"]; + default.value = [ "i686-linux" ]; }; }; diff --git a/foundation/src/system/default.nix b/foundation/src/system/default.nix index aae1d96..d30880c 100644 --- a/foundation/src/system/default.nix +++ b/foundation/src/system/default.nix @@ -1,4 +1,5 @@ -{lib}: { +{ lib }: +{ options.aux = { system = lib.options.create { type = lib.types.string; diff --git a/lib/src/attrs/default.nix b/lib/src/attrs/default.nix index 4c58960..2e723a3 100644 --- a/lib/src/attrs/default.nix +++ b/lib/src/attrs/default.nix @@ -10,185 +10,205 @@ lib: { ## from `y` first if it exists and then `x` otherwise. ## ## @type Attrs a b c => (String -> Any -> Any -> Bool) -> a -> b -> c - mergeRecursiveUntil = predicate: x: y: let - process = path: - builtins.zipAttrsWith ( - name: values: let - currentPath = path ++ [name]; - isSingleValue = builtins.length values == 1; - isComplete = - predicate currentPath - (builtins.elemAt values 1) - (builtins.elemAt values 0); - in - if isSingleValue - then builtins.elemAt values 0 - else if isComplete - then builtins.elemAt values 1 - else process currentPath values - ); - in - process [] [x y]; + mergeRecursiveUntil = + predicate: x: y: + let + process = + path: + builtins.zipAttrsWith ( + name: values: + let + currentPath = path ++ [ name ]; + isSingleValue = builtins.length values == 1; + isComplete = predicate currentPath (builtins.elemAt values 1) (builtins.elemAt values 0); + in + if isSingleValue then + builtins.elemAt values 0 + else if isComplete then + builtins.elemAt values 1 + else + process currentPath values + ); + in + process [ ] [ + x + y + ]; ## Merge two attribute sets recursively. Any values that are _not_ attribute sets ## will be overridden with the value from `y` first if it exists and then `x` ## otherwise. ## ## @type Attrs a b c => a -> b -> c - mergeRecursive = - lib.attrs.mergeRecursiveUntil - (path: x: y: - !(builtins.isAttrs x && builtins.isAttrs y)); + mergeRecursive = lib.attrs.mergeRecursiveUntil ( + path: x: y: + !(builtins.isAttrs x && builtins.isAttrs y) + ); ## Get a value from an attribute set by a path. If the path does not exist, ## a fallback value will be returned instead. ## ## @type (List String) -> a -> Attrs -> a | b - select = path: fallback: target: let - name = builtins.head path; - rest = builtins.tail path; - in - if path == [] - then target - else if target ? ${name} - then lib.attrs.select rest fallback target.${name} - else fallback; + select = + path: fallback: target: + let + name = builtins.head path; + rest = builtins.tail path; + in + if path == [ ] then + target + else if target ? ${name} then + lib.attrs.select rest fallback target.${name} + else + fallback; ## Get a value from an attribute set by a path. If the path does not exist, ## an error will be thrown. ## ## @type (List String) -> Attrs -> a - selectOrThrow = path: target: let - pathAsString = builtins.concatStringsSep "." path; - error = builtins.throw "Path not found in attribute set: ${pathAsString}"; - in - if lib.attrs.has path target - then lib.attrs.select path null target - else error; + selectOrThrow = + path: target: + let + pathAsString = builtins.concatStringsSep "." path; + error = builtins.throw "Path not found in attribute set: ${pathAsString}"; + in + if lib.attrs.has path target then lib.attrs.select path null target else error; ## Zip specific attributes from a list of attribute sets. ## ## @type List String -> (List Any -> Any) -> List Attrs -> Attrs - zipWithNames = names: f: list: let - transform = name: { - inherit name; - value = f name (builtins.catAttrs name list); - }; - results = builtins.map transform names; - in + zipWithNames = + names: f: list: + let + transform = name: { + inherit name; + value = f name (builtins.catAttrs name list); + }; + results = builtins.map transform names; + in builtins.listToAttrs results; ## Match an attribute set against a pattern. ## ## @type Attrs -> Attrs -> Bool - match = pattern: value: let - process = name: values: let - first = builtins.elemAt values 0; - second = builtins.elemAt values 1; - in - if builtins.length values == 1 - then false - else if builtins.isAttrs first - then builtins.isAttrs second && lib.attrs.match first second - else first == second; + match = + pattern: value: + let + process = + name: values: + let + first = builtins.elemAt values 0; + second = builtins.elemAt values 1; + in + if builtins.length values == 1 then + false + else if builtins.isAttrs first then + builtins.isAttrs second && lib.attrs.match first second + else + first == second; - result = lib.attrs.zipWithNames (builtins.attrNames pattern) process [pattern value]; - in + result = lib.attrs.zipWithNames (builtins.attrNames pattern) process [ + pattern + value + ]; + in assert lib.errors.trace (builtins.isAttrs pattern) "Pattern must be an attribute set"; assert lib.errors.trace (builtins.isAttrs value) "Value must be an attribute set"; - builtins.all lib.fp.id (builtins.attrValues result); + builtins.all lib.fp.id (builtins.attrValues result); ## Create a nested attribute set with a value as the leaf node. ## ## @type (List String) -> a -> Attrs - set = path: value: let - length = builtins.length path; - process = depth: - if depth == length - then value - else { - ${builtins.elemAt path depth} = process (depth + 1); - }; - in + set = + path: value: + let + length = builtins.length path; + process = + depth: if depth == length then value else { ${builtins.elemAt path depth} = process (depth + 1); }; + in process 0; ## Check if a path exists in an attribute set. ## ## @type (List String) -> Attrs -> Bool - has = path: target: let - name = builtins.head path; - rest = builtins.tail path; - in - if path == [] - then true - else if target ? ${name} - then lib.attrs.has rest target.${name} - else false; + has = + path: target: + let + name = builtins.head path; + rest = builtins.tail path; + in + if path == [ ] then + true + else if target ? ${name} then + lib.attrs.has rest target.${name} + else + false; ## Depending on a given condition, either use the given value or an empty ## attribute set. ## ## @type Attrs a b => Bool -> a -> a | b - when = condition: value: - if condition - then value - else {}; + when = condition: value: if condition then value else { }; ## Map an attribute set's names and values to a list. ## ## @type Any a => (String -> Any -> a) -> Attrs -> List a - mapToList = f: target: - builtins.map (name: f name target.${name}) (builtins.attrNames target); + mapToList = f: target: builtins.map (name: f name target.${name}) (builtins.attrNames target); ## Map an attribute set recursively. Only non-set leaf nodes will be mapped. ## ## @type (List String -> Any -> Any) -> Attrs -> Attrs - mapRecursive = f: target: - lib.attrs.mapRecursiveWhen (lib.fp.const true) f target; + mapRecursive = f: target: lib.attrs.mapRecursiveWhen (lib.fp.const true) f target; ## Map an attribute set recursively when a given predicate returns true. ## Only leaf nodes according to the predicate will be mapped. ## ## @type (Attrs -> Bool) -> (List String -> Any -> Any) -> Attrs -> Attrs - mapRecursiveWhen = predicate: f: target: let - process = path: - builtins.mapAttrs ( - name: value: - if builtins.isAttrs value && predicate value - then process (path ++ [name]) value - else f (path ++ [name]) value - ); - in - process [] target; + mapRecursiveWhen = + predicate: f: target: + let + process = + path: + builtins.mapAttrs ( + name: value: + if builtins.isAttrs value && predicate value then + process (path ++ [ name ]) value + else + f (path ++ [ name ]) value + ); + in + process [ ] target; ## Filter an attribute set by a given predicate. The filter is only performed ## on the base level of the attribute set. ## ## @type (String -> Any -> Bool) -> Attrs -> Attrs - filter = predicate: target: let - names = builtins.attrNames target; - process = name: let - value = target.${name}; + filter = + predicate: target: + let + names = builtins.attrNames target; + process = + name: + let + value = target.${name}; + in + if predicate name value then [ { inherit name value; } ] else [ ]; + valid = builtins.concatMap process names; in - if predicate name value - then [{inherit name value;}] - else []; - valid = builtins.concatMap process names; - in builtins.listToAttrs valid; ## Generate an attribute set from a list of names and a function that is ## applied to each name. ## ## @type (List String) -> (String -> Any) -> Attrs - generate = names: f: let - pairs = - builtins.map (name: { + generate = + names: f: + let + pairs = builtins.map (name: { inherit name; value = f name; - }) - names; - in + }) names; + in builtins.listToAttrs pairs; }; } diff --git a/lib/src/attrs/default.test.nix b/lib/src/attrs/default.test.nix index 301d74d..31f8a3e 100644 --- a/lib/src/attrs/default.test.nix +++ b/lib/src/attrs/default.test.nix @@ -1,329 +1,342 @@ let lib = import ./../default.nix; -in { +in +{ "merge" = { - "merges two shallow sets" = let - expected = { - x = 1; - y = 2; - }; + "merges two shallow sets" = + let + expected = { + x = 1; + y = 2; + }; - actual = lib.attrs.merge {x = 1;} {y = 2;}; - in + actual = lib.attrs.merge { x = 1; } { y = 2; }; + in expected == actual; - "overwrites values from the first set" = let - expected = { - x = 2; - }; - actual = lib.attrs.merge {x = 1;} {x = 2;}; - in + "overwrites values from the first set" = + let + expected = { + x = 2; + }; + actual = lib.attrs.merge { x = 1; } { x = 2; }; + in actual == expected; - "does not merge nested sets" = let - expected = { - x.y = 2; - }; - actual = lib.attrs.merge {x.z = 1;} {x.y = 2;}; - in + "does not merge nested sets" = + let + expected = { + x.y = 2; + }; + actual = lib.attrs.merge { x.z = 1; } { x.y = 2; }; + in actual == expected; }; "mergeRecursiveUntil" = { - "merges with predicate" = let - expected = { - x.y.z = 1; - }; - actual = - lib.attrs.mergeRecursiveUntil - (path: x: y: lib.lists.last path == "z") - {x.y.z = 2;} - {x.y.z = 1;}; - in + "merges with predicate" = + let + expected = { + x.y.z = 1; + }; + actual = lib.attrs.mergeRecursiveUntil ( + path: x: y: + lib.lists.last path == "z" + ) { x.y.z = 2; } { x.y.z = 1; }; + in actual == expected; - "handles shallow merges" = let - expected = { - x.y.z = 1; - }; - actual = - lib.attrs.mergeRecursiveUntil - (path: x: y: true) - { - x = { - y.z = 2; + "handles shallow merges" = + let + expected = { + x.y.z = 1; + }; + actual = + lib.attrs.mergeRecursiveUntil + ( + path: x: y: + true + ) + { + x = { + y.z = 2; - a = false; - }; - } - {x.y.z = 1;}; - in + a = false; + }; + } + { x.y.z = 1; }; + in actual == expected; }; "mergeRecursive" = { - "merges two sets deeply" = let - expected = { - x.y.z = 1; - }; - actual = - lib.attrs.mergeRecursive - {x.y.z = 2;} - {x.y.z = 1;}; - in + "merges two sets deeply" = + let + expected = { + x.y.z = 1; + }; + actual = lib.attrs.mergeRecursive { x.y.z = 2; } { x.y.z = 1; }; + in actual == expected; }; "select" = { - "selects a nested value" = let - expected = "value"; - actual = - lib.attrs.select - ["x" "y" "z"] - null - { - x.y.z = expected; - }; - in + "selects a nested value" = + let + expected = "value"; + actual = lib.attrs.select [ + "x" + "y" + "z" + ] null { x.y.z = expected; }; + in actual == expected; - "handles empty path" = let - expected = { - x = { - y = { - z = 1; - }; - }; - }; - actual = - lib.attrs.select - [] - null - { + "handles empty path" = + let + expected = { x = { y = { z = 1; }; }; }; - in + actual = lib.attrs.select [ ] null { + x = { + y = { + z = 1; + }; + }; + }; + in actual == expected; - "handles fallback value" = let - expected = "fallback"; - actual = - lib.attrs.select - ["x" "y" "z"] - expected - {}; - in + "handles fallback value" = + let + expected = "fallback"; + actual = lib.attrs.select [ + "x" + "y" + "z" + ] expected { }; + in actual == expected; }; "selectOrThrow" = { - "selects a nested value" = let - expected = "value"; - actual = - lib.attrs.selectOrThrow - ["x" "y" "z"] - { - x.y.z = expected; - }; - in + "selects a nested value" = + let + expected = "value"; + actual = lib.attrs.selectOrThrow [ + "x" + "y" + "z" + ] { x.y.z = expected; }; + in actual == expected; - "handles empty path" = let - expected = { - x = { - y = { - z = 1; - }; - }; - }; - actual = - lib.attrs.selectOrThrow - [] - { + "handles empty path" = + let + expected = { x = { y = { z = 1; }; }; }; - in + actual = lib.attrs.selectOrThrow [ ] { + x = { + y = { + z = 1; + }; + }; + }; + in actual == expected; - "throws on nonexistent path" = let - actual = - lib.attrs.selectOrThrow - ["x" "y" "z"] - {}; + "throws on nonexistent path" = + let + actual = lib.attrs.selectOrThrow [ + "x" + "y" + "z" + ] { }; - evaluated = builtins.tryEval (builtins.deepSeq actual actual); - in + evaluated = builtins.tryEval (builtins.deepSeq actual actual); + in !evaluated.success; }; "set" = { - "creates a nested set" = let - expected = { - x = { - y = { - z = 1; + "creates a nested set" = + let + expected = { + x = { + y = { + z = 1; + }; }; }; - }; - actual = lib.attrs.set ["x" "y" "z"] 1; - in + actual = lib.attrs.set [ + "x" + "y" + "z" + ] 1; + in actual == expected; - "handles empty path" = let - expected = 1; - actual = lib.attrs.set [] 1; - in + "handles empty path" = + let + expected = 1; + actual = lib.attrs.set [ ] 1; + in actual == expected; }; "has" = { - "returns true for a nested value" = let - exists = lib.attrs.has ["x" "y" "z"] {x.y.z = 1;}; - in + "returns true for a nested value" = + let + exists = lib.attrs.has [ + "x" + "y" + "z" + ] { x.y.z = 1; }; + in exists; - "returns false for a nonexistent value" = let - exists = lib.attrs.has ["x" "y" "z"] {}; - in + "returns false for a nonexistent value" = + let + exists = lib.attrs.has [ + "x" + "y" + "z" + ] { }; + in !exists; - "handles empty path" = let - exists = lib.attrs.has [] {}; - in + "handles empty path" = + let + exists = lib.attrs.has [ ] { }; + in exists; }; "when" = { - "returns the value when condition is true" = let - expected = "value"; - actual = lib.attrs.when true expected; - in + "returns the value when condition is true" = + let + expected = "value"; + actual = lib.attrs.when true expected; + in actual == expected; - "returns an empty set when condition is false" = let - expected = {}; - actual = lib.attrs.when false "value"; - in + "returns an empty set when condition is false" = + let + expected = { }; + actual = lib.attrs.when false "value"; + in actual == expected; }; "mapToList" = { - "converts a set to a list" = let - expected = [ - { - name = "x"; - value = 1; - } - { - name = "y"; - value = 2; - } - ]; - actual = - lib.attrs.mapToList - (name: value: {inherit name value;}) - { + "converts a set to a list" = + let + expected = [ + { + name = "x"; + value = 1; + } + { + name = "y"; + value = 2; + } + ]; + actual = lib.attrs.mapToList (name: value: { inherit name value; }) { x = 1; y = 2; }; - in + in actual == expected; }; "mapRecursiveWhen" = { - "maps a set recursively" = let - expected = { - x = { - y = { - z = 2; + "maps a set recursively" = + let + expected = { + x = { + y = { + z = 2; + }; }; }; - }; - actual = - lib.attrs.mapRecursiveWhen - (value: true) - (path: value: value + 1) - { + actual = lib.attrs.mapRecursiveWhen (value: true) (path: value: value + 1) { x = { y = { z = 1; }; }; }; - in + in actual == expected; - "maps a set given a condition" = let - expected = { - x = { - y = { - z = 1; - }; - }; - }; - actual = - lib.attrs.mapRecursiveWhen - (value: !(value ? z)) - (path: value: - # We map before we get to a non-set value - if builtins.isAttrs value - then value - else value + 1) - { + "maps a set given a condition" = + let + expected = { x = { y = { z = 1; }; }; }; - in + actual = + lib.attrs.mapRecursiveWhen (value: !(value ? z)) + ( + path: value: + # We map before we get to a non-set value + if builtins.isAttrs value then value else value + 1 + ) + { + x = { + y = { + z = 1; + }; + }; + }; + in actual == expected; }; "mapRecursive" = { - "maps a set recursively" = let - expected = { - x = { - y = { - z = 2; + "maps a set recursively" = + let + expected = { + x = { + y = { + z = 2; + }; }; }; - }; - actual = - lib.attrs.mapRecursive - (path: value: value + 1) - { + actual = lib.attrs.mapRecursive (path: value: value + 1) { x = { y = { z = 1; }; }; }; - in + in actual == expected; }; "filter" = { - "filters a set" = let - expected = { - y = 2; - }; - actual = - lib.attrs.filter - (name: value: name == "y") - { + "filters a set" = + let + expected = { + y = 2; + }; + actual = lib.attrs.filter (name: value: name == "y") { x = 1; y = 2; }; - in + in actual == expected; }; } diff --git a/lib/src/bools/default.nix b/lib/src/bools/default.nix index f15cf71..7f4a7a3 100644 --- a/lib/src/bools/default.nix +++ b/lib/src/bools/default.nix @@ -4,28 +4,21 @@ lib: { ## Convert a boolean value into a string. ## ## @type Bool -> String - string = value: - if value - then "true" - else "false"; + string = value: if value then "true" else "false"; ## Convert a boolean into either the string "yes" or "no". ## ## @type Bool -> String - yesno = value: - if value - then "yes" - else "no"; + yesno = value: if value then "yes" else "no"; }; ## Choose between two values based on a condition. When true, the first value ## is returned, otherwise the second value is returned. ## ## @type Bool -> a -> b -> a | b - when = condition: x: y: - if condition - then x - else y; + when = + condition: x: y: + if condition then x else y; ## Perform a logical AND operation on two values. ## @@ -35,9 +28,7 @@ lib: { ## Perform a logical AND operation on two functions being applied to a value. ## ## @type (a -> Bool) -> (a -> Bool) -> a -> Bool - and' = f: g: ( - x: (f x) && (g x) - ); + and' = f: g: (x: (f x) && (g x)); ## Perform a logical OR operation on two values. ## @@ -47,9 +38,7 @@ lib: { ## Perform a logical OR operation on two functions being applied to a value. ## ## @type (a -> Bool) -> (a -> Bool) -> a -> Bool - or' = f: g: ( - x: (f x) || (g x) - ); + or' = f: g: (x: (f x) || (g x)); ## Perform a logical NOT operation on a value. ## diff --git a/lib/src/bools/default.test.nix b/lib/src/bools/default.test.nix index 89f2313..1f9c924 100644 --- a/lib/src/bools/default.test.nix +++ b/lib/src/bools/default.test.nix @@ -1,161 +1,190 @@ let lib = import ./../default.nix; -in { +in +{ "into" = { "string" = { - "handles true" = let - expected = "true"; - actual = lib.bools.into.string true; - in + "handles true" = + let + expected = "true"; + actual = lib.bools.into.string true; + in actual == expected; - "handles false" = let - expected = "false"; - actual = lib.bools.into.string false; - in + "handles false" = + let + expected = "false"; + actual = lib.bools.into.string false; + in actual == expected; }; "yesno" = { - "handles true" = let - expected = "yes"; - actual = lib.bools.into.yesno true; - in + "handles true" = + let + expected = "yes"; + actual = lib.bools.into.yesno true; + in actual == expected; - "handles false" = let - expected = "no"; - actual = lib.bools.into.yesno false; - in + "handles false" = + let + expected = "no"; + actual = lib.bools.into.yesno false; + in actual == expected; }; }; "when" = { - "returns first value when true" = let - expected = "foo"; - actual = lib.bools.when true expected "bar"; - in + "returns first value when true" = + let + expected = "foo"; + actual = lib.bools.when true expected "bar"; + in actual == expected; - "returns second value when false" = let - expected = "bar"; - actual = lib.bools.when false "foo" expected; - in + "returns second value when false" = + let + expected = "bar"; + actual = lib.bools.when false "foo" expected; + in actual == expected; }; "and" = { - "returns true when both are true" = let - expected = true; - actual = lib.bools.and true true; - in + "returns true when both are true" = + let + expected = true; + actual = lib.bools.and true true; + in actual == expected; - "returns false when first is false" = let - expected = false; - actual = lib.bools.and false true; - in + "returns false when first is false" = + let + expected = false; + actual = lib.bools.and false true; + in actual == expected; - "returns false when second is false" = let - expected = false; - actual = lib.bools.and true false; - in + "returns false when second is false" = + let + expected = false; + actual = lib.bools.and true false; + in actual == expected; - "returns false when both are false" = let - expected = false; - actual = lib.bools.and false false; - in + "returns false when both are false" = + let + expected = false; + actual = lib.bools.and false false; + in actual == expected; }; - "and'" = let - getTrue = _: true; - getFalse = _: false; - in { - "returns true when both are true" = let - expected = true; - actual = lib.bools.and' getTrue getTrue null; + "and'" = + let + getTrue = _: true; + getFalse = _: false; in - actual == expected; + { + "returns true when both are true" = + let + expected = true; + actual = lib.bools.and' getTrue getTrue null; + in + actual == expected; - "returns false when first is false" = let - expected = false; - actual = lib.bools.and' getFalse getTrue null; - in - actual == expected; + "returns false when first is false" = + let + expected = false; + actual = lib.bools.and' getFalse getTrue null; + in + actual == expected; - "returns false when second is false" = let - expected = false; - actual = lib.bools.and' getTrue getFalse null; - in - actual == expected; + "returns false when second is false" = + let + expected = false; + actual = lib.bools.and' getTrue getFalse null; + in + actual == expected; - "returns false when both are false" = let - expected = false; - actual = lib.bools.and' getFalse getFalse null; - in - actual == expected; - }; + "returns false when both are false" = + let + expected = false; + actual = lib.bools.and' getFalse getFalse null; + in + actual == expected; + }; "or" = { - "returns true when both are true" = let - expected = true; - actual = lib.bools.or true true; - in + "returns true when both are true" = + let + expected = true; + actual = lib.bools.or true true; + in actual == expected; - "returns true when first is true" = let - expected = true; - actual = lib.bools.or true false; - in + "returns true when first is true" = + let + expected = true; + actual = lib.bools.or true false; + in actual == expected; - "returns true when second is true" = let - expected = true; - actual = lib.bools.or false true; - in + "returns true when second is true" = + let + expected = true; + actual = lib.bools.or false true; + in actual == expected; - "returns false when both are false" = let - expected = false; - actual = lib.bools.or false false; - in + "returns false when both are false" = + let + expected = false; + actual = lib.bools.or false false; + in actual == expected; }; - "or'" = let - getTrue = _: true; - getFalse = _: false; - in { - "returns true when both are true" = let - expected = true; - actual = lib.bools.or' getTrue getTrue null; + "or'" = + let + getTrue = _: true; + getFalse = _: false; in - actual == expected; - "returns true when first is true" = let - expected = true; - actual = lib.bools.or' getTrue getFalse null; - in - actual == expected; - "returns true when second is true" = let - expected = true; - actual = lib.bools.or' getFalse getTrue null; - in - actual == expected; - "returns false when both are false" = let - expected = false; - actual = lib.bools.or' getFalse getFalse null; - in - actual == expected; - }; + { + "returns true when both are true" = + let + expected = true; + actual = lib.bools.or' getTrue getTrue null; + in + actual == expected; + "returns true when first is true" = + let + expected = true; + actual = lib.bools.or' getTrue getFalse null; + in + actual == expected; + "returns true when second is true" = + let + expected = true; + actual = lib.bools.or' getFalse getTrue null; + in + actual == expected; + "returns false when both are false" = + let + expected = false; + actual = lib.bools.or' getFalse getFalse null; + in + actual == expected; + }; "not" = { - "returns false when true" = let - expected = false; - actual = lib.bools.not true; - in + "returns false when true" = + let + expected = false; + actual = lib.bools.not true; + in actual == expected; - "returns true when false" = let - expected = true; - actual = lib.bools.not false; - in + "returns true when false" = + let + expected = true; + actual = lib.bools.not false; + in actual == expected; }; } diff --git a/lib/src/dag/default.nix b/lib/src/dag/default.nix index 15bdb6b..608b46d 100644 --- a/lib/src/dag/default.nix +++ b/lib/src/dag/default.nix @@ -4,58 +4,56 @@ lib: { ## Check that a value is a DAG entry. ## ## @type a -> Bool - entry = value: - (value ? value) - && (value ? before) - && (value ? after); + entry = value: (value ? value) && (value ? before) && (value ? after); ## Check that a value is a DAG. ## ## @type a -> Bool - graph = value: let - isContentsValid = builtins.all lib.dag.validate.entry (builtins.attrValues value); - in - builtins.isAttrs value - && isContentsValid; + graph = + value: + let + isContentsValid = builtins.all lib.dag.validate.entry (builtins.attrValues value); + in + builtins.isAttrs value && isContentsValid; }; sort = { ## Apply a topological sort to a DAG. ## ## @type Dag a -> { result :: List a } | { cycle :: List a, loops :: List a } - topographic = graph: let - getEntriesBefore = graph: name: let - before = - lib.attrs.filter - (key: value: builtins.elem name value.before) - graph; + topographic = + graph: + let + getEntriesBefore = + graph: name: + let + before = lib.attrs.filter (key: value: builtins.elem name value.before) graph; + in + builtins.attrNames before; + + normalize = name: value: { + inherit name; + value = value.value; + after = value.after ++ (getEntriesBefore graph name); + }; + + normalized = builtins.mapAttrs normalize graph; + + entries = builtins.attrValues normalized; + + isBefore = a: b: builtins.elem a.name b.after; + + sorted = lib.lists.sort.topographic isBefore entries; in - builtins.attrNames before; - - normalize = name: value: { - inherit name; - value = value.value; - after = value.after ++ (getEntriesBefore graph name); - }; - - normalized = builtins.mapAttrs normalize graph; - - entries = builtins.attrValues normalized; - - isBefore = a: b: builtins.elem a.name b.after; - - sorted = lib.lists.sort.topographic isBefore entries; - in - if sorted ? result - then { - result = - builtins.map (value: { + if sorted ? result then + { + result = builtins.map (value: { name = value.name; value = value.value; - }) - sorted.result; - } - else sorted; + }) sorted.result; + } + else + sorted; }; apply = { @@ -63,107 +61,95 @@ lib: { ## and any entries that do exist are given the appropriate `before` and `after` values. ## ## @type Dag a -> Dag a -> Dag a - defaults = graph: defaults: let - result = - builtins.mapAttrs - ( + defaults = + graph: defaults: + let + result = builtins.mapAttrs ( name: entry: - if defaults ? ${name} - then - if builtins.isString entry - then { + if defaults ? ${name} then + if builtins.isString entry then + { value = entry; - before = defaults.${name}.before or []; - after = defaults.${name}.after or []; + before = defaults.${name}.before or [ ]; + after = defaults.${name}.after or [ ]; } - else - entry - // { - before = (entry.before or []) ++ (defaults.${name}.before or []); - after = (entry.after or []) ++ (defaults.${name}.after or []); - } - else entry - ) - graph; - in + else + entry + // { + before = (entry.before or [ ]) ++ (defaults.${name}.before or [ ]); + after = (entry.after or [ ]) ++ (defaults.${name}.after or [ ]); + } + else + entry + ) graph; + in defaults // result; }; ## Map over the entries in a DAG and modify their values. ## ## @type (String -> a -> b) -> Dag a -> Dag b - map = f: - builtins.mapAttrs - (name: value: - value - // { - value = f name value.value; - }); + map = f: builtins.mapAttrs (name: value: value // { value = f name value.value; }); entry = { ## Create a new DAG entry. ## ## @type List String -> List String -> a -> { before :: List String, after :: List String, value :: a } - between = before: after: value: { - inherit before after value; - }; + between = before: after: value: { inherit before after value; }; ## Create a new DAG entry with no dependencies. ## ## @type a -> { before :: List String, after :: List String, value :: a } - anywhere = lib.dag.entry.between [] []; + anywhere = lib.dag.entry.between [ ] [ ]; ## Create a new DAG entry that occurs before other entries. ## ## @type List String -> a -> { before :: List String, after :: List String, value :: a } - before = before: lib.dag.entry.between before []; + before = before: lib.dag.entry.between before [ ]; ## Create a new DAG entry that occurs after other entries. ## ## @type List String -> a -> { before :: List String, after :: List String, value :: a } - after = lib.dag.entry.between []; + after = lib.dag.entry.between [ ]; }; entries = { ## Create a DAG from a list of entries, prefixed with a tag. ## ## @type String -> List String -> List String -> List a -> Dag a - between = tag: let - process = i: before: after: entries: let - name = "${tag}-${builtins.toString i}"; - entry = builtins.head entries; - rest = builtins.tail entries; + between = + tag: + let + process = + i: before: after: entries: + let + name = "${tag}-${builtins.toString i}"; + entry = builtins.head entries; + rest = builtins.tail entries; + in + if builtins.length entries == 0 then + { } + else if builtins.length entries == 1 then + { "${name}" = lib.dag.entry.between before after entry; } + else + { "${name}" = lib.dag.entry.after after entry; } // (process (i + 1) before [ name ] rest); in - if builtins.length entries == 0 - then {} - else if builtins.length entries == 1 - then { - "${name}" = lib.dag.entry.between before after entry; - } - else - { - "${name}" = lib.dag.entry.after after entry; - } - // ( - process (i + 1) before [name] rest - ); - in process 0; ## Create a DAG from a list of entries, prefixed with a tag, that can occur anywhere. ## ## @type String -> List a -> Dag a - anywhere = tag: lib.dag.entries.between tag [] []; + anywhere = tag: lib.dag.entries.between tag [ ] [ ]; ## Create a DAG from a list of entries, prefixed with a tag, that occurs before other entries. ## ## @type String -> List String -> List a -> Dag a - before = tag: before: lib.dag.entries.between tag before []; + before = tag: before: lib.dag.entries.between tag before [ ]; ## Create a DAG from a list of entries, prefixed with a tag, that occurs after other entries. ## ## @type String -> List String -> List a -> Dag a - after = tag: lib.dag.entries.between tag []; + after = tag: lib.dag.entries.between tag [ ]; }; }; } diff --git a/lib/src/dag/default.test.nix b/lib/src/dag/default.test.nix index f6f4076..a7702b0 100644 --- a/lib/src/dag/default.test.nix +++ b/lib/src/dag/default.test.nix @@ -1,134 +1,159 @@ let lib = import ./../default.nix; -in { +in +{ "validate" = { "entry" = { - "invalid value" = let - expected = false; - actual = lib.dag.validate.entry {}; - in + "invalid value" = + let + expected = false; + actual = lib.dag.validate.entry { }; + in actual == expected; - "a manually created value" = let - expected = true; - actual = lib.dag.validate.entry { - value = null; - before = []; - after = []; - }; - in + "a manually created value" = + let + expected = true; + actual = lib.dag.validate.entry { + value = null; + before = [ ]; + after = [ ]; + }; + in actual == expected; - "entry.between" = let - expected = true; - actual = lib.dag.validate.entry (lib.dag.entry.between [] [] null); - in + "entry.between" = + let + expected = true; + actual = lib.dag.validate.entry (lib.dag.entry.between [ ] [ ] null); + in actual == expected; - "entry.anywhere" = let - expected = true; - actual = lib.dag.validate.entry (lib.dag.entry.anywhere null); - in + "entry.anywhere" = + let + expected = true; + actual = lib.dag.validate.entry (lib.dag.entry.anywhere null); + in actual == expected; - "entry.before" = let - expected = true; - actual = lib.dag.validate.entry (lib.dag.entry.before [] null); - in + "entry.before" = + let + expected = true; + actual = lib.dag.validate.entry (lib.dag.entry.before [ ] null); + in actual == expected; - "entry.after" = let - expected = true; - actual = lib.dag.validate.entry (lib.dag.entry.after [] null); - in + "entry.after" = + let + expected = true; + actual = lib.dag.validate.entry (lib.dag.entry.after [ ] null); + in actual == expected; }; "graph" = { - "invalid value" = let - expected = false; - actual = lib.dag.validate.graph { - x = {}; - }; - in + "invalid value" = + let + expected = false; + actual = lib.dag.validate.graph { x = { }; }; + in actual == expected; - "a manually created value" = let - expected = true; - actual = lib.dag.validate.graph { - x = { - value = null; - before = []; - after = []; + "a manually created value" = + let + expected = true; + actual = lib.dag.validate.graph { + x = { + value = null; + before = [ ]; + after = [ ]; + }; }; - }; - in + in actual == expected; - "entries.between" = let - expected = true; - graph = lib.dag.entries.between "example" [] [] [null null]; - actual = lib.dag.validate.graph graph; - in + "entries.between" = + let + expected = true; + graph = lib.dag.entries.between "example" [ ] [ ] [ + null + null + ]; + actual = lib.dag.validate.graph graph; + in actual == expected; - "entries.anywhere" = let - expected = true; - graph = lib.dag.entries.anywhere "example" [null null]; - actual = lib.dag.validate.graph graph; - in + "entries.anywhere" = + let + expected = true; + graph = lib.dag.entries.anywhere "example" [ + null + null + ]; + actual = lib.dag.validate.graph graph; + in actual == expected; - "entries.before" = let - expected = true; - graph = lib.dag.entries.before "example" [] [null null]; - actual = lib.dag.validate.graph graph; - in + "entries.before" = + let + expected = true; + graph = lib.dag.entries.before "example" [ ] [ + null + null + ]; + actual = lib.dag.validate.graph graph; + in actual == expected; - "entries.after" = let - expected = true; - graph = lib.dag.entries.after "example" [] [null null]; - actual = lib.dag.validate.graph graph; - in + "entries.after" = + let + expected = true; + graph = lib.dag.entries.after "example" [ ] [ + null + null + ]; + actual = lib.dag.validate.graph graph; + in actual == expected; }; }; "sort" = { "topographic" = { - "handles an empty graph" = let - expected = []; - actual = lib.dag.sort.topographic {}; - in + "handles an empty graph" = + let + expected = [ ]; + actual = lib.dag.sort.topographic { }; + in actual.result == expected; - "sorts a graph" = let - expected = [ - { - name = "a"; - value = "a"; - } - { - name = "b"; - value = "b"; - } - { - name = "c"; - value = "c"; - } - { - name = "d"; - value = "d"; - } - ]; - actual = lib.dag.sort.topographic { - a = lib.dag.entry.anywhere "a"; - b = lib.dag.entry.between ["c"] ["a"] "b"; - c = lib.dag.entry.before ["c"] "c"; - d = lib.dag.entry.after ["c"] "d"; - }; - in + "sorts a graph" = + let + expected = [ + { + name = "a"; + value = "a"; + } + { + name = "b"; + value = "b"; + } + { + name = "c"; + value = "c"; + } + { + name = "d"; + value = "d"; + } + ]; + actual = lib.dag.sort.topographic { + a = lib.dag.entry.anywhere "a"; + b = lib.dag.entry.between [ "c" ] [ "a" ] "b"; + c = lib.dag.entry.before [ "c" ] "c"; + d = lib.dag.entry.after [ "c" ] "d"; + }; + in actual.result == expected; }; }; diff --git a/lib/src/default.nix b/lib/src/default.nix index 13ba6d0..8052952 100644 --- a/lib/src/default.nix +++ b/lib/src/default.nix @@ -29,9 +29,11 @@ let ## definitions. ## ## @type (a -> a) -> a - fix = f: let - x = f x; - in + fix = + f: + let + x = f x; + in x; ## Merge two attribute sets recursively until a given predicate returns true. @@ -39,40 +41,42 @@ let ## from `y` first if it exists and then `x` otherwise. ## ## @type Attrs a b c => (String -> Any -> Any -> Bool) -> a -> b -> c - mergeAttrsRecursiveUntil = predicate: x: y: let - process = path: - builtins.zipAttrsWith ( - name: values: let - currentPath = path ++ [name]; - isSingleValue = builtins.length values == 1; - isComplete = - predicate currentPath - (builtins.elemAt values 1) - (builtins.elemAt values 0); - in - if isSingleValue || isComplete - then builtins.elemAt values 0 - else process currentPath values - ); - in - process [] [x y]; + mergeAttrsRecursiveUntil = + predicate: x: y: + let + process = + path: + builtins.zipAttrsWith ( + name: values: + let + currentPath = path ++ [ name ]; + isSingleValue = builtins.length values == 1; + isComplete = predicate currentPath (builtins.elemAt values 1) (builtins.elemAt values 0); + in + if isSingleValue || isComplete then builtins.elemAt values 0 else process currentPath values + ); + in + process [ ] [ + x + y + ]; ## Merge two attribute sets recursively. Any values that are _not_ attribute sets ## will be overridden with the value from `y` first if it exists and then `x` ## otherwise. ## ## @type Attrs a b c => a -> b -> c - mergeAttrsRecursive = - mergeAttrsRecursiveUntil - (path: x: y: - !(builtins.isAttrs x && builtins.isAttrs y)); + mergeAttrsRecursive = mergeAttrsRecursiveUntil ( + path: x: y: + !(builtins.isAttrs x && builtins.isAttrs y) + ); lib = fix ( - self: let - merge = acc: create: - mergeAttrsRecursive acc (create self); + self: + let + merge = acc: create: mergeAttrsRecursive acc (create self); in - builtins.foldl' merge {} libs + builtins.foldl' merge { } libs ); in - lib.points.withExtend (lib.fp.const lib) +lib.points.withExtend (lib.fp.const lib) diff --git a/lib/src/default.test.nix b/lib/src/default.test.nix index c405ea2..fc43a08 100644 --- a/lib/src/default.test.nix +++ b/lib/src/default.test.nix @@ -1,18 +1,22 @@ let lib = import ./../default.nix; -in { +in +{ "extend" = { - "lib is extensible" = let - result = lib.extend (final: prev: prev // { - __injected__ = true; + "lib is extensible" = + let + result = lib.extend ( + final: prev: + prev + // { + __injected__ = true; - fp = prev.fp // { - __injected__ = true; - }; - }); - in - result ? __injected__ - && result.fp ? __injected__ - && result.fp ? const; + fp = prev.fp // { + __injected__ = true; + }; + } + ); + in + result ? __injected__ && result.fp ? __injected__ && result.fp ? const; }; } diff --git a/lib/src/errors/default.nix b/lib/src/errors/default.nix index 9522f78..322f0bf 100644 --- a/lib/src/errors/default.nix +++ b/lib/src/errors/default.nix @@ -5,9 +5,6 @@ lib: { ## ## @notest ## @type Bool -> String -> Bool - trace = condition: message: - if condition - then true - else builtins.trace message false; + trace = condition: message: if condition then true else builtins.trace message false; }; } diff --git a/lib/src/errors/default.test.nix b/lib/src/errors/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/errors/default.test.nix +++ b/lib/src/errors/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/fp/default.nix b/lib/src/fp/default.nix index 152160c..23b39b3 100644 --- a/lib/src/fp/default.nix +++ b/lib/src/fp/default.nix @@ -20,22 +20,26 @@ lib: { ## order they are provided. ## ## @type (List (Any -> Any)) -> Any -> Any - pipe = fs: ( - x: builtins.foldl' (value: f: f value) x fs - ); + pipe = fs: (x: builtins.foldl' (value: f: f value) x fs); ## Reverse the order of arguments to a function that has two parameters. ## ## @type (a -> b -> c) -> b -> a -> c - flip2 = f: a: b: f b a; + flip2 = + f: a: b: + f b a; ## Reverse the order of arguments to a function that has three parameters. ## ## @type (a -> b -> c -> d) -> c -> b -> a -> d - flip3 = f: a: b: c: f c b a; + flip3 = + f: a: b: c: + f c b a; ## Reverse the order of arguments to a function that has four parameters. ## ## @type (a -> b -> c -> d -> e) -> d -> c -> b -> a -> e - flip4 = f: a: b: c: d: f d c b a; + flip4 = + f: a: b: c: d: + f d c b a; ## Get the arguments of a function or functor. ## An attribute set is returned with the arguments as keys. The values @@ -43,23 +47,18 @@ lib: { ## when it does not. ## ## @type Function -> Attrs - args = f: - if f ? __functor - then f.__args__ or (lib.fp.args (f.__functor f)) - else builtins.functionArgs f; + args = + f: if f ? __functor then f.__args__ or (lib.fp.args (f.__functor f)) else builtins.functionArgs f; ## Create a function that is called with only the arguments it specifies. ## ## @type Attrs a => (a -> b) -> a -> b - withDynamicArgs = f: args: let - fArgs = lib.fp.args f; - common = builtins.intersectAttrs fArgs args; - in - if builtins.isAttrs args - then - if fArgs == {} - then f args - else f common - else f args; + withDynamicArgs = + f: args: + let + fArgs = lib.fp.args f; + common = builtins.intersectAttrs fArgs args; + in + if builtins.isAttrs args then if fArgs == { } then f args else f common else f args; }; } diff --git a/lib/src/fp/default.test.nix b/lib/src/fp/default.test.nix index d1d352d..62fe7d4 100644 --- a/lib/src/fp/default.test.nix +++ b/lib/src/fp/default.test.nix @@ -1,139 +1,165 @@ let lib = import ./../default.nix; -in { +in +{ "id" = { - "returns its argument" = let - expected = "foo"; - actual = lib.fp.id expected; - in + "returns its argument" = + let + expected = "foo"; + actual = lib.fp.id expected; + in actual == expected; }; "const" = { - "creates a function that returns its argument" = let - expected = "foo"; - actual = lib.fp.const expected "bar"; - in + "creates a function that returns its argument" = + let + expected = "foo"; + actual = lib.fp.const expected "bar"; + in actual == expected; }; "compose" = { - "composes two functions" = let - f = x: x + 1; - g = x: x * 2; - expected = 5; - actual = lib.fp.compose f g 2; - in + "composes two functions" = + let + f = x: x + 1; + g = x: x * 2; + expected = 5; + actual = lib.fp.compose f g 2; + in actual == expected; }; "pipe" = { - "pipes two functions" = let - f = x: x + 1; - g = x: x * 2; - expected = 5; - actual = lib.fp.pipe [g f] 2; - in + "pipes two functions" = + let + f = x: x + 1; + g = x: x * 2; + expected = 5; + actual = lib.fp.pipe [ + g + f + ] 2; + in actual == expected; }; "flip2" = { - "flips the arguments of a binary function" = let - f = a: b: a - b; - expected = 1; - actual = lib.fp.flip2 f 1 2; - in + "flips the arguments of a binary function" = + let + f = a: b: a - b; + expected = 1; + actual = lib.fp.flip2 f 1 2; + in actual == expected; }; "flip3" = { - "flips the arguments of a ternary function" = let - f = a: b: c: a - b - c; - expected = 0; - actual = lib.fp.flip3 f 1 2 3; - in + "flips the arguments of a ternary function" = + let + f = + a: b: c: + a - b - c; + expected = 0; + actual = lib.fp.flip3 f 1 2 3; + in actual == expected; }; "flip4" = { - "flips the arguments of a quaternary function" = let - f = a: b: c: d: a - b - c - d; - expected = -2; - actual = lib.fp.flip4 f 1 2 3 4; - in + "flips the arguments of a quaternary function" = + let + f = + a: b: c: d: + a - b - c - d; + expected = -2; + actual = lib.fp.flip4 f 1 2 3 4; + in actual == expected; }; "args" = { - "gets a functions attr set arguments" = let - expected = { - x = false; - y = true; - }; - actual = lib.fp.args ({ - x, - y ? null, - }: - null); - in - actual == expected; - - "returns an empty set if the function has no attrs arguments" = let - expected = {}; - actual = lib.fp.args (args: null); - in - actual == expected; - - "supports functors" = let - expected = { - x = false; - y = true; - }; - - actual = lib.fp.args { - __functor = self: { - x, - y ? null, - }: - null; - }; - in - actual == expected; - - "supports cached functor arguments" = let - expected = { - x = false; - y = true; - }; - actual = lib.fp.args { - __args__ = { + "gets a functions attr set arguments" = + let + expected = { x = false; y = true; }; - __functor = self: args: - null; - }; - in + actual = lib.fp.args ( + { + x, + y ? null, + }: + null + ); + in + actual == expected; + + "returns an empty set if the function has no attrs arguments" = + let + expected = { }; + actual = lib.fp.args (args: null); + in + actual == expected; + + "supports functors" = + let + expected = { + x = false; + y = true; + }; + + actual = lib.fp.args { + __functor = + self: + { + x, + y ? null, + }: + null; + }; + in + actual == expected; + + "supports cached functor arguments" = + let + expected = { + x = false; + y = true; + }; + actual = lib.fp.args { + __args__ = { + x = false; + y = true; + }; + __functor = self: args: null; + }; + in actual == expected; }; "withDynamicArgs" = { - "applies a function with dynamic arguments" = let - expected = {x = true;}; - actual = lib.fp.withDynamicArgs (args @ {x}: args) { - x = true; - y = true; - }; - in + "applies a function with dynamic arguments" = + let + expected = { + x = true; + }; + actual = lib.fp.withDynamicArgs (args@{ x }: args) { + x = true; + y = true; + }; + in actual == expected; - "applies all arguments if none are specified" = let - expected = { - x = true; - y = true; - }; - actual = lib.fp.withDynamicArgs (args: args) expected; - in + "applies all arguments if none are specified" = + let + expected = { + x = true; + y = true; + }; + actual = lib.fp.withDynamicArgs (args: args) expected; + in actual == expected; }; } diff --git a/lib/src/generators/default.nix b/lib/src/generators/default.nix index bc23e40..6627e43 100644 --- a/lib/src/generators/default.nix +++ b/lib/src/generators/default.nix @@ -3,142 +3,150 @@ lib: { ## Limit evaluation of a valud to a certain depth. ## ## @type { limit? :: Int | Null, throw? :: Bool } -> a -> a - withRecursion = { - limit ? null, - throw ? true, - }: - assert builtins.isInt limit; let + withRecursion = + { + limit ? null, + throw ? true, + }: + assert builtins.isInt limit; + let special = [ "__functor" "__functionArgs" "__toString" "__pretty__" ]; - attr = next: name: - if builtins.elem name special - then lib.fp.id - else next; - transform = depth: - if limit != null && depth > limit - then - if throw - then builtins.throw "Exceeded maximum eval-depth limit of ${builtins.toString limit} while trying to evaluate with `lib.generators.withRecursion'!" - else lib.fp.const "" - else lib.fp.id; - process = depth: value: let - next = x: process (depth + 1) (transform (depth + 1) x); - in - if builtins.isAttrs value - then builtins.mapAttrs (attr next) value - else if builtins.isList value - then builtins.map next value - else transform (depth + 1) value; + attr = next: name: if builtins.elem name special then lib.fp.id else next; + transform = + depth: + if limit != null && depth > limit then + if throw then + builtins.throw "Exceeded maximum eval-depth limit of ${builtins.toString limit} while trying to evaluate with `lib.generators.withRecursion'!" + else + lib.fp.const "" + else + lib.fp.id; + process = + depth: value: + let + next = x: process (depth + 1) (transform (depth + 1) x); + in + if builtins.isAttrs value then + builtins.mapAttrs (attr next) value + else if builtins.isList value then + builtins.map next value + else + transform (depth + 1) value; in - process 0; + process 0; ## Create a pretty printer for Nix values. ## ## @type { indent? :: String, multiline? :: Bool, allowCustomPrettifiers? :: Bool } -> a -> string - pretty = { - indent ? "", - multiline ? true, - allowCustomPrettifiers ? false, - }: let - process = indent: value: let - prefix = - if multiline - then "\n${indent} " - else " "; - suffix = - if multiline - then "\n${indent}" - else " "; + pretty = + { + indent ? "", + multiline ? true, + allowCustomPrettifiers ? false, + }: + let + process = + indent: value: + let + prefix = if multiline then "\n${indent} " else " "; + suffix = if multiline then "\n${indent}" else " "; - prettyNull = "null"; - prettyNumber = lib.numbers.into.string value; - prettyBool = lib.bools.into.string value; - prettyPath = builtins.toString value; + prettyNull = "null"; + prettyNumber = lib.numbers.into.string value; + prettyBool = lib.bools.into.string value; + prettyPath = builtins.toString value; - prettyString = let - lines = builtins.filter (x: !builtins.isList x) (builtins.split "\n" value); - escapeSingleline = lib.strings.escape.any ["\\" "\"" "\${"]; - escapeMultiline = builtins.replaceStrings ["\${" "''"] ["''\${" "'''"]; - singlelineResult = "\"" + lib.strings.concatMapSep "\\n" escapeSingleline lines + "\""; - multilineResult = let - escapedLines = builtins.map escapeMultiline lines; - # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" - # indentation level. Otherwise, '' is appended to the last line. - lastLine = lib.lists.last escapedLines; - contents = builtins.concatStringsSep prefix (lib.lists.init escapedLines); - contentsSuffix = - if lastLine == "" - then suffix - else prefix + lastLine; + prettyString = + let + lines = builtins.filter (x: !builtins.isList x) (builtins.split "\n" value); + escapeSingleline = lib.strings.escape.any [ + "\\" + "\"" + "\${" + ]; + escapeMultiline = + builtins.replaceStrings + [ + "\${" + "''" + ] + [ + "''\${" + "'''" + ]; + singlelineResult = "\"" + lib.strings.concatMapSep "\\n" escapeSingleline lines + "\""; + multilineResult = + let + escapedLines = builtins.map escapeMultiline lines; + # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" + # indentation level. Otherwise, '' is appended to the last line. + lastLine = lib.lists.last escapedLines; + contents = builtins.concatStringsSep prefix (lib.lists.init escapedLines); + contentsSuffix = if lastLine == "" then suffix else prefix + lastLine; + in + "''" + prefix + contents + contentsSuffix + "''"; + in + if multiline && builtins.length lines > 1 then multilineResult else singlelineResult; + + prettyList = + let + contents = lib.strings.concatMapSep prefix (process (indent + " ")) value; + in + if builtins.length value == 0 then "[ ]" else "[${prefix}${contents}${suffix}]"; + + prettyFunction = + let + args = lib.fp.args value; + markArgOptional = name: default: if default then name + "?" else name; + argsWithDefaults = lib.attrs.mapToList markArgOptional args; + serializedArgs = builtins.concatStringsSep ", " argsWithDefaults; + in + if args == { } then "" else ""; + + prettyAttrs = + let + contents = builtins.concatStringsSep prefix ( + lib.attrs.mapToList ( + name: value: + "${lib.strings.escape.nix.identifier name} = ${ + builtins.addErrorContext "while evaluating an attribute `${name}`" (process (indent + " ") value) + };" + ) value + ); + in + if allowCustomPrettifiers && value ? __pretty__ && value ? value then + value.__pretty__ value.value + else if value == { } then + "{ }" + else if lib.packages.isDerivation value then + "" + else + "{${prefix}${contents}${suffix}}"; in - "''" - + prefix - + contents - + contentsSuffix - + "''"; - in - if multiline && builtins.length lines > 1 - then multilineResult - else singlelineResult; - - prettyList = let - contents = lib.strings.concatMapSep prefix (process (indent + " ")) value; - in - if builtins.length value == 0 - then "[ ]" - else "[${prefix}${contents}${suffix}]"; - - prettyFunction = let - args = lib.fp.args value; - markArgOptional = name: default: - if default - then name + "?" - else name; - argsWithDefaults = lib.attrs.mapToList markArgOptional args; - serializedArgs = builtins.concatStringsSep ", " argsWithDefaults; - in - if args == {} - then "" - else ""; - - prettyAttrs = let - contents = builtins.concatStringsSep prefix (lib.attrs.mapToList - (name: value: "${lib.strings.escape.nix.identifier name} = ${ - builtins.addErrorContext "while evaluating an attribute `${name}`" - (process (indent + " ") value) - };") - value); - in - if allowCustomPrettifiers && value ? __pretty__ && value ? value - then value.__pretty__ value.value - else if value == {} - then "{ }" - else if lib.packages.isDerivation value - then "" - else "{${prefix}${contents}${suffix}}"; + if null == value then + prettyNull + else if builtins.isInt value || builtins.isFloat value then + prettyNumber + else if builtins.isBool value then + prettyBool + else if builtins.isString value then + prettyString + else if builtins.isPath value then + prettyPath + else if builtins.isList value then + prettyList + else if builtins.isFunction value then + prettyFunction + else if builtins.isAttrs value then + prettyAttrs + else + builtins.abort "lib.generators.pretty: should never happen (value = ${value})"; in - if null == value - then prettyNull - else if builtins.isInt value || builtins.isFloat value - then prettyNumber - else if builtins.isBool value - then prettyBool - else if builtins.isString value - then prettyString - else if builtins.isPath value - then prettyPath - else if builtins.isList value - then prettyList - else if builtins.isFunction value - then prettyFunction - else if builtins.isAttrs value - then prettyAttrs - else builtins.abort "lib.generators.pretty: should never happen (value = ${value})"; - in process indent; }; } diff --git a/lib/src/generators/default.test.nix b/lib/src/generators/default.test.nix index 2ef515e..46ffd04 100644 --- a/lib/src/generators/default.test.nix +++ b/lib/src/generators/default.test.nix @@ -1,113 +1,111 @@ let lib = import ./../default.nix; -in { +in +{ "withRecursion" = { - "evaluates within a given limit" = let - expected = { - x = 1; - }; - actual = lib.generators.withRecursion {limit = 100;} expected; - in + "evaluates within a given limit" = + let + expected = { + x = 1; + }; + actual = lib.generators.withRecursion { limit = 100; } expected; + in expected == actual; - "fails when the limit is reached" = let - expected = { - x = 1; - }; - actual = lib.generators.withRecursion {limit = -1;} expected; - evaluated = builtins.tryEval (builtins.deepSeq actual actual); - in + "fails when the limit is reached" = + let + expected = { + x = 1; + }; + actual = lib.generators.withRecursion { limit = -1; } expected; + evaluated = builtins.tryEval (builtins.deepSeq actual actual); + in !evaluated.success; - "does not fail when throw is disabled" = let - expected = { - x = ""; - }; - actual = - lib.generators.withRecursion { + "does not fail when throw is disabled" = + let + expected = { + x = ""; + }; + actual = lib.generators.withRecursion { limit = -1; throw = false; - } - {x = 1;}; - evaluated = builtins.tryEval (builtins.deepSeq actual actual); - in - evaluated.success - && evaluated.value == expected; + } { x = 1; }; + evaluated = builtins.tryEval (builtins.deepSeq actual actual); + in + evaluated.success && evaluated.value == expected; }; "pretty" = { - "formats with defaults" = let - expected = '' - { + "formats with defaults" = + let + expected = '' + { + attrs = { }; + bool = true; + float = 0.0; + function = ; + int = 0; + list = [ ]; + string = "string"; + }''; + actual = lib.generators.pretty { } { attrs = { }; bool = true; float = 0.0; - function = ; - int = 0; - list = [ ]; - string = "string"; - }''; - actual = lib.generators.pretty {} { - attrs = {}; - bool = true; - float = 0.0; - function = x: x; - int = 0; - list = []; - string = "string"; - # NOTE: We are not testing `path` types because they can return out of store - # values which are not deterministic. - # path = ./.; - }; - in - actual == expected; - - "formats with custom prettifiers" = let - expected = '' - { - attrs = { }; - bool = true; - custom = ; - float = 0.0; - function = ; - int = 0; - list = [ ]; - string = "string"; - }''; - actual = - lib.generators.pretty { - allowCustomPrettifiers = true; - } { - attrs = {}; - bool = true; - float = 0.0; function = x: x; int = 0; - list = []; + list = [ ]; + string = "string"; + # NOTE: We are not testing `path` types because they can return out of store + # values which are not deterministic. + # path = ./.; + }; + in + actual == expected; + + "formats with custom prettifiers" = + let + expected = '' + { + attrs = { }; + bool = true; + custom = ; + float = 0.0; + function = ; + int = 0; + list = [ ]; + string = "string"; + }''; + actual = lib.generators.pretty { allowCustomPrettifiers = true; } { + attrs = { }; + bool = true; + float = 0.0; + function = x: x; + int = 0; + list = [ ]; string = "string"; custom = { value = 0; __pretty__ = value: ""; }; }; - in + in actual == expected; - "formats with multiline disabled" = let - expected = "{ attrs = { }; bool = true; float = 0.0; function = ; int = 0; list = [ ]; string = \"string\"; }"; - actual = - lib.generators.pretty { - multiline = false; - } { - attrs = {}; + "formats with multiline disabled" = + let + expected = "{ attrs = { }; bool = true; float = 0.0; function = ; int = 0; list = [ ]; string = \"string\"; }"; + actual = lib.generators.pretty { multiline = false; } { + attrs = { }; bool = true; float = 0.0; function = x: x; int = 0; - list = []; + list = [ ]; string = "string"; }; - in + in actual == expected; }; } diff --git a/lib/src/importers/default.test.nix b/lib/src/importers/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/importers/default.test.nix +++ b/lib/src/importers/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/licenses/all.nix b/lib/src/licenses/all.nix index 7fec5b0..98740f0 100644 --- a/lib/src/licenses/all.nix +++ b/lib/src/licenses/all.nix @@ -7,9 +7,7 @@ acsl14 = { fullName = "Anti-Capitalist Software License v1.4"; url = "https://anticapitalist.software/"; - /* - restrictions on corporations apply for both use and redistribution - */ + # restrictions on corporations apply for both use and redistribution free = false; redistributable = false; }; diff --git a/lib/src/licenses/default.nix b/lib/src/licenses/default.nix index 6dd937e..9821a71 100644 --- a/lib/src/licenses/default.nix +++ b/lib/src/licenses/default.nix @@ -1,33 +1,29 @@ lib: { - licenses = let - raw = import ./all.nix; + licenses = + let + raw = import ./all.nix; - defaults = name: { - inherit name; - free = true; - }; + defaults = name: { + inherit name; + free = true; + }; - withDefaults = name: license: (defaults name) // license; - withSpdx = license: - if license ? spdx - then - license - // { - url = "https://spdx.org/licenses/${license.spdx}.html"; - } - else license; - withRedistributable = license: - { - redistributable = license.free; - } - // license; + withDefaults = name: license: (defaults name) // license; + withSpdx = + license: + if license ? spdx then + license // { url = "https://spdx.org/licenses/${license.spdx}.html"; } + else + license; + withRedistributable = license: { redistributable = license.free; } // license; - normalize = name: - lib.fp.pipe [ - (withDefaults name) - withSpdx - withRedistributable - ]; - in + normalize = + name: + lib.fp.pipe [ + (withDefaults name) + withSpdx + withRedistributable + ]; + in builtins.mapAttrs normalize raw; } diff --git a/lib/src/lists/default.nix b/lib/src/lists/default.nix index f9d89b7..e449a65 100644 --- a/lib/src/lists/default.nix +++ b/lib/src/lists/default.nix @@ -6,50 +6,52 @@ lib: { ## will be wrapped in a list. ## ## @type a | (List a) -> List a - any = value: - if builtins.isList value - then value - else [value]; + any = value: if builtins.isList value then value else [ value ]; }; sort = { ## Perform a natural sort on a list of strings. ## ## @type List String -> List String - natural = list: let - vectorize = string: let - serialize = part: - if builtins.isList part - then lib.strings.into.int (builtins.head part) - else part; - parts = lib.strings.split "(0|[1-9][0-9]*)" string; + natural = + list: + let + vectorize = + string: + let + serialize = part: if builtins.isList part then lib.strings.into.int (builtins.head part) else part; + parts = lib.strings.split "(0|[1-9][0-9]*)" string; + in + builtins.map serialize parts; + prepared = builtins.map (value: [ + (vectorize value) + value + ]) list; + isLess = a: b: (lib.lists.compare lib.numbers.compare (builtins.head a) (builtins.head b)) < 0; in - builtins.map serialize parts; - prepared = builtins.map (value: [(vectorize value) value]) list; - isLess = a: b: (lib.lists.compare lib.numbers.compare (builtins.head a) (builtins.head b)) < 0; - in builtins.map (x: builtins.elemAt x 1) (builtins.sort isLess prepared); ## Perform a topographic sort on a list of items. The predicate function determines whether ## its first argument comes before the second argument. ## ## @type (a -> a -> Bool) -> List a -> List a - topographic = predicate: list: let - searched = lib.lists.search.depthFirst true predicate list; - results = lib.lists.sort.topographic predicate (searched.visited ++ searched.rest); - in - if builtins.length list < 2 - then {result = list;} - else if searched ? cycle - then { - loops = searched.loops; - cycle = lib.lists.reverse ([searched.cycle] ++ searched.visited); - } - else if results ? cycle - then results - else { - result = [searched.minimal] ++ results.result; - }; + topographic = + predicate: list: + let + searched = lib.lists.search.depthFirst true predicate list; + results = lib.lists.sort.topographic predicate (searched.visited ++ searched.rest); + in + if builtins.length list < 2 then + { result = list; } + else if searched ? cycle then + { + loops = searched.loops; + cycle = lib.lists.reverse ([ searched.cycle ] ++ searched.visited); + } + else if results ? cycle then + results + else + { result = [ searched.minimal ] ++ results.result; }; }; search = { @@ -57,89 +59,89 @@ lib: { ## its first argument comes before the second argument. ## ## @type Bool -> (a -> a -> Bool) -> List a - depthFirst = isAcyclical: predicate: list: let - process = current: visited: rest: let - loops = builtins.filter (value: predicate value current) visited; - partitioned = builtins.partition (value: predicate value current) rest; + depthFirst = + isAcyclical: predicate: list: + let + process = + current: visited: rest: + let + loops = builtins.filter (value: predicate value current) visited; + partitioned = builtins.partition (value: predicate value current) rest; + in + if isAcyclical && (builtins.length loops > 0) then + { + cycle = current; + inherit loops visited rest; + } + else if builtins.length partitioned.right == 0 then + { + minimal = current; + inherit visited rest; + } + else + process (builtins.head partitioned.right) ([ current ] ++ visited) ( + builtins.tail partitioned.right ++ partitioned.wrong + ); in - if isAcyclical && (builtins.length loops > 0) - then { - cycle = current; - inherit loops visited rest; - } - else if builtins.length partitioned.right == 0 - then { - minimal = current; - inherit visited rest; - } - else - process - (builtins.head partitioned.right) - ([current] ++ visited) - (builtins.tail partitioned.right ++ partitioned.wrong); - in - process (builtins.head list) [] (builtins.tail list); + process (builtins.head list) [ ] (builtins.tail list); }; ## Map a list using both the index and value of each item. The ## index starts at 0. ## ## @type (Int -> a -> b) -> List a -> List b - mapWithIndex = f: list: - builtins.genList - (i: f i (builtins.elemAt list i)) - (builtins.length list); + mapWithIndex = f: list: builtins.genList (i: f i (builtins.elemAt list i)) (builtins.length list); ## Map a list using both the index and value of each item. The ## index starts at 1. ## ## @type (Int -> a -> b) -> List a -> List b - mapWithIndex1 = f: list: - builtins.genList - (i: f (i + 1) (builtins.elemAt list i)) - (builtins.length list); + mapWithIndex1 = + f: list: builtins.genList (i: f (i + 1) (builtins.elemAt list i)) (builtins.length list); ## Compare two lists using a custom compare function. The compare ## function is called for each element in the lists that need to ## be compared. ## ## @type (a -> b -> -1 | 0 | 1) -> List a -> List b -> Int - compare = compare: a: b: let - result = compare (builtins.head a) (builtins.head b); - in - if a == [] - then - if b == [] - then 0 - else -1 - else if b == [] - then 1 - else if result == 0 - then lib.lists.compare compare (builtins.tail a) (builtins.tail b) - else result; + compare = + compare: a: b: + let + result = compare (builtins.head a) (builtins.head b); + in + if a == [ ] then + if b == [ ] then 0 else -1 + else if b == [ ] then + 1 + else if result == 0 then + lib.lists.compare compare (builtins.tail a) (builtins.tail b) + else + result; ## Get the last element of a list. ## ## @type List a -> a - last = list: - assert lib.errors.trace (list != []) "List cannot be empty"; - builtins.elemAt list (builtins.length list - 1); + last = + list: + assert lib.errors.trace (list != [ ]) "List cannot be empty"; + builtins.elemAt list (builtins.length list - 1); ## Slice part of a list to create a new list. ## ## @type Int -> Int -> List -> List - slice = start: count: list: let - listLength = builtins.length list; - resultLength = - if start >= listLength - then 0 - else if start + count > listLength - then listLength - start - else count; - in - builtins.genList - (i: builtins.elemAt list (start + i)) - resultLength; + slice = + start: count: list: + let + listLength = builtins.length list; + resultLength = + if start >= listLength then + 0 + else if start + count > listLength then + listLength - start + else + count; + in + builtins.genList (i: builtins.elemAt list (start + i)) resultLength; ## Take the first n elements of a list. ## @@ -149,85 +151,78 @@ lib: { ## Drop the first n elements of a list. ## ## @type Int -> List -> List - drop = count: list: let - listLength = builtins.length list; - in + drop = + count: list: + let + listLength = builtins.length list; + in lib.lists.slice count listLength list; ## Take all but the last element of a list. ## ## @type List -> List - init = list: + init = + list: assert lib.errors.trace (builtins.length list != 0) "lib.lists.init: list must not be empty."; - lib.lists.take (builtins.length list - 1) list; + lib.lists.take (builtins.length list - 1) list; ## Reverse a list. ## ## @type List -> List - reverse = list: let - length = builtins.length list; - create = i: builtins.elemAt list (length - i - 1); - in + reverse = + list: + let + length = builtins.length list; + create = i: builtins.elemAt list (length - i - 1); + in builtins.genList create length; ## Interleave a list with a separator. ## ## @type Separator -> List -> List - intersperse = separator: list: let - length = builtins.length list; - in - if length < 2 - then list + intersperse = + separator: list: + let + length = builtins.length list; + in + if length < 2 then + list else builtins.tail ( - builtins.concatMap - (part: [separator part]) - list + builtins.concatMap (part: [ + separator + part + ]) list ); ## Create a list of integers from a starting number to an ending ## number. This *includes* the ending number as well. ## ## @type Int -> Int -> List - range = start: end: - if start > end - then [] - else builtins.genList (i: start + i) (end - start + 1); + range = start: end: if start > end then [ ] else builtins.genList (i: start + i) (end - start + 1); ## Depending on a given condition, either use the given value (as ## a list) or an empty list. ## ## @type Attrs a b => Bool -> a -> a | b - when = condition: value: - if condition - then - if builtins.isList value - then value - else [value] - else []; + when = + condition: value: if condition then if builtins.isList value then value else [ value ] else [ ]; ## Count the number of items in a list that satisfy a given predicate. ## ## @type (a -> Bool) -> List a -> Int - count = predicate: list: - builtins.foldl' ( - total: value: - if predicate value - then total + 1 - else total - ) - 0 - list; + count = + predicate: list: + builtins.foldl' (total: value: if predicate value then total + 1 else total) 0 list; ## Remove duplicate items from a list. ## ## @type List -> List - unique = list: let - filter = result: value: - if builtins.elem value result - then result - else result ++ [value]; - in - builtins.foldl' filter [] list; + unique = + list: + let + filter = result: value: if builtins.elem value result then result else result ++ [ value ]; + in + builtins.foldl' filter [ ] list; }; } diff --git a/lib/src/lists/default.test.nix b/lib/src/lists/default.test.nix index a4460e4..fa7440f 100644 --- a/lib/src/lists/default.test.nix +++ b/lib/src/lists/default.test.nix @@ -1,174 +1,345 @@ let lib = import ./../default.nix; -in { +in +{ "from" = { "any" = { - "returns a list containing the value" = let - expected = [1]; - actual = lib.lists.from.any 1; - in + "returns a list containing the value" = + let + expected = [ 1 ]; + actual = lib.lists.from.any 1; + in actual == expected; - "returns the value if the value was already a list" = let - expected = [1]; - actual = lib.lists.from.any expected; - in + "returns the value if the value was already a list" = + let + expected = [ 1 ]; + actual = lib.lists.from.any expected; + in actual == expected; }; }; "sort" = { "natural" = { - "sorts a list of strings" = let - expected = ["1" "a" "a0" "a1" "b" "c"]; - actual = lib.lists.sort.natural ["c" "a" "b" "a1" "a0" "1"]; - in + "sorts a list of strings" = + let + expected = [ + "1" + "a" + "a0" + "a1" + "b" + "c" + ]; + actual = lib.lists.sort.natural [ + "c" + "a" + "b" + "a1" + "a0" + "1" + ]; + in actual == expected; }; }; "mapWithIndex" = { - "maps a list using index 0" = let - expected = ["0: a" "1: b" "2: c"]; - actual = lib.lists.mapWithIndex (i: v: "${builtins.toString i}: ${v}") ["a" "b" "c"]; - in + "maps a list using index 0" = + let + expected = [ + "0: a" + "1: b" + "2: c" + ]; + actual = lib.lists.mapWithIndex (i: v: "${builtins.toString i}: ${v}") [ + "a" + "b" + "c" + ]; + in actual == expected; }; "mapWithIndex1" = { - "maps a list using index 1" = let - expected = ["1: a" "2: b" "3: c"]; - actual = lib.lists.mapWithIndex1 (i: v: "${builtins.toString i}: ${v}") ["a" "b" "c"]; - in + "maps a list using index 1" = + let + expected = [ + "1: a" + "2: b" + "3: c" + ]; + actual = lib.lists.mapWithIndex1 (i: v: "${builtins.toString i}: ${v}") [ + "a" + "b" + "c" + ]; + in actual == expected; }; "compare" = { "compares two lists" = { - "returns -1 if the first list is smaller" = let - expected = -1; - actual = lib.lists.compare lib.numbers.compare [1 2 3] [1 2 4]; - in + "returns -1 if the first list is smaller" = + let + expected = -1; + actual = + lib.lists.compare lib.numbers.compare + [ + 1 + 2 + 3 + ] + [ + 1 + 2 + 4 + ]; + in actual == expected; - "returns 1 if the first list is larger" = let - expected = 1; - actual = lib.lists.compare lib.numbers.compare [1 2 4] [1 2 3]; - in + "returns 1 if the first list is larger" = + let + expected = 1; + actual = + lib.lists.compare lib.numbers.compare + [ + 1 + 2 + 4 + ] + [ + 1 + 2 + 3 + ]; + in actual == expected; - "returns 0 if the lists are equal" = let - expected = 0; - actual = lib.lists.compare lib.numbers.compare [1 2 3] [1 2 3]; - in + "returns 0 if the lists are equal" = + let + expected = 0; + actual = + lib.lists.compare lib.numbers.compare + [ + 1 + 2 + 3 + ] + [ + 1 + 2 + 3 + ]; + in actual == expected; }; }; "last" = { - "returns the last element of a list" = let - expected = 3; - actual = lib.lists.last [1 2 3]; - in + "returns the last element of a list" = + let + expected = 3; + actual = lib.lists.last [ + 1 + 2 + 3 + ]; + in actual == expected; - "fails if the list is empty" = let - actual = lib.lists.last []; - evaluated = builtins.tryEval actual; - in + "fails if the list is empty" = + let + actual = lib.lists.last [ ]; + evaluated = builtins.tryEval actual; + in !evaluated.success; }; "slice" = { "slices a list" = { - "slices a list from the start" = let - expected = [1 2]; - actual = lib.lists.slice 0 2 [1 2 3]; - in + "slices a list from the start" = + let + expected = [ + 1 + 2 + ]; + actual = lib.lists.slice 0 2 [ + 1 + 2 + 3 + ]; + in actual == expected; - "slices a list from the end" = let - expected = [2 3]; - actual = lib.lists.slice 1 3 [1 2 3]; - in + "slices a list from the end" = + let + expected = [ + 2 + 3 + ]; + actual = lib.lists.slice 1 3 [ + 1 + 2 + 3 + ]; + in actual == expected; - "slices a list from the middle" = let - expected = [2]; - actual = lib.lists.slice 1 1 [1 2 3]; - in + "slices a list from the middle" = + let + expected = [ 2 ]; + actual = lib.lists.slice 1 1 [ + 1 + 2 + 3 + ]; + in actual == expected; }; }; "take" = { - "takes the first n elements" = let - expected = [1 2]; - actual = lib.lists.take 2 [1 2 3]; - in + "takes the first n elements" = + let + expected = [ + 1 + 2 + ]; + actual = lib.lists.take 2 [ + 1 + 2 + 3 + ]; + in actual == expected; }; "drop" = { - "drops the first n elements" = let - expected = [3]; - actual = lib.lists.drop 2 [1 2 3]; - in + "drops the first n elements" = + let + expected = [ 3 ]; + actual = lib.lists.drop 2 [ + 1 + 2 + 3 + ]; + in actual == expected; }; "reverse" = { - "reverses a list" = let - expected = [3 2 1]; - actual = lib.lists.reverse [1 2 3]; - in + "reverses a list" = + let + expected = [ + 3 + 2 + 1 + ]; + actual = lib.lists.reverse [ + 1 + 2 + 3 + ]; + in actual == expected; }; "intersperse" = { - "intersperses a list with a separator" = let - expected = [1 "-" 2 "-" 3]; - actual = lib.lists.intersperse "-" [1 2 3]; - in + "intersperses a list with a separator" = + let + expected = [ + 1 + "-" + 2 + "-" + 3 + ]; + actual = lib.lists.intersperse "-" [ + 1 + 2 + 3 + ]; + in actual == expected; - "handles lists with less than 2 elements" = let - expected = [1]; - actual = lib.lists.intersperse "-" [1]; - in + "handles lists with less than 2 elements" = + let + expected = [ 1 ]; + actual = lib.lists.intersperse "-" [ 1 ]; + in actual == expected; }; "range" = { - "returns a range of numbers" = let - expected = [1 2 3 4 5]; - actual = lib.lists.range 1 5; - in + "returns a range of numbers" = + let + expected = [ + 1 + 2 + 3 + 4 + 5 + ]; + actual = lib.lists.range 1 5; + in actual == expected; }; "when" = { - "returns the list if the condition is true" = let - expected = [1 2 3]; - actual = lib.lists.when true [1 2 3]; - in + "returns the list if the condition is true" = + let + expected = [ + 1 + 2 + 3 + ]; + actual = lib.lists.when true [ + 1 + 2 + 3 + ]; + in actual == expected; - "returns an empty list if the condition is false" = let - expected = []; - actual = lib.lists.when false [1 2 3]; - in + "returns an empty list if the condition is false" = + let + expected = [ ]; + actual = lib.lists.when false [ + 1 + 2 + 3 + ]; + in actual == expected; }; "count" = { - "counts the number of elements in a list" = let - expected = 2; - actual = lib.lists.count (value: value < 3) [1 2 3]; - in + "counts the number of elements in a list" = + let + expected = 2; + actual = lib.lists.count (value: value < 3) [ + 1 + 2 + 3 + ]; + in actual == expected; }; "unique" = { - "removes duplicate elements" = let - expected = [1 2 3]; - actual = lib.lists.unique [1 2 3 1 2 3]; - in + "removes duplicate elements" = + let + expected = [ + 1 + 2 + 3 + ]; + actual = lib.lists.unique [ + 1 + 2 + 3 + 1 + 2 + 3 + ]; + in actual == expected; }; } diff --git a/lib/src/math/default.nix b/lib/src/math/default.nix index 45331a3..96f38c1 100644 --- a/lib/src/math/default.nix +++ b/lib/src/math/default.nix @@ -3,17 +3,11 @@ lib: { ## Return the smaller of two numbers. ## ## @type Int -> Int -> Int - min = x: y: - if x < y - then x - else y; + min = x: y: if x < y then x else y; ## Return the larger of two numbers. ## ## @type Int -> Int -> Int - max = x: y: - if x > y - then x - else y; + max = x: y: if x > y then x else y; }; } diff --git a/lib/src/math/default.test.nix b/lib/src/math/default.test.nix index c9aa0cd..57b08bc 100644 --- a/lib/src/math/default.test.nix +++ b/lib/src/math/default.test.nix @@ -1,19 +1,22 @@ let lib = import ./../default.nix; -in { +in +{ "min" = { - "returns the smaller number" = let - expected = 1; - actual = lib.math.min 1 2; - in + "returns the smaller number" = + let + expected = 1; + actual = lib.math.min 1 2; + in actual == expected; }; "max" = { - "returns the larger number" = let - expected = 2; - actual = lib.math.max 1 2; - in + "returns the larger number" = + let + expected = 2; + actual = lib.math.max 1 2; + in actual == expected; }; } diff --git a/lib/src/modules/default.nix b/lib/src/modules/default.nix index eb7573f..63105ef 100644 --- a/lib/src/modules/default.nix +++ b/lib/src/modules/default.nix @@ -27,88 +27,86 @@ lib: { ## system. ## ## @type Definition -> List (Definition | (List Definition)) - properties = definition: - if lib.types.is "merge" definition - then builtins.concatMap lib.modules.apply.properties definition.content - else if lib.types.is "when" definition - then - if !(builtins.isBool definition.condition) - then builtins.throw "lib.modules.when called with a non-boolean condition" - else if definition.condition - then lib.modules.apply.properties definition.content - else [] - else [definition]; + properties = + definition: + if lib.types.is "merge" definition then + builtins.concatMap lib.modules.apply.properties definition.content + else if lib.types.is "when" definition then + if !(builtins.isBool definition.condition) then + builtins.throw "lib.modules.when called with a non-boolean condition" + else if definition.condition then + lib.modules.apply.properties definition.content + else + [ ] + else + [ definition ]; ## Apply overrides for a definition. This uses the priority system ## to determine which definition to use. The most important (lowest ## priority) choice will be used. ## ## @type List Definition -> { highestPriority :: Int, values :: List (Definition | (List Definition)) } - overrides = definitions: let - getPriority = definition: - if lib.types.is "override" definition.value - then definition.value.priority - else lib.modules.DEFAULT_PRIORITY; - normalize = definition: - if lib.types.is "override" definition.value - then - definition - // { - value = definition.value.content; - } - else definition; - highestPriority = - builtins.foldl' - (priority: definition: lib.math.min priority (getPriority definition)) - 9999 - definitions; - in { - inherit highestPriority; - values = - builtins.concatMap - ( + overrides = + definitions: + let + getPriority = definition: - if getPriority definition == highestPriority - then [(normalize definition)] - else [] - ) - definitions; - }; + if lib.types.is "override" definition.value then + definition.value.priority + else + lib.modules.DEFAULT_PRIORITY; + normalize = + definition: + if lib.types.is "override" definition.value then + definition // { value = definition.value.content; } + else + definition; + highestPriority = builtins.foldl' ( + priority: definition: lib.math.min priority (getPriority definition) + ) 9999 definitions; + in + { + inherit highestPriority; + values = builtins.concatMap ( + definition: if getPriority definition == highestPriority then [ (normalize definition) ] else [ ] + ) definitions; + }; ## Apply ordering for prioritized definitions. ## ## @type List Definition -> List Definition - order = definitions: let - normalize = definition: - if lib.types.is "order" definition - then - definition - // { - value = definition.value.content; - priority = definition.value.priority; - } - else definition; - normalized = builtins.map normalize definitions; - compare = a: b: (a.priority or lib.modules.DEFAULT_PRIORITY) < (b.priority or lib.modules.DEFAULT_PRIORITY); - in + order = + definitions: + let + normalize = + definition: + if lib.types.is "order" definition then + definition + // { + value = definition.value.content; + priority = definition.value.priority; + } + else + definition; + normalized = builtins.map normalize definitions; + compare = + a: b: (a.priority or lib.modules.DEFAULT_PRIORITY) < (b.priority or lib.modules.DEFAULT_PRIORITY); + in builtins.sort compare normalized; ## Normalize the type of an option. This will set a default type if none ## was provided. ## ## @type List String -> Option -> Option - fixup = location: option: - if option.type.getSubModules or null == null - then - option - // { - type = option.type or lib.types.unspecified; - } + fixup = + location: option: + if option.type.getSubModules or null == null then + option // { type = option.type or lib.types.unspecified; } else option // { type = option.type.withSubModules option.options; - options = []; + options = [ ]; }; ## Invert the structure of `merge`, `when`, and `override` definitions so @@ -118,30 +116,32 @@ lib: { ## throw a type error. ## ## @type Definition -> List Definition - invert = config: - if lib.types.is "merge" config - then builtins.concatMap lib.modules.apply.invert config.content - else if lib.types.is "when" config - then - builtins.map - (builtins.mapAttrs (name: value: lib.modules.when config.condition value)) - (lib.modules.apply.invert config.content) - else if lib.types.is "override" config - then - builtins.map - (builtins.mapAttrs (name: value: lib.modules.override config.priority value)) - (lib.modules.apply.invert config.content) - else [config]; + invert = + config: + if lib.types.is "merge" config then + builtins.concatMap lib.modules.apply.invert config.content + else if lib.types.is "when" config then + builtins.map (builtins.mapAttrs (name: value: lib.modules.when config.condition value)) ( + lib.modules.apply.invert config.content + ) + else if lib.types.is "override" config then + builtins.map (builtins.mapAttrs (name: value: lib.modules.override config.priority value)) ( + lib.modules.apply.invert config.content + ) + else + [ config ]; }; validate = { ## Check that a module only specifies supported attributes. ## ## @type Attrs -> Bool - keys = module: let - invalid = builtins.removeAttrs module lib.modules.VALID_KEYS; - in - invalid == {}; + keys = + module: + let + invalid = builtins.removeAttrs module lib.modules.VALID_KEYS; + in + invalid == { }; }; ## Modules only support certain keys at the root level. This list determines @@ -163,58 +163,67 @@ lib: { ## lost in the conversion. ## ## @type String -> String -> Attrs -> Module - normalize = file: key: module: let - invalid = builtins.removeAttrs module lib.modules.VALID_KEYS; - invalidKeys = builtins.concatStringsSep ", " (builtins.attrNames invalid); - in - if lib.modules.validate.keys module - then { - __file__ = builtins.toString module.__file__ or file; - __key__ = builtins.toString module.__key__ or key; - includes = module.includes or []; - excludes = module.excludes or []; - options = module.options or {}; - config = let - base = module.config or {}; - withMeta = config: - if module ? meta - then lib.modules.merge [config {meta = module.meta;}] - else config; - withFreeform = config: - if module ? freeform - then lib.modules.merge [config {__module__.freeform = module.freeform;}] - else config; - in - withFreeform (withMeta base); - } - else builtins.throw "Module `${key}` (${file}) has unsupported attribute(s): ${invalidKeys}"; + normalize = + file: key: module: + let + invalid = builtins.removeAttrs module lib.modules.VALID_KEYS; + invalidKeys = builtins.concatStringsSep ", " (builtins.attrNames invalid); + in + if lib.modules.validate.keys module then + { + __file__ = builtins.toString module.__file__ or file; + __key__ = builtins.toString module.__key__ or key; + includes = module.includes or [ ]; + excludes = module.excludes or [ ]; + options = module.options or { }; + config = + let + base = module.config or { }; + withMeta = + config: + if module ? meta then + lib.modules.merge [ + config + { meta = module.meta; } + ] + else + config; + withFreeform = + config: + if module ? freeform then + lib.modules.merge [ + config + { __module__.freeform = module.freeform; } + ] + else + config; + in + withFreeform (withMeta base); + } + else + builtins.throw "Module `${key}` (${file}) has unsupported attribute(s): ${invalidKeys}"; ## Convert a module that is either a function or an attribute set into ## a resolved attribute set. If the module was a function then it will ## be evaluated and the result will be returned. ## ## @type String -> Attrs | (Attrs -> Attrs) -> Attrs -> Attrs - resolve = key: module: args: let - dynamicArgs = - builtins.mapAttrs - ( + resolve = + key: module: args: + let + dynamicArgs = builtins.mapAttrs ( name: value: - builtins.addErrorContext - "while evaluating the module argument `${name}` in `${key}`" - ( - # The base case here is the set of static arguments supplied in the - # call to `lib.modules.run`. - args.${name} + builtins.addErrorContext "while evaluating the module argument `${name}` in `${key}`" ( + # The base case here is the set of static arguments supplied in the + # call to `lib.modules.run`. + args.${name} # Then, any other arguments must be created dynamically from within # the modules being evaluated. or args.config.__module__.args.dynamic.${name} - ) - ) - (lib.fp.args module); - in - if builtins.isFunction module - then lib.fp.withDynamicArgs module (args // dynamicArgs) - else module; + ) + ) (lib.fp.args module); + in + if builtins.isFunction module then lib.fp.withDynamicArgs module (args // dynamicArgs) else module; ## The default priority to set for values that do not have one provided. ## @@ -325,392 +334,369 @@ lib: { ## Create alias definitions for a given option. ## ## @type (Attrs -> Attrs) -> Option -> Attrs - aliasWith = f: option: let - exists = lib.types.is "option" option && option.isDefined; - value = f (lib.modules.merge option.definitions); - in + aliasWith = + f: option: + let + exists = lib.types.is "option" option && option.isDefined; + value = f (lib.modules.merge option.definitions); + in lib.modules.when exists value; ## Combine multiple modules together. ## ## @type List String -> List Module -> { matched :: Attrs, unmatched :: List Definition } - combine = prefix: modules: let - getConfig = module: - builtins.map - (config: { - __file__ = module.__file__; - inherit config; - }) - (lib.modules.apply.invert module.config); + combine = + prefix: modules: + let + getConfig = + module: + builtins.map (config: { + __file__ = module.__file__; + inherit config; + }) (lib.modules.apply.invert module.config); - configs = - builtins.concatMap - getConfig - modules; + configs = builtins.concatMap getConfig modules; - process = prefix: options: configs: let - byName = attr: f: modules: - builtins.zipAttrsWith - (key: value: builtins.concatLists value) - (builtins.map ( - module: let - subtree = module.${attr}; - in - if builtins.isAttrs subtree - then builtins.mapAttrs (name: f module) subtree - else builtins.throw "Value for `${builtins.concatStringsSep "." prefix}` is of type `${builtins.typeOf subtree}` but an attribute set was expected." - ) - modules); + process = + prefix: options: configs: + let + byName = + attr: f: modules: + builtins.zipAttrsWith (key: value: builtins.concatLists value) ( + builtins.map ( + module: + let + subtree = module.${attr}; + in + if builtins.isAttrs subtree then + builtins.mapAttrs (name: f module) subtree + else + builtins.throw "Value for `${builtins.concatStringsSep "." prefix}` is of type `${builtins.typeOf subtree}` but an attribute set was expected." + ) modules + ); - declarationsByName = - byName - "options" - (module: option: [ - { - __file__ = module.__file__; - options = option; - } - ]) - options; + declarationsByName = byName "options" (module: option: [ + { + __file__ = module.__file__; + options = option; + } + ]) options; - definitionsByName = - byName - "config" - ( - module: value: - builtins.map - (config: { + definitionsByName = byName "config" ( + module: value: + builtins.map (config: { __file__ = module.__file__; inherit config; - }) - (lib.modules.apply.invert value) - ) - configs; + }) (lib.modules.apply.invert value) + ) configs; - definitionsByName' = - byName - "config" - (module: value: [ - { - __file__ = module.__file__; - inherit value; - } - ]) - configs; - - getOptionFromDeclaration = declaration: - if lib.types.is "option" declaration.options - then declaration - else - declaration - // { - options = lib.options.create { - type = lib.types.submodule [{options = declaration.options;}]; - }; - }; - - resultsByName = - builtins.mapAttrs - ( - name: declarations: let - location = prefix ++ [name]; - definitions = definitionsByName.${name} or []; - definitions' = definitionsByName'.${name} or []; - optionDeclarations = - builtins.filter - (declaration: lib.types.is "option" declaration.options) - declarations; - in - if builtins.length optionDeclarations == builtins.length declarations - then let - option = - lib.modules.apply.fixup - location - (lib.options.merge.declarations location declarations); - in { - matched = lib.options.run location option definitions'; - unmatched = []; + definitionsByName' = byName "config" (module: value: [ + { + __file__ = module.__file__; + inherit value; } - else if optionDeclarations != [] - then - if builtins.all (declaration: declaration.options.type.name == "Submodule") optionDeclarations - then let - option = - lib.modules.apply.fixup location - (lib.options.merge.declarations location (builtins.map getOptionFromDeclaration declarations)); - in { + ]) configs; + + getOptionFromDeclaration = + declaration: + if lib.types.is "option" declaration.options then + declaration + else + declaration + // { + options = lib.options.create { type = lib.types.submodule [ { options = declaration.options; } ]; }; + }; + + resultsByName = builtins.mapAttrs ( + name: declarations: + let + location = prefix ++ [ name ]; + definitions = definitionsByName.${name} or [ ]; + definitions' = definitionsByName'.${name} or [ ]; + optionDeclarations = builtins.filter ( + declaration: lib.types.is "option" declaration.options + ) declarations; + in + if builtins.length optionDeclarations == builtins.length declarations then + let + option = lib.modules.apply.fixup location (lib.options.merge.declarations location declarations); + in + { matched = lib.options.run location option definitions'; - unmatched = []; + unmatched = [ ]; } - else builtins.throw "The option `${lib.options.getIdentifier location}` in module `${(builtins.head optionDeclarations).__file__}` would be a parent of the following options, but its type `${(builtins.head optionDeclarations).options.type.description or ""}` does not support nested options." - else process location declarations definitions - ) - declarationsByName; + else if optionDeclarations != [ ] then + if builtins.all (declaration: declaration.options.type.name == "Submodule") optionDeclarations then + let + option = lib.modules.apply.fixup location ( + lib.options.merge.declarations location (builtins.map getOptionFromDeclaration declarations) + ); + in + { + matched = lib.options.run location option definitions'; + unmatched = [ ]; + } + else + builtins.throw "The option `${lib.options.getIdentifier location}` in module `${(builtins.head optionDeclarations).__file__}` would be a parent of the following options, but its type `${ + (builtins.head optionDeclarations).options.type.description or "" + }` does not support nested options." + else + process location declarations definitions + ) declarationsByName; - matched = builtins.mapAttrs (key: value: value.matched) resultsByName; + matched = builtins.mapAttrs (key: value: value.matched) resultsByName; - unmatched = - builtins.mapAttrs (name: value: value.unmatched) resultsByName - // builtins.removeAttrs definitionsByName' (builtins.attrNames matched); - in { - inherit matched; + unmatched = + builtins.mapAttrs (name: value: value.unmatched) resultsByName + // builtins.removeAttrs definitionsByName' (builtins.attrNames matched); + in + { + inherit matched; - unmatched = - if configs == [] - then [] - else - builtins.concatLists ( - lib.attrs.mapToList - ( - name: definitions: - builtins.map (definition: - definition - // { - prefix = [name] ++ (definition.prefix or []); - }) - definitions - ) - unmatched - ); - }; - in + unmatched = + if configs == [ ] then + [ ] + else + builtins.concatLists ( + lib.attrs.mapToList ( + name: definitions: + builtins.map ( + definition: definition // { prefix = [ name ] ++ (definition.prefix or [ ]); } + ) definitions + ) unmatched + ); + }; + in process prefix modules configs; ## Run a set of modules. Custom arguments can also be supplied which will ## be provided to all modules statically as they are not modifiable. ## ## @type { modules? :: List (Attrs | (Attrs -> Attrs)), args? :: Attrs, prefix? :: List String } -> { type :: Module, extend :: lib.modules.run, options :: Attrs, config :: Attrs, __module__ :: Attrs } - run = settings @ { - modules ? [], - args ? {}, - prefix ? [], - }: let - type = lib.types.submodules.of { - inherit modules args; - }; - - extend = extensions @ { - modules ? [], - args ? {}, - prefix ? [], + run = + settings@{ + modules ? [ ], + args ? { }, + prefix ? [ ], }: - lib.modules.run { - modules = (settings.modules or []) ++ (extensions.modules or []); - args = (settings.args or {}) // (extensions.args or {}); - prefix = extensions.prefix or settings.prefix or []; - }; + let + type = lib.types.submodules.of { inherit modules args; }; - collect = let - load = args: file: key: module: let - moduleFromValue = lib.modules.normalize file key (lib.modules.resolve key module args); - moduleFromPath = - lib.modules.normalize - (builtins.toString module) - (builtins.toString module) - (lib.modules.resolve (builtins.toString module) (import module) args); - in - if builtins.isAttrs module || builtins.isFunction module - then moduleFromValue - else if builtins.isString module || builtins.isPath module - then moduleFromPath - else builtins.throw "The provided module must be either an attribute set, function, or path but got ${builtins.typeOf module}"; + extend = + extensions@{ + modules ? [ ], + args ? { }, + prefix ? [ ], + }: + lib.modules.run { + modules = (settings.modules or [ ]) ++ (extensions.modules or [ ]); + args = (settings.args or { }) // (extensions.args or { }); + prefix = extensions.prefix or settings.prefix or [ ]; + }; - normalize = parentFile: parentKey: modules: args: let - normalized = - lib.lists.mapWithIndex1 - ( - i: value: let - module = load args parentFile "${parentKey}:unknown-${builtins.toString i}" value; - tree = normalize module.__file__ module.__key__ module.includes args; - in { - inherit module; - key = module.__key__; - modules = tree.modules; - excludes = module.excludes ++ tree.excludes; - } - ) - modules; - in { - modules = normalized; - excludes = builtins.concatLists (builtins.catAttrs "excludes" normalized); - }; + collect = + let + load = + args: file: key: module: + let + moduleFromValue = lib.modules.normalize file key (lib.modules.resolve key module args); + moduleFromPath = lib.modules.normalize (builtins.toString module) (builtins.toString module) ( + lib.modules.resolve (builtins.toString module) (import module) args + ); + in + if builtins.isAttrs module || builtins.isFunction module then + moduleFromValue + else if builtins.isString module || builtins.isPath module then + moduleFromPath + else + builtins.throw "The provided module must be either an attribute set, function, or path but got ${builtins.typeOf module}"; - withExclusions = path: { - modules, - excludes, - }: let - getKey = module: - if builtins.isString module && (builtins.substring 0 1 module != "/") - then (builtins.toString path) + "/" + module - else builtins.toString module; - excludedKeys = builtins.map getKey excludes; - removeExcludes = - builtins.filter - (value: !(builtins.elem value.key excludedKeys)); - in - builtins.map - (value: value.module) - (builtins.genericClosure { - startSet = removeExcludes modules; - operator = value: removeExcludes value.modules; - }); - - process = path: modules: args: - withExclusions path (normalize "" "" modules args); - in - process; - - internal = { - __file__ = "virtual:aux/internal"; - __key__ = "virtual:aux/internal"; - - options = { - __module__ = { - args = { - static = lib.options.create { - type = lib.types.attrs.lazy lib.types.raw; - writable = false; - internal = false; - description = "Static arguments provided to lib.modules.run which cannot be changed."; + normalize = + parentFile: parentKey: modules: args: + let + normalized = lib.lists.mapWithIndex1 ( + i: value: + let + module = load args parentFile "${parentKey}:unknown-${builtins.toString i}" value; + tree = normalize module.__file__ module.__key__ module.includes args; + in + { + inherit module; + key = module.__key__; + modules = tree.modules; + excludes = module.excludes ++ tree.excludes; + } + ) modules; + in + { + modules = normalized; + excludes = builtins.concatLists (builtins.catAttrs "excludes" normalized); }; - dynamic = lib.options.create { - type = lib.types.attrs.lazy lib.types.raw; + withExclusions = + path: + { modules, excludes }: + let + getKey = + module: + if builtins.isString module && (builtins.substring 0 1 module != "/") then + (builtins.toString path) + "/" + module + else + builtins.toString module; + excludedKeys = builtins.map getKey excludes; + removeExcludes = builtins.filter (value: !(builtins.elem value.key excludedKeys)); + in + builtins.map (value: value.module) ( + builtins.genericClosure { + startSet = removeExcludes modules; + operator = value: removeExcludes value.modules; + } + ); - ${ - if prefix == [] - then null - else "internal" - } = - true; + process = + path: modules: args: + withExclusions path (normalize "" "" modules args); + in + process; - visible = false; + internal = { + __file__ = "virtual:aux/internal"; + __key__ = "virtual:aux/internal"; - description = "Additional arguments pased to each module."; + options = { + __module__ = { + args = { + static = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + writable = false; + internal = false; + description = "Static arguments provided to lib.modules.run which cannot be changed."; + }; + + dynamic = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + + ${if prefix == [ ] then null else "internal"} = true; + + visible = false; + + description = "Additional arguments pased to each module."; + }; }; - }; - check = lib.options.create { - type = lib.types.bool; - default.value = true; - internal = true; - description = "Whether to perform checks on option definitions."; - }; + check = lib.options.create { + type = lib.types.bool; + default.value = true; + internal = true; + description = "Whether to perform checks on option definitions."; + }; - freeform = lib.options.create { - type = lib.types.nullish lib.types.type; - default.value = null; - internal = true; - description = "If set, all options that don't have a declared type will be merged using this type."; + freeform = lib.options.create { + type = lib.types.nullish lib.types.type; + default.value = null; + internal = true; + description = "If set, all options that don't have a declared type will be merged using this type."; + }; }; }; - }; - config = { - __module__ = { - args = { - static = args; + config = { + __module__ = { + args = { + static = args; - dynamic = { - meta = { - inherit extend type; + dynamic = { + meta = { + inherit extend type; + }; }; }; }; }; }; - }; - merged = let - collected = - collect - (args.path or "") - ([internal] ++ modules) - ( - { - inherit options config; + merged = + let + collected = collect (args.path or "") ([ internal ] ++ modules) ( + { + inherit options config; - # The library does not include `extend` out of the box to avoid infinite recursion - # in most cases. Instead, we supply an estensible version here for modules to consume. - # This is only something that affects internal use of `lib`, the properly exported - # `lib` is augmented with an `extend` method. - lib = lib.points.withExtend (lib.fp.const lib); - } - // args - ); - in - lib.modules.combine - prefix (lib.lists.reverse collected); - - options = merged.matched; - - config = let - declared = - lib.attrs.mapRecursiveWhen - (value: !(lib.types.is "option" value)) - (name: value: value.value) - options; - - freeform = let - definitions = - builtins.map - (definition: { - __file__ = definition.__file__; - value = lib.attrs.set definition.prefix definition.value; - }) - merged.unmatched; - in - if definitions == [] - then {} - else declared.__module__.freeform.merge prefix definitions; - in - if declared.__module__.freeform == null - then declared - else - lib.attrs.mergeRecursive - freeform - declared; - - checked = - if config.__module__.check && config.__module__.freeform == null && merged.unmatched != [] - then let - first = builtins.head merged.unmatched; - - identifier = lib.options.getIdentifier (prefix ++ first.prefix); - definitions = - builtins.addErrorContext "while evaluating the error message for definitions of non-existent option `${identifier}`" - ( - builtins.addErrorContext "while evaluating a definition from `${first.__file__}`" - (lib.options.getDefinitions [first]) + # The library does not include `extend` out of the box to avoid infinite recursion + # in most cases. Instead, we supply an estensible version here for modules to consume. + # This is only something that affects internal use of `lib`, the properly exported + # `lib` is augmented with an `extend` method. + lib = lib.points.withExtend (lib.fp.const lib); + } + // args ); + in + lib.modules.combine prefix (lib.lists.reverse collected); - message = "The option `${identifier}` does not exist. Definitions:${definitions}"; - in - if builtins.attrNames options == ["__module__"] - then - if lib.options.getIdentifier prefix == "" - then - builtins.throw '' - ${message} + options = merged.matched; - You are trying to declare options in `config` rather than `options`. - '' + config = + let + declared = lib.attrs.mapRecursiveWhen (value: !(lib.types.is "option" value)) ( + name: value: value.value + ) options; + + freeform = + let + definitions = builtins.map (definition: { + __file__ = definition.__file__; + value = lib.attrs.set definition.prefix definition.value; + }) merged.unmatched; + in + if definitions == [ ] then { } else declared.__module__.freeform.merge prefix definitions; + in + if declared.__module__.freeform == null then + declared + else + lib.attrs.mergeRecursive freeform declared; + + checked = + if config.__module__.check && config.__module__.freeform == null && merged.unmatched != [ ] then + let + first = builtins.head merged.unmatched; + + identifier = lib.options.getIdentifier (prefix ++ first.prefix); + definitions = + builtins.addErrorContext + "while evaluating the error message for definitions of non-existent option `${identifier}`" + ( + builtins.addErrorContext "while evaluating a definition from `${first.__file__}`" ( + lib.options.getDefinitions [ first ] + ) + ); + + message = "The option `${identifier}` does not exist. Definitions:${definitions}"; + in + if builtins.attrNames options == [ "__module__" ] then + if lib.options.getIdentifier prefix == "" then + builtins.throw '' + ${message} + + You are trying to declare options in `config` rather than `options`. + '' + else + builtins.throw '' + ${message} + + There are no options defined in `${lib.options.getIdentifier prefix}`. + Are you sure you declared your options correctly? + '' else - builtins.throw '' - ${message} + builtins.throw message + else + null; - There are no options defined in `${lib.options.getIdentifier prefix}`. - Are you sure you declared your options correctly? - '' - else builtins.throw message - else null; - - withCheck = builtins.seq checked; - in { - inherit type extend; - options = withCheck options; - config = withCheck (builtins.removeAttrs config ["__module__"]); - __module__ = withCheck config.__module__; - }; + withCheck = builtins.seq checked; + in + { + inherit type extend; + options = withCheck options; + config = withCheck (builtins.removeAttrs config [ "__module__" ]); + __module__ = withCheck config.__module__; + }; }; } diff --git a/lib/src/modules/default.test.nix b/lib/src/modules/default.test.nix index 9e30e79..ff98eb5 100644 --- a/lib/src/modules/default.test.nix +++ b/lib/src/modules/default.test.nix @@ -1,715 +1,703 @@ let lib = import ./../default.nix; -in { +in +{ "apply" = { "properties" = { - "handles normal values" = let - expected = [{}]; - actual = lib.modules.apply.properties {}; - in + "handles normal values" = + let + expected = [ { } ]; + actual = lib.modules.apply.properties { }; + in actual == expected; - "handles merge" = let - expected = [{x = 1;} {x = 2;}]; - actual = lib.modules.apply.properties (lib.modules.merge [{x = 1;} {x = 2;}]); - in - actual - == expected; + "handles merge" = + let + expected = [ + { x = 1; } + { x = 2; } + ]; + actual = lib.modules.apply.properties ( + lib.modules.merge [ + { x = 1; } + { x = 2; } + ] + ); + in + actual == expected; - "handles when" = let - expected = [[{x = 1;}]]; - actual = lib.modules.apply.properties (lib.modules.when true [{x = 1;}]); - in + "handles when" = + let + expected = [ [ { x = 1; } ] ]; + actual = lib.modules.apply.properties (lib.modules.when true [ { x = 1; } ]); + in actual == expected; }; "overrides" = { - "handles normal values" = let - expected = { - highestPriority = 100; - values = [ - { - value = 1; - } - ]; - }; - actual = lib.modules.apply.overrides [ - { - value = 1; - } - ]; - in + "handles normal values" = + let + expected = { + highestPriority = 100; + values = [ { value = 1; } ]; + }; + actual = lib.modules.apply.overrides [ { value = 1; } ]; + in actual == expected; - "handles overrides" = let - expected = { - highestPriority = 100; - values = [ - {value = "world";} + "handles overrides" = + let + expected = { + highestPriority = 100; + values = [ { value = "world"; } ]; + }; + actual = lib.modules.apply.overrides [ + { value = "world"; } + { value = lib.modules.override 101 "hello"; } ]; - }; - actual = lib.modules.apply.overrides [ - {value = "world";} - {value = lib.modules.override 101 "hello";} - ]; - in + in actual == expected; }; "order" = { - "handles normal values" = let - expected = [{}]; - actual = lib.modules.apply.order [{}]; - in + "handles normal values" = + let + expected = [ { } ]; + actual = lib.modules.apply.order [ { } ]; + in actual == expected; - "handles priority" = let - expected = [ - { - value = 1; - priority = 10; - } - { - value = 3; - priority = 50; - } - {value = 2;} - ]; - actual = lib.modules.apply.order [ - { - value = 1; - priority = 10; - } - {value = 2;} - { - value = 3; - priority = 50; - } - ]; - in + "handles priority" = + let + expected = [ + { + value = 1; + priority = 10; + } + { + value = 3; + priority = 50; + } + { value = 2; } + ]; + actual = lib.modules.apply.order [ + { + value = 1; + priority = 10; + } + { value = 2; } + { + value = 3; + priority = 50; + } + ]; + in actual == expected; }; "fixup" = { - "sets default type for option" = let - actual = lib.modules.apply.fixup [] ( - lib.options.create {} - ); - in + "sets default type for option" = + let + actual = lib.modules.apply.fixup [ ] (lib.options.create { }); + in actual.type.name == "Unspecified"; }; "invert" = { - "inverts merge" = let - expected = [{x = 1;} {x = 2;}]; - actual = - lib.modules.apply.invert (lib.modules.merge [{x = 1;} {x = 2;}]); - in - actual - == expected; - - "inverts when" = let - expected = [ - { - x = { - __type__ = "when"; - condition = true; - content = 1; - }; - y = { - __type__ = "when"; - condition = true; - content = 2; - }; - } - ]; - actual = lib.modules.apply.invert (lib.modules.when true { - x = 1; - y = 2; - }); - in + "inverts merge" = + let + expected = [ + { x = 1; } + { x = 2; } + ]; + actual = lib.modules.apply.invert ( + lib.modules.merge [ + { x = 1; } + { x = 2; } + ] + ); + in actual == expected; - "inverts overrides" = let - expected = [ - { - x = { - __type__ = "override"; - priority = 100; - content = 1; - }; - y = { - __type__ = "override"; - priority = 100; - content = 2; - }; - } - ]; - actual = lib.modules.apply.invert (lib.modules.override 100 { - x = 1; - y = 2; - }); - in + "inverts when" = + let + expected = [ + { + x = { + __type__ = "when"; + condition = true; + content = 1; + }; + y = { + __type__ = "when"; + condition = true; + content = 2; + }; + } + ]; + actual = lib.modules.apply.invert ( + lib.modules.when true { + x = 1; + y = 2; + } + ); + in + actual == expected; + + "inverts overrides" = + let + expected = [ + { + x = { + __type__ = "override"; + priority = 100; + content = 1; + }; + y = { + __type__ = "override"; + priority = 100; + content = 2; + }; + } + ]; + actual = lib.modules.apply.invert ( + lib.modules.override 100 { + x = 1; + y = 2; + } + ); + in actual == expected; }; }; "validate" = { "keys" = { - "handles an empty set" = let - value = lib.modules.validate.keys {}; - in + "handles an empty set" = + let + value = lib.modules.validate.keys { }; + in value; - "handles a valid module" = let - value = lib.modules.validate.keys { - __file__ = "virtual:aux/example"; - __key__ = "aux/example"; - includes = []; - excludes = []; - options = {}; - config = {}; - freeform = null; - meta = {}; - }; - in + "handles a valid module" = + let + value = lib.modules.validate.keys { + __file__ = "virtual:aux/example"; + __key__ = "aux/example"; + includes = [ ]; + excludes = [ ]; + options = { }; + config = { }; + freeform = null; + meta = { }; + }; + in value; - "handles an invalid module" = let - value = lib.modules.validate.keys { - invalid = null; - }; - in + "handles an invalid module" = + let + value = lib.modules.validate.keys { invalid = null; }; + in !value; }; }; "normalize" = { - "handles an empty set" = let - expected = { - __file__ = "/aux/example.nix"; - __key__ = "example"; - config = {}; - excludes = []; - includes = []; - options = {}; - }; - actual = lib.modules.normalize "/aux/example.nix" "example" {}; - in + "handles an empty set" = + let + expected = { + __file__ = "/aux/example.nix"; + __key__ = "example"; + config = { }; + excludes = [ ]; + includes = [ ]; + options = { }; + }; + actual = lib.modules.normalize "/aux/example.nix" "example" { }; + in actual == expected; - "handles an example module" = let - expected = { - __file__ = "myfile.nix"; - __key__ = "mykey"; - config = { - x = true; + "handles an example module" = + let + expected = { + __file__ = "myfile.nix"; + __key__ = "mykey"; + config = { + x = true; + }; + excludes = [ ]; + includes = [ ]; + options = { }; }; - excludes = []; - includes = []; - options = {}; - }; - actual = lib.modules.normalize "/aux/example.nix" "example" { - __file__ = "myfile.nix"; - __key__ = "mykey"; - config.x = true; - }; - in + actual = lib.modules.normalize "/aux/example.nix" "example" { + __file__ = "myfile.nix"; + __key__ = "mykey"; + config.x = true; + }; + in actual == expected; }; "resolve" = { - "handles an attribute set" = let - expected = {config.x = 1;}; - actual = lib.modules.resolve "example" {config.x = 1;} {}; - in + "handles an attribute set" = + let + expected = { + config.x = 1; + }; + actual = lib.modules.resolve "example" { config.x = 1; } { }; + in actual == expected; - "handles a function" = let - expected = {config.x = 1;}; - actual = lib.modules.resolve "example" (lib.fp.const {config.x = 1;}) {}; - in + "handles a function" = + let + expected = { + config.x = 1; + }; + actual = lib.modules.resolve "example" (lib.fp.const { config.x = 1; }) { }; + in actual == expected; - "handles a function with arguments" = let - expected = {config.x = 1;}; - actual = lib.modules.resolve "example" (args: {config.x = args.x;}) {x = 1;}; - in + "handles a function with arguments" = + let + expected = { + config.x = 1; + }; + actual = lib.modules.resolve "example" (args: { config.x = args.x; }) { x = 1; }; + in actual == expected; }; "getFiles" = { - "gets the files for a list of modules" = let - expected = ["/aux/example.nix"]; - actual = lib.modules.getFiles [{__file__ = "/aux/example.nix";}]; - in - actual - == expected; + "gets the files for a list of modules" = + let + expected = [ "/aux/example.nix" ]; + actual = lib.modules.getFiles [ { __file__ = "/aux/example.nix"; } ]; + in + actual == expected; }; "combine" = { - "handles empty modules" = let - expected = { - matched = {}; - unmatched = []; - }; - actual = lib.modules.combine [] [ - (lib.modules.normalize "/aux/example.nix" "example" {}) - ]; - in + "handles empty modules" = + let + expected = { + matched = { }; + unmatched = [ ]; + }; + actual = lib.modules.combine [ ] [ (lib.modules.normalize "/aux/example.nix" "example" { }) ]; + in actual == expected; - "handles a single module" = let - expected = { - matched = {}; - unmatched = [ - { - __file__ = "/aux/example.nix"; - prefix = ["x"]; - value = 1; - } - ]; - }; - actual = lib.modules.combine [] [ - (lib.modules.normalize "/aux/example.nix" "example" { - config = { - x = 1; - }; - }) - ]; - in - actual == expected; - - "handles multiple modules" = let - unmatched = [ - { - __file__ = "/aux/example2.nix"; - prefix = ["y"]; - value = 2; - } - ]; - actual = lib.modules.combine [] [ - (lib.modules.normalize "/aux/example1.nix" "example2" { - options = { - x = lib.options.create {}; - }; - - config = { - x = 1; - }; - }) - (lib.modules.normalize "/aux/example2.nix" "example2" { - config = { - y = 2; - }; - }) - ]; - in - (actual.unmatched == unmatched) - && actual.matched ? x; - }; - - "run" = { - "empty" = let - evaluated = lib.modules.run { - modules = [ - { - options.aux = { - message = lib.options.create { - type = lib.types.string; - }; - }; - + "handles a single module" = + let + expected = { + matched = { }; + unmatched = [ + { + __file__ = "/aux/example.nix"; + prefix = [ "x" ]; + value = 1; + } + ]; + }; + actual = lib.modules.combine [ ] [ + (lib.modules.normalize "/aux/example.nix" "example" { config = { - aux.message = "Hello, World!"; - }; - } - ]; - }; - in - evaluated ? config; - - "hello world" = let - expected = "Hello, World!"; - - evaluated = lib.modules.run { - modules = [ - { - options.aux = { - message = lib.options.create { - type = lib.types.string; - }; - }; - - config = { - aux.message = "Hello, World!"; - }; - } - ]; - }; - - actual = evaluated.config.aux.message; - in - actual == expected; - - "recursive" = let - expected = "Hello, World!"; - - evaluated = lib.modules.run { - modules = [ - ({config}: { - options.aux = { - message = lib.options.create { - type = lib.types.string; - }; - - proxy = lib.options.create { - type = lib.types.string; - }; - }; - - config = { - aux = { - proxy = "Hello, World!"; - message = config.aux.proxy; - }; + x = 1; }; }) ]; - }; - - actual = evaluated.config.aux.message; - in + in actual == expected; - "conditional" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ + "handles multiple modules" = + let + unmatched = [ { - options.aux = { - message = lib.options.create { - type = lib.types.string; - }; - }; - config = { - aux = { - message = lib.modules.when true expected; - }; - }; + __file__ = "/aux/example2.nix"; + prefix = [ "y" ]; + value = 2; } ]; - }; - in - evaluated.config.aux.message == expected; - - "conditional list" = let - expected = ["Hello, World!"]; - evaluated = lib.modules.run { - modules = [ - { - options.aux = { - message = lib.options.create { - type = lib.types.list.of lib.types.string; - }; - }; - config = { - aux = { - message = lib.modules.when true expected; - }; - }; - } - ]; - }; - in - evaluated.config.aux.message == expected; - - "submodules" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { + actual = lib.modules.combine [ ] [ + (lib.modules.normalize "/aux/example1.nix" "example2" { options = { - aux = lib.options.create { - default.value = { - message = "hi"; - }; - type = lib.types.attrs.of (lib.types.submodule ({name}: { - # freeform = lib.types.any; - options.message = lib.options.create { - type = lib.types.string; - }; - })); - }; + x = lib.options.create { }; }; - config = { - aux = { - x = { - message = "Hello, World!"; - }; - }; - }; - } - ]; - }; - in - evaluated.config.aux.x.message == expected; - "submodules without shorthand" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodules.of { - shorthand = false; - modules = [ - { - options.message = lib.options.create { - type = lib.types.string; - }; - } - ]; - }; - }; - }; config = { - aux = { - options = { - message2 = lib.options.create { - type = lib.types.string; - }; + x = 1; + }; + }) + (lib.modules.normalize "/aux/example2.nix" "example2" { + config = { + y = 2; + }; + }) + ]; + in + (actual.unmatched == unmatched) && actual.matched ? x; + }; + + "run" = { + "empty" = + let + evaluated = lib.modules.run { + modules = [ + { + options.aux = { + message = lib.options.create { type = lib.types.string; }; + }; + + config = { + aux.message = "Hello, World!"; + }; + } + ]; + }; + in + evaluated ? config; + + "hello world" = + let + expected = "Hello, World!"; + + evaluated = lib.modules.run { + modules = [ + { + options.aux = { + message = lib.options.create { type = lib.types.string; }; + }; + + config = { + aux.message = "Hello, World!"; + }; + } + ]; + }; + + actual = evaluated.config.aux.message; + in + actual == expected; + + "recursive" = + let + expected = "Hello, World!"; + + evaluated = lib.modules.run { + modules = [ + ( + { config }: + { + options.aux = { + message = lib.options.create { type = lib.types.string; }; + + proxy = lib.options.create { type = lib.types.string; }; }; config = { - message = expected; - message2 = expected; + aux = { + proxy = "Hello, World!"; + message = config.aux.proxy; + }; }; - }; - }; - } - ]; - }; - in - evaluated.config.aux.message == evaluated.config.aux.message2; + } + ) + ]; + }; - "function submodules" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodules.of { - shorthand = false; - modules = [ - { - options.message = lib.options.create { - type = lib.types.string; - }; - } - ]; + actual = evaluated.config.aux.message; + in + actual == expected; + + "conditional" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options.aux = { + message = lib.options.create { type = lib.types.string; }; + }; + config = { + aux = { + message = lib.modules.when true expected; }; }; - }; - config = { - aux = args: { - config.message = expected; - }; - }; - } - ]; - }; - in + } + ]; + }; + in evaluated.config.aux.message == expected; - "merges submodules" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodules.of { - shorthand = false; - modules = [ - { - options.message = lib.options.create { - type = lib.types.string; - }; - } - ]; + "conditional list" = + let + expected = [ "Hello, World!" ]; + evaluated = lib.modules.run { + modules = [ + { + options.aux = { + message = lib.options.create { type = lib.types.list.of lib.types.string; }; + }; + config = { + aux = { + message = lib.modules.when true expected; }; }; - }; - config = { - aux = args: { - options.message2 = lib.options.create { - type = lib.types.string; - }; + } + ]; + }; + in + evaluated.config.aux.message == expected; - config.message = expected; - }; - }; - } - { - config = { - aux.config.message2 = expected; - }; - } - ]; - }; - in - evaluated.config.aux.message == evaluated.config.aux.message2; - - "flexible shorthand" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodules.of { - shorthand = true; - modules = [ - { - options.message = lib.options.create { - type = lib.types.string; - }; - } - ]; + "submodules" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + default.value = { + message = "hi"; + }; + type = lib.types.attrs.of ( + lib.types.submodule ( + { name }: + { + # freeform = lib.types.any; + options.message = lib.options.create { type = lib.types.string; }; + } + ) + ); }; }; - }; - config = { - aux = args: { - options.message2 = lib.options.create { - type = lib.types.string; - }; - - config.message = expected; - }; - }; - } - { - config = { - aux.message2 = expected; - }; - } - ]; - }; - in - evaluated.config.aux.message == evaluated.config.aux.message2; - - "base level submodule" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodule { - options.message = lib.options.create { - type = lib.types.string; + config = { + aux = { + x = { + message = "Hello, World!"; }; }; }; - }; - config = { - aux = args: { - options.message2 = lib.options.create { - type = lib.types.string; - }; + } + ]; + }; + in + evaluated.config.aux.x.message == expected; - config.message = expected; + "submodules without shorthand" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodules.of { + shorthand = false; + modules = [ { options.message = lib.options.create { type = lib.types.string; }; } ]; + }; + }; }; - }; - } - { - config = { - aux.message2 = expected; - }; - } - ]; - }; - in + config = { + aux = { + options = { + message2 = lib.options.create { type = lib.types.string; }; + }; + + config = { + message = expected; + message2 = expected; + }; + }; + }; + } + ]; + }; + in evaluated.config.aux.message == evaluated.config.aux.message2; - "base level submodule (freeform)" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodule { - freeform = lib.types.any; - - options.message = lib.options.create { - type = lib.types.string; + "function submodules" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodules.of { + shorthand = false; + modules = [ { options.message = lib.options.create { type = lib.types.string; }; } ]; }; }; }; - }; - config = { - aux = args: { - options.message2 = lib.options.create { - type = lib.types.string; - }; - - config.message = expected; + config = { + aux = args: { config.message = expected; }; }; - }; - } - { - config = { - aux.exists = true; - aux.message2 = expected; - }; - } - ]; - }; - in - (evaluated.config.aux.message == evaluated.config.aux.message2) - && evaluated.config.aux.exists; + } + ]; + }; + in + evaluated.config.aux.message == expected; - "nested submodules" = let - expected = "Hello, World!"; - evaluated = lib.modules.run { - modules = [ - { - options = { - aux = lib.options.create { - type = lib.types.submodule { - freeform = lib.types.any; - - options.message = lib.options.create { - type = lib.types.string; + "merges submodules" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodules.of { + shorthand = false; + modules = [ { options.message = lib.options.create { type = lib.types.string; }; } ]; }; }; }; - }; - config = { - aux = args: { - options.message2 = lib.options.create { - type = lib.types.string; - }; + config = { + aux = args: { + options.message2 = lib.options.create { type = lib.types.string; }; - config.message = expected; + config.message = expected; + }; }; - }; - } - { - config = { - aux.exists = true; - aux.message2 = expected; - }; - } - ]; - }; - in - (evaluated.config.aux.message == evaluated.config.aux.message2) - && evaluated.config.aux.exists; + } + { + config = { + aux.config.message2 = expected; + }; + } + ]; + }; + in + evaluated.config.aux.message == evaluated.config.aux.message2; + + "flexible shorthand" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodules.of { + shorthand = true; + modules = [ { options.message = lib.options.create { type = lib.types.string; }; } ]; + }; + }; + }; + config = { + aux = args: { + options.message2 = lib.options.create { type = lib.types.string; }; + + config.message = expected; + }; + }; + } + { + config = { + aux.message2 = expected; + }; + } + ]; + }; + in + evaluated.config.aux.message == evaluated.config.aux.message2; + + "base level submodule" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodule { options.message = lib.options.create { type = lib.types.string; }; }; + }; + }; + config = { + aux = args: { + options.message2 = lib.options.create { type = lib.types.string; }; + + config.message = expected; + }; + }; + } + { + config = { + aux.message2 = expected; + }; + } + ]; + }; + in + evaluated.config.aux.message == evaluated.config.aux.message2; + + "base level submodule (freeform)" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodule { + freeform = lib.types.any; + + options.message = lib.options.create { type = lib.types.string; }; + }; + }; + }; + config = { + aux = args: { + options.message2 = lib.options.create { type = lib.types.string; }; + + config.message = expected; + }; + }; + } + { + config = { + aux.exists = true; + aux.message2 = expected; + }; + } + ]; + }; + in + (evaluated.config.aux.message == evaluated.config.aux.message2) && evaluated.config.aux.exists; + + "nested submodules" = + let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodule { + freeform = lib.types.any; + + options.message = lib.options.create { type = lib.types.string; }; + }; + }; + }; + config = { + aux = args: { + options.message2 = lib.options.create { type = lib.types.string; }; + + config.message = expected; + }; + }; + } + { + config = { + aux.exists = true; + aux.message2 = expected; + }; + } + ]; + }; + in + (evaluated.config.aux.message == evaluated.config.aux.message2) && evaluated.config.aux.exists; }; } diff --git a/lib/src/numbers/default.nix b/lib/src/numbers/default.nix index 7921cd1..0df6ebb 100644 --- a/lib/src/numbers/default.nix +++ b/lib/src/numbers/default.nix @@ -4,54 +4,55 @@ lib: { ## Convert a number into a string. ## ## @type Int | Float -> String - string = value: - if builtins.isInt value - then builtins.toString value - else builtins.toJSON value; + string = value: if builtins.isInt value then builtins.toString value else builtins.toJSON value; ## Convert a number into a list of digits in the given base. ## ## @type Int -> Int -> List Int - base = base: target: let - process = value: let - r = value - ((value / base) * base); - q = (value - r) / base; + base = + base: target: + let + process = + value: + let + r = value - ((value / base) * base); + q = (value - r) / base; + in + if value < base then [ value ] else [ r ] ++ process q; + result = process target; in - if value < base - then [value] - else [r] ++ process q; - result = process target; - in assert lib.errors.trace (builtins.isInt base) "Base must be an integer."; assert lib.errors.trace (builtins.isInt target) "Target must be an integer."; assert lib.errors.trace (base >= 2) "Base must be at least 2."; assert lib.errors.trace (target >= 0) "Target cannot be negative."; - lib.lists.reverse result; + lib.lists.reverse result; ## Convert a number into a hexadecimal string. ## ## @type Int -> String - hex = value: let - serialize = part: - if part < 10 - then builtins.toString part - else if part == 10 - then "A" - else if part == 11 - then "B" - else if part == 12 - then "C" - else if part == 13 - then "D" - else if part == 14 - then "E" - else if part == 15 - then "F" - else builtins.throw "Invalid hex digit."; - in - lib.strings.concatMap - serialize - (lib.numbers.into.base 16 value); + hex = + value: + let + serialize = + part: + if part < 10 then + builtins.toString part + else if part == 10 then + "A" + else if part == 11 then + "B" + else if part == 12 then + "C" + else if part == 13 then + "D" + else if part == 14 then + "E" + else if part == 15 then + "F" + else + builtins.throw "Invalid hex digit."; + in + lib.strings.concatMap serialize (lib.numbers.into.base 16 value); }; ## Compare two numbers. When the first number is less than the second, -1 @@ -59,11 +60,13 @@ lib: { ## returned. When the numbers are equal, 0 is returned. ## ## @type Int -> Int -> Int - compare = a: b: - if a < b - then -1 - else if a > b - then 1 - else 0; + compare = + a: b: + if a < b then + -1 + else if a > b then + 1 + else + 0; }; } diff --git a/lib/src/numbers/default.test.nix b/lib/src/numbers/default.test.nix index 78ea058..9b858fc 100644 --- a/lib/src/numbers/default.test.nix +++ b/lib/src/numbers/default.test.nix @@ -1,55 +1,67 @@ let lib = import ./../default.nix; -in { +in +{ "into" = { "string" = { - "converts an int into a string" = let - expected = "1"; - actual = lib.numbers.into.string 1; - in + "converts an int into a string" = + let + expected = "1"; + actual = lib.numbers.into.string 1; + in actual == expected; - "converts a float into a string" = let - expected = "1.0"; - actual = lib.numbers.into.string 1.0; - in + "converts a float into a string" = + let + expected = "1.0"; + actual = lib.numbers.into.string 1.0; + in actual == expected; }; "base" = { - "converts a number into a given base" = let - expected = [1 0 0]; - actual = lib.numbers.into.base 2 4; - in + "converts a number into a given base" = + let + expected = [ + 1 + 0 + 0 + ]; + actual = lib.numbers.into.base 2 4; + in actual == expected; }; "hex" = { - "converts a number into a hex string" = let - expected = "64"; - actual = lib.numbers.into.hex 100; - in + "converts a number into a hex string" = + let + expected = "64"; + actual = lib.numbers.into.hex 100; + in actual == expected; }; }; "compare" = { - "returns -1 when first is less than second" = let - expected = -1; - actual = lib.numbers.compare 1 2; - in + "returns -1 when first is less than second" = + let + expected = -1; + actual = lib.numbers.compare 1 2; + in actual == expected; - "returns 0 when first is equal to second" = let - expected = 0; - actual = lib.numbers.compare 1 1; - in + "returns 0 when first is equal to second" = + let + expected = 0; + actual = lib.numbers.compare 1 1; + in actual == expected; - "returns 1 when first is greater than second" = let - expected = 1; - actual = lib.numbers.compare 2 1; - in + "returns 1 when first is greater than second" = + let + expected = 1; + actual = lib.numbers.compare 2 1; + in actual == expected; }; } diff --git a/lib/src/options/default.nix b/lib/src/options/default.nix index f256195..6b8ce80 100644 --- a/lib/src/options/default.nix +++ b/lib/src/options/default.nix @@ -4,165 +4,184 @@ lib: { ## Merge a list of option definitions into a single value. ## ## @type Location -> List Definition -> Any - default = location: definitions: let - values = lib.options.getDefinitionValues definitions; - first = builtins.elemAt values 0; - mergedFunctions = x: - lib.options.mergeDefault - location - (builtins.map (f: f x) values); - mergedLists = builtins.concatLists values; - mergedAttrs = builtins.foldl' lib.attrs.merge {} values; - mergedBools = builtins.any lib.bools.or false values; - mergedStrings = lib.strings.concat values; - in - if builtins.length values == 1 - then builtins.elemAt values 0 - else if builtins.all builtins.isFunction values - then mergedFunctions - else if builtins.all builtins.isList values - then mergedLists - else if builtins.all builtins.isAttrs values - then mergedAttrs - else if builtins.all builtins.isBool values - then mergedBools - else if builtins.all lib.strings.isString values - then mergedStrings - else if builtins.all builtins.isInt values && builtins.all (x: x == first) values - then first + default = + location: definitions: + let + values = lib.options.getDefinitionValues definitions; + first = builtins.elemAt values 0; + mergedFunctions = x: lib.options.mergeDefault location (builtins.map (f: f x) values); + mergedLists = builtins.concatLists values; + mergedAttrs = builtins.foldl' lib.attrs.merge { } values; + mergedBools = builtins.any lib.bools.or false values; + mergedStrings = lib.strings.concat values; + in + if builtins.length values == 1 then + builtins.elemAt values 0 + else if builtins.all builtins.isFunction values then + mergedFunctions + else if builtins.all builtins.isList values then + mergedLists + else if builtins.all builtins.isAttrs values then + mergedAttrs + else if builtins.all builtins.isBool values then + mergedBools + else if builtins.all lib.strings.isString values then + mergedStrings + else if builtins.all builtins.isInt values && builtins.all (x: x == first) values then + first # TODO: Improve this error message to show the location and definitions for the option. - else builtins.throw "Cannot merge definitions."; + else + builtins.throw "Cannot merge definitions."; ## Merge multiple option definitions together. ## ## @type Location -> Type -> List Definition - definitions = location: type: definitions: let - identifier = lib.options.getIdentifier location; - resolve = definition: let - properties = - builtins.addErrorContext - "while evaluating definitions from `${definition.__file__}`:" - (lib.modules.apply.properties definition.value); - normalize = value: { - __file__ = definition.__file__; - inherit value; - }; + definitions = + location: type: definitions: + let + identifier = lib.options.getIdentifier location; + resolve = + definition: + let + properties = builtins.addErrorContext "while evaluating definitions from `${definition.__file__}`:" ( + lib.modules.apply.properties definition.value + ); + normalize = value: { + __file__ = definition.__file__; + inherit value; + }; + in + builtins.map normalize properties; + + resolved = builtins.concatMap resolve definitions; + overridden = lib.modules.apply.overrides resolved; + + values = + if builtins.any (definition: lib.types.is "order" definition.value) overridden.values then + lib.modules.apply.order overridden.values + else + overridden.values; + + isDefined = values != [ ]; + + invalid = builtins.filter (definition: !(type.check definition.value)) values; + + merged = + if isDefined then + if builtins.all (definition: type.check definition.value) values then + type.merge location values + else + builtins.throw "A definition for `${identifier}` is not of type `${type.description}`. Definition values:${lib.options.getDefinitions invalid}" + else + builtins.throw "The option `${identifier}` is used but not defined."; + + optional = if isDefined then { value = merged; } else { }; in - builtins.map normalize properties; + { + inherit + isDefined + values + merged + optional + ; - resolved = builtins.concatMap resolve definitions; - overridden = lib.modules.apply.overrides resolved; - - values = - if builtins.any (definition: lib.types.is "order" definition.value) overridden.values - then lib.modules.apply.order overridden.values - else overridden.values; - - isDefined = values != []; - - invalid = builtins.filter (definition: !(type.check definition.value)) values; - - merged = - if isDefined - then - if builtins.all (definition: type.check definition.value) values - then type.merge location values - else builtins.throw "A definition for `${identifier}` is not of type `${type.description}`. Definition values:${lib.options.getDefinitions invalid}" - else builtins.throw "The option `${identifier}` is used but not defined."; - - optional = - if isDefined - then {value = merged;} - else {}; - in { - inherit isDefined values merged optional; - - raw = { - inherit values; - inherit (overridden) highestPriority; + raw = { + inherit values; + inherit (overridden) highestPriority; + }; }; - }; ## Merge multiple option declarations together. ## ## @type Location -> List Option - declarations = location: options: let - merge = result: option: let - mergedType = result.type.mergeType option.options.type.functor; - isTypeMergeable = mergedType != null; - shared = name: option.options ? ${name} && result ? ${name}; - typeSet = lib.attrs.when ((shared "type") && isTypeMergeable) { - type = mergedType; - }; - files = result.declarations; - serializedFiles = builtins.concatStringsSep " and " files; - getSubModules = option.options.type.getSubModules or null; - submodules = - if getSubModules != null + declarations = + location: options: + let + merge = + result: option: + let + mergedType = result.type.mergeType option.options.type.functor; + isTypeMergeable = mergedType != null; + shared = name: option.options ? ${name} && result ? ${name}; + typeSet = lib.attrs.when ((shared "type") && isTypeMergeable) { type = mergedType; }; + files = result.declarations; + serializedFiles = builtins.concatStringsSep " and " files; + getSubModules = option.options.type.getSubModules or null; + submodules = + if getSubModules != null then + builtins.map (module: { + __file__ = option.__file__; + includes = [ module ]; + }) getSubModules + ++ result.options + else + result.options; + in + if + shared "default" + || shared "example" + || shared "description" + || shared "apply" + || (shared "type" && !isTypeMergeable) then - builtins.map - (module: { - __file__ = option.__file__; - includes = [module]; - }) - getSubModules - ++ result.options - else result.options; + builtins.throw "The option `${lib.options.getIdentifier location}` in `${option.__file__}` is already declared in ${serializedFiles}" + else + option.options + // result + // { + declarations = result.declarations ++ [ option.__file__ ]; + options = submodules; + } + // typeSet; in - if shared "default" || shared "example" || shared "description" || shared "apply" || (shared "type" && !isTypeMergeable) - then builtins.throw "The option `${lib.options.getIdentifier location}` in `${option.__file__}` is already declared in ${serializedFiles}" - else - option.options - // result - // { - declarations = result.declarations ++ [option.__file__]; - options = submodules; - } - // typeSet; - in - builtins.foldl' - merge - { + builtins.foldl' merge { inherit location; - declarations = []; - options = []; - } - options; + declarations = [ ]; + options = [ ]; + } options; ## Merge an option, only supporting a single unique definition. ## ## @type String -> Location -> List Definition -> Any - unique = message: location: definitions: let - identifier = lib.options.getIdentifier location; - total = builtins.length definitions; - first = builtins.elemAt definitions 0; - in - if total == 1 - then first.value - else if total == 0 - then builtins.throw "Cannot merge unused option `${identifier}`.\n${message}" - else builtins.throw "The option `${identifier}` is defined multiple times, but must be unique.\n${message}\nDefinitions:${lib.options.getDefinitions definitions}"; + unique = + message: location: definitions: + let + identifier = lib.options.getIdentifier location; + total = builtins.length definitions; + first = builtins.elemAt definitions 0; + in + if total == 1 then + first.value + else if total == 0 then + builtins.throw "Cannot merge unused option `${identifier}`.\n${message}" + else + builtins.throw "The option `${identifier}` is defined multiple times, but must be unique.\n${message}\nDefinitions:${lib.options.getDefinitions definitions}"; ## Merge a single instance of an option. ## ## @type Location -> List Definition -> Any one = lib.options.merge.unique ""; - equal = location: definitions: let - identifier = lib.options.getIdentifier location; - first = builtins.elemAt definitions 0; - rest = builtins.tail definitions; - merge = x: y: - if x != y - then builtins.throw "The option `${identifier}` has conflicting definitions:${lib.options.getDefinitions definitions}" - else x; - merged = builtins.foldl' merge first rest; - in - if builtins.length definitions == 0 - then builtins.throw "Cannot merge unused option `${identifier}`." - else if builtins.length definitions == 1 - then first.value - else merged.value; + equal = + location: definitions: + let + identifier = lib.options.getIdentifier location; + first = builtins.elemAt definitions 0; + rest = builtins.tail definitions; + merge = + x: y: + if x != y then + builtins.throw "The option `${identifier}` has conflicting definitions:${lib.options.getDefinitions definitions}" + else + x; + merged = builtins.foldl' merge first rest; + in + if builtins.length definitions == 0 then + builtins.throw "Cannot merge unused option `${identifier}`." + else if builtins.length definitions == 1 then + first.value + else + merged.value; }; ## Check whether a value is an option. @@ -173,135 +192,148 @@ lib: { ## Create an option. ## ## @type { type? :: String | Null, apply? :: (a -> b) | Null, default? :: { value :: a, text :: String }, example? :: String | Null, visible? :: Bool | Null, internal? :: Bool | Null, writable? :: Bool | Null, description? :: String | Null } -> Option a - create = settings @ { - type ? lib.types.unspecified, - apply ? null, - default ? {}, - example ? null, - visible ? null, - internal ? null, - writable ? null, - description ? null, - }: { - __type__ = "option"; - inherit type apply default example visible internal writable description; - }; + create = + settings@{ + type ? lib.types.unspecified, + apply ? null, + default ? { }, + example ? null, + visible ? null, + internal ? null, + writable ? null, + description ? null, + }: + { + __type__ = "option"; + inherit + type + apply + default + example + visible + internal + writable + description + ; + }; ## Create a sink option. ## ## @type @alias lib.options.create - sink = settings: let - defaults = { - internal = true; - visible = false; - default = false; - description = "A sink option for unused definitions"; - type = lib.types.create { - name = "sink"; - check = lib.fp.const true; - merge = lib.fp.const (lib.fp.const false); + sink = + settings: + let + defaults = { + internal = true; + visible = false; + default = false; + description = "A sink option for unused definitions"; + type = lib.types.create { + name = "sink"; + check = lib.fp.const true; + merge = lib.fp.const (lib.fp.const false); + }; + apply = value: builtins.throw "Cannot read the value of a Sink option."; }; - apply = value: builtins.throw "Cannot read the value of a Sink option."; - }; - in + in lib.options.create (defaults // settings); ## Get the definition values from a list of options definitions. ## ## @type List Definition -> Any - getDefinitionValues = definitions: - builtins.map (definition: definition.value) definitions; + getDefinitionValues = definitions: builtins.map (definition: definition.value) definitions; ## Convert a list of option identifiers into a single identifier. ## ## @type List String -> String - getIdentifier = location: let - special = [ - # lib.types.attrs.of (lib.types.submodule {}) - "" - # lib.types.list.of (submodule {}) - "*" - # lib.types.function - "" - ]; - escape = part: - if builtins.elem part special - then part - else lib.strings.escape.nix.identifier part; - in + getIdentifier = + location: + let + special = [ + # lib.types.attrs.of (lib.types.submodule {}) + "" + # lib.types.list.of (submodule {}) + "*" + # lib.types.function + "" + ]; + escape = part: if builtins.elem part special then part else lib.strings.escape.nix.identifier part; + in lib.strings.concatMapSep "." escape location; ## Get a string message of the definitions for an option. ## ## @type List Definition -> String - getDefinitions = definitions: let - serialize = definition: let - valueWithRecursionLimit = - lib.generators.withRecursion { - limit = 10; - throw = false; - } - definition.value; + getDefinitions = + definitions: + let + serialize = + definition: + let + valueWithRecursionLimit = lib.generators.withRecursion { + limit = 10; + throw = false; + } definition.value; - eval = builtins.tryEval ( - lib.generators.pretty {} - valueWithRecursionLimit - ); + eval = builtins.tryEval (lib.generators.pretty { } valueWithRecursionLimit); - lines = lib.strings.split "\n" eval.value; - linesLength = builtins.length lines; - firstFiveLines = lib.lists.take 5 lines; + lines = lib.strings.split "\n" eval.value; + linesLength = builtins.length lines; + firstFiveLines = lib.lists.take 5 lines; - ellipsis = lib.lists.when (linesLength > 5) "..."; + ellipsis = lib.lists.when (linesLength > 5) "..."; - value = builtins.concatStringsSep "\n " (firstFiveLines ++ ellipsis); + value = builtins.concatStringsSep "\n " (firstFiveLines ++ ellipsis); - result = - if ! eval.success - then "" - else if linesLength > 1 - then ":\n " + value - else ": " + value; - in "\n- In `${definition.__file__}`${result}"; - in + result = + if !eval.success then + "" + else if linesLength > 1 then + ":\n " + value + else + ": " + value; + in + "\n- In `${definition.__file__}`${result}"; + in lib.strings.concatMap serialize definitions; ## Run a set of definitions, calculating the resolved value and associated information. ## ## @type Location -> Option -> List Definition -> String & { value :: Any, highestPriority :: Int, isDefined :: Bool, files :: List String, definitions :: List Any, definitionsWithLocations :: List Definition } - run = location: option: definitions: let - identifier = lib.options.getIdentifier location; + run = + location: option: definitions: + let + identifier = lib.options.getIdentifier location; - definitionsWithDefault = - if option ? default && option.default ? value - then - [ - { - __file__ = builtins.head option.declarations; - value = lib.modules.overrides.option option.default.value; - } - ] - ++ definitions - else definitions; + definitionsWithDefault = + if option ? default && option.default ? value then + [ + { + __file__ = builtins.head option.declarations; + value = lib.modules.overrides.option option.default.value; + } + ] + ++ definitions + else + definitions; - merged = - if option.writable or null == false && builtins.length definitionsWithDefault > 1 - then let - separatedDefinitions = builtins.map (definition: - definition - // { - value = (lib.options.merge.definitions location option.type [definition]).merged; - }) - definitionsWithDefault; - in - builtins.throw "The option `${identifier}` is not writable, but is set more than once:${lib.options.getDefinitions separatedDefinitions}" - else lib.options.merge.definitions location option.type definitionsWithDefault; + merged = + if option.writable or null == false && builtins.length definitionsWithDefault > 1 then + let + separatedDefinitions = builtins.map ( + definition: + definition + // { + value = (lib.options.merge.definitions location option.type [ definition ]).merged; + } + ) definitionsWithDefault; + in + builtins.throw "The option `${identifier}` is not writable, but is set more than once:${lib.options.getDefinitions separatedDefinitions}" + else + lib.options.merge.definitions location option.type definitionsWithDefault; - value = - if option.apply or null != null - then option.apply merged.merged - else merged.merged; - in + value = if option.apply or null != null then option.apply merged.merged else merged.merged; + in option // { value = builtins.addErrorContext "while evaluating the option `${identifier}`:" value; diff --git a/lib/src/options/default.test.nix b/lib/src/options/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/options/default.test.nix +++ b/lib/src/options/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/packages/default.nix b/lib/src/packages/default.nix index a1513d0..40f7f3c 100644 --- a/lib/src/packages/default.nix +++ b/lib/src/packages/default.nix @@ -5,53 +5,48 @@ lib: { ## `lib.paths.into.drv` for convenience. ## ## @type a -> Bool - isDerivation = value: - value.type or null == "derivation"; + isDerivation = value: value.type or null == "derivation"; ## Sanitize a string to produce a valid name for a derivation. ## ## @type String -> String - sanitizeDerivationName = let - validate = builtins.match "[[:alnum:]+_?=-][[:alnum:]+._?=-]*"; - in + sanitizeDerivationName = + let + validate = builtins.match "[[:alnum:]+_?=-][[:alnum:]+._?=-]*"; + in value: # First detect the common case of already valid strings, to speed those up - if builtins.stringLength value <= 207 && validate value != null - then builtins.unsafeDiscardStringContext value - else - lib.fp.pipe [ - # Get rid of string context. This is safe under the assumption that the - # resulting string is only used as a derivation name - builtins.unsafeDiscardStringContext + if builtins.stringLength value <= 207 && validate value != null then + builtins.unsafeDiscardStringContext value + else + lib.fp.pipe [ + # Get rid of string context. This is safe under the assumption that the + # resulting string is only used as a derivation name + builtins.unsafeDiscardStringContext - # Strip all leading "." - (x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) + # Strip all leading "." + (x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) - (lib.strings.split "[^[:alnum:]+._?=-]+") + (lib.strings.split "[^[:alnum:]+._?=-]+") - # Replace invalid character ranges with a "-" - (lib.strings.concatMap (x: - if builtins.isList x - then "-" - else x)) + # Replace invalid character ranges with a "-" + (lib.strings.concatMap (x: if builtins.isList x then "-" else x)) - # Limit to 211 characters (minus 4 chars for ".drv") - (x: builtins.substring (lib.math.max (builtins.stringLength x - 207) 0) (-1) x) + # Limit to 211 characters (minus 4 chars for ".drv") + (x: builtins.substring (lib.math.max (builtins.stringLength x - 207) 0) (-1) x) - # If the result is empty, replace it with "unknown" - (x: - if builtins.stringLength x == 0 - then "unknown" - else x) - ] - value; + # If the result is empty, replace it with "unknown" + (x: if builtins.stringLength x == 0 then "unknown" else x) + ] value; ## Get an output of a derivation. ## ## @type String -> Derivation -> String - getOutput = output: package: - if ! package ? outputSpecified || !package.outputSpecified - then package.${output} or package.out or package - else package; + getOutput = + output: package: + if !package ? outputSpecified || !package.outputSpecified then + package.${output} or package.out or package + else + package; }; } diff --git a/lib/src/packages/default.test.nix b/lib/src/packages/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/packages/default.test.nix +++ b/lib/src/packages/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/paths/default.nix b/lib/src/paths/default.nix index 8f3800d..9279985 100644 --- a/lib/src/paths/default.nix +++ b/lib/src/paths/default.nix @@ -4,19 +4,19 @@ lib: { ## Convert a path into a derivation. ## ## @type Path -> Derivation - drv = value: let - path = builtins.storePath value; - result = { - type = "derivation"; - name = - lib.packages.sanitizeDerivationName - (builtins.substring 33 (-1) (builtins.baseNameOf path)); - outPath = path; - outputs = ["out"]; - outputName = "out"; - out = result; - }; - in + drv = + value: + let + path = builtins.storePath value; + result = { + type = "derivation"; + name = lib.packages.sanitizeDerivationName (builtins.substring 33 (-1) (builtins.baseNameOf path)); + outPath = path; + outputs = [ "out" ]; + outputName = "out"; + out = result; + }; + in result; }; @@ -24,31 +24,30 @@ lib: { ## Check whether a path is contained within the Nix store. ## ## @type Path -> Bool - store = value: - if lib.strings.validate.stringifiable value - then - builtins.substring 0 1 (builtins.toString value) - == "/" + store = + value: + if lib.strings.validate.stringifiable value then + builtins.substring 0 1 (builtins.toString value) == "/" && builtins.dirOf (builtins.toString value) == builtins.storeDir - else false; + else + false; }; ## Create a search path from a list of paths. ## ## @type String -> [String] -> String - search = target: paths: - lib.strings.concatMapSep - ":" - (path: path + "/" + target) - (builtins.filter (value: value != null) paths); + search = + target: paths: + lib.strings.concatMapSep ":" (path: path + "/" + target) ( + builtins.filter (value: value != null) paths + ); ## Create a search path from a list of packages. ## ## @type String -> [Derivation] -> String - searchFromOutput = output: target: packages: - lib.paths.search - target - (builtins.map (lib.packages.getOutput output) packages); + searchFromOutput = + output: target: packages: + lib.paths.search target (builtins.map (lib.packages.getOutput output) packages); ## Create a search path for the binary output of a package. ## diff --git a/lib/src/paths/default.test.nix b/lib/src/paths/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/paths/default.test.nix +++ b/lib/src/paths/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/points/default.nix b/lib/src/points/default.nix index bc967aa..99bae5f 100644 --- a/lib/src/points/default.nix +++ b/lib/src/points/default.nix @@ -6,9 +6,11 @@ lib: { ## definitions. ## ## @type (a -> a) -> a - fix = f: let - x = f x; - in + fix = + f: + let + x = f x; + in x; ## Calculate the fixed point of a function. This will evaluate the function `f` @@ -18,35 +20,35 @@ lib: { ## attribute that is set to the original function passed to `fix'`. ## ## @type (a -> a) -> a & { __unfix__ :: (a -> a) } - fix' = f: let - x = - f x - // { + fix' = + f: + let + x = f x // { __unfix__ = f; }; - in + in x; ## Extend a function's output with an additional function. This is the basis for ## features like overlays. ## ## @type (a -> b -> c) -> (a -> b) -> a -> b & c - extends = g: f: self: let - previous = f self; - next = g self previous; - in + extends = + g: f: self: + let + previous = f self; + next = g self previous; + in previous // next; ## Add an `extend` method to the result of a function. ## ## @type (a -> b) -> b & { extend :: (a -> b -> c) -> b & c } - withExtend = f: let - create = self: - (f self) - // { - extend = g: lib.points.withExtend (lib.points.extends g f); - }; - in + withExtend = + f: + let + create = self: (f self) // { extend = g: lib.points.withExtend (lib.points.extends g f); }; + in lib.points.fix' create; }; } diff --git a/lib/src/points/default.test.nix b/lib/src/points/default.test.nix index 79597c1..1eeb20d 100644 --- a/lib/src/points/default.test.nix +++ b/lib/src/points/default.test.nix @@ -1,60 +1,52 @@ let lib = import ./../default.nix; -in { +in +{ "fix" = { - "calculates a fixed point" = let - expected = { - original = 0; - calculated = 1; - }; - actual = lib.points.fix ( - self: { + "calculates a fixed point" = + let + expected = { + original = 0; + calculated = 1; + }; + actual = lib.points.fix (self: { original = 0; calculated = self.original + 1; - } - ); - in + }); + in actual == expected; }; "fix'" = { - "allows unfixing a fixed point" = let - expected = { - original = 0; - calculated = 6; - }; - result = lib.points.fix' ( - self: { + "allows unfixing a fixed point" = + let + expected = { + original = 0; + calculated = 6; + }; + result = lib.points.fix' (self: { original = 0; calculated = self.original + 1; - } - ); - actual = result.__unfix__ { - original = 5; - }; - in + }); + actual = result.__unfix__ { original = 5; }; + in actual == expected; }; "extends" = { - "overlays two functions' return values" = let - first = self: previous: { - z = 3; - }; + "overlays two functions' return values" = + let + first = self: previous: { z = 3; }; - second = self: { - y = 2; - }; + second = self: { y = 2; }; - expected = { - y = 2; - z = 3; - }; + expected = { + y = 2; + z = 3; + }; - actual = lib.points.extends first second { - x = 1; - }; - in + actual = lib.points.extends first second { x = 1; }; + in actual == expected; }; } diff --git a/lib/src/strings/default.nix b/lib/src/strings/default.nix index b427139..fb558a2 100644 --- a/lib/src/strings/default.nix +++ b/lib/src/strings/default.nix @@ -9,39 +9,44 @@ lib: { ## Convert a string into a list of characters. ## ## @type String -> List String - chars = value: let - range = lib.lists.range 0 (builtins.stringLength value - 1); - pick = index: builtins.substring index 1 value; - in + chars = + value: + let + range = lib.lists.range 0 (builtins.stringLength value - 1); + pick = index: builtins.substring index 1 value; + in builtins.map pick range; shell = { ## Convert a value into a shell variable. ## ## @type String -> Any -> String - var = name: target: let - baseVar = "${name}=${lib.strings.escape.shell.arg target}"; - listVar = "declare -a ${name}=(${lib.strings.escape.shell.args target})"; - attrsVar = "declare -A ${name}=(${ - builtins.concatStringsSep " " (lib.attrs.mapToList - (k: v: "[${lib.strings.escape.shell.arg k}]=${lib.strings.escape.shell.arg v}") - target) - })"; - in + var = + name: target: + let + baseVar = "${name}=${lib.strings.escape.shell.arg target}"; + listVar = "declare -a ${name}=(${lib.strings.escape.shell.args target})"; + attrsVar = "declare -A ${name}=(${ + builtins.concatStringsSep " " ( + lib.attrs.mapToList ( + k: v: "[${lib.strings.escape.shell.arg k}]=${lib.strings.escape.shell.arg v}" + ) target + ) + })"; + in assert lib.errors.trace (lib.strings.validate.posix name) "Invalid shell variable name: ${name}"; - if builtins.isAttrs target && !lib.strings.validate.stringifiable target - then attrsVar - else if builtins.isList target - then listVar - else baseVar; + if builtins.isAttrs target && !lib.strings.validate.stringifiable target then + attrsVar + else if builtins.isList target then + listVar + else + baseVar; ## Create shell variables for a map of values. ## ## @type Attrs -> String - vars = target: - builtins.concatStringsSep - "\n" - (lib.attrs.mapToList lib.strings.into.shell.var target); + vars = + target: builtins.concatStringsSep "\n" (lib.attrs.mapToList lib.strings.into.shell.var target); }; }; @@ -49,36 +54,45 @@ lib: { ## Escape parts of a string. ## ## @type List String -> String -> String - any = patterns: source: let - escaped = builtins.map (x: "\\${x}") patterns; - replacer = builtins.replaceStrings patterns escaped; - in + any = + patterns: source: + let + escaped = builtins.map (x: "\\${x}") patterns; + replacer = builtins.replaceStrings patterns escaped; + in replacer source; ## Escape a given set of characters in a string using their ## ASCII code prefixed with "\x". ## ## @type List String -> String - c = list: let - serialize = char: let - hex = lib.numbers.into.hex (lib.strings.into.int char); - in "\\x${lib.strings.lower hex}"; - in + c = + list: + let + serialize = + char: + let + hex = lib.numbers.into.hex (lib.strings.into.int char); + in + "\\x${lib.strings.lower hex}"; + in builtins.replaceStrings list (builtins.map serialize list); nix = { ## Escape a string of Nix code. ## ## @type String -> String - value = value: lib.strings.escape.any ["$"] (builtins.toJSON value); + value = value: lib.strings.escape.any [ "$" ] (builtins.toJSON value); ## Escape a string for use as a Nix identifier. ## ## @type String -> String - identifier = value: - if builtins.match "[a-zA-Z_][a-zA-Z0-9_'-]*" value != null - then value - else lib.strings.escape.nix.value value; + identifier = + value: + if builtins.match "[a-zA-Z_][a-zA-Z0-9_'-]*" value != null then + value + else + lib.strings.escape.nix.value value; }; ## Escape a string for use in a regular expression. @@ -91,14 +105,26 @@ lib: { ## @type String -> String xml = builtins.replaceStrings - ["\"" "'" "<" ">" "&"] - [""" "'" "<" ">" "&"]; + [ + "\"" + "'" + "<" + ">" + "&" + ] + [ + """ + "'" + "<" + ">" + "&" + ]; shell = { ## Escape a string for use as a shell argument. ## ## @type String -> String - arg = value: "'${builtins.replaceStrings ["'"] ["'\\''"] (builtins.toString value)}'"; + arg = value: "'${builtins.replaceStrings [ "'" ] [ "'\\''" ] (builtins.toString value)}'"; ## Escape multiple strings for use as shell arguments. ## @@ -116,18 +142,14 @@ lib: { ## Check if a value can be used as a string. ## ## @type Any -> Bool - stringifiable = value: - builtins.isString value - || builtins.isPath value - || value ? outPath - || value ? __toString; + stringifiable = + value: builtins.isString value || builtins.isPath value || value ? outPath || value ? __toString; ## Check whether a string is empty. This includes strings that ## only contain whitespace. ## ## @type String -> Bool - empty = value: - builtins.match "[ \t\n]*" value != null; + empty = value: builtins.match "[ \t\n]*" value != null; }; order = { @@ -136,45 +158,45 @@ lib: { ## @type String -> OrderedString anywhere = value: { inherit value; - deps = []; + deps = [ ]; }; ## Create an ordered string that will be placed before its dependencies. ## ## @type String -> List String -> OrderedString - after = deps: value: { - inherit deps value; - }; + after = deps: value: { inherit deps value; }; ## Apply the order for a list of ordered strings. This function also supports ## plain strings in the list so long as they have an accompanying static definition ## provided. ## ## @type Attrs -> List (OrderedString | String) - apply = static: items: let - process = complete: remaining: let - next = builtins.head remaining; + apply = + static: items: + let + process = + complete: remaining: + let + next = builtins.head remaining; - before = process complete next.deps; - after = process before.complete (builtins.tail remaining); + before = process complete next.deps; + after = process before.complete (builtins.tail remaining); + in + if builtins.length remaining == 0 then + { + inherit complete; + result = [ ]; + } + else if builtins.isAttrs next then + { + inherit complete; + result = before.result ++ [ next.value ] ++ after.result; + } + else + process (complete // { "${next}" = true; }) ([ static.${next} ] ++ builtins.tail remaining); + + processed = process { } items; in - if builtins.length remaining == 0 - then { - inherit complete; - result = []; - } - else if builtins.isAttrs next - then { - inherit complete; - result = before.result ++ [next.value] ++ after.result; - } - else - process - (complete // {"${next}" = true;}) - ([static.${next}] ++ builtins.tail remaining); - - processed = process {} items; - in processed.result; }; @@ -182,10 +204,7 @@ lib: { ## an empty string. ## ## @type Bool -> String -> String - when = condition: value: - if condition - then value - else ""; + when = condition: value: if condition then value else ""; ## A table of ASCII characters mapped to their integer character code. ## @@ -210,7 +229,8 @@ lib: { ## Concatenate and map a list of strings together with a separator. ## ## @type String -> (a -> String) -> List a -> String - concatMapSep = separator: f: list: + concatMapSep = + separator: f: list: builtins.concatStringsSep separator (builtins.map f list); ## Change a string to uppercase. @@ -231,82 +251,92 @@ lib: { ## Split a string by a separator. ## ## @type String -> String -> List String - split = separator: value: let - escaped = lib.strings.escape.regex (builtins.toString separator); - raw = builtins.split escaped (builtins.toString value); - parts = builtins.filter builtins.isString raw; - in + split = + separator: value: + let + escaped = lib.strings.escape.regex (builtins.toString separator); + raw = builtins.split escaped (builtins.toString value); + parts = builtins.filter builtins.isString raw; + in builtins.map (lib.strings.withContext value) parts; ## Check if a string starts with a given prefix. ## ## @type String -> String -> Bool - hasPrefix = prefix: value: let - text = builtins.substring 0 (builtins.stringLength prefix) value; - in + hasPrefix = + prefix: value: + let + text = builtins.substring 0 (builtins.stringLength prefix) value; + in text == prefix; ## Check if a string ends with a given suffix. ## ## @type String -> String -> Bool - hasSuffix = suffix: value: let - valueLength = builtins.stringLength value; - suffixLength = builtins.stringLength suffix; - text = builtins.substring (valueLength - suffixLength) valueLength value; - in - (valueLength >= suffixLength) - && text == suffix; + hasSuffix = + suffix: value: + let + valueLength = builtins.stringLength value; + suffixLength = builtins.stringLength suffix; + text = builtins.substring (valueLength - suffixLength) valueLength value; + in + (valueLength >= suffixLength) && text == suffix; ## Check if a string contains a given infix. ## ## @type String -> String -> Bool - hasInfix = infix: value: - builtins.match ".*${lib.strings.escape.regex infix}.*" "${value}" != null; + hasInfix = infix: value: builtins.match ".*${lib.strings.escape.regex infix}.*" "${value}" != null; ## Remove a prefix from a string if it exists. ## ## @type String -> String -> String - removePrefix = prefix: value: let - prefixLength = builtins.stringLength prefix; - valueLength = builtins.stringLength value; - in - if lib.strings.hasPrefix prefix value - then builtins.substring prefixLength (valueLength - prefixLength) value - else value; + removePrefix = + prefix: value: + let + prefixLength = builtins.stringLength prefix; + valueLength = builtins.stringLength value; + in + if lib.strings.hasPrefix prefix value then + builtins.substring prefixLength (valueLength - prefixLength) value + else + value; ## Remove a suffix from a string if it exists. ## ## @type String -> String -> String - removeSuffix = suffix: value: let - suffixLength = builtins.stringLength suffix; - valueLength = builtins.stringLength value; - in - if lib.strings.hasSuffix suffix value - then builtins.substring 0 (valueLength - suffixLength) value - else value; + removeSuffix = + suffix: value: + let + suffixLength = builtins.stringLength suffix; + valueLength = builtins.stringLength value; + in + if lib.strings.hasSuffix suffix value then + builtins.substring 0 (valueLength - suffixLength) value + else + value; ## Pad the start of a string with a character until it reaches ## a given length. ## ## @type Integer -> String -> String - padStart = length: char: value: let - valueLength = builtins.stringLength value; - padding = builtins.genList (_: char) (length - valueLength); - in - if valueLength < length - then (builtins.concatStringsSep "" padding) + value - else value; + padStart = + length: char: value: + let + valueLength = builtins.stringLength value; + padding = builtins.genList (_: char) (length - valueLength); + in + if valueLength < length then (builtins.concatStringsSep "" padding) + value else value; ## Pad the end of a string with a character until it reaches ## a given length. ## ## @type Integer -> String -> String - padEnd = length: char: value: let - valueLength = builtins.stringLength value; - padding = builtins.genList (_: char) (length - valueLength); - in - if valueLength < length - then value + (builtins.concatStringsSep "" padding) - else value; + padEnd = + length: char: value: + let + valueLength = builtins.stringLength value; + padding = builtins.genList (_: char) (length - valueLength); + in + if valueLength < length then value + (builtins.concatStringsSep "" padding) else value; }; } diff --git a/lib/src/strings/default.test.nix b/lib/src/strings/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/strings/default.test.nix +++ b/lib/src/strings/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/types/default.nix b/lib/src/types/default.nix index 4251e86..e088244 100644 --- a/lib/src/types/default.nix +++ b/lib/src/types/default.nix @@ -5,17 +5,12 @@ lib: { ## sets with a `__type__` symbol. ## ## @type String -> Attrs -> Bool - is = name: value: - value.__type__ or null == name; + is = name: value: value.__type__ or null == name; ## Assign a type to an attribute set. ## ## @type String -> Attrs -> Attrs - set = name: value: - value - // { - __type__ = name; - }; + set = name: value: value // { __type__ = name; }; ## Create a default functor for a type. This handles merging of type values ## by referencing wrapped and payload values. See the types implemented below @@ -24,11 +19,7 @@ lib: { ## @type String -> Attrs functor = name: { inherit name; - type = - lib.attrs.select - (lib.strings.split "." name) - null - lib.types; + type = lib.attrs.select (lib.strings.split "." name) null lib.types; wrapped = null; payload = null; merge = null; @@ -37,60 +28,61 @@ lib: { ## Merge two types. ## ## @type Attrs -> Attrs -> Attrs - merge = f: g: let - wrapped = f.wrapped.mergeType g.wrapped.functor; - payload = f.merge f.payload g.payload; - in - if f.name != g.name - then null - else if f.wrapped == null && g.wrapped == null && f.payload == null && g.payload == null - then f.type - else if f.wrapped != null && g.wrapped != null && wrapped != null - then f.type wrapped - else if f.payload != null && g.payload != null && payload != null - then f.type payload - else null; + merge = + f: g: + let + wrapped = f.wrapped.mergeType g.wrapped.functor; + payload = f.merge f.payload g.payload; + in + if f.name != g.name then + null + else if f.wrapped == null && g.wrapped == null && f.payload == null && g.payload == null then + f.type + else if f.wrapped != null && g.wrapped != null && wrapped != null then + f.type wrapped + else if f.payload != null && g.payload != null && payload != null then + f.type payload + else + null; ## Create a new type. ## ## @type Attrs -> Attrs - create = settings @ { - name, - description ? name, - fallback ? {}, - check ? lib.fp.const true, - merge ? lib.options.merge.default, - functor ? lib.types.functor name, - mergeType ? lib.types.merge functor, - getSubOptions ? lib.fp.const {}, - getSubModules ? null, - withSubModules ? lib.fp.const null, - children ? {}, - }: { - __type__ = "type"; - inherit - name - description - fallback - check - merge - functor - mergeType - getSubOptions - getSubModules - withSubModules - children - ; - }; + create = + settings@{ + name, + description ? name, + fallback ? { }, + check ? lib.fp.const true, + merge ? lib.options.merge.default, + functor ? lib.types.functor name, + mergeType ? lib.types.merge functor, + getSubOptions ? lib.fp.const { }, + getSubModules ? null, + withSubModules ? lib.fp.const null, + children ? { }, + }: + { + __type__ = "type"; + inherit + name + description + fallback + check + merge + functor + mergeType + getSubOptions + getSubModules + withSubModules + children + ; + }; ## Add a check to a type. ## ## @type Attrs -> (Any -> Bool) -> Attrs - withCheck = type: check: - type - // { - check = value: type.check value && check value; - }; + withCheck = type: check: type // { check = value: type.check value && check value; }; ## A type that allows any value and will only use a single definition. ## @@ -110,58 +102,63 @@ lib: { name = "Any"; description = "any"; check = lib.fp.const true; - merge = location: definitions: let - identifier = lib.options.getIdentifier location; - first = builtins.elemAt definitions 0; + merge = + location: definitions: + let + identifier = lib.options.getIdentifier location; + first = builtins.elemAt definitions 0; - files = builtins.map lib.modules.getFiles definitions; - serializedFiles = builtins.concatStringsSep " and " files; + files = builtins.map lib.modules.getFiles definitions; + serializedFiles = builtins.concatStringsSep " and " files; - getType = value: - if builtins.isAttrs value && lib.strings.validate.stringifiable value - then "StringifiableAttrs" - else builtins.typeOf value; + getType = + value: + if builtins.isAttrs value && lib.strings.validate.stringifiable value then + "StringifiableAttrs" + else + builtins.typeOf value; - commonType = - builtins.foldl' ( + commonType = builtins.foldl' ( type: definition: - if getType definition.value != type - then builtins.throw "The option `${identifier}` has conflicting definitions in ${files}" - else type - ) (getType first.value) - definitions; + if getType definition.value != type then + builtins.throw "The option `${identifier}` has conflicting definitions in ${files}" + else + type + ) (getType first.value) definitions; - mergeStringifiableAttrs = lib.options.merge.one; + mergeStringifiableAttrs = lib.options.merge.one; - mergeSet = (lib.types.attrs.of lib.types.any).merge; + mergeSet = (lib.types.attrs.of lib.types.any).merge; - mergeList = - if builtins.length definitions > 1 - then builtins.throw "The option `${identifier}` has conflicting definitions in ${files}" - else (lib.types.list.of lib.types.any).merge; + mergeList = + if builtins.length definitions > 1 then + builtins.throw "The option `${identifier}` has conflicting definitions in ${files}" + else + (lib.types.list.of lib.types.any).merge; - mergeLambda = location: definitions: x: let - resolvedLocation = location ++ [""]; - resolvedDefinitions = - builtins.map (definition: { - __file__ = definition.__file__; - value = definition.value x; - }) - definitions; + mergeLambda = + location: definitions: x: + let + resolvedLocation = location ++ [ "" ]; + resolvedDefinitions = builtins.map (definition: { + __file__ = definition.__file__; + value = definition.value x; + }) definitions; + in + lib.types.any.merge resolvedLocation resolvedDefinitions; + + merge = + if commonType == "set" then + mergeSet + else if commonType == "list" then + mergeList + else if commonType == "StringifiableAttrs" then + mergeStringifiableAttrs + else if commonType == "lambda" then + mergeLambda + else + lib.options.merge.equal; in - lib.types.any.merge resolvedLocation resolvedDefinitions; - - merge = - if commonType == "set" - then mergeSet - else if commonType == "list" - then mergeList - else if commonType == "StringifiableAttrs" - then mergeStringifiableAttrs - else if commonType == "lambda" - then mergeLambda - else lib.options.merge.equal; - in merge location definitions; }; @@ -195,107 +192,106 @@ lib: { merge = lib.options.merge.equal; }; - ints = let - description = start: end: "${builtins.toString start} and ${builtins.toString end} (inclusive)"; - ## Create a type that allows an integer value between a given range. - ## - ## @type Int -> Int -> Attrs - between = start: end: - assert lib.errors.trace (start <= end) "lib.types.ints.between start must be less than or equal to end"; - lib.types.withCheck - lib.types.int - (value: value >= start && value <= end) + ints = + let + description = start: end: "${builtins.toString start} and ${builtins.toString end} (inclusive)"; + ## Create a type that allows an integer value between a given range. + ## + ## @type Int -> Int -> Attrs + between = + start: end: + assert lib.errors.trace ( + start <= end + ) "lib.types.ints.between start must be less than or equal to end"; + lib.types.withCheck lib.types.int (value: value >= start && value <= end) // { name = "IntBetween"; description = "integer between ${description start end}"; }; - ## Create a type that allows an integer value between a given range with a specific - ## number of bits. - ## - ## @type Int -> Int -> Attrs - sign = bits: range: let - start = 0 - (range / 2); - end = range / 2 - 1; - in - between start end - // { - name = "IntSigned${builtins.toString bits}"; - description = "${builtins.toString bits} bit signed integer between ${description start end}"; - }; + ## Create a type that allows an integer value between a given range with a specific + ## number of bits. + ## + ## @type Int -> Int -> Attrs + sign = + bits: range: + let + start = 0 - (range / 2); + end = range / 2 - 1; + in + between start end + // { + name = "IntSigned${builtins.toString bits}"; + description = "${builtins.toString bits} bit signed integer between ${description start end}"; + }; - ## Create a type that allows an unsigned integer value between a given range with a specific - ## number of bits. - ## - ## @type Int -> Int -> Attrs - unsign = bits: range: let - start = 0; - end = range - 1; + ## Create a type that allows an unsigned integer value between a given range with a specific + ## number of bits. + ## + ## @type Int -> Int -> Attrs + unsign = + bits: range: + let + start = 0; + end = range - 1; + in + between start end + // { + name = "IntUnsigned${builtins.toString bits}"; + description = "${builtins.toString bits} bit unsigned integer between ${description start end}"; + }; in - between start end - // { - name = "IntUnsigned${builtins.toString bits}"; - description = "${builtins.toString bits} bit unsigned integer between ${description start end}"; - }; - in { - inherit between; + { + inherit between; - ## A type that allows a positive integer value. - ## - ## @type Attrs - positive = - lib.types.withCheck - lib.types.int - (value: value > 0) - // { + ## A type that allows a positive integer value. + ## + ## @type Attrs + positive = lib.types.withCheck lib.types.int (value: value > 0) // { name = "IntPositive"; description = "positive integer"; }; - ## A type that allows a positive integer value or zero. - ## - ## @type Attrs - unsigned = - lib.types.withCheck - lib.types.int - (value: value >= 0) - // { + ## A type that allows a positive integer value or zero. + ## + ## @type Attrs + unsigned = lib.types.withCheck lib.types.int (value: value >= 0) // { name = "IntUnsigned"; description = "unsigned integer"; }; - ## A type that allows an 8bit unsigned integer. - ## - ## @type Attrs - u8 = unsign 8 256; + ## A type that allows an 8bit unsigned integer. + ## + ## @type Attrs + u8 = unsign 8 256; - ## A type that allows a 16bit unsigned integer. - ## - ## @type Attrs - u16 = unsign 16 65536; + ## A type that allows a 16bit unsigned integer. + ## + ## @type Attrs + u16 = unsign 16 65536; - ## A type that allows a 32bit unsigned integer. - ## - ## @type Attrs - u32 = unsign 32 4294967296; + ## A type that allows a 32bit unsigned integer. + ## + ## @type Attrs + u32 = unsign 32 4294967296; - # u64 = unsign 64 18446744073709551616; + # u64 = unsign 64 18446744073709551616; - ## A type that allows an 8bit signed integer. - ## - ## @type Attrs - s8 = sign 8 256; + ## A type that allows an 8bit signed integer. + ## + ## @type Attrs + s8 = sign 8 256; - ## A type that allows a 16bit signed integer. - ## - ## @type Attrs - s16 = sign 16 65536; + ## A type that allows a 16bit signed integer. + ## + ## @type Attrs + s16 = sign 16 65536; - ## A type that allows a 32bit signed integer. - ## - ## @type Attrs - s32 = sign 32 4294967296; - }; + ## A type that allows a 32bit signed integer. + ## + ## @type Attrs + s32 = sign 32 4294967296; + }; ## A type that allows a floating point value. The merged definitions must all be ## the same. @@ -313,47 +309,42 @@ lib: { ## @type Attrs number = lib.types.either lib.types.int lib.types.float; - numbers = let - description = start: end: "${builtins.toString start} and ${builtins.toString end} (inclusive)"; - ## Create a type that allows a number value between a given range. - ## - ## @type Int -> Int -> Attrs - between = start: end: - assert lib.errors.trace (start <= end) "lib.types.numbers.between start must be less than or equal to end"; - lib.types.withCheck - lib.types.number - (value: value >= start && value <= end) + numbers = + let + description = start: end: "${builtins.toString start} and ${builtins.toString end} (inclusive)"; + ## Create a type that allows a number value between a given range. + ## + ## @type Int -> Int -> Attrs + between = + start: end: + assert lib.errors.trace ( + start <= end + ) "lib.types.numbers.between start must be less than or equal to end"; + lib.types.withCheck lib.types.number (value: value >= start && value <= end) // { name = "NumberBetween"; description = "numbereger between ${description start end}"; }; - in { - inherit between; + in + { + inherit between; - ## A type that allows a positive number value. - ## - ## @type Attrs - positive = - lib.types.withCheck - lib.types.int - (value: value > 0) - // { + ## A type that allows a positive number value. + ## + ## @type Attrs + positive = lib.types.withCheck lib.types.int (value: value > 0) // { name = "NumberPositive"; description = "positive number"; }; - ## A type that allows a positive number value or zero. - ## - ## @type Attrs - positiveOrZero = - lib.types.withCheck - lib.types.int - (value: value >= 0) - // { + ## A type that allows a positive number value or zero. + ## + ## @type Attrs + positiveOrZero = lib.types.withCheck lib.types.int (value: value >= 0) // { name = "NumberPositiveOrZero"; description = "number that is zero or greater"; }; - }; + }; ## A type that allows a port value. This values an unsigned 16bit integer. ## @@ -366,9 +357,11 @@ lib: { version = lib.types.create { name = "Version"; description = "version"; - check = value: let - parts = builtins.splitVersion value; - in + check = + value: + let + parts = builtins.splitVersion value; + in builtins.isString value && builtins.length parts > 0; merge = lib.options.merge.equal; }; @@ -400,7 +393,8 @@ lib: { ## definitions must all be the same. ## ## @type String -> Attrs - matching = pattern: + matching = + pattern: lib.types.create { name = "StringMatching ${pattern}"; description = "string matching the pattern ${pattern}"; @@ -412,44 +406,38 @@ lib: { ## definitions must all be the same. ## ## @type String -> Attrs - concat = separator: + concat = + separator: lib.types.create { name = "StringConcat"; description = - if separator == "" - then "concatenated string" - else "string concatenated with ${builtins.toJSON separator}"; + if separator == "" then + "concatenated string" + else + "string concatenated with ${builtins.toJSON separator}"; check = value: lib.types.string.check value; - merge = location: definitions: - builtins.concatStringsSep - separator - (lib.options.getDefinitionValues definitions); - functor = - lib.types.functor "strings.concat" - // { - payload = separator; - merge = x: y: - if x == y - then x - else null; - }; + merge = + location: definitions: + builtins.concatStringsSep separator (lib.options.getDefinitionValues definitions); + functor = lib.types.functor "strings.concat" // { + payload = separator; + merge = x: y: if x == y then x else null; + }; }; ## A type that allows a string value that is a single line with an optional new line ## at the end. ## ## @type Attrs - line = let - matcher = lib.types.strings.matching "[^\n\r]*\n?"; - in + line = + let + matcher = lib.types.strings.matching "[^\n\r]*\n?"; + in lib.types.create { name = "StringLine"; description = "single line string with an optional new line at the end"; check = matcher.check; - merge = location: definitions: - lib.strings.removeSuffix - "\n" - (matcher.merge location definitions); + merge = location: definitions: lib.strings.removeSuffix "\n" (matcher.merge location definitions); }; ## A type that allows a string value joined by new lines. @@ -466,45 +454,48 @@ lib: { any = lib.types.create { name = "Attrs"; description = "attribute set"; - fallback = {value = {};}; + fallback = { + value = { }; + }; check = builtins.isAttrs; - merge = location: definitions: - builtins.foldl' - (result: definition: result // definition.value) - {} - definitions; + merge = + location: definitions: + builtins.foldl' (result: definition: result // definition.value) { } definitions; }; ## Create a type that allows an attribute set containing a specific type of value. ## ## @type Attrs -> Attrs - of = type: + of = + type: lib.types.create { name = "AttrsOf"; description = "AttrsOf (${type.name})"; - fallback = {value = {};}; + fallback = { + value = { }; + }; check = builtins.isAttrs; - merge = location: definitions: let - normalize = definition: - builtins.mapAttrs - (name: value: { - __file__ = definition.__file__; - value = value; - }) - definition.value; - normalized = builtins.map normalize definitions; - zipper = name: definitions: - (lib.options.merge.definitions (location ++ [name]) type definitions).optional; - filtered = - lib.attrs.filter - (name: value: value ? value) - (builtins.zipAttrsWith zipper normalized); - in + merge = + location: definitions: + let + normalize = + definition: + builtins.mapAttrs (name: value: { + __file__ = definition.__file__; + value = value; + }) definition.value; + normalized = builtins.map normalize definitions; + zipper = + name: definitions: (lib.options.merge.definitions (location ++ [ name ]) type definitions).optional; + filtered = lib.attrs.filter (name: value: value ? value) (builtins.zipAttrsWith zipper normalized); + in builtins.mapAttrs (name: value: value.value) filtered; - getSubOptions = prefix: type.getSubOptions (prefix ++ [""]); + getSubOptions = prefix: type.getSubOptions (prefix ++ [ "" ]); getSubModules = type.getSubModules; withSubModules = modules: lib.types.attrs.of (type.withSubModules modules); - functor = lib.types.functor "attrs.of" // {wrapped = type;}; + functor = lib.types.functor "attrs.of" // { + wrapped = type; + }; children = { element = type; }; @@ -515,31 +506,39 @@ lib: { ## not support certain properties like `lib.modules.when`. ## ## @type Attrs -> Attrs - lazy = type: + lazy = + type: lib.types.create { name = "LazyAttrsOf"; description = "LazyAttrsOf (${type.name})"; - fallback = {value = {};}; + fallback = { + value = { }; + }; check = builtins.isAttrs; - merge = location: definitions: let - normalize = definition: - builtins.mapAttrs - (name: value: { - __file__ = definition.__file__; - value = value; - }) - definition.value; - normalized = builtins.map normalize definitions; - zipper = name: definitions: let - merged = lib.options.merge.definitions (location ++ [name]) type definitions; + merge = + location: definitions: + let + normalize = + definition: + builtins.mapAttrs (name: value: { + __file__ = definition.__file__; + value = value; + }) definition.value; + normalized = builtins.map normalize definitions; + zipper = + name: definitions: + let + merged = lib.options.merge.definitions (location ++ [ name ]) type definitions; + in + merged.optional.value or type.fallback.value or merged.merged; in - merged.optional.value or type.fallback.value or merged.merged; - in builtins.zipAttrsWith zipper normalized; - getSubOptions = prefix: type.getSubOptions (prefix ++ [""]); + getSubOptions = prefix: type.getSubOptions (prefix ++ [ "" ]); getSubModules = type.getSubModules; withSubModules = modules: lib.types.attrs.lazy (type.withSubModules modules); - functor = lib.types.functor "attrs.lazy" // {wrapped = type;}; + functor = lib.types.functor "attrs.lazy" // { + wrapped = type; + }; children = { element = type; }; @@ -553,12 +552,15 @@ lib: { name = "Derivation"; description = "derivation"; check = value: lib.packages.isDerivation value || lib.paths.validate.store value; - merge = location: definitions: let - merged = lib.options.merge.one location definitions; - in - if builtins.isPath merged || (builtins.isString merged && !(builtins.hasContext merged)) - then lib.paths.into.drv merged - else merged; + merge = + location: definitions: + let + merged = lib.options.merge.one location definitions; + in + if builtins.isPath merged || (builtins.isString merged && !(builtins.hasContext merged)) then + lib.paths.into.drv merged + else + merged; }; derivations = { @@ -566,11 +568,9 @@ lib: { ## `shellPath` attribute. ## ## @type Attrs - shell = - lib.types.derivation - // { - check = value: lib.packages.isDerivation && builtins.hasAttr "shellPath" value; - }; + shell = lib.types.derivation // { + check = value: lib.packages.isDerivation && builtins.hasAttr "shellPath" value; + }; }; ## A type that allows a path value. The merged definitions must all be the same. @@ -579,9 +579,9 @@ lib: { path = lib.types.create { name = "Path"; description = "path"; - check = value: - lib.strings.validate.stringifiable value - && builtins.substring 0 1 (builtins.toString value) == "/"; + check = + value: + lib.strings.validate.stringifiable value && builtins.substring 0 1 (builtins.toString value) == "/"; merge = lib.options.merge.equal; }; @@ -594,21 +594,25 @@ lib: { ## Create a type that allows a list containing a specific type of value. ## ## @type Attrs -> Attrs - of = type: + of = + type: lib.types.create { name = "ListOf"; description = "ListOf (${type.name})"; - fallback = {value = [];}; + fallback = { + value = [ ]; + }; check = builtins.isList; - merge = location: definitions: let - result = - lib.lists.mapWithIndex1 ( + merge = + location: definitions: + let + result = lib.lists.mapWithIndex1 ( i: definition: - lib.lists.mapWithIndex1 ( - j: value: let - resolved = - lib.options.merge.definitions - (location ++ ["[definition ${builtins.toString i}-entry ${j}]"]) + lib.lists.mapWithIndex1 ( + j: value: + let + resolved = + lib.options.merge.definitions (location ++ [ "[definition ${builtins.toString i}-entry ${j}]" ]) type [ { @@ -616,21 +620,21 @@ lib: { value = value; } ]; - in - resolved.optional - ) - definition.value - ) - definitions; - merged = builtins.concatLists result; - filtered = builtins.filter (definition: definition ? value) merged; - values = lib.options.getDefinitionValues filtered; - in + in + resolved.optional + ) definition.value + ) definitions; + merged = builtins.concatLists result; + filtered = builtins.filter (definition: definition ? value) merged; + values = lib.options.getDefinitionValues filtered; + in values; - getSubOptions = prefix: type.getSubOptions (prefix ++ ["*"]); + getSubOptions = prefix: type.getSubOptions (prefix ++ [ "*" ]); getSubModules = type.getSubModules; withSubModules = modules: lib.types.list.of (type.withSubModules modules); - functor = lib.types.functor "list.of" // {wrapped = type;}; + functor = lib.types.functor "list.of" // { + wrapped = type; + }; children = { element = type; }; @@ -639,20 +643,20 @@ lib: { ## A type that allows a non-empty list containing a specific type of value. ## ## @type Attrs -> Attrs - required = type: - lib.types.withCheck - (lib.types.list.of type) - (value: value != []) + required = + type: + lib.types.withCheck (lib.types.list.of type) (value: value != [ ]) // { description = "non-empty list of ${type.description}"; - fallback = {}; + fallback = { }; }; }; ## Create a type that must be a unique value. ## ## @type String -> Attrs -> Attrs - unique = message: type: + unique = + message: type: lib.types.create { name = "Unique"; description = type.description; @@ -662,7 +666,9 @@ lib: { getSubOptions = type.getSubOptions; getSubModules = type.getSubModules; withSubModules = modules: lib.types.unique message (type.withSubModules modules); - functor = lib.types.functor "unique" // {wrapped = type;}; + functor = lib.types.functor "unique" // { + wrapped = type; + }; children = { element = type; }; @@ -672,7 +678,8 @@ lib: { ## does not merge the definitions. ## ## @type Attrs -> Attrs - single = type: + single = + type: lib.types.create { name = "Single"; description = type.description; @@ -682,7 +689,9 @@ lib: { getSubOptions = type.getSubOptions; getSubModules = type.getSubModules; withSubModules = modules: lib.types.single (type.withSubModules modules); - functor = lib.types.functor "unique" // {wrapped = type;}; + functor = lib.types.functor "unique" // { + wrapped = type; + }; children = { element = type; }; @@ -691,27 +700,35 @@ lib: { ## Create a type that may be either a given type or null. ## ## @type Attrs -> Attrs - nullish = type: + nullish = + type: lib.types.create { name = "Nullish"; description = "null or ${type.description}"; - fallback = {value = null;}; + fallback = { + value = null; + }; check = value: value == null || type.check value; - merge = location: definitions: let - identifier = lib.options.getIdentifier location; - files = builtins.map lib.modules.getFiles definitions; - serializedFiles = builtins.concatStringsSep " and " files; - totalNulls = lib.lists.count (definition: definition == null) definitions; - in - if totalNulls == builtins.length definitions - then null - else if totalNulls != 0 - then builtins.throw "The option `${identifier}` is defined as both null and not null in ${serializedFiles}" - else type.merge location definitions; + merge = + location: definitions: + let + identifier = lib.options.getIdentifier location; + files = builtins.map lib.modules.getFiles definitions; + serializedFiles = builtins.concatStringsSep " and " files; + totalNulls = lib.lists.count (definition: definition == null) definitions; + in + if totalNulls == builtins.length definitions then + null + else if totalNulls != 0 then + builtins.throw "The option `${identifier}` is defined as both null and not null in ${serializedFiles}" + else + type.merge location definitions; getSubOptions = type.getSubOptions; getSubModules = type.getSubModules; withSubModules = modules: lib.types.nullish (type.withSubModules modules); - functor = lib.types.functor "nullish" // {wrapped = type;}; + functor = lib.types.functor "nullish" // { + wrapped = type; + }; children = { element = type; }; @@ -720,24 +737,29 @@ lib: { ## Create a type that allows a function which returns a given type. ## ## @type Attrs -> Attrs - function = type: + function = + type: lib.types.create { name = "Function"; description = "function that returns ${type.description}"; check = builtins.isFunction; - merge = location: definitions: args: let - normalize = definition: { - __file__ = definition.__file__; - value = definition.value args; - }; - normalized = builtins.map normalize definitions; - merged = lib.options.merge.definitions (location ++ [""]) type normalized; - in + merge = + location: definitions: args: + let + normalize = definition: { + __file__ = definition.__file__; + value = definition.value args; + }; + normalized = builtins.map normalize definitions; + merged = lib.options.merge.definitions (location ++ [ "" ]) type normalized; + in merged.merged; - getSubOptions = prefix: type.getSubOptions (prefix ++ [""]); + getSubOptions = prefix: type.getSubOptions (prefix ++ [ "" ]); getSubModules = type.getSubModules; withSubModules = modules: lib.types.function (type.withSubModules modules); - functor = lib.types.functor "function" // {wrapped = type;}; + functor = lib.types.functor "function" // { + wrapped = type; + }; children = { element = type; }; @@ -746,10 +768,7 @@ lib: { ## Create a submodule from a list of modules (or a module directly). ## ## @type (Module | (List Module)) -> Attrs - submodule = modules: - lib.types.submodules.of { - modules = lib.lists.from.any modules; - }; + submodule = modules: lib.types.submodules.of { modules = lib.lists.from.any modules; }; submodules = { ## Create a type from a list of submodules. This is particularly useful for use @@ -757,118 +776,127 @@ lib: { ## dynamic types. ## ## @type { modules :: List Module, args? :: Attrs, description? :: String | Null, shorthand? :: Bool } -> Attrs - of = settings @ { - modules, - args ? {}, - description ? null, - shorthand ? true, - }: let - getModules = builtins.map ( - definition: - if shorthand && builtins.isAttrs definition.value - then let - # TODO: Figure out if we can apply additional attributes to the generated module. - # Currently this causes issues to do with redefined options. - rest = - builtins.removeAttrs - (lib.attrs.filter (name: value: builtins.elem name lib.modules.VALID_KEYS) definition.value) - ["freeform"]; - in - if definition.value ? config - then + of = + settings@{ + modules, + args ? { }, + description ? null, + shorthand ? true, + }: + let + getModules = builtins.map ( + definition: + if shorthand && builtins.isAttrs definition.value then + let + # TODO: Figure out if we can apply additional attributes to the generated module. + # Currently this causes issues to do with redefined options. + rest = builtins.removeAttrs (lib.attrs.filter ( + name: value: builtins.elem name lib.modules.VALID_KEYS + ) definition.value) [ "freeform" ]; + in + if definition.value ? config then rest // { __file__ = definition.__file__; config = definition.value.config; } - else let - config = builtins.removeAttrs definition.value lib.modules.VALID_KEYS; - in + else + let + config = builtins.removeAttrs definition.value lib.modules.VALID_KEYS; + in rest // { __file__ = definition.__file__; config = config; } - else { - __file__ = definition.__file__; - includes = [definition.value]; - } - ); - - base = lib.modules.run { - inherit args; - - modules = - [ + else { - config.__module__.args.dynamic.name = lib.modules.overrides.default ""; + __file__ = definition.__file__; + includes = [ definition.value ]; } - ] - ++ modules; - }; + ); - freeform = base.__module__.freeform; - name = "Submodule"; - in + base = lib.modules.run { + inherit args; + + modules = [ + { config.__module__.args.dynamic.name = lib.modules.overrides.default ""; } + ] ++ modules; + }; + + freeform = base.__module__.freeform; + name = "Submodule"; + in lib.types.create { inherit name; - description = - if description != null - then description - else freeform.description or name; - fallback = {value = {};}; - check = value: builtins.isAttrs value || builtins.isFunction value || lib.types.path.check value; - merge = location: definitions: let - result = base.extend { - prefix = location; - modules = - [{config.__module__.args.dynamic.name = lib.lists.last location;}] - ++ getModules definitions; - }; - in - result.config; - getSubOptions = prefix: let - result = base.extend {inherit prefix;}; - in - result.options - // lib.attrs.when (freeform != null) { - __freeformOptions__ = freeform.getSubOptions prefix; - }; - getSubModules = modules; - withSubModules = modules: - lib.types.submodules.of { - inherit args description modules shorthand; - }; - children = lib.attrs.when (freeform != null) { - inherit freeform; + description = if description != null then description else freeform.description or name; + fallback = { + value = { }; }; - functor = - lib.types.functor "submodule" - // { - type = lib.types.submodules.of; - payload = { - inherit modules args description shorthand; + check = value: builtins.isAttrs value || builtins.isFunction value || lib.types.path.check value; + merge = + location: definitions: + let + result = base.extend { + prefix = location; + modules = [ + { config.__module__.args.dynamic.name = lib.lists.last location; } + ] ++ getModules definitions; }; - merge = x: y: { - modules = x.modules ++ y.modules; + in + result.config; + getSubOptions = + prefix: + let + result = base.extend { inherit prefix; }; + in + result.options + // lib.attrs.when (freeform != null) { __freeformOptions__ = freeform.getSubOptions prefix; }; + getSubModules = modules; + withSubModules = + modules: + lib.types.submodules.of { + inherit + args + description + modules + shorthand + ; + }; + children = lib.attrs.when (freeform != null) { inherit freeform; }; + functor = lib.types.functor "submodule" // { + type = lib.types.submodules.of; + payload = { + inherit + modules + args + description + shorthand + ; + }; + merge = x: y: { + modules = x.modules ++ y.modules; - args = let + args = + let intersection = builtins.intersectAttrs x.args y.args; in - if intersection == {} - then x.args // y.args - else builtins.throw "A submodule option is declared multiple times with the same args: ${builtins.toString (builtins.attrNames intersection)}"; + if intersection == { } then + x.args // y.args + else + builtins.throw "A submodule option is declared multiple times with the same args: ${builtins.toString (builtins.attrNames intersection)}"; - description = - if x.description == null - then y.description - else if y.description == null - then x.description - else if x.description == y.description - then x.description - else builtins.throw "A submodule description is declared multiple times with conflicting values"; - }; + description = + if x.description == null then + y.description + else if y.description == null then + x.description + else if x.description == y.description then + x.description + else + builtins.throw "A submodule description is declared multiple times with conflicting values"; }; + }; }; }; @@ -876,17 +904,17 @@ lib: { ## A module that is imported in another part of the configuration. ## ## @type Attrs - default = lib.types.deferred.of { - modules = []; - }; + default = lib.types.deferred.of { modules = [ ]; }; ## Create a submodule type from a list of modules which will be imported in ## another part of the configuration. ## ## @type { modules :: List Module } -> Attrs - of = settings @ {modules}: let - submodule = lib.types.submodule modules; - in + of = + settings@{ modules }: + let + submodule = lib.types.submodule modules; + in lib.types.create { name = "Deferred"; description = "module"; @@ -894,28 +922,21 @@ lib: { merge = location: definitions: { includes = modules - ++ builtins.map - (definition: { + ++ builtins.map (definition: { __file__ = "${definition.__file__}; via ${lib.options.getIdentifier location}"; - includes = [definition.value]; - }) - definitions; + includes = [ definition.value ]; + }) definitions; }; getSubOptions = submodule.getSubOptions; getSubModules = submodule.getSubModules; - withSubModules = modules: - lib.types.deferred.of { - modules = modules; - }; - functor = - lib.types.functor "deferred.of" - // { - type = lib.types.deferred.of; - payload = {inherit modules;}; - merge = x: y: { - modules = x.modules ++ y.modules; - }; + withSubModules = modules: lib.types.deferred.of { modules = modules; }; + functor = lib.types.functor "deferred.of" // { + type = lib.types.deferred.of; + payload = { + inherit modules; }; + merge = x: y: { modules = x.modules ++ y.modules; }; + }; }; }; @@ -936,86 +957,94 @@ lib: { name = "Option"; description = "option"; check = lib.types.is "option"; - merge = location: definitions: let - first = builtins.elemAt definitions 0; - modules = - builtins.map (definition: { + merge = + location: definitions: + let + first = builtins.elemAt definitions 0; + modules = builtins.map (definition: { __file__ = definition.__file__; - options = lib.options.create { - type = definition.value; - }; - }) - definitions; - merged = lib.modules.fixup location (lib.options.merge.declarations location modules); - in - if builtins.length definitions == 1 - then first.value - else merged.type; + options = lib.options.create { type = definition.value; }; + }) definitions; + merged = lib.modules.fixup location (lib.options.merge.declarations location modules); + in + if builtins.length definitions == 1 then first.value else merged.type; }; ## Create a type that allows a specific primitive value from a given list. ## ## @type List Any -> Attrs - enum = values: let - serialize = value: - if builtins.isString value - then ''"${value}"'' - else if builtins.isInt value - then builtins.toString value - else if builtins.isBool value - then lib.bools.into.string value - else ''<${builtins.typeOf value}>''; - in + enum = + values: + let + serialize = + value: + if builtins.isString value then + ''"${value}"'' + else if builtins.isInt value then + builtins.toString value + else if builtins.isBool value then + lib.bools.into.string value + else + ''<${builtins.typeOf value}>''; + in lib.types.create { name = "Enum"; description = - if values == [] - then "empty enum" - else if builtins.length values == 1 - then "value ${serialize (builtins.elemAt values 0)} (singular enum)" - else "one of ${lib.strings.concatMapSep ", " serialize values}"; + if values == [ ] then + "empty enum" + else if builtins.length values == 1 then + "value ${serialize (builtins.elemAt values 0)} (singular enum)" + else + "one of ${lib.strings.concatMapSep ", " serialize values}"; check = value: builtins.elem value values; merge = lib.options.merge.equal; - functor = - lib.types.functor "enum" - // { - payload = values; - merge = x: y: lib.lists.unique (x ++ y); - }; + functor = lib.types.functor "enum" // { + payload = values; + merge = x: y: lib.lists.unique (x ++ y); + }; }; ## Create a type that allows either of two types. ## ## @type Attrs -> Attrs -> Attrs - either = left: right: let - name = "Either"; - functor = - lib.types.functor name - // { - wrapped = [left right]; + either = + left: right: + let + name = "Either"; + functor = lib.types.functor name // { + wrapped = [ + left + right + ]; }; - in + in lib.types.create { inherit name functor; description = "${left.description} or ${right.description}"; check = value: left.check value || right.check value; - merge = location: definitions: let - values = lib.options.getDefinitionValues definitions; - isLeft = builtins.all left.check values; - isRight = builtins.all right.check values; - in - if isLeft - then left.merge location definitions - else if isRight - then right.merge location definitions - else lib.options.merge.one location definitions; - mergeType = f: let - mergedLeft = left.mergeType (builtins.elemAt f.wrapped 0).functor; - mergedRight = right.mergeType (builtins.elemAt f.wrapped 1).functor; - in - if (f.name == name) && (mergedLeft != null) && (mergedRight != null) - then functor.type mergedLeft mergedRight - else null; + merge = + location: definitions: + let + values = lib.options.getDefinitionValues definitions; + isLeft = builtins.all left.check values; + isRight = builtins.all right.check values; + in + if isLeft then + left.merge location definitions + else if isRight then + right.merge location definitions + else + lib.options.merge.one location definitions; + mergeType = + f: + let + mergedLeft = left.mergeType (builtins.elemAt f.wrapped 0).functor; + mergedRight = right.mergeType (builtins.elemAt f.wrapped 1).functor; + in + if (f.name == name) && (mergedLeft != null) && (mergedRight != null) then + functor.type mergedLeft mergedRight + else + null; children = { inherit left right; }; @@ -1024,50 +1053,48 @@ lib: { ## Create a type that allows a value of one of the given types. ## ## @type List Attrs -> Attrs - one = types: let - first = builtins.elemAt types 0; - rest = builtins.tail types; - in - if types == [] - then builtins.throw "lib.types.one must be given at least one type" - else builtins.foldl' lib.types.either first rest; + one = + types: + let + first = builtins.elemAt types 0; + rest = builtins.tail types; + in + if types == [ ] then + builtins.throw "lib.types.one must be given at least one type" + else + builtins.foldl' lib.types.either first rest; ## Create a type that allows a value which is either the final type or is transformable ## to the final type. ## ## @type Attrs -> (Any -> Any) -> Attrs -> Attrs - coerce = initial: transform: final: let - in - if initial.getSubModules != null - then builtins.throw "lib.types.coerce's first argument may not have submodules, but got ${initial.description}" + coerce = + initial: transform: final: + let + in + if initial.getSubModules != null then + builtins.throw "lib.types.coerce's first argument may not have submodules, but got ${initial.description}" else lib.types.create { name = "Coerce"; description = "${initial.description} that is transformed to ${final.description}"; fallback = final.fallback; check = value: final.check value || (initial.check value && final.check (transform value)); - merge = location: definitions: let - process = value: - if initial.check value - then transform value - else value; - normalize = definition: - definition - // { - value = process definition.value; - }; - normalized = builtins.map normalize definitions; - in + merge = + location: definitions: + let + process = value: if initial.check value then transform value else value; + normalize = definition: definition // { value = process definition.value; }; + normalized = builtins.map normalize definitions; + in final.merge location normalized; getSubOptions = final.getSubOptions; getSubModules = final.getSubModules; - withSubModules = modules: - lib.types.coerce - initial - transform - (final.withSubModules modules); + withSubModules = modules: lib.types.coerce initial transform (final.withSubModules modules); mergeType = x: y: null; - functor = lib.types.functor "coerce" // {wrapped = final;}; + functor = lib.types.functor "coerce" // { + wrapped = final; + }; children = { inherit initial final; }; @@ -1077,19 +1104,23 @@ lib: { ## Create a type that allows a DAG (Directed Acyclic Graph) of a given type. ## ## @type Attrs -> Attrs - of = type: let - resolved = lib.types.attrs.of (lib.types.dag.entry type); - in + of = + type: + let + resolved = lib.types.attrs.of (lib.types.dag.entry type); + in lib.types.create { name = "Dag"; description = "Dag of ${type.description}"; check = resolved.check; merge = resolved.merge; fallback = resolved.fallback; - getSubOptions = prefix: type.getSubOptions (prefix ++ [""]); + getSubOptions = prefix: type.getSubOptions (prefix ++ [ "" ]); getSubModules = type.getSubModules; withSubModules = modules: lib.types.dag.of (type.withSubModules modules); - functor = lib.types.functor "dag.of" // {wrapped = type;}; + functor = lib.types.functor "dag.of" // { + wrapped = type; + }; children = { element = type; resolved = resolved; @@ -1099,43 +1130,40 @@ lib: { ## Create a type that allows a DAG entry of a given type. ## ## @type Attrs -> Attrs - entry = type: let - submodule = lib.types.submodule ({name}: { - options = { - value = lib.options.create { - type = type; - }; - before = lib.options.create { - type = lib.types.list.of lib.types.string; - }; - after = lib.options.create { - type = lib.types.list.of lib.types.string; - }; - }; - }); - normalize = definition: let - value = - if definition ? priority - then lib.modules.order definition.priority definition.value - else definition.value; + entry = + type: + let + submodule = lib.types.submodule ( + { name }: + { + options = { + value = lib.options.create { type = type; }; + before = lib.options.create { type = lib.types.list.of lib.types.string; }; + after = lib.options.create { type = lib.types.list.of lib.types.string; }; + }; + } + ); + normalize = + definition: + let + value = + if definition ? priority then + lib.modules.order definition.priority definition.value + else + definition.value; + in + if lib.dag.validate.entry definition.value then definition.value else lib.dag.entry.anywhere value; in - if lib.dag.validate.entry definition.value - then definition.value - else lib.dag.entry.anywhere value; - in lib.types.create { name = "DagEntry"; description = "DagEntry (${type.description})"; - merge = location: definitions: - submodule.merge - location - ( - builtins.map - (definition: { + merge = + location: definitions: + submodule.merge location ( + builtins.map (definition: { __file__ = definition.__file__; value = normalize definition; - }) - definitions + }) definitions ); }; }; diff --git a/lib/src/types/default.test.nix b/lib/src/types/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/types/default.test.nix +++ b/lib/src/types/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/lib/src/versions/default.nix b/lib/src/versions/default.nix index 7225eea..e58e213 100644 --- a/lib/src/versions/default.nix +++ b/lib/src/versions/default.nix @@ -28,25 +28,31 @@ lib: { ## Get the major version from a version string. ## ## @type String -> String - major = version: let - parts = builtins.splitVersion version; - in + major = + version: + let + parts = builtins.splitVersion version; + in builtins.elemAt parts 0; ## Get the minor version from a version string. ## ## @type String -> String - minor = version: let - parts = builtins.splitVersion version; - in + minor = + version: + let + parts = builtins.splitVersion version; + in builtins.elemAt parts 1; ## Get the patch version from a version string. ## ## @type String -> String - patch = version: let - parts = builtins.splitVersion version; - in + patch = + version: + let + parts = builtins.splitVersion version; + in builtins.elemAt parts 2; }; } diff --git a/lib/src/versions/default.test.nix b/lib/src/versions/default.test.nix index 00ebf8d..2c21ad2 100644 --- a/lib/src/versions/default.test.nix +++ b/lib/src/versions/default.test.nix @@ -1,3 +1,4 @@ let lib = import ./../default.nix; -in {} +in +{ } diff --git a/tidepool/src/builders/basic.nix b/tidepool/src/builders/basic.nix index 2ee4109..125ff64 100644 --- a/tidepool/src/builders/basic.nix +++ b/tidepool/src/builders/basic.nix @@ -1,80 +1,76 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.builders.basic; lib' = config.lib; inherit (config) foundation; -in { +in +{ config.builders = { basic = { executable = "${foundation.stage2-bash}/bin/bash"; - build = package: let - phases = package.phases; - sorted = lib.dag.sort.topographic phases; + build = + package: + let + phases = package.phases; + sorted = lib.dag.sort.topographic phases; - script = - lib.strings.concatMapSep "\n" ( - entry: - if builtins.isFunction entry.value - then entry.value package - else entry.value - ) - sorted.result; + script = lib.strings.concatMapSep "\n" ( + entry: if builtins.isFunction entry.value then entry.value package else entry.value + ) sorted.result; - system = package.platform.build.double; + system = package.platform.build.double; - built = builtins.derivation ( - package.env - // { - inherit (package) name; - inherit script system; + built = builtins.derivation ( + package.env + // { + inherit (package) name; + inherit script system; - passAsFile = ["script"]; + passAsFile = [ "script" ]; - SHELL = cfg.executable; + SHELL = cfg.executable; - PATH = let - bins = lib.paths.bin ( - (lib'.packages.dependencies.getPackages package.deps.build.host) - ++ [ - foundation.stage2-bash - foundation.stage2-coreutils - ] - ); - in - builtins.concatStringsSep ":" ([bins] ++ (lib.lists.when (package.env ? PATH) [package.env.PATH])); + PATH = + let + bins = lib.paths.bin ( + (lib'.packages.dependencies.getPackages package.deps.build.host) + ++ [ + foundation.stage2-bash + foundation.stage2-coreutils + ] + ); + in + builtins.concatStringsSep ":" ( + [ bins ] ++ (lib.lists.when (package.env ? PATH) [ package.env.PATH ]) + ); - builder = cfg.executable; + builder = cfg.executable; - args = [ - "-e" - (builtins.toFile "bash-builder.sh" '' - export CONFIG_SHELL=$SHELL + args = [ + "-e" + (builtins.toFile "bash-builder.sh" '' + export CONFIG_SHELL=$SHELL - # Normalize the NIX_BUILD_CORES variable. The value might be 0, which - # means that we're supposed to try and auto-detect the number of - # available CPU cores at run-time. - NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" - if ((NIX_BUILD_CORES <= 0)); then - guess=$(nproc 2>/dev/null || true) - ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) - fi - export NIX_BUILD_CORES + # Normalize the NIX_BUILD_CORES variable. The value might be 0, which + # means that we're supposed to try and auto-detect the number of + # available CPU cores at run-time. + NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" + if ((NIX_BUILD_CORES <= 0)); then + guess=$(nproc 2>/dev/null || true) + ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) + fi + export NIX_BUILD_CORES - bash -eux $scriptPath - '') - ]; - } - ); - in - built - // { - inherit (package) meta; - }; + bash -eux $scriptPath + '') + ]; + } + ); + in + built // { inherit (package) meta; }; }; }; } diff --git a/tidepool/src/builders/default.nix b/tidepool/src/builders/default.nix index 7cb7012..7d68594 100644 --- a/tidepool/src/builders/default.nix +++ b/tidepool/src/builders/default.nix @@ -1,18 +1,15 @@ -{ - lib, - config, -}: let +{ lib, config }: +let lib' = config.lib; -in { - includes = [ - ./basic.nix - ]; +in +{ + includes = [ ./basic.nix ]; options = { builders = lib.options.create { description = "A set of builders that can be used to build packages."; type = lib.types.attrs.of lib'.types.builder; - default.value = {}; + default.value = { }; }; }; } diff --git a/tidepool/src/export.nix b/tidepool/src/export.nix index 880c25d..9909928 100644 --- a/tidepool/src/export.nix +++ b/tidepool/src/export.nix @@ -1,11 +1,10 @@ # This file handles creating all of the exports for this project and is not # exported itself. -{ - lib, - config, -}: let +{ lib, config }: +let lib' = config.lib; -in { +in +{ freeform = lib.types.any; config = { diff --git a/tidepool/src/exports/lib.nix b/tidepool/src/exports/lib.nix index 89da50c..a839ac2 100644 --- a/tidepool/src/exports/lib.nix +++ b/tidepool/src/exports/lib.nix @@ -1,16 +1,11 @@ +{ lib, config }: +let +in { - lib, - config, -}: let -in { options = { - exports.lib = lib.options.create { - default.value = {}; - }; + exports.lib = lib.options.create { default.value = { }; }; - exported.lib = lib.options.create { - default.value = {}; - }; + exported.lib = lib.options.create { default.value = { }; }; }; config = { diff --git a/tidepool/src/exports/modules.nix b/tidepool/src/exports/modules.nix index 69f9f36..4116257 100644 --- a/tidepool/src/exports/modules.nix +++ b/tidepool/src/exports/modules.nix @@ -1,7 +1,5 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.exports; type = lib.types.one [ @@ -9,12 +7,13 @@ (lib.types.attrs.any) (lib.types.function lib.types.attrs.any) ]; -in { +in +{ options = { exports = { modules = lib.options.create { type = lib.types.attrs.of type; - default.value = {}; + default.value = { }; description = "An attribute set of modules to export."; }; }; @@ -22,7 +21,7 @@ in { exported = { modules = lib.options.create { type = lib.types.attrs.of type; - default.value = {}; + default.value = { }; description = "An attribute set of modules to export."; }; }; diff --git a/tidepool/src/exports/packages.nix b/tidepool/src/exports/packages.nix index 111c34c..fbe7b5f 100644 --- a/tidepool/src/exports/packages.nix +++ b/tidepool/src/exports/packages.nix @@ -1,53 +1,45 @@ -{ - config, - lib, -}: let +{ config, lib }: +let lib' = config.lib; -in { +in +{ options = { exports.packages = lib.options.create { type = lib.types.attrs.of (lib'.types.raw); - default.value = {}; + default.value = { }; }; exported.packages = lib.options.create { type = lib.types.attrs.of (lib.types.attrs.of lib.types.derivation); - default.value = {}; + default.value = { }; }; }; config = { - exported.packages = let - all = lib.attrs.generate lib'.systems.doubles.all ( - system: let - all = - builtins.mapAttrs - ( - name: package: let + exported.packages = + let + all = lib.attrs.generate lib'.systems.doubles.all ( + system: + let + all = builtins.mapAttrs ( + name: package: + let result = lib'.packages.build package system system system; in - result - ) - config.exports.packages; + result + ) config.exports.packages; - available = - lib.attrs.filter - (name: package: builtins.elem system package.meta.platforms) - all; + available = lib.attrs.filter (name: package: builtins.elem system package.meta.platforms) all; - packages = - builtins.mapAttrs - (name: package: package.package) - available; - in + packages = builtins.mapAttrs (name: package: package.package) available; + in packages - ); + ); - available = - lib.attrs.filter - (system: packages: builtins.length (builtins.attrNames packages) != 0) - all; - in + available = lib.attrs.filter ( + system: packages: builtins.length (builtins.attrNames packages) != 0 + ) all; + in available; }; } diff --git a/tidepool/src/lib/default.nix b/tidepool/src/lib/default.nix index 573c40e..9e4fc09 100644 --- a/tidepool/src/lib/default.nix +++ b/tidepool/src/lib/default.nix @@ -1,9 +1,8 @@ -{ - lib, - config, -}: let +{ lib, config }: +let cfg = config.lib; -in { +in +{ includes = [ ./options.nix ./packages.nix @@ -14,7 +13,7 @@ in { options = { lib = lib.options.create { type = lib.types.attrs.any; - default.value = {}; + default.value = { }; description = "An attribute set of values to be added to `lib`."; apply = value: lib.extend (final: prev: prev.attrs.mergeRecursive prev value); }; diff --git a/tidepool/src/lib/options.nix b/tidepool/src/lib/options.nix index daf3531..96c9ec0 100644 --- a/tidepool/src/lib/options.nix +++ b/tidepool/src/lib/options.nix @@ -1,8 +1,7 @@ +{ lib, config }: +let +in { - lib, - config, -}: let -in { config = { lib.options = { package = lib.options.create { diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index 11d152d..1b1ae7b 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -2,63 +2,76 @@ lib, lib', config, -}: { +}: +{ config = { lib.packages = { dependencies = { - getPackages = dependencies: let - available = - builtins.filter - (dependency: !(builtins.isNull dependency)) - (builtins.attrValues dependencies); - in + getPackages = + dependencies: + let + available = builtins.filter (dependency: !(builtins.isNull dependency)) ( + builtins.attrValues dependencies + ); + in builtins.map (dependency: dependency.package) available; }; - getLatest = alias: let - versions = builtins.attrNames alias.versions; - sorted = builtins.sort (lib.versions.gte) versions; - in + getLatest = + alias: + let + versions = builtins.attrNames alias.versions; + sorted = builtins.sort (lib.versions.gte) versions; + in builtins.head sorted; - build = package: build: host: target: let - resolved = - if package ? versions - then package.versions.${config.preferences.packages.version} or (package.versions.${lib'.packages.getLatest package}) - else package; + build = + package: build: host: target: + let + resolved = + if package ? versions then + package.versions.${config.preferences.packages.version} + or (package.versions.${lib'.packages.getLatest package}) + else + package; - buildDependencies = build': host': target': builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); + buildDependencies = + build': host': target': + builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); - result = resolved.extend ({config}: { - config = { - platform = { - build = build; - host = host; - target = lib.modules.override 150 target; - }; + result = resolved.extend ( + { config }: + { + config = { + platform = { + build = build; + host = host; + target = lib.modules.override 150 target; + }; - deps = { - build = { - only = buildDependencies build build build resolved.deps.build.only; - build = buildDependencies build build target resolved.deps.build.build; - host = buildDependencies build host target resolved.deps.build.host; - target = buildDependencies build target target resolved.deps.build.target; + deps = { + build = { + only = buildDependencies build build build resolved.deps.build.only; + build = buildDependencies build build target resolved.deps.build.build; + host = buildDependencies build host target resolved.deps.build.host; + target = buildDependencies build target target resolved.deps.build.target; + }; + host = { + only = buildDependencies host host host resolved.deps.host.only; + host = buildDependencies host host target resolved.deps.host.host; + target = buildDependencies host target target resolved.deps.host.target; + }; + target = { + only = buildDependencies target target target resolved.deps.target.only; + target = buildDependencies target target target resolved.deps.target.target; + }; + }; + + package = config.builder.build config; }; - host = { - only = buildDependencies host host host resolved.deps.host.only; - host = buildDependencies host host target resolved.deps.host.host; - target = buildDependencies host target target resolved.deps.host.target; - }; - target = { - only = buildDependencies target target target resolved.deps.target.only; - target = buildDependencies target target target resolved.deps.target.target; - }; - }; - - package = config.builder.build config; - }; - }); - in + } + ); + in result; }; }; diff --git a/tidepool/src/lib/systems.nix b/tidepool/src/lib/systems.nix index 6ff7988..a1a1408 100644 --- a/tidepool/src/lib/systems.nix +++ b/tidepool/src/lib/systems.nix @@ -1,33 +1,34 @@ -{ - lib, - config, -}: let +{ lib, config }: +let lib' = config.lib; types = config.lib.systems.types; - setTypes = type: let - assign = name: value: - assert lib.errors.trace (type.check value) "${name} is not of type ${type.name}: ${lib.generators.pretty {} value}"; - lib.types.set type.name ({inherit name;} // value); - in + setTypes = + type: + let + assign = + name: value: + assert lib.errors.trace (type.check value) + "${name} is not of type ${type.name}: ${lib.generators.pretty { } value}"; + lib.types.set type.name ({ inherit name; } // value); + in builtins.mapAttrs assign; - matchAnyAttrs = patterns: - if builtins.isList patterns - then + matchAnyAttrs = + patterns: + if builtins.isList patterns then value: - builtins.any (pattern: - if builtins.isFunction pattern - then pattern value - else matchAnyAttrs pattern value) - patterns - else lib.attrs.match patterns; + builtins.any ( + pattern: if builtins.isFunction pattern then pattern value else matchAnyAttrs pattern value + ) patterns + else + lib.attrs.match patterns; - getDoubles = predicate: - builtins.map - lib'.systems.into.double - (builtins.filter predicate lib'.systems.doubles.all); -in { + getDoubles = + predicate: + builtins.map lib'.systems.into.double (builtins.filter predicate lib'.systems.doubles.all); +in +{ config = { lib.systems = { match = builtins.mapAttrs (lib.fp.const matchAnyAttrs) lib'.systems.patterns; @@ -88,7 +89,7 @@ in { UBIFS_FS_ZLIB y UBIFS_FS_DEBUG n ''; - makeFlags = ["LOADADDR=0x8000"]; + makeFlags = [ "LOADADDR=0x8000" ]; target = "uImage"; # TODO reenable once manual-config's config actually builds a .dtb and this is checked to be working #DTB = true; @@ -202,7 +203,7 @@ in { KGDB_SERIAL_CONSOLE y KGDB_KDB y ''; - makeFlags = ["LOADADDR=0x0200000"]; + makeFlags = [ "LOADADDR=0x0200000" ]; target = "uImage"; DTB = true; # Beyond 3.10 }; @@ -290,7 +291,7 @@ in { UBIFS_FS_ZLIB y UBIFS_FS_DEBUG n ''; - makeFlags = ["LOADADDR=0x10800000"]; + makeFlags = [ "LOADADDR=0x10800000" ]; target = "uImage"; DTB = true; }; @@ -599,130 +600,392 @@ in { }; }; - mipsel-linux-gnu = - { - triple = "mipsel-unknown-linux-gnu"; - } - // lib'.systems.platforms.gcc_mips32r2_o32; + mipsel-linux-gnu = { + triple = "mipsel-unknown-linux-gnu"; + } // lib'.systems.platforms.gcc_mips32r2_o32; # This function takes a minimally-valid "platform" and returns an # attrset containing zero or more additional attrs which should be # included in the platform in order to further elaborate it. - select = platform: - # x86 - /**/ - if platform.isx86 - then lib'.systems.platforms.pc + select = + platform: + # x86 + if platform.isx86 then + lib'.systems.platforms.pc # ARM - else if platform.isAarch32 - then let - version = platform.system.cpu.version or null; - in - if version == null - then lib'.systems.platforms.pc - else if lib.versions.gte "6" version - then lib'.systems.platforms.sheevaplug - else if lib.versions.gte "7" version - then lib'.systems.platforms.raspberrypi - else lib'.systems.platforms.armv7l-hf-multiplatform - else if platform.isAarch64 - then - if platform.isDarwin - then lib'.systems.platforms.apple-m1 - else lib'.systems.platforms.aarch64-multiplatform - else if platform.isRiscV - then lib'.systems.platforms.riscv-multiplatform - else if platform.system.cpu == types.cpus.mipsel - then lib'.systems.platforms.mipsel-linux-gnu - else if platform.system.cpu == types.cpus.powerpc64le - then lib'.systems.platforms.powernv - else {}; + else if platform.isAarch32 then + let + version = platform.system.cpu.version or null; + in + if version == null then + lib'.systems.platforms.pc + else if lib.versions.gte "6" version then + lib'.systems.platforms.sheevaplug + else if lib.versions.gte "7" version then + lib'.systems.platforms.raspberrypi + else + lib'.systems.platforms.armv7l-hf-multiplatform + else if platform.isAarch64 then + if platform.isDarwin then + lib'.systems.platforms.apple-m1 + else + lib'.systems.platforms.aarch64-multiplatform + else if platform.isRiscV then + lib'.systems.platforms.riscv-multiplatform + else if platform.system.cpu == types.cpus.mipsel then + lib'.systems.platforms.mipsel-linux-gnu + else if platform.system.cpu == types.cpus.powerpc64le then + lib'.systems.platforms.powernv + else + { }; }; architectures = { features = { # x86_64 Generic # Spec: https://gitlab.com/x86-psABIs/x86-64-ABI/ - default = []; - x86-64 = []; - x86-64-v2 = ["sse3" "ssse3" "sse4_1" "sse4_2"]; - x86-64-v3 = ["sse3" "ssse3" "sse4_1" "sse4_2" "avx" "avx2" "fma"]; - x86-64-v4 = ["sse3" "ssse3" "sse4_1" "sse4_2" "avx" "avx2" "avx512" "fma"]; + default = [ ]; + x86-64 = [ ]; + x86-64-v2 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + ]; + x86-64-v3 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "avx" + "avx2" + "fma" + ]; + x86-64-v4 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "avx" + "avx2" + "avx512" + "fma" + ]; # x86_64 Intel - nehalem = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes"]; - westmere = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes"]; - sandybridge = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx"]; - ivybridge = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx"]; - haswell = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma"]; - broadwell = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma"]; - skylake = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma"]; - skylake-avx512 = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - cannonlake = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - icelake-client = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - icelake-server = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - cascadelake = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - cooperlake = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - tigerlake = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma"]; - alderlake = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma"]; + nehalem = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + ]; + westmere = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + ]; + sandybridge = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + ]; + ivybridge = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + ]; + haswell = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "fma" + ]; + broadwell = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "fma" + ]; + skylake = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "fma" + ]; + skylake-avx512 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + cannonlake = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + icelake-client = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + icelake-server = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + cascadelake = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + cooperlake = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + tigerlake = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; + alderlake = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + "avx2" + "fma" + ]; # x86_64 AMD - btver1 = ["sse3" "ssse3" "sse4_1" "sse4_2"]; - btver2 = ["sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx"]; - bdver1 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "fma" "fma4"]; - bdver2 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "fma" "fma4"]; - bdver3 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "fma" "fma4"]; - bdver4 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" "fma4"]; - znver1 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma"]; - znver2 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma"]; - znver3 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma"]; - znver4 = ["sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "avx512" "fma"]; + btver1 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + ]; + btver2 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "aes" + "avx" + ]; + bdver1 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "fma" + "fma4" + ]; + bdver2 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "fma" + "fma4" + ]; + bdver3 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "fma" + "fma4" + ]; + bdver4 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "avx2" + "fma" + "fma4" + ]; + znver1 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "avx2" + "fma" + ]; + znver2 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "avx2" + "fma" + ]; + znver3 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "avx2" + "fma" + ]; + znver4 = [ + "sse3" + "ssse3" + "sse4_1" + "sse4_2" + "sse4a" + "aes" + "avx" + "avx2" + "avx512" + "fma" + ]; # other - armv5te = []; - armv6 = []; - armv7-a = []; - armv8-a = []; - mips32 = []; - loongson2f = []; + armv5te = [ ]; + armv6 = [ ]; + armv7-a = [ ]; + armv8-a = [ ]; + mips32 = [ ]; + loongson2f = [ ]; }; # a superior CPU has all the features of an inferior and is able to build and test code for it inferiors = { # x86_64 Generic - default = []; - x86-64 = []; - x86-64-v2 = ["x86-64"]; - x86-64-v3 = ["x86-64-v2"] ++ lib'.systems.architectures.inferiors.x86-64-v2; - x86-64-v4 = ["x86-64-v3"] ++ lib'.systems.architectures.inferiors.x86-64-v3; + default = [ ]; + x86-64 = [ ]; + x86-64-v2 = [ "x86-64" ]; + x86-64-v3 = [ "x86-64-v2" ] ++ lib'.systems.architectures.inferiors.x86-64-v2; + x86-64-v4 = [ "x86-64-v3" ] ++ lib'.systems.architectures.inferiors.x86-64-v3; # x86_64 Intel # https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html - nehalem = ["x86-64-v2"] ++ lib'.systems.architectures.inferiors.x86-64-v2; - westmere = ["nehalem"] ++ lib'.systems.architectures.inferiors.nehalem; - sandybridge = ["westmere"] ++ lib'.systems.architectures.inferiors.westmere; - ivybridge = ["sandybridge"] ++ lib'.systems.architectures.inferiors.sandybridge; + nehalem = [ "x86-64-v2" ] ++ lib'.systems.architectures.inferiors.x86-64-v2; + westmere = [ "nehalem" ] ++ lib'.systems.architectures.inferiors.nehalem; + sandybridge = [ "westmere" ] ++ lib'.systems.architectures.inferiors.westmere; + ivybridge = [ "sandybridge" ] ++ lib'.systems.architectures.inferiors.sandybridge; - haswell = lib.unique (["ivybridge" "x86-64-v3"] ++ lib'.systems.architectures.inferiors.ivybridge ++ lib'.systems.architectures.inferiors.x86-64-v3); - broadwell = ["haswell"] ++ lib'.systems.architectures.inferiors.haswell; - skylake = ["broadwell"] ++ lib'.systems.architectures.inferiors.broadwell; + haswell = lib.unique ( + [ + "ivybridge" + "x86-64-v3" + ] + ++ lib'.systems.architectures.inferiors.ivybridge + ++ lib'.systems.architectures.inferiors.x86-64-v3 + ); + broadwell = [ "haswell" ] ++ lib'.systems.architectures.inferiors.haswell; + skylake = [ "broadwell" ] ++ lib'.systems.architectures.inferiors.broadwell; - skylake-avx512 = lib.unique (["skylake" "x86-64-v4"] ++ lib'.systems.architectures.inferiors.skylake ++ lib'.systems.architectures.inferiors.x86-64-v4); - cannonlake = ["skylake-avx512"] ++ lib'.systems.architectures.inferiors.skylake-avx512; - icelake-client = ["cannonlake"] ++ lib'.systems.architectures.inferiors.cannonlake; - icelake-server = ["icelake-client"] ++ lib'.systems.architectures.inferiors.icelake-client; - cascadelake = ["cannonlake"] ++ lib'.systems.architectures.inferiors.cannonlake; - cooperlake = ["cascadelake"] ++ lib'.systems.architectures.inferiors.cascadelake; - tigerlake = ["icelake-server"] ++ lib'.systems.architectures.inferiors.icelake-server; + skylake-avx512 = lib.unique ( + [ + "skylake" + "x86-64-v4" + ] + ++ lib'.systems.architectures.inferiors.skylake + ++ lib'.systems.architectures.inferiors.x86-64-v4 + ); + cannonlake = [ "skylake-avx512" ] ++ lib'.systems.architectures.inferiors.skylake-avx512; + icelake-client = [ "cannonlake" ] ++ lib'.systems.architectures.inferiors.cannonlake; + icelake-server = [ "icelake-client" ] ++ lib'.systems.architectures.inferiors.icelake-client; + cascadelake = [ "cannonlake" ] ++ lib'.systems.architectures.inferiors.cannonlake; + cooperlake = [ "cascadelake" ] ++ lib'.systems.architectures.inferiors.cascadelake; + tigerlake = [ "icelake-server" ] ++ lib'.systems.architectures.inferiors.icelake-server; # CX16 does not exist on alderlake, while it does on nearly all other intel CPUs - alderlake = []; + alderlake = [ ]; # x86_64 AMD # TODO: fill this (need testing) - btver1 = []; - btver2 = []; - bdver1 = []; - bdver2 = []; - bdver3 = []; - bdver4 = []; + btver1 = [ ]; + btver2 = [ ]; + bdver1 = [ ]; + bdver2 = [ ]; + bdver3 = [ ]; + bdver4 = [ ]; # Regarding `skylake` as inferior of `znver1`, there are reports of # successful usage by Gentoo users and Phoronix benchmarking of different # `-march` targets. @@ -742,86 +1005,155 @@ in { # https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html # https://en.wikichip.org/wiki/amd/microarchitectures/zen # https://en.wikichip.org/wiki/intel/microarchitectures/skylake - znver1 = ["skylake"] ++ lib'.systems.architectures.inferiors.skylake; # Includes haswell and x86-64-v3 - znver2 = ["znver1"] ++ lib'.systems.architectures.inferiors.znver1; - znver3 = ["znver2"] ++ lib'.systems.architectures.inferiors.znver2; - znver4 = lib.unique (["znver3" "x86-64-v4"] ++ lib'.systems.architectures.inferiors.znver3 ++ lib'.systems.architectures.inferiors.x86-64-v4); + znver1 = [ "skylake" ] ++ lib'.systems.architectures.inferiors.skylake; # Includes haswell and x86-64-v3 + znver2 = [ "znver1" ] ++ lib'.systems.architectures.inferiors.znver1; + znver3 = [ "znver2" ] ++ lib'.systems.architectures.inferiors.znver2; + znver4 = lib.unique ( + [ + "znver3" + "x86-64-v4" + ] + ++ lib'.systems.architectures.inferiors.znver3 + ++ lib'.systems.architectures.inferiors.x86-64-v4 + ); # other - armv5te = []; - armv6 = []; - armv7-a = []; - armv8-a = []; - mips32 = []; - loongson2f = []; + armv5te = [ ]; + armv6 = [ ]; + armv7-a = [ ]; + armv8-a = [ ]; + mips32 = [ ]; + loongson2f = [ ]; }; }; validate = { - architecture = let - isSupported = feature: x: - builtins.elem feature (lib'.systems.architectures.features.${x} or []); - in { - sse3Support = isSupported "sse3"; - ssse3Support = isSupported "ssse3"; - sse4_1Support = isSupported "sse4_1"; - sse4_2Support = isSupported "sse4_2"; - sse4_aSupport = isSupported "sse4a"; - avxSupport = isSupported "avx"; - avx2Support = isSupported "avx2"; - avx512Support = isSupported "avx512"; - aesSupport = isSupported "aes"; - fmaSupport = isSupported "fma"; - fma4Support = isSupported "fma4"; - }; + architecture = + let + isSupported = feature: x: builtins.elem feature (lib'.systems.architectures.features.${x} or [ ]); + in + { + sse3Support = isSupported "sse3"; + ssse3Support = isSupported "ssse3"; + sse4_1Support = isSupported "sse4_1"; + sse4_2Support = isSupported "sse4_2"; + sse4_aSupport = isSupported "sse4a"; + avxSupport = isSupported "avx"; + avx2Support = isSupported "avx2"; + avx512Support = isSupported "avx512"; + aesSupport = isSupported "aes"; + fmaSupport = isSupported "fma"; + fma4Support = isSupported "fma4"; + }; - compatible = a: b: + compatible = + a: b: lib.any lib.id [ # x86 - (b == lib'.systems.types.cpus.i386 && lib'.systems.validate.compatible a lib'.systems.types.cpus.i486) - (b == lib'.systems.types.cpus.i486 && lib'.systems.validate.compatible a lib'.systems.types.cpus.i586) - (b == lib'.systems.types.cpus.i586 && lib'.systems.validate.compatible a lib'.systems.types.cpus.i686) + ( + b == lib'.systems.types.cpus.i386 && lib'.systems.validate.compatible a lib'.systems.types.cpus.i486 + ) + ( + b == lib'.systems.types.cpus.i486 && lib'.systems.validate.compatible a lib'.systems.types.cpus.i586 + ) + ( + b == lib'.systems.types.cpus.i586 && lib'.systems.validate.compatible a lib'.systems.types.cpus.i686 + ) # XXX: Not true in some cases. Like in WSL mode. - (b == lib'.systems.types.cpus.i686 && lib'.systems.validate.compatible a lib'.systems.types.cpus.x86_64) + ( + b == lib'.systems.types.cpus.i686 + && lib'.systems.validate.compatible a lib'.systems.types.cpus.x86_64 + ) # ARMv4 - (b == lib'.systems.types.cpus.arm && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv5tel) + ( + b == lib'.systems.types.cpus.arm + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv5tel + ) # ARMv5 - (b == lib'.systems.types.cpus.armv5tel && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv6l) + ( + b == lib'.systems.types.cpus.armv5tel + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv6l + ) # ARMv6 - (b == lib'.systems.types.cpus.armv6l && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv6m) - (b == lib'.systems.types.cpus.armv6m && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7l) + ( + b == lib'.systems.types.cpus.armv6l + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv6m + ) + ( + b == lib'.systems.types.cpus.armv6m + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7l + ) # ARMv7 - (b == lib'.systems.types.cpus.armv7l && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7a) - (b == lib'.systems.types.cpus.armv7l && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7r) - (b == lib'.systems.types.cpus.armv7l && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7m) + ( + b == lib'.systems.types.cpus.armv7l + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7a + ) + ( + b == lib'.systems.types.cpus.armv7l + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7r + ) + ( + b == lib'.systems.types.cpus.armv7l + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv7m + ) # ARMv8 (b == lib'.systems.types.cpus.aarch64 && a == lib'.systems.types.cpus.armv8a) - (b == lib'.systems.types.cpus.armv8a && lib'.systems.validate.compatible a lib'.systems.types.cpus.aarch64) - (b == lib'.systems.types.cpus.armv8r && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv8a) - (b == lib'.systems.types.cpus.armv8m && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv8a) + ( + b == lib'.systems.types.cpus.armv8a + && lib'.systems.validate.compatible a lib'.systems.types.cpus.aarch64 + ) + ( + b == lib'.systems.types.cpus.armv8r + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv8a + ) + ( + b == lib'.systems.types.cpus.armv8m + && lib'.systems.validate.compatible a lib'.systems.types.cpus.armv8a + ) # PowerPC - (b == lib'.systems.types.cpus.powerpc && lib'.systems.validate.compatible a lib'.systems.types.cpus.powerpc64) - (b == lib'.systems.types.cpus.powerpcle && lib'.systems.validate.compatible a lib'.systems.types.cpus.powerpc64le) + ( + b == lib'.systems.types.cpus.powerpc + && lib'.systems.validate.compatible a lib'.systems.types.cpus.powerpc64 + ) + ( + b == lib'.systems.types.cpus.powerpcle + && lib'.systems.validate.compatible a lib'.systems.types.cpus.powerpc64le + ) # MIPS - (b == lib'.systems.types.cpus.mips && lib'.systems.validate.compatible a lib'.systems.types.cpus.mips64) - (b == lib'.systems.types.cpus.mipsel && lib'.systems.validate.compatible a lib'.systems.types.cpus.mips64el) + ( + b == lib'.systems.types.cpus.mips + && lib'.systems.validate.compatible a lib'.systems.types.cpus.mips64 + ) + ( + b == lib'.systems.types.cpus.mipsel + && lib'.systems.validate.compatible a lib'.systems.types.cpus.mips64el + ) # RISCV - (b == lib'.systems.types.cpus.riscv32 && lib'.systems.validate.compatible a lib'.systems.types.cpus.riscv64) + ( + b == lib'.systems.types.cpus.riscv32 + && lib'.systems.validate.compatible a lib'.systems.types.cpus.riscv64 + ) # SPARC - (b == lib'.systems.types.cpus.sparc && lib'.systems.validate.compatible a lib'.systems.types.cpus.sparc64) + ( + b == lib'.systems.types.cpus.sparc + && lib'.systems.validate.compatible a lib'.systems.types.cpus.sparc64 + ) # WASM - (b == lib'.systems.types.cpus.wasm32 && lib'.systems.validate.compatible a lib'.systems.types.cpus.wasm64) + ( + b == lib'.systems.types.cpus.wasm32 + && lib'.systems.validate.compatible a lib'.systems.types.cpus.wasm64 + ) # identity (b == a) @@ -840,13 +1172,8 @@ in { name = "Cpu"; description = "Instruction set architecture name and information"; merge = lib.options.merge.one; - check = x: - types.bits.check x.bits - && ( - if 8 < x.bits - then types.endian.check x.endian - else !(x ? endian) - ); + check = + x: types.bits.check x.bits && (if 8 < x.bits then types.endian.check x.endian else !(x ? endian)); }; family = lib.types.create { @@ -865,9 +1192,9 @@ in { name = "Kernel"; description = "Kernel name and information"; merge = lib.options.merge.one; - check = value: - types.exec.check value.exec - && builtins.all types.family.check (builtins.attrValues value.families); + check = + value: + types.exec.check value.exec && builtins.all types.family.check (builtins.attrValues value.families); }; abi = lib.types.create { @@ -887,12 +1214,13 @@ in { name = "system"; description = "fully parsed representation of llvm- or nix-style platform tuple"; merge = lib.options.merge.one; - check = { - cpu, - vendor, - kernel, - abi, - }: + check = + { + cpu, + vendor, + kernel, + abi, + }: types.cpu.check cpu && types.vendor.check vendor && types.kernel.check kernel @@ -902,43 +1230,49 @@ in { endian = lib.types.enum (builtins.attrValues types.endians); endians = setTypes types.generic.endian { - big = {}; - little = {}; + big = { }; + little = { }; }; - bits = lib.types.enum [8 16 32 64 128]; + bits = lib.types.enum [ + 8 + 16 + 32 + 64 + 128 + ]; exec = lib.types.enum (builtins.attrValues types.execs); execs = setTypes types.generic.exec { - aout = {}; # a.out - elf = {}; - macho = {}; - pe = {}; - wasm = {}; - unknown = {}; + aout = { }; # a.out + elf = { }; + macho = { }; + pe = { }; + wasm = { }; + unknown = { }; }; vendor = lib.types.enum (builtins.attrValues types.vendors); vendors = setTypes types.generic.vendor { - apple = {}; - pc = {}; - knuth = {}; + apple = { }; + pc = { }; + knuth = { }; # Actually matters, unlocking some MinGW-w64-specific options in GCC. See # bottom of https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/ - w64 = {}; + w64 = { }; - none = {}; - unknown = {}; + none = { }; + unknown = { }; }; family = lib.types.enum (builtins.attrValues types.families); families = setTypes types.generic.family { - bsd = {}; - darwin = {}; + bsd = { }; + darwin = { }; }; kernel = lib.types.enum (builtins.attrValues types.kernels); @@ -955,66 +1289,76 @@ in { }; ios = { exec = types.execs.macho; - families = {darwin = types.families.darwin;}; + families = { + darwin = types.families.darwin; + }; }; # A tricky thing about FreeBSD is that there is no stable ABI across # versions. That means that putting in the version as part of the # config string is paramount. freebsd12 = { exec = types.execs.elf; - families = {bsd = types.families.bsd;}; + families = { + bsd = types.families.bsd; + }; name = "freebsd"; version = 12; }; freebsd13 = { exec = types.execs.elf; - families = {bsd = types.families.bsd;}; + families = { + bsd = types.families.bsd; + }; name = "freebsd"; version = 13; }; linux = { exec = types.execs.elf; - families = {}; + families = { }; }; netbsd = { exec = types.execs.elf; - families = {bsd = types.families.bsd;}; + families = { + bsd = types.families.bsd; + }; }; none = { exec = types.execs.unknown; - families = {}; + families = { }; }; openbsd = { exec = types.execs.elf; - families = {bsd = types.families.bsd;}; + families = { + bsd = types.families.bsd; + }; }; solaris = { exec = types.execs.elf; - families = {}; + families = { }; }; wasi = { exec = types.execs.wasm; - families = {}; + families = { }; }; redox = { exec = types.execs.elf; - families = {}; + families = { }; }; windows = { exec = types.execs.pe; - families = {}; + families = { }; }; ghcjs = { exec = types.execs.unknown; - families = {}; + families = { }; }; genode = { exec = types.execs.elf; - families = {}; + families = { }; }; mmixware = { exec = types.execs.unknown; - families = {}; + families = { }; }; # aliases @@ -1307,19 +1651,23 @@ in { abi = lib.types.enum (builtins.attrValues types.abis); abis = setTypes types.generic.abi { - cygnus = {}; - msvc = {}; + cygnus = { }; + msvc = { }; # Note: eabi is specific to ARM and PowerPC. # On PowerPC, this corresponds to PPCEABI. # On ARM, this corresponds to ARMEABI. - eabi = {float = "soft";}; - eabihf = {float = "hard";}; + eabi = { + float = "soft"; + }; + eabihf = { + float = "hard"; + }; # Other architectures should use ELF in embedded situations. - elf = {}; + elf = { }; - androideabi = {}; + androideabi = { }; android = { assertions = [ { @@ -1331,8 +1679,12 @@ in { ]; }; - gnueabi = {float = "soft";}; - gnueabihf = {float = "hard";}; + gnueabi = { + float = "soft"; + }; + gnueabihf = { + float = "hard"; + }; gnu = { assertions = [ { @@ -1349,208 +1701,259 @@ in { } ]; }; - gnuabi64 = {abi = "64";}; - muslabi64 = {abi = "64";}; + gnuabi64 = { + abi = "64"; + }; + muslabi64 = { + abi = "64"; + }; # NOTE: abi=n32 requires a 64-bit MIPS chip! That is not a typo. # It is basically the 64-bit abi with 32-bit pointers. Details: # https://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf - gnuabin32 = {abi = "n32";}; - muslabin32 = {abi = "n32";}; + gnuabin32 = { + abi = "n32"; + }; + muslabin32 = { + abi = "n32"; + }; - gnuabielfv2 = {abi = "elfv2";}; - gnuabielfv1 = {abi = "elfv1";}; + gnuabielfv2 = { + abi = "elfv2"; + }; + gnuabielfv1 = { + abi = "elfv1"; + }; - musleabi = {float = "soft";}; - musleabihf = {float = "hard";}; - musl = {}; + musleabi = { + float = "soft"; + }; + musleabihf = { + float = "hard"; + }; + musl = { }; - uclibceabi = {float = "soft";}; - uclibceabihf = {float = "hard";}; - uclibc = {}; + uclibceabi = { + float = "soft"; + }; + uclibceabihf = { + float = "hard"; + }; + uclibc = { }; - unknown = {}; + unknown = { }; }; }; from = { - string = value: let - parts = lib.strings.split "-" value; - skeleton = lib'.systems.skeleton parts; - system = lib'.systems.create (lib'.systems.from.skeleton skeleton); - in + string = + value: + let + parts = lib.strings.split "-" value; + skeleton = lib'.systems.skeleton parts; + system = lib'.systems.create (lib'.systems.from.skeleton skeleton); + in system; - skeleton = spec @ { - cpu, - vendor ? assert false; null, - kernel, - abi ? assert false; null, - }: let - getCpu = name: types.cpus.${name} or (throw "Unknown CPU type: ${name}"); - getVendor = name: types.vendors.${name} or (throw "Unknown vendor: ${name}"); - getKernel = name: types.kernels.${name} or (throw "Unknown kernel: ${name}"); - getAbi = name: types.abis.${name} or (throw "Unknown ABI: ${name}"); + skeleton = + spec@{ + cpu, + vendor ? + assert false; + null, + kernel, + abi ? + assert false; + null, + }: + let + getCpu = name: types.cpus.${name} or (throw "Unknown CPU type: ${name}"); + getVendor = name: types.vendors.${name} or (throw "Unknown vendor: ${name}"); + getKernel = name: types.kernels.${name} or (throw "Unknown kernel: ${name}"); + getAbi = name: types.abis.${name} or (throw "Unknown ABI: ${name}"); - resolved = { - cpu = getCpu spec.cpu; + resolved = { + cpu = getCpu spec.cpu; - vendor = - if spec ? vendor - then getVendor spec.vendor - else if lib'.systems.match.isDarwin resolved - then types.vendors.apple - else if lib'.systems.match.isWindows resolved - then types.vendors.pc - else types.vendors.unknown; + vendor = + if spec ? vendor then + getVendor spec.vendor + else if lib'.systems.match.isDarwin resolved then + types.vendors.apple + else if lib'.systems.match.isWindows resolved then + types.vendors.pc + else + types.vendors.unknown; - kernel = - if lib.strings.hasPrefix "darwin" spec.kernel - then getKernel "darwin" - else if lib.strings.hasPrefix "netbsd" spec.kernel - then getKernel "netbsd" - else getKernel spec.kernel; + kernel = + if lib.strings.hasPrefix "darwin" spec.kernel then + getKernel "darwin" + else if lib.strings.hasPrefix "netbsd" spec.kernel then + getKernel "netbsd" + else + getKernel spec.kernel; - abi = - if spec ? abi - then getAbi spec.abi - else if lib'.systems.match.isLinux resolved || lib'.systems.match.isWindows resolved - then - if lib'.systems.match.isAarch32 resolved - then - if lib.versions.gte "6" (resolved.cpu.version) - then types.abis.gnueabihf - else types.abis.gnueabi - else if lib'.systems.match.isPower64 resolved && lib'.systems.match.isBigEndian resolved - then types.abis.gnuabielfv2 - else types.abis.gnu - else types.abis.unknown; - }; - in + abi = + if spec ? abi then + getAbi spec.abi + else if lib'.systems.match.isLinux resolved || lib'.systems.match.isWindows resolved then + if lib'.systems.match.isAarch32 resolved then + if lib.versions.gte "6" (resolved.cpu.version) then types.abis.gnueabihf else types.abis.gnueabi + else if lib'.systems.match.isPower64 resolved && lib'.systems.match.isBigEndian resolved then + types.abis.gnuabielfv2 + else + types.abis.gnu + else + types.abis.unknown; + }; + in resolved; }; into = { - double = { - cpu, - kernel, - abi, - ... - }: let - kernelName = kernel.name + builtins.toString (kernel.version or ""); - in - if abi == types.abis.cygnus - then "${cpu.name}-cygwin" - else if kernel.families ? darwin - then "${cpu.name}-darwin" - else "${cpu.name}-${kernelName}"; + double = + { + cpu, + kernel, + abi, + ... + }: + let + kernelName = kernel.name + builtins.toString (kernel.version or ""); + in + if abi == types.abis.cygnus then + "${cpu.name}-cygwin" + else if kernel.families ? darwin then + "${cpu.name}-darwin" + else + "${cpu.name}-${kernelName}"; - triple = { - cpu, - vendor, - kernel, - abi, - ... - }: let - kernelName = kernel.name + builtins.toString (kernel.version or ""); - netbsdExec = - if - (cpu.family == "arm" && cpu.bits == 32) - || (cpu.family == "sparc" && cpu.bits == 32) - || (cpu.family == "m68k" && cpu.bits == 32) - || (cpu.family == "x86" && cpu.bits == 32) - then types.execs.aout - else types.execs.elf; + triple = + { + cpu, + vendor, + kernel, + abi, + ... + }: + let + kernelName = kernel.name + builtins.toString (kernel.version or ""); + netbsdExec = + if + (cpu.family == "arm" && cpu.bits == 32) + || (cpu.family == "sparc" && cpu.bits == 32) + || (cpu.family == "m68k" && cpu.bits == 32) + || (cpu.family == "x86" && cpu.bits == 32) + then + types.execs.aout + else + types.execs.elf; - exec = - lib.strings.when - (kernel.name == "netbsd" && netbsdExec != kernel.exec) - kernel.exec.name; - abi' = lib.strings.when (abi != types.abis.unknown) "-${abi.name}"; - in "${cpu.name}-${vendor.name}-${kernelName}${exec}${abi'}"; + exec = lib.strings.when (kernel.name == "netbsd" && netbsdExec != kernel.exec) kernel.exec.name; + abi' = lib.strings.when (abi != types.abis.unknown) "-${abi.name}"; + in + "${cpu.name}-${vendor.name}-${kernelName}${exec}${abi'}"; }; - create = components: + create = + components: assert types.platform.check components; - lib.types.set "system" components; + lib.types.set "system" components; - skeleton = parts: let - length = builtins.length parts; + skeleton = + parts: + let + length = builtins.length parts; - first = builtins.elemAt parts 0; - second = builtins.elemAt parts 1; - third = builtins.elemAt parts 2; - fourth = builtins.elemAt parts 3; - in - if length == 1 - then - if first == "avr" - then { - cpu = first; - kernel = "none"; - abi = "unknown"; - } - else builtins.throw "Target specification with 1 component is ambiguous." - else if length == 2 - then - if second == "cygwin" - then { - cpu = first; - kernel = "windows"; - abi = "cygnus"; - } - else if second == "windows" - then { - cpu = first; - kernel = "windows"; - abi = "msvc"; - } - else if second == "elf" - then { - cpu = first; - vendor = "unkonwn"; - kernel = "none"; - abi = second; - } - else { - cpu = first; - kernel = second; - } - else if length == 3 - then - if second == "linux" || (builtins.elem third ["eabi" "eabihf" "elf" "gnu"]) - then { - cpu = first; - vendor = "unknown"; - kernel = second; - abi = third; - } + first = builtins.elemAt parts 0; + second = builtins.elemAt parts 1; + third = builtins.elemAt parts 2; + fourth = builtins.elemAt parts 3; + in + if length == 1 then + if first == "avr" then + { + cpu = first; + kernel = "none"; + abi = "unknown"; + } + else + builtins.throw "Target specification with 1 component is ambiguous." + else if length == 2 then + if second == "cygwin" then + { + cpu = first; + kernel = "windows"; + abi = "cygnus"; + } + else if second == "windows" then + { + cpu = first; + kernel = "windows"; + abi = "msvc"; + } + else if second == "elf" then + { + cpu = first; + vendor = "unkonwn"; + kernel = "none"; + abi = second; + } + else + { + cpu = first; + kernel = second; + } + else if length == 3 then + if + second == "linux" + || (builtins.elem third [ + "eabi" + "eabihf" + "elf" + "gnu" + ]) + then + { + cpu = first; + vendor = "unknown"; + kernel = second; + abi = third; + } else if (second == "apple") || lib.strings.hasPrefix "freebsd" third || lib.strings.hasPrefix "netbsd" third || lib.strings.hasPrefix "genode" third - || (builtins.elem third ["wasi" "redox" "mmixware" "ghcjs" "mingw32"]) - then { + || (builtins.elem third [ + "wasi" + "redox" + "mmixware" + "ghcjs" + "mingw32" + ]) + then + { + cpu = first; + vendor = second; + kernel = if third == "mingw32" then "windows" else third; + } + else + builtins.throw "Target specification with 3 components is ambiguous." + else if length == 4 then + { cpu = first; vendor = second; - kernel = - if third == "mingw32" - then "windows" - else third; + kernel = third; + abi = fourth; } - else builtins.throw "Target specification with 3 components is ambiguous." - else if length == 4 - then { - cpu = first; - vendor = second; - kernel = third; - abi = fourth; - } - else builtins.throw "Invalid component count for creating system skeleton. Expected 1-4, but got ${builtins.toString length}."; + else + builtins.throw "Invalid component count for creating system skeleton. Expected 1-4, but got ${builtins.toString length}."; patterns = { - isi686 = {cpu = types.cpus.i686;}; + isi686 = { + cpu = types.cpus.i686; + }; isx86_32 = { cpu = { family = "x86"; @@ -1563,7 +1966,11 @@ in { bits = 64; }; }; - isPower = {cpu = {family = "power";};}; + isPower = { + cpu = { + family = "power"; + }; + }; isPower64 = { cpu = { family = "power"; @@ -1574,16 +1981,26 @@ in { # so it sometimes causes issues in certain packages that makes the wrong # assumption on the used ABI. isAbiElfv2 = [ - {abi = {abi = "elfv2";};} { - abi = {name = "musl";}; + abi = { + abi = "elfv2"; + }; + } + { + abi = { + name = "musl"; + }; cpu = { family = "power"; bits = 64; }; } ]; - isx86 = {cpu = {family = "x86";};}; + isx86 = { + cpu = { + family = "x86"; + }; + }; isAarch32 = { cpu = { family = "arm"; @@ -1591,18 +2008,39 @@ in { }; }; isArmv7 = - map ({arch, ...}: {cpu = {inherit arch;};}) - (builtins.filter (cpu: lib.strings.hasPrefix "armv7" cpu.arch or "") - (builtins.attrValues types.cpus)); + map + ( + { arch, ... }: + { + cpu = { + inherit arch; + }; + } + ) + ( + builtins.filter (cpu: lib.strings.hasPrefix "armv7" cpu.arch or "") (builtins.attrValues types.cpus) + ); isAarch64 = { cpu = { family = "arm"; bits = 64; }; }; - isAarch = {cpu = {family = "arm";};}; - isMicroBlaze = {cpu = {family = "microblaze";};}; - isMips = {cpu = {family = "mips";};}; + isAarch = { + cpu = { + family = "arm"; + }; + }; + isMicroBlaze = { + cpu = { + family = "microblaze"; + }; + }; + isMips = { + cpu = { + family = "mips"; + }; + }; isMips32 = { cpu = { family = "mips"; @@ -1620,17 +2058,29 @@ in { family = "mips"; bits = 64; }; - abi = {abi = "n32";}; + abi = { + abi = "n32"; + }; }; isMips64n64 = { cpu = { family = "mips"; bits = 64; }; - abi = {abi = "64";}; + abi = { + abi = "64"; + }; + }; + isMmix = { + cpu = { + family = "mmix"; + }; + }; + isRiscV = { + cpu = { + family = "riscv"; + }; }; - isMmix = {cpu = {family = "mmix";};}; - isRiscV = {cpu = {family = "riscv";};}; isRiscV32 = { cpu = { family = "riscv"; @@ -1643,16 +2093,56 @@ in { bits = 64; }; }; - isRx = {cpu = {family = "rx";};}; - isSparc = {cpu = {family = "sparc";};}; - isWasm = {cpu = {family = "wasm";};}; - isMsp430 = {cpu = {family = "msp430";};}; - isVc4 = {cpu = {family = "vc4";};}; - isAvr = {cpu = {family = "avr";};}; - isAlpha = {cpu = {family = "alpha";};}; - isOr1k = {cpu = {family = "or1k";};}; - isM68k = {cpu = {family = "m68k";};}; - isS390 = {cpu = {family = "s390";};}; + isRx = { + cpu = { + family = "rx"; + }; + }; + isSparc = { + cpu = { + family = "sparc"; + }; + }; + isWasm = { + cpu = { + family = "wasm"; + }; + }; + isMsp430 = { + cpu = { + family = "msp430"; + }; + }; + isVc4 = { + cpu = { + family = "vc4"; + }; + }; + isAvr = { + cpu = { + family = "avr"; + }; + }; + isAlpha = { + cpu = { + family = "alpha"; + }; + }; + isOr1k = { + cpu = { + family = "or1k"; + }; + }; + isM68k = { + cpu = { + family = "m68k"; + }; + }; + isS390 = { + cpu = { + family = "s390"; + }; + }; isS390x = { cpu = { family = "s390"; @@ -1665,26 +2155,92 @@ in { bits = 64; }; }; - isJavaScript = {cpu = types.cpus.javascript;}; + isJavaScript = { + cpu = types.cpus.javascript; + }; - is32bit = {cpu = {bits = 32;};}; - is64bit = {cpu = {bits = 64;};}; - isILP32 = builtins.map (a: {abi = {abi = a;};}) ["n32" "ilp32" "x32"]; - isBigEndian = {cpu = {endian = types.endians.big;};}; - isLittleEndian = {cpu = {endian = types.endians.little;};}; + is32bit = { + cpu = { + bits = 32; + }; + }; + is64bit = { + cpu = { + bits = 64; + }; + }; + isILP32 = + builtins.map + (a: { + abi = { + abi = a; + }; + }) + [ + "n32" + "ilp32" + "x32" + ]; + isBigEndian = { + cpu = { + endian = types.endians.big; + }; + }; + isLittleEndian = { + cpu = { + endian = types.endians.little; + }; + }; - isBSD = {kernel = {families = {bsd = types.families.bsd;};};}; - isDarwin = {kernel = {families = {darwin = types.families.darwin;};};}; - isUnix = [lib'.systems.match.isBSD lib'.systems.match.isDarwin lib'.systems.match.isLinux lib'.systems.match.isSunOS lib'.systems.match.isCygwin lib'.systems.match.isRedox]; + isBSD = { + kernel = { + families = { + bsd = types.families.bsd; + }; + }; + }; + isDarwin = { + kernel = { + families = { + darwin = types.families.darwin; + }; + }; + }; + isUnix = [ + lib'.systems.match.isBSD + lib'.systems.match.isDarwin + lib'.systems.match.isLinux + lib'.systems.match.isSunOS + lib'.systems.match.isCygwin + lib'.systems.match.isRedox + ]; - isMacOS = {kernel = types.kernels.macos;}; - isiOS = {kernel = types.kernels.ios;}; - isLinux = {kernel = types.kernels.linux;}; - isSunOS = {kernel = types.kernels.solaris;}; - isFreeBSD = {kernel = {name = "freebsd";};}; - isNetBSD = {kernel = types.kernels.netbsd;}; - isOpenBSD = {kernel = types.kernels.openbsd;}; - isWindows = {kernel = types.kernels.windows;}; + isMacOS = { + kernel = types.kernels.macos; + }; + isiOS = { + kernel = types.kernels.ios; + }; + isLinux = { + kernel = types.kernels.linux; + }; + isSunOS = { + kernel = types.kernels.solaris; + }; + isFreeBSD = { + kernel = { + name = "freebsd"; + }; + }; + isNetBSD = { + kernel = types.kernels.netbsd; + }; + isOpenBSD = { + kernel = types.kernels.openbsd; + }; + isWindows = { + kernel = types.kernels.windows; + }; isCygwin = { kernel = types.kernels.windows; abi = types.abis.cygnus; @@ -1693,16 +2249,47 @@ in { kernel = types.kernels.windows; abi = types.abis.gnu; }; - isWasi = {kernel = types.kernels.wasi;}; - isRedox = {kernel = types.kernels.redox;}; - isGhcjs = {kernel = types.kernels.ghcjs;}; - isGenode = {kernel = types.kernels.genode;}; - isNone = {kernel = types.kernels.none;}; + isWasi = { + kernel = types.kernels.wasi; + }; + isRedox = { + kernel = types.kernels.redox; + }; + isGhcjs = { + kernel = types.kernels.ghcjs; + }; + isGenode = { + kernel = types.kernels.genode; + }; + isNone = { + kernel = types.kernels.none; + }; - isAndroid = [{abi = types.abis.android;} {abi = types.abis.androideabi;}]; - isGnu = builtins.map (value: {abi = value;}) [types.abis.gnuabi64 types.abis.gnuabin32 types.abis.gnu types.abis.gnueabi types.abis.gnueabihf types.abis.gnuabielfv1 types.abis.gnuabielfv2]; - isMusl = builtins.map (value: {abi = value;}) [types.abis.musl types.abis.musleabi types.abis.musleabihf types.abis.muslabin32 types.abis.muslabi64]; - isUClibc = builtins.map (value: {abi = value;}) [types.abis.uclibc types.abis.uclibceabi types.abis.uclibceabihf]; + isAndroid = [ + { abi = types.abis.android; } + { abi = types.abis.androideabi; } + ]; + isGnu = builtins.map (value: { abi = value; }) [ + types.abis.gnuabi64 + types.abis.gnuabin32 + types.abis.gnu + types.abis.gnueabi + types.abis.gnueabihf + types.abis.gnuabielfv1 + types.abis.gnuabielfv2 + ]; + isMusl = builtins.map (value: { abi = value; }) [ + types.abis.musl + types.abis.musleabi + types.abis.musleabihf + types.abis.muslabin32 + types.abis.muslabi64 + ]; + isUClibc = builtins.map (value: { abi = value; }) [ + types.abis.uclibc + types.abis.uclibceabi + types.abis.uclibceabihf + ]; isEfi = [ { @@ -1723,8 +2310,16 @@ in { version = "8"; }; } - {cpu = {family = "riscv";};} - {cpu = {family = "x86";};} + { + cpu = { + family = "riscv"; + }; + } + { + cpu = { + family = "x86"; + }; + } ]; }; @@ -1866,34 +2461,48 @@ in { freebsd = getDoubles lib'.systems.match.isFreeBSD; # Should be better, but MinGW is unclear. gnu = - getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnu; - }) - ++ getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnueabi; - }) - ++ getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnueabihf; - }) - ++ getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnuabin32; - }) - ++ getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnuabi64; - }) - ++ getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnuabielfv1; - }) - ++ getDoubles (lib.attrs.match { - kernel = types.kernels.linux; - abi = types.abis.gnuabielfv2; - }); + getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnu; + } + ) + ++ getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnueabi; + } + ) + ++ getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnueabihf; + } + ) + ++ getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnuabin32; + } + ) + ++ getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnuabi64; + } + ) + ++ getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnuabielfv1; + } + ) + ++ getDoubles ( + lib.attrs.match { + kernel = types.kernels.linux; + abi = types.abis.gnuabielfv2; + } + ); illumos = getDoubles lib'.systems.match.isSunOS; linux = getDoubles lib'.systems.match.isLinux; netbsd = getDoubles lib'.systems.match.isNetBSD; @@ -1906,288 +2515,284 @@ in { embedded = getDoubles lib'.systems.match.isNone; - mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "armv7a-linux" "aarch64-linux" "powerpc64-linux" "powerpc64le-linux" "aarch64-darwin" "riscv64-linux"]; + mesaPlatforms = [ + "i686-linux" + "x86_64-linux" + "x86_64-darwin" + "armv5tel-linux" + "armv6l-linux" + "armv7l-linux" + "armv7a-linux" + "aarch64-linux" + "powerpc64-linux" + "powerpc64le-linux" + "aarch64-darwin" + "riscv64-linux" + ]; }; - withBuildInfo = args: let - settings = - if builtins.isString args - then {system = args;} - else args; + withBuildInfo = + args: + let + settings = if builtins.isString args then { system = args; } else args; - resolved = - { - system = lib'.systems.from.string ( - if settings ? triple - then settings.triple - else settings.system - ); + resolved = + { + system = lib'.systems.from.string (if settings ? triple then settings.triple else settings.system); - inherit - ({ - linux-kernel = settings.linux-kernel or {}; - gcc = settings.gcc or {}; - rustc = settings.rustc or {}; - } - // lib'.systems.platforms.select resolved) - linux-kernel - gcc - rustc - ; + inherit + ( + { + linux-kernel = settings.linux-kernel or { }; + gcc = settings.gcc or { }; + rustc = settings.rustc or { }; + } + // lib'.systems.platforms.select resolved + ) + linux-kernel + gcc + rustc + ; - double = lib'.systems.into.double resolved.system; - triple = lib'.systems.into.triple resolved.system; + double = lib'.systems.into.double resolved.system; + triple = lib'.systems.into.triple resolved.system; - isExecutable = platform: - (resolved.isAndroid == platform.isAndroid) - && resolved.system.kernel == platform.system.kernel - && lib'.systems.validate.compatible resolved.system.cpu platform.system.cpu; + isExecutable = + platform: + (resolved.isAndroid == platform.isAndroid) + && resolved.system.kernel == platform.system.kernel + && lib'.systems.validate.compatible resolved.system.cpu platform.system.cpu; - # The difference between `isStatic` and `hasSharedLibraries` is mainly the - # addition of the `staticMarker` (see make-derivation.nix). Some - # platforms, like embedded machines without a libc (e.g. arm-none-eabi) - # don't support dynamic linking, but don't get the `staticMarker`. - # `pkgsStatic` sets `isStatic=true`, so `pkgsStatic.hostPlatform` always - # has the `staticMarker`. - isStatic = resolved.isWasm || resolved.isRedox; + # The difference between `isStatic` and `hasSharedLibraries` is mainly the + # addition of the `staticMarker` (see make-derivation.nix). Some + # platforms, like embedded machines without a libc (e.g. arm-none-eabi) + # don't support dynamic linking, but don't get the `staticMarker`. + # `pkgsStatic` sets `isStatic=true`, so `pkgsStatic.hostPlatform` always + # has the `staticMarker`. + isStatic = resolved.isWasm || resolved.isRedox; - # It is important that hasSharedLibraries==false when the platform has no - # dynamic library loader. Various tools (including the gcc build system) - # have knowledge of which platforms are incapable of dynamic linking, and - # will still build on/for those platforms with --enable-shared, but simply - # omit any `.so` build products such as libgcc_s.so. When that happens, - # it causes hard-to-troubleshoot build failures. - hasSharedLibraries = - !resolved.isStatic - && ( - # Linux (allows multiple libcs) - resolved.isAndroid - || resolved.isGnu - || resolved.isMusl - # BSDs - || resolved.isDarwin - || resolved.isSunOS - || resolved.isOpenBSD - || resolved.isFreeBSD - || resolved.isNetBSD - # Windows - || resolved.isCygwin - || resolved.isMinGW - ); + # It is important that hasSharedLibraries==false when the platform has no + # dynamic library loader. Various tools (including the gcc build system) + # have knowledge of which platforms are incapable of dynamic linking, and + # will still build on/for those platforms with --enable-shared, but simply + # omit any `.so` build products such as libgcc_s.so. When that happens, + # it causes hard-to-troubleshoot build failures. + hasSharedLibraries = + !resolved.isStatic + && ( + # Linux (allows multiple libcs) + resolved.isAndroid + || resolved.isGnu + || resolved.isMusl + # BSDs + || resolved.isDarwin + || resolved.isSunOS + || resolved.isOpenBSD + || resolved.isFreeBSD + || resolved.isNetBSD + # Windows + || resolved.isCygwin + || resolved.isMinGW + ); - libc = - if resolved.isDarwin - then "libSystem" - else if resolved.isMinGW - then "msvcrt" - else if resolved.isWasi - then "wasilibc" - else if resolved.isRedox - then "relibc" - else if resolved.isMusl - then "musl" - else if resolved.isUClibc - then "uclibc" - else if resolved.isAndroid - then "bionic" - else if resolved.isLinux - then "glibc" - else if resolved.isFreeBSD - then "fblibc" - else if resolved.isNetBSD - then "nblibc" - else if resolved.isAvr - then "avrlibc" - else if resolved.isGhcjs - then null - else if resolved.isNone - then "newlib" - else "native/impure"; + libc = + if resolved.isDarwin then + "libSystem" + else if resolved.isMinGW then + "msvcrt" + else if resolved.isWasi then + "wasilibc" + else if resolved.isRedox then + "relibc" + else if resolved.isMusl then + "musl" + else if resolved.isUClibc then + "uclibc" + else if resolved.isAndroid then + "bionic" + else if resolved.isLinux then + "glibc" + else if resolved.isFreeBSD then + "fblibc" + else if resolved.isNetBSD then + "nblibc" + else if resolved.isAvr then + "avrlibc" + else if resolved.isGhcjs then + null + else if resolved.isNone then + "newlib" + else + "native/impure"; - linker = - if resolved.isDarwin - then "cctools" - else "bfd"; + linker = if resolved.isDarwin then "cctools" else "bfd"; - extensions = - (lib.attrs.when resolved.hasSharedLibraries { - shared = - if resolved.isDarwin - then ".dylib" - else if resolved.isWindows - then ".dll" - else ".so"; - }) - // { - static = - if resolved.isWindows - then ".lib" - else ".a"; + extensions = + (lib.attrs.when resolved.hasSharedLibraries { + shared = + if resolved.isDarwin then + ".dylib" + else if resolved.isWindows then + ".dll" + else + ".so"; + }) + // { + static = if resolved.isWindows then ".lib" else ".a"; - library = - if resolved.isStatic - then resolved.extensions.static - else resolved.extensions.shared; + library = if resolved.isStatic then resolved.extensions.static else resolved.extensions.shared; - executable = - if resolved.isWindows - then ".exe" - else ""; + executable = if resolved.isWindows then ".exe" else ""; + }; + + uname = { + system = + if resolved.system.kernel.name == "linux" then + "Linux" + else if resolved.system.kernel.name == "windows" then + "Windows" + else if resolved.system.kernel.name == "darwin" then + "Darwin" + else if resolved.system.kernel.name == "netbsd" then + "NetBSD" + else if resolved.system.kernel.name == "freebsd" then + "FreeBSD" + else if resolved.system.kernel.name == "openbsd" then + "OpenBSD" + else if resolved.system.kernel.name == "wasi" then + "Wasi" + else if resolved.system.kernel.name == "redox" then + "Redox" + else if resolved.system.kernel.name == "redox" then + "Genode" + else + null; + + processor = + if resolved.isPower64 then + "ppc64${lib.strings.when resolved.isLittleEndian "le"}" + else if resolved.isPower then + "ppc${lib.strings.when resolved.isLittleEndian "le"}" + else if resolved.isMips64 then + "mips64" + else + resolved.system.cpu.name; + + release = null; }; - uname = { - system = - if resolved.system.kernel.name == "linux" - then "Linux" - else if resolved.system.kernel.name == "windows" - then "Windows" - else if resolved.system.kernel.name == "darwin" - then "Darwin" - else if resolved.system.kernel.name == "netbsd" - then "NetBSD" - else if resolved.system.kernel.name == "freebsd" - then "FreeBSD" - else if resolved.system.kernel.name == "openbsd" - then "OpenBSD" - else if resolved.system.kernel.name == "wasi" - then "Wasi" - else if resolved.system.kernel.name == "redox" - then "Redox" - else if resolved.system.kernel.name == "redox" - then "Genode" - else null; + useAndroidPrebuilt = false; + useiOSPrebuilt = false; - processor = - if resolved.isPower64 - then "ppc64${lib.strings.when resolved.isLittleEndian "le"}" - else if resolved.isPower - then "ppc${lib.strings.when resolved.isLittleEndian "le"}" - else if resolved.isMips64 - then "mips64" - else resolved.system.cpu.name; + linux.arch = + if resolved.isAarch32 then + "arm" + else if resolved.isAarch64 then + "arm64" + else if resolved.isx86_32 then + "i386" + else if resolved.isx86_64 then + "x86_64" + # linux kernel does not distinguish microblaze/microblazeel + else if resolved.isMicroBlaze then + "microblaze" + else if resolved.isMips32 then + "mips" + else if resolved.isMips64 then + "mips" # linux kernel does not distinguish mips32/mips64 + else if resolved.isPower then + "powerpc" + else if resolved.isRiscV then + "riscv" + else if resolved.isS390 then + "s390" + else if resolved.isLoongArch64 then + "loongarch" + else + resolved.system.cpu.name; - release = null; - }; + uboot.arch = + if resolved.isx86_32 then + "x86" # not i386 + else if resolved.isMips64 then + "mips64" # uboot *does* distinguish between mips32/mips64 + else + resolved.linux.arch; # other cases appear to agree with linuxArch - useAndroidPrebuilt = false; - useiOSPrebuilt = false; + qemu.arch = + if resolved.isAarch32 then + "arm" + else if resolved.isS390 && !resolved.isS390x then + null + else if resolved.isx86_64 then + "x86_64" + else if resolved.isx86 then + "i386" + else if resolved.isMips64n32 then + "mipsn32${lib.strings.when resolved.isLittleEndian "el"}" + else if resolved.isMips64 then + "mips64${lib.strings.when resolved.isLittleEndian "el"}" + else + resolved.uname.processor; - linux.arch = - if resolved.isAarch32 - then "arm" - else if resolved.isAarch64 - then "arm64" - else if resolved.isx86_32 - then "i386" - else if resolved.isx86_64 - then "x86_64" - # linux kernel does not distinguish microblaze/microblazeel - else if resolved.isMicroBlaze - then "microblaze" - else if resolved.isMips32 - then "mips" - else if resolved.isMips64 - then "mips" # linux kernel does not distinguish mips32/mips64 - else if resolved.isPower - then "powerpc" - else if resolved.isRiscV - then "riscv" - else if resolved.isS390 - then "s390" - else if resolved.isLoongArch64 - then "loongarch" - else resolved.system.cpu.name; + efi.arch = + if resolved.isx86_32 then + "ia32" + else if resolved.isx86_64 then + "x64" + else if resolved.isAarch32 then + "arm" + else if resolved.isAarch64 then + "aa64" + else + resolved.system.cpu.name; - uboot.arch = - if resolved.isx86_32 - then "x86" # not i386 - else if resolved.isMips64 - then "mips64" # uboot *does* distinguish between mips32/mips64 - else resolved.linux.arch; # other cases appear to agree with linuxArch + darwin = { + arch = + if resolved.system.cpu.name == "armv7a" then + "armv7" + else if resolved.system.cpu.name == "aarch64" then + "arm64" + else + resolved.system.cpu.name; - qemu.arch = - if resolved.isAarch32 - then "arm" - else if resolved.isS390 && !resolved.isS390x - then null - else if resolved.isx86_64 - then "x86_64" - else if resolved.isx86 - then "i386" - else if resolved.isMips64n32 - then "mipsn32${lib.strings.when resolved.isLittleEndian "el"}" - else if resolved.isMips64 - then "mips64${lib.strings.when resolved.isLittleEndian "el"}" - else resolved.uname.processor; + platform = + if resolved.isMacOS then + "macos" + else if resolved.isiOS then + "ios" + else + null; - efi.arch = - if resolved.isx86_32 - then "ia32" - else if resolved.isx86_64 - then "x64" - else if resolved.isAarch32 - then "arm" - else if resolved.isAarch64 - then "aa64" - else resolved.system.cpu.name; + sdk = { + version = resolved.darwinSdkVersion or (if resolved.isAarch64 then "11.0" else "10.12"); - darwin = { - arch = - if resolved.system.cpu.name == "armv7a" - then "armv7" - else if resolved.system.cpu.name == "aarch64" - then "arm64" - else resolved.system.cpu.name; + min = resolved.darwin.sdk.version; - platform = - if resolved.isMacOS - then "macos" - else if resolved.isiOS - then "ios" - else null; - - sdk = { - version = - resolved.darwinSdkVersion - or ( - if resolved.isAarch64 - then "11.0" - else "10.12" - ); - - min = resolved.darwin.sdk.version; - - variable = - if resolved.isMacOS - then "MACOSX_DEPLOYMENT_TARGET" - else if resolved.isiOS - then "IPHONEOS_DEPLOYMENT_TARGET" - else null; + variable = + if resolved.isMacOS then + "MACOSX_DEPLOYMENT_TARGET" + else if resolved.isiOS then + "IPHONEOS_DEPLOYMENT_TARGET" + else + null; + }; }; - }; - } - // builtins.mapAttrs (name: match: match resolved.system) lib'.systems.match - // builtins.mapAttrs (name: validate: validate (resolved.gcc.arch or "default")) lib'.systems.validate.architecture - // (builtins.removeAttrs settings ["system"]); + } + // builtins.mapAttrs (name: match: match resolved.system) lib'.systems.match + // builtins.mapAttrs ( + name: validate: validate (resolved.gcc.arch or "default") + ) lib'.systems.validate.architecture + // (builtins.removeAttrs settings [ "system" ]); - assertions = - builtins.foldl' - ( - result: { - assertion, - message, - }: - if assertion resolved - then result - else builtins.throw message - ) - true - (resolved.system.abi.assertions or []); - in + assertions = builtins.foldl' ( + result: { assertion, message }: if assertion resolved then result else builtins.throw message + ) true (resolved.system.abi.assertions or [ ]); + in assert resolved.useAndroidPrebuilt -> resolved.isAndroid; assert assertions; # And finally, return the generated system info. - resolved; + resolved; }; }; } diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index 7a579ac..7833e30 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -2,52 +2,57 @@ lib, lib', config, -}: { +}: +{ config = { lib.types = { - license = let - type = lib.types.submodule ({config}: { - options = { - name = { - full = lib.options.create { - description = "The full name of the license."; - type = lib.types.string; + license = + let + type = lib.types.submodule ( + { config }: + { + options = { + name = { + full = lib.options.create { + description = "The full name of the license."; + type = lib.types.string; + }; + + short = lib.options.create { + description = "The short name of the license."; + type = lib.types.string; + }; + }; + + spdx = lib.options.create { + description = "The SPDX identifier for the license."; + type = lib.types.nullish lib.types.string; + default.value = null; + }; + + url = lib.options.create { + description = "The URL for the license."; + type = lib.types.nullish lib.types.string; + }; + + free = lib.options.create { + description = "Whether the license is free."; + type = lib.types.bool; + default.value = true; + }; + + redistributable = lib.options.create { + description = "Whether the license is allows redistribution."; + type = lib.types.bool; + default = { + text = "config.free"; + value = config.free; + }; + }; }; - - short = lib.options.create { - description = "The short name of the license."; - type = lib.types.string; - }; - }; - - spdx = lib.options.create { - description = "The SPDX identifier for the license."; - type = lib.types.nullish lib.types.string; - default.value = null; - }; - - url = lib.options.create { - description = "The URL for the license."; - type = lib.types.nullish lib.types.string; - }; - - free = lib.options.create { - description = "Whether the license is free."; - type = lib.types.bool; - default.value = true; - }; - - redistributable = lib.options.create { - description = "Whether the license is allows redistribution."; - type = lib.types.bool; - default = { - text = "config.free"; - value = config.free; - }; - }; - }; - }); - in + } + ); + in lib.types.either type (lib.types.list.of type); builder = lib.types.submodule { @@ -63,251 +68,254 @@ packages = lib.types.attrs.of (lib'.types.alias); - alias = lib.types.attrs.of (lib.types.submodule { - options = { - versions = lib.options.create { - description = "All available package versions."; - type = lib.types.attrs.of lib'.types.package; + alias = lib.types.attrs.of ( + lib.types.submodule { + options = { + versions = lib.options.create { + description = "All available package versions."; + type = lib.types.attrs.of lib'.types.package; + }; }; - }; - }); + } + ); - dependencies = lib.types.attrs.of (lib.types.nullish (lib.types.either lib'.types.alias lib'.types.package)); + dependencies = lib.types.attrs.of ( + lib.types.nullish (lib.types.either lib'.types.alias lib'.types.package) + ); - package = lib.types.submodule ({ - config, - meta, - }: { - options = { - extend = lib.options.create { - description = "Extend the package's submodules with additional configuration."; - type = lib.types.function lib.types.raw; - default.value = value: let - result = meta.extend { - modules = - if builtins.isAttrs value - then [{config = value;}] - else lib.lists.from.any value; + package = lib.types.submodule ( + { config, meta }: + { + options = { + extend = lib.options.create { + description = "Extend the package's submodules with additional configuration."; + type = lib.types.function lib.types.raw; + default.value = + value: + let + result = meta.extend { + modules = if builtins.isAttrs value then [ { config = value; } ] else lib.lists.from.any value; + }; + in + result.config; + }; + + name = lib.options.create { + description = "The name of the package."; + type = lib.types.string; + default = { + text = "\${config.pname}-\${config.version}"; + value = + if config.pname != null && config.version != null then "${config.pname}-${config.version}" else ""; }; - in - result.config; - }; - - name = lib.options.create { - description = "The name of the package."; - type = lib.types.string; - default = { - text = "\${config.pname}-\${config.version}"; - value = - if config.pname != null && config.version != null - then "${config.pname}-${config.version}" - else ""; }; - }; - pname = lib.options.create { - description = "The program name for the package"; - type = lib.types.nullish lib.types.string; - default.value = null; - }; - - version = lib.options.create { - description = "The version for the package."; - type = lib.types.nullish lib.types.version; - default.value = null; - }; - - meta = { - description = lib.options.create { - description = "The description for the package."; + pname = lib.options.create { + description = "The program name for the package"; type = lib.types.nullish lib.types.string; default.value = null; }; - homepage = lib.options.create { - description = "The homepage for the package."; - type = lib.types.nullish lib.types.string; + version = lib.options.create { + description = "The version for the package."; + type = lib.types.nullish lib.types.version; default.value = null; }; - license = lib.options.create { - description = "The license for the package."; - type = lib.types.nullish lib'.types.license; - default.value = null; - }; - - free = lib.options.create { - description = "Whether the package is free."; - type = lib.types.bool; - default.value = true; - }; - - insecure = lib.options.create { - description = "Whether the package is insecure."; - type = lib.types.bool; - default.value = false; - }; - - broken = lib.options.create { - description = "Whether the package is broken."; - type = lib.types.bool; - default.value = false; - }; - - main = lib.options.create { - description = "The main entry point for the package."; - type = lib.types.nullish lib.types.string; - default.value = null; - }; - - platforms = lib.options.create { - description = "The platforms the package supports."; - type = lib.types.list.of lib.types.string; - default.value = []; - }; - }; - - platform = { - build = lib.options.create { - description = "The build platform for the package."; - type = lib.types.string; - default.value = "x86_64-linux"; - apply = raw: let - system = lib'.systems.from.string raw; - x = lib'.systems.withBuildInfo raw; - in - x; - }; - - host = lib.options.create { - description = "The host platform for the package."; - type = lib.types.string; - default.value = "x86_64-linux"; - # apply = raw: let - # system = lib'.systems.from.string raw; - # in { - # inherit raw system; - - # double = lib'.systems.into.double system; - # triple = lib'.systems.into.triple system; - # }; - apply = raw: let - system = lib'.systems.from.string raw; - x = lib'.systems.withBuildInfo raw; - in - x; - }; - - target = lib.options.create { - description = "The target platform for the package."; - type = lib.types.string; - default.value = "x86_64-linux"; - # apply = raw: let - # system = lib'.systems.from.string raw; - # in { - # inherit raw system; - - # double = lib'.systems.into.double system; - # triple = lib'.systems.into.triple system; - # }; - apply = raw: let - system = lib'.systems.from.string raw; - x = lib'.systems.withBuildInfo raw; - in - x; - }; - }; - - phases = lib.options.create { - description = "The phases for the package."; - type = lib.types.dag.of ( - lib.types.either - lib.types.string - (lib.types.function lib.types.string) - ); - default.value = {}; - }; - - env = lib.options.create { - description = "The environment for the package."; - type = lib.types.attrs.of lib.types.string; - default.value = {}; - }; - - builder = lib.options.create { - description = "The builder for the package."; - type = lib'.types.builder; - }; - - deps = { - build = { - only = lib.options.create { - description = "Dependencies which are only used in the build environment."; - type = lib'.types.dependencies; - default.value = {}; + meta = { + description = lib.options.create { + description = "The description for the package."; + type = lib.types.nullish lib.types.string; + default.value = null; }; + homepage = lib.options.create { + description = "The homepage for the package."; + type = lib.types.nullish lib.types.string; + default.value = null; + }; + + license = lib.options.create { + description = "The license for the package."; + type = lib.types.nullish lib'.types.license; + default.value = null; + }; + + free = lib.options.create { + description = "Whether the package is free."; + type = lib.types.bool; + default.value = true; + }; + + insecure = lib.options.create { + description = "Whether the package is insecure."; + type = lib.types.bool; + default.value = false; + }; + + broken = lib.options.create { + description = "Whether the package is broken."; + type = lib.types.bool; + default.value = false; + }; + + main = lib.options.create { + description = "The main entry point for the package."; + type = lib.types.nullish lib.types.string; + default.value = null; + }; + + platforms = lib.options.create { + description = "The platforms the package supports."; + type = lib.types.list.of lib.types.string; + default.value = [ ]; + }; + }; + + platform = { build = lib.options.create { - description = "Dependencies which are created in the build environment and are executed in the build environment."; - type = lib'.types.dependencies; - default.value = {}; + description = "The build platform for the package."; + type = lib.types.string; + default.value = "x86_64-linux"; + apply = + raw: + let + system = lib'.systems.from.string raw; + x = lib'.systems.withBuildInfo raw; + in + x; }; host = lib.options.create { - description = "Dependencies which are created in the build environment and are executed in the host environment."; - type = lib'.types.dependencies; - default.value = {}; + description = "The host platform for the package."; + type = lib.types.string; + default.value = "x86_64-linux"; + # apply = raw: let + # system = lib'.systems.from.string raw; + # in { + # inherit raw system; + + # double = lib'.systems.into.double system; + # triple = lib'.systems.into.triple system; + # }; + apply = + raw: + let + system = lib'.systems.from.string raw; + x = lib'.systems.withBuildInfo raw; + in + x; }; target = lib.options.create { - description = "Dependencies which are created in the build environment and are executed in the target environment."; - type = lib'.types.dependencies; - default.value = {}; + description = "The target platform for the package."; + type = lib.types.string; + default.value = "x86_64-linux"; + # apply = raw: let + # system = lib'.systems.from.string raw; + # in { + # inherit raw system; + + # double = lib'.systems.into.double system; + # triple = lib'.systems.into.triple system; + # }; + apply = + raw: + let + system = lib'.systems.from.string raw; + x = lib'.systems.withBuildInfo raw; + in + x; }; }; - host = { - only = lib.options.create { - description = "Dependencies which are only used in the host environment."; - type = lib'.types.dependencies; - default.value = {}; + phases = lib.options.create { + description = "The phases for the package."; + type = lib.types.dag.of (lib.types.either lib.types.string (lib.types.function lib.types.string)); + default.value = { }; + }; + + env = lib.options.create { + description = "The environment for the package."; + type = lib.types.attrs.of lib.types.string; + default.value = { }; + }; + + builder = lib.options.create { + description = "The builder for the package."; + type = lib'.types.builder; + }; + + deps = { + build = { + only = lib.options.create { + description = "Dependencies which are only used in the build environment."; + type = lib'.types.dependencies; + default.value = { }; + }; + + build = lib.options.create { + description = "Dependencies which are created in the build environment and are executed in the build environment."; + type = lib'.types.dependencies; + default.value = { }; + }; + + host = lib.options.create { + description = "Dependencies which are created in the build environment and are executed in the host environment."; + type = lib'.types.dependencies; + default.value = { }; + }; + + target = lib.options.create { + description = "Dependencies which are created in the build environment and are executed in the target environment."; + type = lib'.types.dependencies; + default.value = { }; + }; }; - host = lib.options.create { - description = "Dependencies which are executed in the host environment."; - type = lib'.types.dependencies; - default.value = {}; + host = { + only = lib.options.create { + description = "Dependencies which are only used in the host environment."; + type = lib'.types.dependencies; + default.value = { }; + }; + + host = lib.options.create { + description = "Dependencies which are executed in the host environment."; + type = lib'.types.dependencies; + default.value = { }; + }; + + target = lib.options.create { + description = "Dependencies which are executed in the host environment which produces code for the target environment."; + type = lib'.types.dependencies; + default.value = { }; + }; }; - target = lib.options.create { - description = "Dependencies which are executed in the host environment which produces code for the target environment."; - type = lib'.types.dependencies; - default.value = {}; + target = { + only = lib.options.create { + description = "Dependencies which are only used in the target environment."; + type = lib'.types.dependencies; + default.value = { }; + }; + + target = lib.options.create { + description = "Dependencies which are executed in the target environment."; + type = lib'.types.dependencies; + default.value = { }; + }; }; }; - target = { - only = lib.options.create { - description = "Dependencies which are only used in the target environment."; - type = lib'.types.dependencies; - default.value = {}; - }; - - target = lib.options.create { - description = "Dependencies which are executed in the target environment."; - type = lib'.types.dependencies; - default.value = {}; - }; + package = lib.options.create { + description = "The built derivation."; + type = lib.types.derivation; + default.value = config.builder.build config; }; }; - - package = lib.options.create { - description = "The built derivation."; - type = lib.types.derivation; - default.value = config.builder.build config; - }; - }; - }); + } + ); }; }; } diff --git a/tidepool/src/mirrors/default.nix b/tidepool/src/mirrors/default.nix index 6de6799..79eaab4 100644 --- a/tidepool/src/mirrors/default.nix +++ b/tidepool/src/mirrors/default.nix @@ -1,5 +1 @@ -{ - includes = [ - ./gnu.nix - ]; -} +{ includes = [ ./gnu.nix ]; } diff --git a/tidepool/src/mirrors/gnu.nix b/tidepool/src/mirrors/gnu.nix index a38a329..45f2181 100644 --- a/tidepool/src/mirrors/gnu.nix +++ b/tidepool/src/mirrors/gnu.nix @@ -1,4 +1,5 @@ -{lib}: { +{ lib }: +{ options.mirrors = { gnu = lib.options.create { description = "The GNU mirror to use"; diff --git a/tidepool/src/packages/default.nix b/tidepool/src/packages/default.nix index 09d4d70..b6a57bf 100644 --- a/tidepool/src/packages/default.nix +++ b/tidepool/src/packages/default.nix @@ -2,36 +2,39 @@ lib, lib', config, -}: let +}: +let doubles = lib'.systems.doubles.all; - packages = builtins.removeAttrs config.packages ["cross"]; -in { - includes = [ - ./foundation - ]; + packages = builtins.removeAttrs config.packages [ "cross" ]; +in +{ + includes = [ ./foundation ]; options = { packages = lib.options.create { description = "The package set."; type = lib.types.submodule { - freeform = lib.types.attrs.of (lib.types.submodule { - freeform = lib'.types.alias; - }); + freeform = lib.types.attrs.of (lib.types.submodule { freeform = lib'.types.alias; }); - options.cross = lib.attrs.generate doubles (system: + options.cross = lib.attrs.generate doubles ( + system: lib.options.create { description = "The cross-compiled package set for the ${system} target."; type = lib'.types.packages; - default = {}; - }); + default = { }; + } + ); }; }; preferences.packages = { version = lib.options.create { description = "The preferred package version when using aliases."; - type = lib.types.enum ["latest" "stable"]; + type = lib.types.enum [ + "latest" + "stable" + ]; default.value = "latest"; }; }; @@ -39,15 +42,17 @@ in { config.packages.cross = lib.attrs.generate doubles ( system: - builtins.mapAttrs - ( - namespace: - builtins.mapAttrs - (name: alias: let - setHost = package: - if package != {} - then - (package.extend ({config}: { + builtins.mapAttrs ( + namespace: + builtins.mapAttrs ( + name: alias: + let + setHost = + package: + if package != { } then + (package.extend ( + { config }: + { config = { platform = { host = lib.modules.overrides.force system; @@ -72,21 +77,17 @@ in { }; }; }; - })) - .config - else package; + } + )).config + else + package; - updated = - alias - // { - versions = - builtins.mapAttrs - (version: package: setHost package) - alias.versions; - }; - in - updated) + updated = alias // { + versions = builtins.mapAttrs (version: package: setHost package) alias.versions; + }; + in + updated ) - packages + ) packages ); } diff --git a/tidepool/src/packages/foundation/binutils/default.nix b/tidepool/src/packages/foundation/binutils/default.nix index 1121354..b66ba7d 100644 --- a/tidepool/src/packages/foundation/binutils/default.nix +++ b/tidepool/src/packages/foundation/binutils/default.nix @@ -3,115 +3,117 @@ lib', config, options, -}: let - inherit - (config) +}: +let + inherit (config) mirrors builders # These are the upstream foundational packages exported from the Aux Foundation project. - + foundation ; -in { +in +{ config.packages.foundation.binutils = { versions = { - "latest" = { - config, - meta, - }: { - options = { - src = lib.options.create { - type = lib.types.derivation; - description = "Source for the package."; + "latest" = + { config, meta }: + { + options = { + src = lib.options.create { + type = lib.types.derivation; + description = "Source for the package."; + }; + }; + + config = { + meta = { + platforms = [ "i686-linux" ]; + }; + + pname = "binutils"; + version = "2.41"; + + builder = builders.basic; + + env = { + PATH = lib.paths.bin [ + foundation.stage2-gcc + foundation.stage2-binutils + foundation.stage2-gnumake + foundation.stage2-gnupatch + foundation.stage2-gnused + foundation.stage2-gnugrep + foundation.stage2-gawk + foundation.stage2-diffutils + foundation.stage2-findutils + foundation.stage2-gnutar + foundation.stage1-xz + ]; + }; + + phases = + let + patches = [ + # Make binutils output deterministic by default. + ./patches/deterministic.patch + ]; + + configureFlags = [ + # "CC=musl-gcc" + "LDFLAGS=--static" + "--prefix=${builtins.placeholder "out"}" + "--build=${config.platform.build.triple}" + "--host=${config.platform.host.triple}" + "--target=${config.platform.target.triple}" + + "--with-sysroot=/" + "--enable-deterministic-archives" + # depends on bison + "--disable-gprofng" + + # Turn on --enable-new-dtags by default to make the linker set + # RUNPATH instead of RPATH on binaries. This is important because + # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. + "--enable-new-dtags" + + # By default binutils searches $libdir for libraries. This brings in + # libbfd and libopcodes into a default visibility. Drop default lib + # path to force users to declare their use of these libraries. + "--with-lib-path=:" + + "--disable-multilib" + ]; + in + { + unpack = lib.dag.entry.before [ "patch" ] '' + tar xf ${config.src} + cd binutils-${config.version} + ''; + + patch = lib.dag.entry.between [ "configure" ] [ "unpack" ] '' + ${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches} + ''; + + configure = lib.dag.entry.between [ "build" ] [ "patch" ] '' + bash ./configure ${builtins.concatStringsSep " " configureFlags} + ''; + + build = lib.dag.entry.between [ "install" ] [ "configure" ] '' + make -j $NIX_BUILD_CORES + ''; + + install = lib.dag.entry.after [ "build" ] '' + make -j $NIX_BUILD_CORES install-strip + ''; + }; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/binutils/binutils-${config.version}.tar.xz"; + sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA="; + }; }; }; - - config = { - meta = { - platforms = ["i686-linux"]; - }; - - pname = "binutils"; - version = "2.41"; - - builder = builders.basic; - - env = { - PATH = lib.paths.bin [ - foundation.stage2-gcc - foundation.stage2-binutils - foundation.stage2-gnumake - foundation.stage2-gnupatch - foundation.stage2-gnused - foundation.stage2-gnugrep - foundation.stage2-gawk - foundation.stage2-diffutils - foundation.stage2-findutils - foundation.stage2-gnutar - foundation.stage1-xz - ]; - }; - - phases = let - patches = [ - # Make binutils output deterministic by default. - ./patches/deterministic.patch - ]; - - configureFlags = [ - # "CC=musl-gcc" - "LDFLAGS=--static" - "--prefix=${builtins.placeholder "out"}" - "--build=${config.platform.build.triple}" - "--host=${config.platform.host.triple}" - "--target=${config.platform.target.triple}" - - "--with-sysroot=/" - "--enable-deterministic-archives" - # depends on bison - "--disable-gprofng" - - # Turn on --enable-new-dtags by default to make the linker set - # RUNPATH instead of RPATH on binaries. This is important because - # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. - "--enable-new-dtags" - - # By default binutils searches $libdir for libraries. This brings in - # libbfd and libopcodes into a default visibility. Drop default lib - # path to force users to declare their use of these libraries. - "--with-lib-path=:" - - "--disable-multilib" - ]; - in { - unpack = lib.dag.entry.before ["patch"] '' - tar xf ${config.src} - cd binutils-${config.version} - ''; - - patch = lib.dag.entry.between ["configure"] ["unpack"] '' - ${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches} - ''; - - configure = lib.dag.entry.between ["build"] ["patch"] '' - bash ./configure ${builtins.concatStringsSep " " configureFlags} - ''; - - build = lib.dag.entry.between ["install"] ["configure"] '' - make -j $NIX_BUILD_CORES - ''; - - install = lib.dag.entry.after ["build"] '' - make -j $NIX_BUILD_CORES install-strip - ''; - }; - - src = builtins.fetchurl { - url = "${mirrors.gnu}/binutils/binutils-${config.version}.tar.xz"; - sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA="; - }; - }; - }; }; }; } diff --git a/tidepool/src/packages/foundation/default.nix b/tidepool/src/packages/foundation/default.nix index 8b62be3..a22eab9 100644 --- a/tidepool/src/packages/foundation/default.nix +++ b/tidepool/src/packages/foundation/default.nix @@ -3,7 +3,8 @@ lib', config, options, -}: { +}: +{ includes = [ ./gcc ./binutils diff --git a/tidepool/src/packages/foundation/gcc/default.nix b/tidepool/src/packages/foundation/gcc/default.nix index 03214a9..98f9ae6 100644 --- a/tidepool/src/packages/foundation/gcc/default.nix +++ b/tidepool/src/packages/foundation/gcc/default.nix @@ -3,235 +3,234 @@ lib', config, options, -}: let - inherit - (config) +}: +let + inherit (config) mirrors builders # These are the upstream foundational packages exported from the Aux Foundation project. - + foundation ; -in { +in +{ config.packages.foundation.gcc = { versions = { - "latest" = { - config, - meta, - }: { - options = { - src = lib.options.create { - type = lib.types.derivation; - description = "Source for the package."; - }; - - cc = { + "latest" = + { config, meta }: + { + options = { src = lib.options.create { type = lib.types.derivation; - description = "The cc source for the package."; + description = "Source for the package."; + }; + + cc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The cc source for the package."; + }; + }; + + gmp = { + src = lib.options.create { + type = lib.types.derivation; + description = "The gmp source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of gmp."; + }; + }; + + mpfr = { + src = lib.options.create { + type = lib.types.derivation; + description = "The mpfr source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpfr."; + }; + }; + + mpc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The mpc source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpc."; + }; + }; + + isl = { + src = lib.options.create { + type = lib.types.derivation; + description = "The isl source for the package."; + }; + version = lib.options.create { + type = lib.types.string; + description = "Version of isl."; + }; }; }; - gmp = { - src = lib.options.create { - type = lib.types.derivation; - description = "The gmp source for the package."; + config = { + meta = { + platforms = [ "i686-linux" ]; }; - version = lib.options.create { - type = lib.types.string; - description = "Version of gmp."; - }; - }; + pname = "gcc"; + version = "13.2.0"; - mpfr = { - src = lib.options.create { - type = lib.types.derivation; - description = "The mpfr source for the package."; + builder = builders.basic; + + env = { + PATH = + let + gcc = + if + config.platform.build.triple == config.platform.host.triple + # If we're on the same system then we can use the existing GCC instance. + then + foundation.stage2-gcc + # Otherwise we are going to need a cross-compiler. + else + # TODO: Create a gcc-cross package. + (meta.extend (args: { + config = { + platform = { + build = config.platform.build.triple; + host = config.platform.build.triple; + target = lib.modules.override.force config.platform.host.triple; + }; + }; + })).config.package; + in + lib.paths.bin [ + foundation.stage2-gcc + foundation.stage2-binutils + foundation.stage2-gnumake + foundation.stage2-gnused + foundation.stage2-gnugrep + foundation.stage2-gawk + foundation.stage2-diffutils + foundation.stage2-findutils + foundation.stage2-gnutar + foundation.stage2-gzip + foundation.stage2-bzip2 + foundation.stage1-xz + ]; }; - version = lib.options.create { - type = lib.types.string; - description = "Version of mpfr."; - }; - }; + phases = + let + host = lib'.systems.withBuildInfo config.platform.host; - mpc = { - src = lib.options.create { - type = lib.types.derivation; - description = "The mpc source for the package."; + mbits = if host.system.cpu.family == "x86" then if host.is64bit then "-m64" else "-m32" else ""; + in + { + unpack = lib.dag.entry.before [ "patch" ] '' + # Unpack + tar xf ${config.src} + tar xf ${config.gmp.src} + tar xf ${config.mpfr.src} + tar xf ${config.mpc.src} + tar xf ${config.isl.src} + cd gcc-${config.version} + + ln -s ../gmp-${config.gmp.version} gmp + ln -s ../mpfr-${config.mpfr.version} mpfr + ln -s ../mpc-${config.mpc.version} mpc + ln -s ../isl-${config.isl.version} isl + ''; + + patch = lib.dag.entry.between [ "configure" ] [ "unpack" ] '' + # Patch + # force musl even if host triple is gnu + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + ''; + + configure = lib.dag.entry.between [ "build" ] [ "patch" ] '' + # Configure + export CC="gcc -Wl,-dynamic-linker -march=${ + host.gcc.arch or host.system.cpu.family + } ${mbits} -Wl,${foundation.stage1-musl}/lib/libc.so" + export CXX="g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" + export LIBRARY_PATH="${foundation.stage1-musl}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${config.platform.build.triple} \ + --host=${config.platform.host.triple} \ + --target=${config.platform.target.triple} \ + --with-native-system-header-dir=/include \ + --with-sysroot=${foundation.stage1-musl} \ + --enable-languages=c,c++ \ + --disable-bootstrap \ + --disable-libsanitizer \ + --disable-lto \ + --disable-multilib \ + --disable-plugin \ + CFLAGS=-static \ + CXXFLAGS=-static + ''; + + build = lib.dag.entry.between [ "install" ] [ "configure" ] '' + # Build + make -j $NIX_BUILD_CORES + ''; + + install = lib.dag.entry.after [ "build" ] '' + # Install + make -j $NIX_BUILD_CORES install-strip + ''; + }; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/gcc/gcc-${config.version}/gcc-${config.version}.tar.xz"; + sha256 = "4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; }; - version = lib.options.create { - type = lib.types.string; - description = "Version of mpc."; + gmp = { + version = "6.3.0"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/gmp/gmp-${config.gmp.version}.tar.xz"; + sha256 = "o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; + }; }; - }; - isl = { - src = lib.options.create { - type = lib.types.derivation; - description = "The isl source for the package."; + mpfr = { + version = "4.2.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpfr/mpfr-${config.mpfr.version}.tar.xz"; + sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; }; - version = lib.options.create { - type = lib.types.string; - description = "Version of isl."; + + mpc = { + version = "1.3.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpc/mpc-${config.mpc.version}.tar.gz"; + sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + }; + + isl = { + version = "0.24"; + src = builtins.fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${config.isl.version}.tar.bz2"; + sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; }; }; }; - - config = { - meta = { - platforms = ["i686-linux"]; - }; - - pname = "gcc"; - version = "13.2.0"; - - builder = builders.basic; - - env = { - PATH = let - gcc = - if config.platform.build.triple == config.platform.host.triple - # If we're on the same system then we can use the existing GCC instance. - then foundation.stage2-gcc - # Otherwise we are going to need a cross-compiler. - else - # TODO: Create a gcc-cross package. - (meta.extend (args: { - config = { - platform = { - build = config.platform.build.triple; - host = config.platform.build.triple; - target = lib.modules.override.force config.platform.host.triple; - }; - }; - })) - .config - .package; - in - lib.paths.bin [ - foundation.stage2-gcc - foundation.stage2-binutils - foundation.stage2-gnumake - foundation.stage2-gnused - foundation.stage2-gnugrep - foundation.stage2-gawk - foundation.stage2-diffutils - foundation.stage2-findutils - foundation.stage2-gnutar - foundation.stage2-gzip - foundation.stage2-bzip2 - foundation.stage1-xz - ]; - }; - - phases = let - host = lib'.systems.withBuildInfo config.platform.host; - - mbits = - if host.system.cpu.family == "x86" - then - if host.is64bit - then "-m64" - else "-m32" - else ""; - in { - unpack = lib.dag.entry.before ["patch"] '' - # Unpack - tar xf ${config.src} - tar xf ${config.gmp.src} - tar xf ${config.mpfr.src} - tar xf ${config.mpc.src} - tar xf ${config.isl.src} - cd gcc-${config.version} - - ln -s ../gmp-${config.gmp.version} gmp - ln -s ../mpfr-${config.mpfr.version} mpfr - ln -s ../mpc-${config.mpc.version} mpc - ln -s ../isl-${config.isl.version} isl - ''; - - patch = lib.dag.entry.between ["configure"] ["unpack"] '' - # Patch - # force musl even if host triple is gnu - sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host - ''; - - configure = lib.dag.entry.between ["build"] ["patch"] '' - # Configure - export CC="gcc -Wl,-dynamic-linker -march=${host.gcc.arch or host.system.cpu.family} ${mbits} -Wl,${foundation.stage1-musl}/lib/libc.so" - export CXX="g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" - export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" - export LIBRARY_PATH="${foundation.stage1-musl}/lib" - - bash ./configure \ - --prefix=$out \ - --build=${config.platform.build.triple} \ - --host=${config.platform.host.triple} \ - --target=${config.platform.target.triple} \ - --with-native-system-header-dir=/include \ - --with-sysroot=${foundation.stage1-musl} \ - --enable-languages=c,c++ \ - --disable-bootstrap \ - --disable-libsanitizer \ - --disable-lto \ - --disable-multilib \ - --disable-plugin \ - CFLAGS=-static \ - CXXFLAGS=-static - ''; - - build = lib.dag.entry.between ["install"] ["configure"] '' - # Build - make -j $NIX_BUILD_CORES - ''; - - install = lib.dag.entry.after ["build"] '' - # Install - make -j $NIX_BUILD_CORES install-strip - ''; - }; - - src = builtins.fetchurl { - url = "${mirrors.gnu}/gcc/gcc-${config.version}/gcc-${config.version}.tar.xz"; - sha256 = "4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; - }; - - gmp = { - version = "6.3.0"; - src = builtins.fetchurl { - url = "${mirrors.gnu}/gmp/gmp-${config.gmp.version}.tar.xz"; - sha256 = "o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; - }; - }; - - mpfr = { - version = "4.2.1"; - src = builtins.fetchurl { - url = "${mirrors.gnu}/mpfr/mpfr-${config.mpfr.version}.tar.xz"; - sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; - }; - }; - - mpc = { - version = "1.3.1"; - src = builtins.fetchurl { - url = "${mirrors.gnu}/mpc/mpc-${config.mpc.version}.tar.gz"; - sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; - }; - }; - - isl = { - version = "0.24"; - src = builtins.fetchurl { - url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${config.isl.version}.tar.bz2"; - sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; - }; - }; - }; - }; }; }; } diff --git a/tidepool/src/packages/foundation/glibc/default.nix b/tidepool/src/packages/foundation/glibc/default.nix index 6fe7e50..3a55dc0 100644 --- a/tidepool/src/packages/foundation/glibc/default.nix +++ b/tidepool/src/packages/foundation/glibc/default.nix @@ -3,110 +3,111 @@ lib', config, options, -}: let - inherit - (config) +}: +let + inherit (config) mirrors builders # These are the upstream foundational packages exported from the Aux Foundation project. - + foundation ; -in { +in +{ config.packages.foundation.glibc = { versions = { - "latest" = { - config, - meta, - }: { - options = { - src = lib.options.create { - type = lib.types.derivation; - description = "Source for the package."; + "latest" = + { config, meta }: + { + options = { + src = lib.options.create { + type = lib.types.derivation; + description = "Source for the package."; + }; + }; + + config = { + meta = { + platforms = [ "i686-linux" ]; + }; + + pname = "gcc"; + version = "2.38"; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/libc/glibc-${config.version}.tar.xz"; + sha256 = "+4KZiZiyspllRnvBtp0VLpwwfSzzAcnq+0VVt3DvP9I="; + }; + + builder = builders.basic; + + env = { + PATH = + let + gcc = + if + config.platform.build.triple == config.platform.host.triple + # If we're on the same system then we can use the existing GCC instance. + then + foundation.stage2-gcc + # Otherwise we are going to need a cross-compiler. + else + (meta.extend (args: { + config = { + platform = { + build = config.platform.build.triple; + host = config.platform.build.triple; + target = lib.modules.override.force config.platform.host.triple; + }; + }; + })).config.package; + in + lib.paths.bin [ + foundation.stage2-gcc + foundation.stage2-binutils + foundation.stage2-gnumake + foundation.stage2-gnused + foundation.stage2-gnugrep + foundation.stage2-gawk + foundation.stage2-diffutils + foundation.stage2-findutils + foundation.stage2-gnutar + foundation.stage2-gzip + foundation.stage2-bzip2 + foundation.stage1-xz + ]; + }; + + phases = { + unpack = lib.dag.entry.before [ "patch" ] '' + tar xf ${config.src} + cd glibc-${config.version} + ''; + + configure = lib.dag.entry.between [ "build" ] [ "patch" ] '' + mkdir build + cd build + # libstdc++.so is built against musl and fails to link + export CXX=false + bash ../configure \ + --prefix=$out \ + --build=${config.platform.build.triple} \ + --host=${config.platform.host.triple} \ + --with-headers=${foundation.stage1-linux-headers}/include + ''; + + build = lib.dag.entry.between [ "install" ] [ "configure" ] '' + # Build + make -j $NIX_BUILD_CORES + ''; + + install = lib.dag.entry.after [ "build" ] '' + # Install + make -j $NIX_BUILD_CORES install-strip + ''; + }; }; }; - - config = { - meta = { - platforms = ["i686-linux"]; - }; - - pname = "gcc"; - version = "2.38"; - - src = builtins.fetchurl { - url = "${mirrors.gnu}/libc/glibc-${config.version}.tar.xz"; - sha256 = "+4KZiZiyspllRnvBtp0VLpwwfSzzAcnq+0VVt3DvP9I="; - }; - - builder = builders.basic; - - env = { - PATH = let - gcc = - if config.platform.build.triple == config.platform.host.triple - # If we're on the same system then we can use the existing GCC instance. - then foundation.stage2-gcc - # Otherwise we are going to need a cross-compiler. - else - (meta.extend (args: { - config = { - platform = { - build = config.platform.build.triple; - host = config.platform.build.triple; - target = lib.modules.override.force config.platform.host.triple; - }; - }; - })) - .config - .package; - in - lib.paths.bin [ - foundation.stage2-gcc - foundation.stage2-binutils - foundation.stage2-gnumake - foundation.stage2-gnused - foundation.stage2-gnugrep - foundation.stage2-gawk - foundation.stage2-diffutils - foundation.stage2-findutils - foundation.stage2-gnutar - foundation.stage2-gzip - foundation.stage2-bzip2 - foundation.stage1-xz - ]; - }; - - phases = { - unpack = lib.dag.entry.before ["patch"] '' - tar xf ${config.src} - cd glibc-${config.version} - ''; - - configure = lib.dag.entry.between ["build"] ["patch"] '' - mkdir build - cd build - # libstdc++.so is built against musl and fails to link - export CXX=false - bash ../configure \ - --prefix=$out \ - --build=${config.platform.build.triple} \ - --host=${config.platform.host.triple} \ - --with-headers=${foundation.stage1-linux-headers}/include - ''; - - build = lib.dag.entry.between ["install"] ["configure"] '' - # Build - make -j $NIX_BUILD_CORES - ''; - - install = lib.dag.entry.after ["build"] '' - # Install - make -j $NIX_BUILD_CORES install-strip - ''; - }; - }; - }; }; }; } diff --git a/tidepool/src/packages/foundation/linux-headers/default.nix b/tidepool/src/packages/foundation/linux-headers/default.nix index d8ba05e..cb85a6f 100644 --- a/tidepool/src/packages/foundation/linux-headers/default.nix +++ b/tidepool/src/packages/foundation/linux-headers/default.nix @@ -3,87 +3,83 @@ lib', config, options, -}: let - inherit - (config) +}: +let + inherit (config) mirrors builders # These are the upstream foundational packages exported from the Aux Foundation project. - + foundation ; -in { +in +{ config.packages.foundation.linux-headers = { versions = { - "latest" = { - config, - meta, - }: { - options = { - src = lib.options.create { - type = lib.types.derivation; - description = "Source for the package."; - }; - }; - - config = { - meta = { - platforms = ["i686-linux"]; + "latest" = + { config, meta }: + { + options = { + src = lib.options.create { + type = lib.types.derivation; + description = "Source for the package."; + }; }; - pname = "linux-headers"; - version = "6.5.6"; + config = { + meta = { + platforms = [ "i686-linux" ]; + }; - builder = builders.basic; + pname = "linux-headers"; + version = "6.5.6"; - env = { - PATH = lib.paths.bin [ - foundation.stage2-gcc - foundation.stage1-musl - foundation.stage2-binutils - foundation.stage2-gnumake - foundation.stage2-gnupatch - foundation.stage2-gnused - foundation.stage2-gnugrep - foundation.stage2-gawk - foundation.stage2-diffutils - foundation.stage2-findutils - foundation.stage2-gnutar - foundation.stage1-xz - ]; - }; + builder = builders.basic; - phases = { - unpack = lib.dag.entry.before ["patch"] '' - tar xf ${config.src} - cd linux-${config.version} - ''; + env = { + PATH = lib.paths.bin [ + foundation.stage2-gcc + foundation.stage1-musl + foundation.stage2-binutils + foundation.stage2-gnumake + foundation.stage2-gnupatch + foundation.stage2-gnused + foundation.stage2-gnugrep + foundation.stage2-gawk + foundation.stage2-diffutils + foundation.stage2-findutils + foundation.stage2-gnutar + foundation.stage1-xz + ]; + }; - patch = - lib.dag.entry.between ["configure"] ["unpack"] '' + phases = { + unpack = lib.dag.entry.before [ "patch" ] '' + tar xf ${config.src} + cd linux-${config.version} ''; - configure = - lib.dag.entry.between ["build"] ["patch"] '' + patch = lib.dag.entry.between [ "configure" ] [ "unpack" ] ''''; + + configure = lib.dag.entry.between [ "build" ] [ "patch" ] ''''; + + build = lib.dag.entry.between [ "install" ] [ "configure" ] '' + make -j $NIX_BUILD_CORES CC=musl-gcc HOSTCC=musl-gcc ARCH=${config.platform.host.linux.arch} headers ''; - build = lib.dag.entry.between ["install"] ["configure"] '' - make -j $NIX_BUILD_CORES CC=musl-gcc HOSTCC=musl-gcc ARCH=${config.platform.host.linux.arch} headers - ''; + install = lib.dag.entry.after [ "build" ] '' + find usr/include -name '.*' -exec rm {} + + mkdir -p $out + cp -rv usr/include $out/ + ''; + }; - install = lib.dag.entry.after ["build"] '' - find usr/include -name '.*' -exec rm {} + - mkdir -p $out - cp -rv usr/include $out/ - ''; - }; - - src = builtins.fetchurl { - url = "https://cdn.kernel.org/pub/linux/kernel/v${lib.versions.major config.version}.x/linux-${config.version}.tar.xz"; - sha256 = "eONtQhRUcFHCTfIUD0zglCjWxRWtmnGziyjoCUqV0vY="; + src = builtins.fetchurl { + url = "https://cdn.kernel.org/pub/linux/kernel/v${lib.versions.major config.version}.x/linux-${config.version}.tar.xz"; + sha256 = "eONtQhRUcFHCTfIUD0zglCjWxRWtmnGziyjoCUqV0vY="; + }; }; }; - }; }; }; }