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

Improve listOrDagOf #2124

Closed
piegamesde opened this issue Jun 19, 2021 · 5 comments
Closed

Improve listOrDagOf #2124

piegamesde opened this issue Jun 19, 2021 · 5 comments

Comments

@piegamesde
Copy link
Contributor

piegamesde commented Jun 19, 2021

Issue description

Context #1164 #1151 NixOS/nixpkgs#1800

The current solution may work in the sense that it provides a possibility to have a partial order on attributes. However, it leads to very poor user experience when many entries need to be linearly ordered: manually creating that order as of now leads to a lot of boilerplate and reduced maintainability of the code:

{
  "john.example.com" = {
    hostname = "example.com";
    user = "john";
  };
  foo = lib.hm.dag.entryAfter ["john.example.com"] {
    hostname = "example.com";
    identityFile = "/home/john/.ssh/foo_rsa";
  };
  bar = lib.hm.dag.entryAfter ["foo"] {
    hostname = "example.org";
    identityFile = "/home/john/.ssh/bar_rsa";
  };
  baz = lib.hm.dag.entryAfter ["bar"] {
    hostname = "example.net";
    user = "jane";
    identityFile = "/home/jane/.ssh/bar_rsa";
  };
}

Potential ideas for improvement (both general and specific to the SSH module, where the problem is the most prominent):

  1. Have a method that takes a list and creates a DAG with a linear ordering.
  2. Un-deprecate the list type for that option. Maybe under the constraint that merging is disallowed or gives a warning. Many times, no merging is needed anyways.
  3. Go back to extraConfig, which is what the nixpkgs module does anyways.

Meta

CC @rycee @mweinelt

Technical details

  • system: "x86_64-linux"
  • host os: Linux 5.12.10-arch1-1, Arch Linux, noversion
  • multi-user?: no
  • sandbox: yes
  • version: nix-env (Nix) 2.3.10
  • channels(piegames): "nixpkgs-21.05.993.93963c27b93, nixpkgs-unstable-21.11pre295670.189a1368878"
  • nixpkgs: ~/.nix-defexpr/channels/nixpkgs
@piegamesde
Copy link
Contributor Author

piegamesde commented Jun 19, 2021

I hacked something together:

dagEntriesLinear = namePrefix: entries:
let
  makeEntry = i: v: let
    newVal = {
      data = v;
      before = [];
      after = if i == 0 then [] else ["${namePrefix}.${toString (i - 1)}"];
    };
  in
    lib.nameValuePair "${namePrefix}.${toString i}" newVal;
in
  lib.trivial.pipe entries [
    (lib.lists.imap0 makeEntry)
    lib.listToAttrs
  ];

@stale
Copy link

stale bot commented Sep 18, 2021

Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.

Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Sep 18, 2021
@piegamesde
Copy link
Contributor Author

Still relevant to me.

@stale stale bot removed the status: stale label Sep 18, 2021
@stale
Copy link

stale bot commented Dec 17, 2021

Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.

Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Dec 17, 2021
@piegamesde
Copy link
Contributor Author

As per the helper function posted above, I consider this issue resolved. I'd appreciate if somebody took the time to turn this into a PR though.

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

No branches or pull requests

1 participant