diff --git a/tidepool/default.nix b/tidepool/default.nix index 1671f00..35be863 100644 --- a/tidepool/default.nix +++ b/tidepool/default.nix @@ -6,19 +6,32 @@ let system = "i686-linux"; }; - modules = import ./src/modules.nix; - result = lib.modules.run { - modules = (builtins.attrValues modules) ++ [ - ./src/export.nix + modules = [ + ./src/modules.nix { __file__ = ./default.nix; - options.foundation = lib.options.create { type = lib.types.attrs.of lib.types.derivation; }; + options = { + lib = lib.options.create { + type = lib.types.attrs.any; + default.value = { }; + description = "An attribute set of values to be added to `lib`."; + apply = value: lib.extend (final: prev: lib.attrs.mergeRecursive lib value); + }; - config.foundation = foundation; + foundation = lib.options.create { + type = lib.types.attrs.of lib.types.derivation; + }; + }; + + config = { + inherit foundation; + }; } ]; }; in -result.config.exported // { inherit (result) config; } +result.config // { + extend = result.extend; +} diff --git a/tidepool/src/builders/basic.nix b/tidepool/src/builders/basic.nix index f2e01d2..fdb5734 100644 --- a/tidepool/src/builders/basic.nix +++ b/tidepool/src/builders/basic.nix @@ -106,16 +106,19 @@ in ]; } ); + + result = + built + // { + inherit (package) meta extend; + extras = { + inherit package context; + phases = builtins.listToAttrs sorted.result; + } // package.extras; + }; in # (builtins.trace "build: ${package.name} -> build=${package.platform.build.triple} host=${package.platform.host.triple} target=${package.platform.target.triple}") - built - // { - inherit (package) meta; - extras = { - inherit package context; - phases = builtins.listToAttrs sorted.result; - } // package.extras; - }; + result; }; }; } diff --git a/tidepool/src/export.nix b/tidepool/src/export.nix deleted file mode 100644 index 6c71c3a..0000000 --- a/tidepool/src/export.nix +++ /dev/null @@ -1,41 +0,0 @@ -# This file handles creating all of the exports for this project and is not -# exported itself. -{ config }: -let - inherit (config) lib; -in -{ - # freeform = lib.types.any; - - config = { - exports = { - inherit lib; - modules = import ./modules.nix; - - packages = { - aux-a = config.packages.aux.a; - aux-b = config.packages.aux.b; - - foundation-gcc = config.packages.foundation.gcc; - foundation-glibc = config.packages.foundation.glibc; - foundation-binutils = config.packages.foundation.binutils; - foundation-linux-headers = config.packages.foundation.linux-headers; - - cross-foundation-glibc-x86_64-linux = config.packages.cross.x86_64-linux.foundation.glibc; - cross-foundation-binutils-x86_64-linux = config.packages.cross.x86_64-linux.foundation.binutils; - - cross-tool-foundation-gcc-newlib-x86_64-linux = - config.packages.cross-tools.x86_64-linux.foundation.gcc-newlib; - cross-tool-foundation-gcc-x86_64-linux = - config.packages.cross-tools.x86_64-linux.foundation.gcc-cross; - cross-foundation-gcc-x86_64-linux = config.packages.cross.x86_64-linux.foundation.gcc-bootstrap; - - example-a = config.packages.foundation.gcc.versions.latest.extend { - platform = { - target = lib.modules.override 0 "x86_64-linux"; - }; - }; - }; - }; - }; -} diff --git a/tidepool/src/exports/default.nix b/tidepool/src/exports/default.nix deleted file mode 100644 index 7ac4917..0000000 --- a/tidepool/src/exports/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ - includes = [ - ./lib.nix - ./packages.nix - ./modules.nix - ]; -} diff --git a/tidepool/src/exports/lib.nix b/tidepool/src/exports/lib.nix deleted file mode 100644 index a839ac2..0000000 --- a/tidepool/src/exports/lib.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ lib, config }: -let -in -{ - options = { - exports.lib = lib.options.create { default.value = { }; }; - - exported.lib = lib.options.create { default.value = { }; }; - }; - - config = { - exported.lib = config.exports.lib; - }; -} diff --git a/tidepool/src/exports/modules.nix b/tidepool/src/exports/modules.nix deleted file mode 100644 index 4116257..0000000 --- a/tidepool/src/exports/modules.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ lib, config }: -let - cfg = config.exports; - - type = lib.types.one [ - lib.types.path - (lib.types.attrs.any) - (lib.types.function lib.types.attrs.any) - ]; -in -{ - options = { - exports = { - modules = lib.options.create { - type = lib.types.attrs.of type; - default.value = { }; - description = "An attribute set of modules to export."; - }; - }; - - exported = { - modules = lib.options.create { - type = lib.types.attrs.of type; - default.value = { }; - description = "An attribute set of modules to export."; - }; - }; - }; - - config = { - exported.modules = cfg.modules; - }; -} diff --git a/tidepool/src/exports/packages.nix b/tidepool/src/exports/packages.nix deleted file mode 100644 index fbe7b5f..0000000 --- a/tidepool/src/exports/packages.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ config, lib }: -let - lib' = config.lib; -in -{ - options = { - exports.packages = lib.options.create { - type = lib.types.attrs.of (lib'.types.raw); - default.value = { }; - }; - - exported.packages = lib.options.create { - type = lib.types.attrs.of (lib.types.attrs.of lib.types.derivation); - default.value = { }; - }; - }; - - config = { - 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; - - available = lib.attrs.filter (name: package: builtins.elem system package.meta.platforms) all; - - 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; - }; -} diff --git a/tidepool/src/lib/default.nix b/tidepool/src/lib/default.nix index 9e4fc09..fa47f84 100644 --- a/tidepool/src/lib/default.nix +++ b/tidepool/src/lib/default.nix @@ -1,7 +1,3 @@ -{ lib, config }: -let - cfg = config.lib; -in { includes = [ ./options.nix @@ -9,17 +5,4 @@ in ./systems.nix ./types.nix ]; - - options = { - lib = lib.options.create { - type = lib.types.attrs.any; - default.value = { }; - description = "An attribute set of values to be added to `lib`."; - apply = value: lib.extend (final: prev: prev.attrs.mergeRecursive prev value); - }; - }; - - config = { - __module__.args.dynamic.lib' = config.lib; - }; } diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index 9bdd84e..1c4da24 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -1,6 +1,6 @@ -{ lib, config }: +{ config }: let - lib' = config.lib; + inherit (config) lib; in { config = { @@ -16,7 +16,7 @@ in build = build': host': target': - builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); + builtins.mapAttrs (name: dep: lib.packages.build dep build' host' target'); collect = package: @@ -131,19 +131,19 @@ in type = lib.types.submodule { options = { build = { - only = lib.options.create { type = lib.types.list.of lib'.types.package; }; - build = lib.options.create { type = lib.types.list.of lib'.types.package; }; - host = lib.options.create { type = lib.types.list.of lib'.types.package; }; - target = lib.options.create { type = lib.types.list.of lib'.types.package; }; + only = lib.options.create { type = lib.types.list.of lib.types.package; }; + build = lib.options.create { type = lib.types.list.of lib.types.package; }; + host = lib.options.create { type = lib.types.list.of lib.types.package; }; + target = lib.options.create { type = lib.types.list.of lib.types.package; }; }; host = { - only = lib.options.create { type = lib.types.list.of lib'.types.package; }; - host = lib.options.create { type = lib.types.list.of lib'.types.package; }; - target = lib.options.create { type = lib.types.list.of lib'.types.package; }; + only = lib.options.create { type = lib.types.list.of lib.types.package; }; + host = lib.options.create { type = lib.types.list.of lib.types.package; }; + target = lib.options.create { type = lib.types.list.of lib.types.package; }; }; target = { - only = lib.options.create { type = lib.types.list.of lib'.types.package; }; - target = lib.options.create { type = lib.types.list.of lib'.types.package; }; + only = lib.options.create { type = lib.types.list.of lib.types.package; }; + target = lib.options.create { type = lib.types.list.of lib.types.package; }; }; }; }; @@ -211,13 +211,15 @@ in path: let dependencies = lib.attrs.selectOrThrow path collected; - hooks = builtins.map ( - dependency: - let - getHooks = dependency.hooks or (lib.fp.const { }); - in - getHooks ctx - ) dependencies; + hooks = builtins.map + ( + dependency: + let + getHooks = dependency.hooks or (lib.fp.const { }); + in + getHooks ctx + ) + dependencies; in hooks; in @@ -279,18 +281,18 @@ in alias: if alias ? versions then alias.versions.${config.preferences.packages.version} - or (alias.versions.${lib'.packages.getLatest alias}) + or (alias.versions.${lib.packages.getLatest alias}) else alias; build = alias: build: host: target: let - package = lib'.packages.resolve alias; + package = lib.packages.resolve alias; buildDependencies = build': host': target': - builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); + builtins.mapAttrs (name: dep: lib.packages.build dep build' host' target'); platform = { build = lib.modules.overrides.force build; @@ -300,7 +302,7 @@ in withPlatform = lib.modules.run { modules = package.__modules__ ++ [ - lib'.types.package.children.submodule + lib.types.package.children.submodule ( { config }: { @@ -339,7 +341,7 @@ in withPackage = lib.modules.run { modules = package.__modules__ ++ [ - lib'.types.package.children.submodule + lib.types.package.children.submodule ( { config }: { @@ -358,6 +360,23 @@ in }; in withPackage.config; + + create = namespace: name: alias: { + ${namespace} = { + ${name} = lib.modules.merge [ + alias + { + versions = builtins.mapAttrs + (version: package: { + id = lib.modules.overrides.default name; + version = lib.modules.overrides.default version; + namespace = lib.modules.overrides.default namespace; + }) + alias.versions; + } + ]; + }; + }; }; }; } diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index 4d61718..4ad6c77 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -1,8 +1,8 @@ -{ lib, config }: +{ config }@global: let - inherit (config) preferences builders; + inherit (config) lib; - lib' = config.lib; + pretty = lib.generators.pretty { }; in { config = { @@ -57,8 +57,8 @@ in lib.types.either type (lib.types.list.of type); platform = - lib.types.coerce lib.types.string lib'.systems.withBuildInfo - lib'.systems.types.platformWithBuildInfo; + lib.types.coerce lib.types.string lib.systems.withBuildInfo + lib.systems.types.platformWithBuildInfo; builder = lib.types.submodule { freeform = lib.types.any; @@ -66,12 +66,94 @@ in options = { build = lib.options.create { description = "The build function which takes a package definition and creates a derivation."; - type = lib.types.function lib.types.derivation; + type = lib.types.function lib.types.artifact; }; }; }; - packages = lib.types.attrs.of (lib.types.attrs.of lib'.types.alias); + aliasesx = lib.types.attrs.of (lib.types.submodule ({ config, name }: { + freeform = lib.types.attrs.of lib.types.alias; + + config = builtins.mapAttrs (x: { }) config; + })); + + aliases = + let + normalize = + value: + if builtins.isFunction value || builtins.isList value then + value + else if value ? __modules__ then + value.__modules__ + else + { config = value; }; + + initial = lib.types.raw; + + transform = + value: + let + result = + builtins.mapAttrs + (namespace: aliases: + builtins.mapAttrs + (id: alias: + alias // { + versions = builtins.mapAttrs + (version: package: + { + __modules__ = (lib.lists.from.any (normalize package)) ++ [ + { + config = { + id = lib.modules.overrides.default id; + version = lib.modules.overrides.default version; + namespace = lib.modules.overrides.default namespace; + }; + } + ]; + } + ) + alias.versions; + } + ) + aliases + ) + value; + in + result; + + final = lib.types.attrs.of (lib.types.attrs.of lib.types.alias); + in + lib.types.coerce initial transform final; + + platforms = { + build = lib.types.attrs.of lib.types.platforms.host; + host = lib.types.attrs.of lib.types.platforms.target; + target = lib.types.attrs.of (lib.types.attrs.of lib.types.platforms.alias); + alias = lib.types.submodule { + options = { + stable = lib.options.create { + description = "The stable version of the artifact."; + type = lib.types.nullish lib.types.artifact; + default.value = null; + }; + latest = lib.options.create { + description = "The latest version of the artifact."; + type = lib.types.artifact; + default.value = null; + }; + versions = lib.options.create { + description = "Available versions of the artifact."; + type = lib.types.attrs.of lib.types.artifact; + default.value = { }; + }; + }; + }; + }; + + artifact = lib.types.nullish (lib.types.withCheck + lib.types.derivation + (value: value ? extend && builtins.isFunction value.extend)); dependencies = build: host: target: @@ -81,31 +163,48 @@ in transform = value: let - package = lib'.packages.resolve value; + package = lib.packages.resolve value; in - lib'.packages.build package build host target; + lib.packages.build package build host target; in - lib.types.attrs.of (lib.types.coerce initial transform lib'.types.package); + lib.types.attrs.of (lib.types.coerce initial transform lib.types.package); - alias = lib.types.submodule { + alias = lib.types.submodule ({ config, name }: { options = { + extend = lib.options.create { + description = "Extend the default version with additional attributes."; + type = lib.types.function lib.types.raw; + writable = false; + default.value = + let + default = config.${global.config.preferences.packages.version}; + in + default.extend or (builtins.throw "Package \"${name}\" does not have a ${global.config.preferences.packages.version} release."); + }; + stable = lib.options.create { description = "The stable version of the package."; - type = lib.types.nullish lib'.types.package; + type = lib.types.nullish lib.types.package; + default.value = null; }; latest = lib.options.create { description = "The latest version of the package."; - type = lib'.types.package; + type = lib.types.package; + default.value = + if config.versions == { } then + null + else + config.versions.${lib.packages.getLatest config}; }; versions = lib.options.create { description = "Available versions of the package."; - type = lib.types.attrs.of lib'.types.package; + type = lib.types.attrs.of lib.types.package; default.value = { }; }; }; - }; + }); package = let @@ -137,6 +236,11 @@ in result = lib.modules.run { prefix = location; + + args = { + global = config; + }; + modules = modules ++ [ submodule { config.__modules__ = modules; } @@ -145,7 +249,28 @@ in in result.config; - final = lib.types.raw; + final = lib.types.raw // { + merge = location: definitions: + let + modules = builtins.concatMap + (definition: lib.lists.from.any (normalize definition.value)) + definitions; + + result = lib.modules.run { + prefix = location; + + args = { + global = config; + }; + + modules = modules ++ [ + submodule + { config.__modules__ = modules; } + ]; + }; + in + result.config; + }; deps = build: host: target: @@ -154,25 +279,25 @@ in build = { only = lib.options.create { description = "Dependencies which are only used in the build environment."; - type = lib'.types.dependencies build build build; + type = lib.types.dependencies build build build; 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 build build target; + type = lib.types.dependencies build build target; 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 build host target; + type = lib.types.dependencies build host target; 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 build target target; + type = lib.types.dependencies build target target; default.value = { }; }; }; @@ -180,19 +305,19 @@ in host = { only = lib.options.create { description = "Dependencies which are only used in the host environment."; - type = lib'.types.dependencies host host host; + type = lib.types.dependencies host host host; default.value = { }; }; host = lib.options.create { description = "Dependencies which are executed in the host environment."; - type = lib'.types.dependencies host host target; + type = lib.types.dependencies host host target; 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 host target target; + type = lib.types.dependencies host target target; default.value = { }; }; }; @@ -200,13 +325,13 @@ in target = { only = lib.options.create { description = "Dependencies which are only used in the target environment."; - type = lib'.types.dependencies target target target; + type = lib.types.dependencies target target target; default.value = { }; }; target = lib.options.create { description = "Dependencies which are executed in the target environment."; - type = lib'.types.dependencies target target target; + type = lib.types.dependencies target target target; default.value = { }; }; }; @@ -214,7 +339,7 @@ in }; submodule = - { config, meta }: + { config, meta, name }: let build = config.platform.build; host = config.platform.host; @@ -225,39 +350,10 @@ in __modules__ = lib.options.create { description = "User specified modules for the package definition."; type = lib.types.list.of (initial // { merge = lib.options.merge.one; }); - # writable = false; internal = true; default.value = [ ]; }; - # extend = lib.options.create { - # description = "Extend the package definition."; - # type = lib.types.function lib.types.raw; - # internal = true; - # writable = false; - # default.value = module: - # let - # normalized = - # if builtins.isList module then - # module - # else if builtins.isFunction module || module ? config then - # [ module ] - # else - # [{ - # config = module; - # }]; - # result = meta.extend { - # modules = - # normalized ++ [ - # { - # config.__modules__ = lib.modules.overrides.force (config.__modules__ ++ normalized); - # } - # ]; - # }; - # in - # result.config; - # }; - extend = lib.options.create { description = "Extend the package definition."; type = lib.types.function lib.types.raw; @@ -281,6 +377,10 @@ in modules = config.__modules__ ++ normalized; result = lib.modules.run { + args = { + global = config; + }; + modules = [ submodule { config.__modules__ = modules; } @@ -305,7 +405,7 @@ in license = lib.options.create { description = "The license for the package."; - type = lib.types.nullish lib'.types.license; + type = lib.types.nullish lib.types.license; default.value = null; }; @@ -349,20 +449,20 @@ in platform = { build = lib.options.create { description = "The build platform for the package."; - type = lib'.types.platform; - default.value = lib'.systems.withBuildInfo "x86_64-linux"; + type = lib.types.platform; + default.value = lib.systems.withBuildInfo "x86_64-linux"; }; host = lib.options.create { description = "The host platform for the package."; - type = lib'.types.platform; - default.value = lib'.systems.withBuildInfo "x86_64-linux"; + type = lib.types.platform; + default.value = lib.systems.withBuildInfo "x86_64-linux"; }; target = lib.options.create { description = "The target platform for the package."; - type = lib'.types.platform; - default.value = lib'.systems.withBuildInfo "x86_64-linux"; + type = lib.types.platform; + default.value = lib.systems.withBuildInfo "x86_64-linux"; }; }; @@ -370,27 +470,32 @@ in 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 ""; + text = "\${config.id}-\${config.version}"; + value = "${config.namespace}-${config.id}-${config.version}"; }; }; - pname = lib.options.create { + namespace = lib.options.create { + description = "The namespace that the package belongs to."; + type = lib.types.string; + default.value = "unknown"; + }; + + id = lib.options.create { description = "The program name for the package"; - type = lib.types.nullish lib.types.string; - default.value = null; + type = lib.types.string; + default.value = "unknown"; }; version = lib.options.create { description = "The version for the package."; type = lib.types.nullish lib.types.version; - default.value = null; + default.value = "unknown"; }; builder = lib.options.create { description = "The builder for the package."; - type = lib'.types.builder; + type = lib.types.builder; }; env = lib.options.create { @@ -402,7 +507,7 @@ in package = lib.options.create { description = "The built derivation."; type = lib.types.derivation; - default.value = config.builder.build config; + default.value = (builtins.trace "building: ${config.name}") config.builder.build config; }; phases = lib.options.create { @@ -435,19 +540,19 @@ in default.value = { }; apply = value: { build = { - only = lib'.packages.dependencies.build build build build value.build.only; - build = lib'.packages.dependencies.build build build target value.build.build; - host = lib'.packages.dependencies.build build host target value.build.host; - target = lib'.packages.dependencies.build build target target value.build.target; + only = lib.packages.dependencies.build build build build value.build.only; + build = lib.packages.dependencies.build build build target value.build.build; + host = lib.packages.dependencies.build build host target value.build.host; + target = lib.packages.dependencies.build build target target value.build.target; }; host = { - only = lib'.packages.dependencies.build host host host value.host.only; - host = lib'.packages.dependencies.build host host target value.host.host; - target = lib'.packages.dependencies.build host target target value.host.target; + only = lib.packages.dependencies.build host host host value.host.only; + host = lib.packages.dependencies.build host host target value.host.host; + target = lib.packages.dependencies.build host target target value.host.target; }; target = { - only = lib'.packages.dependencies.build target target target value.target.only; - target = lib'.packages.dependencies.build target target target value.target.target; + only = lib.packages.dependencies.build target target target value.target.only; + target = lib.packages.dependencies.build target target target value.target.target; }; }; }; diff --git a/tidepool/src/modules.nix b/tidepool/src/modules.nix index 3c0e055..cfd9fc7 100644 --- a/tidepool/src/modules.nix +++ b/tidepool/src/modules.nix @@ -1,7 +1,8 @@ { - builders = ./builders; - exports = ./exports; - lib = ./lib; - mirrors = ./mirrors; - packages = ./packages; + includes = [ + ./builders + ./lib + ./mirrors + ./packages + ]; } diff --git a/tidepool/src/packages/aux/a.nix b/tidepool/src/packages/aux/a.nix index 7efef9b..968b9c6 100644 --- a/tidepool/src/packages/aux/a.nix +++ b/tidepool/src/packages/aux/a.nix @@ -4,20 +4,17 @@ let in { config.packages.aux.a = { + stable = packages.aux.a.versions."1.0.0"; + versions = { - "latest" = + "1.0.0" = { config }: { config = { meta = { - platforms = [ "i686-linux" ]; + platforms = [ "i686-linux" "x86_64-linux" ]; }; - name = "${config.pname}-${config.version}"; - - pname = "a"; - version = "1.0.0"; - builder = builders.basic; deps.build.host = { diff --git a/tidepool/src/packages/aux/b.nix b/tidepool/src/packages/aux/b.nix index c94fc2b..744ab2a 100644 --- a/tidepool/src/packages/aux/b.nix +++ b/tidepool/src/packages/aux/b.nix @@ -3,9 +3,9 @@ let inherit (config) lib builders packages; in { - config.packages.aux.b = { + config.packages = lib.packages.create "aux" "b" { versions = { - "latest" = + "1.0.0" = { config }: { options = { @@ -14,22 +14,17 @@ in config = { meta = { - platforms = [ "i686-linux" ]; + platforms = [ "i686-linux" "x86_64-linux" ]; }; - name = "${config.pname}-${config.version}"; - custom = true; - pname = "b"; - version = "1.0.0"; - builder = builders.basic; deps = { build = { host = { - c = packages.aux.c.versions.latest.extend { + c = packages.aux.c.extend { propagate = true; }; }; diff --git a/tidepool/src/packages/aux/c.nix b/tidepool/src/packages/aux/c.nix index 2f09cf2..1c20859 100644 --- a/tidepool/src/packages/aux/c.nix +++ b/tidepool/src/packages/aux/c.nix @@ -1,11 +1,11 @@ { config }: let - inherit (config) lib builders packages; + inherit (config) lib builders; in { config.packages.aux.c = { versions = { - "latest" = + "1.0.0" = { config }: { options = { @@ -17,13 +17,8 @@ in platforms = [ "i686-linux" ]; }; - name = "${config.pname}-${config.version}"; - custom = true; - pname = "c"; - version = "1.0.0"; - builder = builders.basic; context = { diff --git a/tidepool/src/packages/default.nix b/tidepool/src/packages/default.nix index 8c9fc06..ce2ed96 100644 --- a/tidepool/src/packages/default.nix +++ b/tidepool/src/packages/default.nix @@ -4,10 +4,74 @@ let doubles = lib.systems.doubles.all; - packages = builtins.removeAttrs config.packages [ - "cross" - "cross-tools" - ]; + packages = lib.attrs.filter (name: value: !(builtins.elem name doubles) && name != "context" && name != "platforms") config.packages; + + platforms = lib.attrs.generate doubles ( + build: + lib.options.create { + description = "Packages which are built on the ${build} system."; + default.value = { }; + type = lib.types.submodule { + freeform = lib.types.platforms.build; + + options = lib.attrs.generate doubles + ( + host: + lib.options.create { + description = "Packages which are run on the ${host} system."; + default.value = { }; + type = lib.types.submodule { + freeform = lib.types.platforms.host; + + options = lib.attrs.generate doubles ( + target: + lib.options.create { + description = "Packages which are cross-compiled for the ${target} system."; + type = lib.types.platforms.target; + default.value = + let + outputs = builtins.mapAttrs + (namespace: aliases: + builtins.mapAttrs + (id: alias: + let + override = { + platform = { + inherit build host target; + }; + }; + produce = path: + let + entry = lib.attrs.select path null alias; + in + if entry == null || !(entry ? extend) then + null + else if (builtins.elem build entry.meta.platforms) && (builtins.elem host entry.meta.platforms) && (builtins.elem target entry.meta.platforms) then + (lib.packages.build entry build host target).package + else + null; + in + { + stable = produce [ "stable" ]; + latest = produce [ "latest" ]; + + versions = builtins.mapAttrs + (version: alias: produce [ "versions" version ]) + alias.versions; + }) + aliases + ) + packages; + in + outputs; + } + ); + }; + } + ); + }; + } + ); in { includes = [ @@ -20,26 +84,12 @@ in options = { packages = lib.options.create { description = "The package set."; + default.value = { }; type = lib.types.submodule { - freeform = lib.types.packages; + freeform = lib.types.aliases; - options = { - cross-tools = lib.attrs.generate doubles ( - system: - lib.options.create { - description = "The cross-compilation tools for the ${system} target."; - type = lib.types.packages; - default.value = { }; - } - ); - cross = lib.attrs.generate doubles ( - system: - lib.options.create { - description = "The cross-compiled package set for the ${system} target."; - type = lib.types.packages; - default.value = { }; - } - ); + options = platforms // { + inherit platforms; # NOTE: We may offer a way to set default context values. For this reason we have # nested `options` under `context` rather than using a plain option directly under `packages`. @@ -63,64 +113,4 @@ in }; }; }; - - config = { - packages.cross-tools = lib.attrs.generate doubles ( - system: - builtins.mapAttrs ( - namespace: - builtins.mapAttrs ( - name: alias: - let - setTarget = - package: - package - // { - __modules__ = package.__modules__ ++ [ - { - config.platform = { - target = lib.modules.override 5 system; - }; - } - ]; - }; - - updated = alias // { - versions = builtins.mapAttrs (version: package: setTarget package) alias.versions; - }; - in - updated - ) - ) packages - ); - packages.cross = lib.attrs.generate doubles ( - system: - builtins.mapAttrs ( - namespace: - builtins.mapAttrs ( - name: alias: - let - setPlatform = - package: - package - // { - __modules__ = package.__modules__ ++ [ - { - config.platform = { - host = lib.modules.override 5 system; - target = lib.modules.override 5 system; - }; - } - ]; - }; - - updated = alias // { - versions = builtins.mapAttrs (version: package: setPlatform package) alias.versions; - }; - in - updated - ) - ) packages - ); - }; } diff --git a/tidepool/src/packages/foundation/default.nix b/tidepool/src/packages/foundation/default.nix index 268593a..e86ee73 100644 --- a/tidepool/src/packages/foundation/default.nix +++ b/tidepool/src/packages/foundation/default.nix @@ -1,8 +1,7 @@ -{ - lib, - lib', - config, - options, +{ lib +, config +, options +, }: { includes = [ @@ -12,37 +11,4 @@ ./glibc # ./xz ]; - - config = { - packages = { - # example = { - # x = { - # versions = { - # "latest" = {config}: { - # config = { - # meta = { - # platforms = ["i686-linux" "x86_64-linux"]; - # }; - - # pname = "x"; - # version = "1.0.0"; - - # builder = builders.basic; - - # phases = { - # build = '' - # make --build ${config.platform.build.double} --host ${config.platform.host.double} - # ''; - - # install = lib.dag.entry.after ["build"] '' - # make install DESTDIR=$out - # ''; - # }; - # }; - # }; - # }; - # }; - # }; - }; - }; } diff --git a/tidepool/src/packages/foundation/gcc/bootstrap.nix b/tidepool/src/packages/foundation/gcc/bootstrap.nix deleted file mode 100644 index 8ed5def..0000000 --- a/tidepool/src/packages/foundation/gcc/bootstrap.nix +++ /dev/null @@ -1,81 +0,0 @@ -{ config, options }: -let - inherit (config) - lib - packages - ; -in -{ - config.packages.foundation.gcc-bootstrap = { - versions = { - "latest" = config.packages.foundation.gcc.versions.latest.extend ( - { config }: - { - config = { - meta = { - platforms = lib.modules.override 0 [ - "i686-linux" - ]; - }; - - deps = { - build = { - build = { - gcc = lib.modules.override 0 ( - packages.foundation.gcc-cross.versions.latest.extend { - platform = lib.modules.override 0 { - build = "i686-linux"; - target = config.platform.target; - host = "i686-linux"; - }; - } - ); - binutils = lib.modules.override 0 ( - packages.foundation.binutils.versions.latest.extend { - platform = lib.modules.override 0 { - build = "i686-linux"; - target = config.platform.target; - host = config.platform.host; - }; - } - ); - glibc = lib.modules.override 0 ( - packages.foundation.glibc.versions.latest.extend { - platform = lib.modules.override 0 { - build = "i686-linux"; - target = config.platform.target; - host = config.platform.host; - }; - } - ); - }; - }; - }; - - env = { - LIBRARY_PATH = lib.modules.override 0 "${config.deps.build.build.glibc.package}/lib"; - LDFLAGS_FOR_TARGET = lib.modules.override 0 "-L$(pwd)/${config.platform.target.triple}/libgcc -L${config.deps.build.build.glibc.package}/lib"; - }; - - configureFlags = lib.modules.override 0 [ - "--prefix=${builtins.placeholder "out"}" - # Pretend we're native even though we're not - "--build=${config.platform.target.triple}" - "--host=${config.platform.host.triple}" - "--target=${config.platform.target.triple}" - "--with-as=${config.deps.build.build.binutils.package}/bin/as" - "--with-ld=${config.deps.build.build.binutils.package}/bin/ld" - "--enable-languages=c,c++" - "--disable-bootstrap" - "--disable-libsanitizer" - "--disable-multilib" - "--with-native-system-header-dir=${config.deps.build.build.glibc.package}/include" - "--with-gxx-include-dir=${placeholder "out"}/include/c++/${config.version}/" - "--with-build-sysroot=/" - ]; - }; - } - ); - }; - }; -} diff --git a/tidepool/src/packages/foundation/gcc/default.nix b/tidepool/src/packages/foundation/gcc/default.nix index f2e801b..c8d6784 100644 --- a/tidepool/src/packages/foundation/gcc/default.nix +++ b/tidepool/src/packages/foundation/gcc/default.nix @@ -14,12 +14,12 @@ in includes = [ ./newlib.nix ./cross.nix - ./bootstrap.nix + # ./bootstrap.nix ]; config.packages.foundation.gcc = { versions = { - "latest" = + "13.2.0" = { config, meta }: { options = { @@ -107,9 +107,10 @@ in (config.platform.target.triple != config.platform.host.triple) && (config.platform.host.triple == config.platform.target.triple); - programPrefix = lib.strings.when ( - config.platform.build.triple != config.platform.target.triple - ) "${config.platform.target.triple}-"; + programPrefix = lib.strings.when + ( + config.platform.build.triple != config.platform.target.triple + ) "${config.platform.target.triple}-"; libc = if isBootstrapped then foundation.stage1-musl else config.deps.build.build.glibc.package; libcLd = @@ -128,7 +129,7 @@ in ]; }; - pname = "gcc-${config.platform.build.double}--${config.platform.host.double}--${config.platform.target.double}"; + id = "gcc-${config.platform.build.double}--${config.platform.host.double}--${config.platform.target.double}"; version = "13.2.0"; builder = builders.basic; @@ -317,6 +318,75 @@ in }; }; }; + + # "bootstrap" = config.packages.foundation.gcc.versions.latest.extend ( + # { config }: + # { + # config = { + # meta = { + # platforms = lib.modules.override 0 [ + # "i686-linux" + # ]; + # }; + # + # deps = { + # build = { + # build = { + # gcc = lib.modules.override 0 ( + # packages.foundation.gcc-cross.versions.latest.extend { + # platform = lib.modules.override 0 { + # build = "i686-linux"; + # target = config.platform.target; + # host = "i686-linux"; + # }; + # } + # ); + # binutils = lib.modules.override 0 ( + # packages.foundation.binutils.versions.latest.extend { + # platform = lib.modules.override 0 { + # build = "i686-linux"; + # target = config.platform.target; + # host = config.platform.host; + # }; + # } + # ); + # glibc = lib.modules.override 0 ( + # packages.foundation.glibc.versions.latest.extend { + # platform = lib.modules.override 0 { + # build = "i686-linux"; + # target = config.platform.target; + # host = config.platform.host; + # }; + # } + # ); + # }; + # }; + # }; + # + # env = { + # LIBRARY_PATH = lib.modules.override 0 "${config.deps.build.build.glibc.package}/lib"; + # LDFLAGS_FOR_TARGET = lib.modules.override 0 "-L$(pwd)/${config.platform.target.triple}/libgcc -L${config.deps.build.build.glibc.package}/lib"; + # }; + # + # configureFlags = lib.modules.override 0 [ + # "--prefix=${builtins.placeholder "out"}" + # # Pretend we're native even though we're not + # "--build=${config.platform.target.triple}" + # "--host=${config.platform.host.triple}" + # "--target=${config.platform.target.triple}" + # "--with-as=${config.deps.build.build.binutils.package}/bin/as" + # "--with-ld=${config.deps.build.build.binutils.package}/bin/ld" + # "--enable-languages=c,c++" + # "--disable-bootstrap" + # "--disable-libsanitizer" + # "--disable-multilib" + # "--with-native-system-header-dir=${config.deps.build.build.glibc.package}/include" + # "--with-gxx-include-dir=${placeholder "out"}/include/c++/${config.version}/" + # "--with-build-sysroot=/" + # ]; + # }; + # } + # ); }; }; }