Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Discussions #232

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# DevOS 2.0

- We want to be a good ecosystem citizen, therefore we want to rebase on [`gytis/flake-utils-plus`](https://github.com/gytis-ivaskevicius/flake-utils-plus).
- `gytis/flake-utils-plus` is designed to be incorporated in upstream flake-utils. As the name suggests, it wraps and extends `flake-utils` for nixos related use cases.
- `devos-lib` shall be another layer that wraps `flakes-utils-plus` and adds accoustomed devos amentities, such as:
- automagic importers, for pure convenience, but without prescribing a particular folder layout (that is something for devos templates to achieve).
- additional configuration generators, such as for `deploy-rs` or `home-manager` or other future integrations (eg. mobile nixos, etc) that we want to offer as a convenience.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be so down with implementing deploy-rs and HM as part of the flake-utils-plus ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least deploy-rs currently has a dependency injected of a deploy.lib library function, though.

I still regard being dependency-free as a feature. 😉

Copy link

@gytis-ivaskevicius gytis-ivaskevicius Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, I am planning to keep fup dependency-free :)

- other amentities (tbd)



## Importers

Importers declutter the top level flake. The goal is to have a bunch of lines that read like a very clean table of contents:

```nix
concept1 = ./concept1;
concept2 = ./concept2;
concept3 = { "..." = "..."; };
concept4 = [];
```
Comment on lines +16 to +21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly relevant but having all attributes interpreted like so would be pretty cool:

{
  concept1 = ./some/directory; # Evaluates to 'concept1 = { fileNameWithoutNixExtension = {...}; }'
  concept2 = ./someFile.nix; # Evaluates to  'concept2 = { "..." = "..."; }'
  concept3 = { "..." = "..."; }; # Evaluates to 'concept3 = { "..." = "..."; }'
  concept4 = [];  # Evaluates to 'concept4 = []'
}

It seems important to enable dual use (importing files or declaring inline), in order to allow people to generate user
flakes that put emphasis on different aspects of using devos lib (by sheer looking on the folder hierarchy).

Some context about importers, and how we might want them to behave:

- https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/8
- https://github.com/blaggacao/devos/blob/5d80663bcd3f65cc95fd965b49becc7b24ebf9d4/lib/devos/importer.nix


## Config Generators

Configuration Generators generate configurations for particular entities. In practice and for now,

- a [nixosConfigurationsGenerator](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/51cb739c9c9c2258bc70747eb7bc22975ae244bd/systemFlake.nix#L61-L64) creates nixosConfigurations,
- based on which a [deployConfigurationsGenerator](https://github.com/blaggacao/devos/blob/5d80663bcd3f65cc95fd965b49becc7b24ebf9d4/lib/devos/configGenerators.nix#L14-L25) generates deploy-rs configurations &
- a [hmConfigurationsGenerator](https://github.com/blaggacao/devos/blob/5d80663bcd3f65cc95fd965b49becc7b24ebf9d4/lib/devos/configGenerators.nix#L34-L45) generates home manager configurations.

See also: https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/10


## API

The devos-lib onion:

- `builtins`
- `numtide/flake-utils`
- `gytis/flake-utils-plus`
- `divnix/devos` (the lib)

While flake-utils-plus exports a generic [`utils.systemFlake`](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/51cb739c9c9c2258bc70747eb7bc22975ae244bd/flake.nix#L37) user function
and is restricted from including dependencies, devos-lib should export a `devos.systemFlake` without such restrictions and that can include
additional (eventually third-party mediated) generatros, such as `deploy-rs`, while implementing a strict superset of
`utils.systemFlake` api and, on the other hand, a `devos.mkFlake` with importer amenities included and a slightly different api for convenience.

### `devos.systemFlake`

```nix
# devos.systemFlake
{
# adopt flake-utils-plus, file upstream issues where discussion is needed
self
, defaultSystem ? "x86_64-linux"
, supportedSystems ? flake-utils.lib.defaultSystems
, name # or inputs, see: https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/12
, nixosHosts ? { NAME = { # https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/16
system = "...";
channelName = "...";
extraArgs = { };
modules = [ ];
};}
, channels ? {
input = "...";
overlaysBuilder = channels: [ (final: prev: { })];
config = { };
patches = [ ];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point I'm like "can we just pay some C++ nerd to properly implement channels patching as part of Nix binary instead" :D

Copy link
Contributor Author

@blaggacao blaggacao Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually that seems like a good venue. We could start by lobbying more heavily and probably Ma29 could lend us a hand.

x-ref NixOS/nix#3920

}
, channelsConfig ? { }
, sharedModules ? [ ]
, sharedOverlays ? [ ]
, nixosSpecialArgs ? { } # https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/13#issuecomment-814512835

, hmConfigurations ? { }
, hmProfiles ? { NAME = {
modules = [ ];
extraArgs = { };
# what else makes sense, here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe system is still required, also maybe having an option to pick which channel is used would be nice since a lot of people are running core system on stable, HM on unstable channels

};}

, deployConfigurations ? { }

, ... # passed through / https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/14}
```

### `devos.mkFlake`

This is all about importer amentities over `devos.systemFlake`.

For example people should be able to define either paths or functions as arguments.
Also we might consider special (import !only!) magic like reducing:

```nix
{
nixos = {
modules = ./modules;
profiles = ./profiles;
specialArgs = { }; # https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/13#issuecomment-814512835
hosts = ./hosts;
suites = ./suites;
};
}
```

to

```nix
{
nixos = ./os; # with default fallback folder naming scheme
}
```

#### Part 1: Passthrough API from `devos.systemFlake`

We should not change the api here, but rather seek upstream amendmend.
```nix
# devos.mkFlake
{
self
, defaultSystem ? "x86_64-linux"
, supportedSystems ? flake-utils.lib.defaultSystems
, name # or inputs, see: https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If namespacing is no longer a goal, name isn't necessary. inputs is also unecessary, because you can just use self.inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it boils down to how foreign flakes should be consumed. So it's kind of a difficult normative call to make. As I argue in the linked issue, flake.nix have a relatively strict output schema. I only might speculate the intention was to also consume flake by them and not the en-globing corresponding input (not inputs!) object, itself.

, channels ? {
input = "...";
overlaysBuilder = channels: [ (final: prev: { })]; # TODO: do we want another interface here? Also: how to handle module backports?
config = { };
patches = [ ];
}
, channelsConfig ? { }
# TODO: two dimensions:
# - shared vs. "per-host"
# - external (consuming other devos flakes) vs internal
, sharedModules ? [ ]
, sharedOverlays ? [ ]
Comment on lines +142 to +143
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say call sharedOverlays just overlays and sharedModules something like internalModules. That makes it clear that those modules are only for simple things and they won't get exported. And theres no need to call it sharedOverlays if theres no "unshared overlays".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, we have:

  • shared modules (for all hosts)
  • non-shared modules (for some hosts)
  • shared overlays (for all hosts)
  • non shared overlays (for specific hosts)
  • but also external shared modules and external host specific modules
  • and also external shared and unshared overlays

... in theory. We have to make a good cut, I guess.

Copy link

@gytis-ivaskevicius gytis-ivaskevicius Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sharedOverlays vs overlays - calling it overlays would mean a name conflict between abstraction and flake itself.

internalModules - I'd say naming could be better than that. Maybe something that actually represents that its auto imported to all the configurations?

Overall, I'm quite a fan of sharedXyz since naming is clear, more or less makes sense, and does not conflict with actual flake attributes

Copy link
Contributor Author

@blaggacao blaggacao Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW simpleFlake calls it preOverlays — since the order of application matters in overlays.

, ... # passed through
}
```

#### Part 2: Devos NixOS/hm/... configuration API
```nix
# devos.mkFlake
{
# allow setting those in a variety of (polished ways)
# like suites = { one = {}; two = {};}; instead of ./suites
, nixos ? {
modules = ./modules;
profiles = ./profiles;
specialArgs = { }; # https://github.com/gytis-ivaskevicius/flake-utils-plus/issues/13#issuecomment-814512835
hosts = ./hosts;
suites = ./suites;
, hm ? {
modules = ./users/modules;
profiles = ./users/profiles;
specialArgs = { };
suites = ./users/suites;
}
Comment on lines +154 to +165

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm.modules = ./abc; is not a valid syntax due to missing profiles/specialArgs/suites. I am not sure if thats intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to take those values at face value & in a first step applying maybeImporters and only in a second step function instantiators, the latter passing all nescessary args around.

Does that make sense or did I misread your comment?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the way default values are implemented - if hm.modules is defined - hm.profiles/hm.specialArgs/hm.suites must be manually defined as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! @Pacman99 in the meanwhile is an expert of validating, crosschecking and defaulting values via the module system.

I think it will be a mix of a:

  • coustom type
  • sane defaults
  • apply transformations
  • ...

}
```