Skip to content

Instantly share code, notes, and snippets.

@cmacrae
Last active December 24, 2019 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmacrae/e41c431da8294d37f89602dd20b82f34 to your computer and use it in GitHub Desktop.
Save cmacrae/e41c431da8294d37f89602dd20b82f34 to your computer and use it in GitHub Desktop.
Help wanted for my first Nix function(s)

About

I'm trying to get a bit of a better grasp on the Nix language, rather than just as a vehicle for systems configuration.
As such, I have two configuration files that I'd like to take Nix sets/a list of sets to template out these files from.

1. The inputs config

I want to write a function that takes this:

{
  inputs = {
    "1:1:AT_Translated_Set_2_keyboard" = {
      xkb_layout = "gb";
      xkb_options = "ctrl:nocaps";
    };

    "1739:0:Synaptics_TM3381-002" = {
      pointer_accel = "0.7";
      tap = "enabled";
      dwt = "enabled";
      natural_scroll = "enabled";
    };
  };
}

And outputs this as a string:

input "1:1:AT_Translated_Set_2_keyboard" {
    xkb_layout gb
    xkb_options ctrl:nocaps
}

input "1739:0:Synaptics_TM3381-002" {
    pointer_accel 0.7
    tap enabled
    dwt enabled
    natural_scroll enabled
}

2. The outputs config

I'd like to write a function that takes this:

{
  outputs = [
    { eDP1 = {};}

    {
      "DP-1" = {
        position = "0,0";
        transform = "270";
      };

      "HDMI-A-2" = { position = "1440,470"; };
      "eDP-1" = { position = "1440,1910"; };
    }

    {
      "DP-3" = { position = "450,0"; };
      "DP-4" = { position = "0,1440"; };
      "eDP-1" = { position = "800,2880"; };
    }
  ];
}

And outputs this:

{
  output eDP-1
}
{
  output DP-1 position 0,0 transform 270
  output HDMI-A-2 position 1440,470
  output eDP-1 position 1440,1910
}
{
  output DP-3 position 450,0
  output DP-4 position 0,1440
  output eDP-1 position 800,2880
}

Any pointers to functions that do something similar that I can read as a point of reference,
or any help in general on how to do this would be greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment