Compare commits

..

4 commits

6 changed files with 60 additions and 162 deletions

View file

@ -15,9 +15,8 @@ jobs:
- name: Update pins - name: Update pins
run: nix-shell --run "npins update" run: nix-shell --run "npins update"
- name: Create PR - name: Create PR
uses: https://github.com/KiaraGrouwstra/gitea-create-pull-request@f9f80aa5134bc5c03c38f5aaa95053492885b397 uses: peter-evans/create-pull-request@v7
with: with:
remote-instance-api-version: v1
token: "${{ secrets.DEPLOY_KEY }}" token: "${{ secrets.DEPLOY_KEY }}"
branch: npins-update branch: npins-update
commit-message: "npins: update sources" commit-message: "npins: update sources"

View file

@ -1,13 +1,9 @@
let let
inherit (import ../default.nix { }) pkgs inputs; inherit (import ../default.nix { }) pkgs;
inherit (pkgs) lib; inherit (pkgs) lib;
inherit (lib) mkOption;
eval = eval =
module: module:
(lib.evalModules { (lib.evalModules {
specialArgs = {
inherit inputs;
};
modules = [ modules = [
module module
./data-model.nix ./data-model.nix
@ -20,51 +16,32 @@ in
test-eval = { test-eval = {
expr = expr =
let let
fediversity = eval ( example = eval {
{ config, ... }: runtime-environments.bar.nixos = {
{
config = {
applications.hello =
{ ... }:
{
description = ''Command-line tool that will print "Hello, world!" on the terminal'';
module = module =
{ ... }: { ... }:
{ {
options = { system.stateVersion = "25.05";
enable = lib.mkEnableOption "Hello in the shell";
}; };
}; };
implementation = applications.foo = {
cfg: module =
lib.optionalAttrs cfg.enable { { pkgs, ... }:
dummy.login-shell.packages.hello = pkgs.hello; {
environment.systemPackages = [
pkgs.hello
];
}; };
}; };
}; };
options = {
example-configuration = mkOption {
type = config.configuration;
readOnly = true;
default = {
enable = true;
applications.hello.enable = true;
};
};
};
}
);
in in
{ {
inherit (fediversity) has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module;
example-configuration has-application = lib.isAttrs example.applications.foo.module;
;
}; };
expected = { expected = {
example-configuration = { has-runtime = true;
enable = true; has-application = true;
applications.hello.enable = true;
};
}; };
}; };
} }

View file

@ -1,89 +1,45 @@
{ {
lib, lib,
config,
... ...
}: }:
let let
inherit (lib) mkOption types; inherit (lib) types mkOption;
inherit (lib.types)
attrsOf
attrTag
deferredModuleWith
submodule
optionType
functionTo
;
functionType = import ./function.nix;
application-resources = {
options.resources = mkOption {
# TODO: maybe transpose, and group the resources by type instead
type = attrsOf (
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources)
);
};
};
in in
with types;
{ {
_class = "nixops4Deployment"; _class = "nixops4Deployment";
options = { options = {
runtime-environments = mkOption {
description = "Collection of runtime environments into which applications can be deployed";
type = attrsOf (attrTag {
nixos = mkOption {
description = "A single NixOS machine";
type = submodule {
options = {
module = mkOption {
description = "The NixOS module describing the base configuration for that machine";
type = deferredModule;
};
};
};
};
});
};
applications = mkOption { applications = mkOption {
description = "Collection of Fediversity applications"; description = "Collection of Fediversity applications";
type = attrsOf ( type = attrsOf (submoduleWith {
submodule (application: { modules = [
_class = "fediversity-application"; {
options = { options = {
description = mkOption {
description = "Description to be shown in the application overview";
type = types.str;
};
module = mkOption { module = mkOption {
description = "Operator-facing configuration options for the application"; description = "The NixOS module for that application, for configuring that application";
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; }; type = deferredModule;
};
implementation = mkOption {
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = application.config.config-mapping.function-type;
};
resources = mkOption {
description = "Compute resources required by an application";
type = functionTo application.config.config-mapping.output-type;
readOnly = true;
default = input: (application.config.implementation input).output;
};
config-mapping = mkOption {
description = "Function type for the mapping from application configuration to required resources";
type = submodule functionType;
readOnly = true;
default = {
input-type = application.config.module;
output-type = application-resources;
}; };
}; };
};
})
);
};
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submodule {
options = {
enable = lib.mkEnableOption {
description = "your Fediversity configuration";
};
applications = lib.mapAttrs (
_name: application:
mkOption {
description = application.description;
type = submodule application.module;
default = { };
} }
) config.applications; ];
}; });
};
}; };
}; };
} }

View file

@ -1,37 +0,0 @@
/**
Modular function type
*/
{ config, lib, ... }:
let
inherit (lib) mkOption types;
inherit (types)
deferredModule
submodule
functionTo
optionType
;
in
{
options = {
input-type = mkOption {
type = deferredModule;
};
output-type = mkOption {
type = deferredModule;
};
function-type = mkOption {
type = optionType;
readOnly = true;
default = functionTo (submodule {
options = {
input = mkOption {
type = submodule config.input-type;
};
output = mkOption {
type = submodule config.output-type;
};
};
});
};
};
}

View file

@ -202,8 +202,11 @@ in
}; };
}; };
# needed to place a config file with home-manager users.users.${name} = {
users.users.${name}.isNormalUser = true; # TODO[Niols]: change to system user or document why we specifically
# need a normal user.
isNormalUser = true;
};
users.groups.${name} = { }; users.groups.${name} = { };
systemd.services.${name} = { systemd.services.${name} = {

View file

@ -69,11 +69,11 @@ in
config = { config = {
## FIXME: This should clearly go somewhere else; and we should have a ## FIXME: This should clearly go somewhere else; and we should have a
## `staging` vs. `production` setting somewhere. ## `staging` vs. `production` setting somewhere.
security.acme = { # use a priority higher than mkDefault for panel deployment to work,
# yet lower than default so this will not clash with the setting in tests.
security.acme = lib.modules.mkOverride 900 {
acceptTerms = true; acceptTerms = true;
# use a priority more urgent than mkDefault for panel deployment to work, defaults.email = "something@fediversity.net";
# yet looser than default so this will not clash with the setting in tests.
defaults.email = lib.modules.mkOverride 200 "something@fediversity.net";
# defaults.server = "https://acme-staging-v02.api.letsencrypt.org/directory"; # defaults.server = "https://acme-staging-v02.api.letsencrypt.org/directory";
}; };
}; };