feat: working package export

This commit is contained in:
Jake Hamilton 2024-06-14 04:47:54 -07:00
parent cdc90a4656
commit fea8c2cd9c
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
11 changed files with 168 additions and 59 deletions

View file

@ -26,6 +26,7 @@ may collaborate.
## Experiments
| Name | Phase | Description |
| ------------------------------ | --------- | -------------------------------------------------------------------------- |
| ------------------------------ | --------- | ------------------------------------------------------------------------------------ |
| [Aux Lib](./lib) | Iteration | A library of common functions used in the Aux ecosystem. |
| [Aux Foundation](./foundation) | Iteration | Foundational packages which allow for bootstrapping a greater package set. |
| [Aux Tidepool](./tidepool) | Idea | An initial package set built on top of Aux Foundation using Aux Lib's module system. |

View file

@ -317,6 +317,20 @@ lib: {
vm = lib.modules.override 10;
};
## Create alias definitions for a given option.
##
## @type Option -> Attrs
alias = lib.modules.aliasWith lib.fp.id;
## 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
lib.modules.when exists value;
## Combine multiple modules together.
##
## @type List String -> List Module -> { matched :: Attrs, unmatched :: List Definition }

28
tidepool/README.md Normal file
View file

@ -0,0 +1,28 @@
# Aux Tidepool
Aux Tidepool is an initial package set built on top of [Aux Foundation](../foundation). Packages
are created and managed using [Aux Lib](../lib)'s module system to allow for highly dynamic and
extensible configuration.
## Usage
Packages can be imported both with and without Nix Flakes. To import them using Nix Flakes,
add this repository as an input.
```nix
inputs.tidepool.url = "https://git.auxolotl.org/auxolotl/labs/archive/main.tar.gz?dir=tidepool";
```
To import this library without using Nix Flakes, you will need to use `fetchTarball` and
import the library entrypoint.
```nix
let
labs = builtins.fetchTarball {
url = "https://git.auxolotl.org/auxolotl/labs/archive/main.tar.gz";
sha256 = "<sha256>";
};
tidepool = import "${labs}/tidepool" {};
in
# ...
```

View file

@ -31,3 +31,5 @@
};
in
result.config
# result.config.exported

View file

@ -8,10 +8,10 @@
},
"locked": {
"dir": "foundation",
"dirtyRev": "856b88321e5f19019332f8b60b729095c2260340-dirty",
"dirtyShortRev": "856b883-dirty",
"lastModified": 1718299377,
"narHash": "sha256-L6zriSSFi45uJ8u3HVsZ6iDHjNtQBB+aDWQfiReoLkM=",
"dirtyRev": "cdc90a46565dadea3b3c8f673b8b55d4ff75ea92-dirty",
"dirtyShortRev": "cdc90a4-dirty",
"lastModified": 1718356339,
"narHash": "sha256-BSiyT1q5xSlO1DyNJlkRWI82WWxVtQ1Xy8zPOqdqUlU=",
"type": "git",
"url": "file:../?dir=foundation"
},
@ -24,10 +24,10 @@
"lib": {
"locked": {
"dir": "lib",
"dirtyRev": "856b88321e5f19019332f8b60b729095c2260340-dirty",
"dirtyShortRev": "856b883-dirty",
"lastModified": 1718299377,
"narHash": "sha256-L6zriSSFi45uJ8u3HVsZ6iDHjNtQBB+aDWQfiReoLkM=",
"dirtyRev": "cdc90a46565dadea3b3c8f673b8b55d4ff75ea92-dirty",
"dirtyShortRev": "cdc90a4-dirty",
"lastModified": 1718356339,
"narHash": "sha256-BSiyT1q5xSlO1DyNJlkRWI82WWxVtQ1Xy8zPOqdqUlU=",
"type": "git",
"url": "file:../?dir=lib"
},

View file

@ -3,20 +3,43 @@
lib,
}: let
lib' = config.lib;
cfg = config.exports;
in {
options = {
exports.packages = lib.options.create {
type = lib.types.attrs.of (lib.types.function (lib.types.nullish lib.types.derivation));
default.value = {};
};
exported.packages = lib.options.create {
type = lib.types.attrs.of (lib.types.attrs.of lib.types.derivation);
default.value = {};
};
};
config = {
exported.packages = {
# i686-linux = config.packages.foundation;
};
exported.packages = let
all = lib.attrs.generate lib'.systems.doubles.all (
system: let
packages =
builtins.mapAttrs
(name: resolve: resolve system)
cfg.packages;
available =
lib.attrs.filter
(name: package: package != null)
packages;
in
available
);
available =
lib.attrs.filter
(system: packages: builtins.length (builtins.attrNames packages) != 0)
all;
in
available;
};
}

View file

@ -6,6 +6,7 @@
in {
includes = [
./options.nix
./packages.nix
./systems.nix
./types.nix
];

View file

@ -0,0 +1,37 @@
{
lib,
config,
}: let
lib' = config.lib;
in {
config = {
lib.packages = {
get = path: let
resolved =
if builtins.isList path
then path
else lib.strings.split "." path;
package = lib.attrs.selectOrThrow resolved config.packages.generic;
in
assert lib.errors.trace (builtins.length resolved > 1) "Packages must have a namespace specified.";
package
// {
namespace = lib.modules.override 99 (builtins.head resolved);
};
export = path: system: let
resolved =
if builtins.isList path
then path
else lib.strings.split "." path;
package = lib'.packages.get resolved;
targeted = lib.attrs.selectOrThrow resolved config.packages.targeted.${system};
in
if builtins.elem system package.meta.platforms
then targeted.package
else null;
};
};
}

View file

@ -53,11 +53,6 @@ in {
meta = lib.types.submodule {
options = {
name = lib.options.create {
type = lib.types.string;
description = "The name of the package.";
};
description = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
@ -138,7 +133,7 @@ in {
lib'.types.package.targeted'
{
config = {
namespace = namespace;
namespace = lib.modules.override 99 namespace;
platform = {
build = system;
@ -164,7 +159,7 @@ in {
lib'.types.package.targeted'
{
config = {
namespace = namespace;
namespace = lib.modules.override 99 namespace;
platform = {
build = system;
@ -194,6 +189,11 @@ in {
config,
}: {
options = {
namespace = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
};
pname = lib.options.create {
type = lib.types.string;
default = {

View file

@ -0,0 +1,39 @@
{
lib,
config,
options,
}: let
lib' = config.lib;
in {
config = {
exports.packages.example-x = lib'.packages.export "example.x";
packages = {
generic = {
example = {
x = {
meta.platforms = ["i686-linux" "x86_64-linux"];
version = "1.0.0";
builder.build = package:
derivation {
name = package.name;
builder = "/bin/sh";
system = package.platform.build;
};
phases = {
build = package: ''
make --build ${package.platform.build} --host ${package.platform.host}
'';
install = lib.dag.entry.after ["build"] ''
make install DESTDIR=$out
'';
};
};
};
};
};
};
}

View file

@ -17,16 +17,6 @@
packages
);
targeted' = {
i686-linux =
getPackages "i686-linux" generic
// {
cross = {
x86_64-linux = getPackages "x86_64-linux" generic;
};
};
};
targeted = lib.attrs.generate lib'.systems.doubles.all (system:
getPackages system generic
// {
@ -36,7 +26,7 @@
});
in {
includes = [
# ./aux/foundation.nix
./aux/foundation.nix
];
options = {
@ -54,32 +44,6 @@ in {
config = {
packages = {
generic = {
example = {
x = {
meta.platforms = ["i686-linux" "x86_64-linux"];
version = "1.0.0";
builder.build = package:
derivation {
name = package.name;
builder = "/bin/sh";
system = package.platform.build;
};
phases = {
build = package: ''
make --build ${package.platform.build} --host ${package.platform.host}
'';
install = lib.dag.entry.after ["build"] ''
make install DESTDIR=$out
'';
};
};
};
};
inherit targeted;
};
};