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 untrusted user: jakehamilton
GPG key ID: 9762169A1B35EA68
11 changed files with 168 additions and 59 deletions

View file

@ -26,6 +26,7 @@ may collaborate.
## Experiments ## Experiments
| Name | Phase | Description | | Name | Phase | Description |
| ------------------------------ | --------- | -------------------------------------------------------------------------- | | ------------------------------ | --------- | ------------------------------------------------------------------------------------ |
| [Aux Lib](./lib) | Iteration | A library of common functions used in the Aux ecosystem. | | [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 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; 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. ## Combine multiple modules together.
## ##
## @type List String -> List Module -> { matched :: Attrs, unmatched :: List Definition } ## @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 in
result.config result.config
# result.config.exported

View file

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

View file

@ -3,20 +3,43 @@
lib, lib,
}: let }: let
lib' = config.lib; lib' = config.lib;
cfg = config.exports;
in { in {
options = { options = {
exports.packages = lib.options.create { exports.packages = lib.options.create {
type = lib.types.attrs.of (lib.types.function (lib.types.nullish lib.types.derivation));
default.value = {}; default.value = {};
}; };
exported.packages = lib.options.create { exported.packages = lib.options.create {
type = lib.types.attrs.of (lib.types.attrs.of lib.types.derivation);
default.value = {}; default.value = {};
}; };
}; };
config = { config = {
exported.packages = { exported.packages = let
# i686-linux = config.packages.foundation; 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 { in {
includes = [ includes = [
./options.nix ./options.nix
./packages.nix
./systems.nix ./systems.nix
./types.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 { meta = lib.types.submodule {
options = { options = {
name = lib.options.create {
type = lib.types.string;
description = "The name of the package.";
};
description = lib.options.create { description = lib.options.create {
type = lib.types.nullish lib.types.string; type = lib.types.nullish lib.types.string;
default.value = null; default.value = null;
@ -138,7 +133,7 @@ in {
lib'.types.package.targeted' lib'.types.package.targeted'
{ {
config = { config = {
namespace = namespace; namespace = lib.modules.override 99 namespace;
platform = { platform = {
build = system; build = system;
@ -164,7 +159,7 @@ in {
lib'.types.package.targeted' lib'.types.package.targeted'
{ {
config = { config = {
namespace = namespace; namespace = lib.modules.override 99 namespace;
platform = { platform = {
build = system; build = system;
@ -194,6 +189,11 @@ in {
config, config,
}: { }: {
options = { options = {
namespace = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
};
pname = lib.options.create { pname = lib.options.create {
type = lib.types.string; type = lib.types.string;
default = { 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 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: targeted = lib.attrs.generate lib'.systems.doubles.all (system:
getPackages system generic getPackages system generic
// { // {
@ -36,7 +26,7 @@
}); });
in { in {
includes = [ includes = [
# ./aux/foundation.nix ./aux/foundation.nix
]; ];
options = { options = {
@ -54,32 +44,6 @@ in {
config = { config = {
packages = { 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; inherit targeted;
}; };
}; };