Skip to content

Conversation

rycee
Copy link
Member

@rycee rycee commented Aug 21, 2025

Description

This is some experiments in making the systemd unit descriptions more typed by using freeform modules.

Checklist

  • Change is backwards compatible.

    Technically no, with this change we would, for example, reject ExecStart = 42 (which is nonsense) but quite possibly also valid configurations.

  • Code formatted with nix fmt or
    nix-shell -p treefmt nixfmt deadnix keep-sorted --run treefmt.

  • Code tested through nix run .#tests -- test-all or
    nix-shell --pure tests -A run.all.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    
  • If this PR adds an exciting new feature or contains a breaking change.

    • Generate a news entry. See News

      Will do this if leaving draft.

We add types for a few of the most common attributes.
@rycee rycee force-pushed the systemd-unit-freeform-module branch from 1cbf9fd to 282b7c7 Compare August 21, 2025 21:06
@github-actions github-actions bot removed the system label Aug 21, 2025
unitBaseType "service" {
options.Service = {
Environment = mkOption {
type = with types; either str (listOf str);
Copy link
Member Author

Choose a reason for hiding this comment

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

It would probably be possible to support something like attrsOf primitive as a more ergonomic way to express variable assignment (similar to the sessionVariables options).

Comment on lines +107 to +108
type = with types; either str (listOf str);
apply = p: if builtins.isList p then p else [ p ];
Copy link
Contributor

Choose a reason for hiding this comment

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

This is lib.toList (a no-op on lists), but otherwise using coercedTo str lib.toList (listOf str) removes the need for apply.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, very nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants