Commit 0c60d398 authored by K900's avatar K900
Browse files

Merge remote-tracking branch 'origin/master' into staging-next

parents d6b2d520 c259fefc
Loading
Loading
Loading
Loading
+354 −136
Original line number Diff line number Diff line
/* Collection of functions useful for debugging
/**
  Collection of functions useful for debugging
  broken nix expressions.

  * `trace`-like functions take two values, print
@@ -32,78 +33,189 @@ rec {

  # -- TRACING --

  /* Conditionally trace the supplied message, based on a predicate.
  /**
    Conditionally trace the supplied message, based on a predicate.

     Type: traceIf :: bool -> string -> a -> a

     Example:
    # Inputs

    `pred`

    : Predicate to check

    `msg`

    : Message that should be traced

    `x`

    : Value to return

    # Type

    ```
    traceIf :: bool -> string -> a -> a
    ```

    # Examples
    :::{.example}
    ## `lib.debug.traceIf` usage example

    ```nix
    traceIf true "hello" 3
    trace: hello
    => 3
    ```

    :::
  */
  traceIf =
    # Predicate to check
    pred:
    # Message that should be traced
    msg:
    # Value to return
    x: if pred then trace msg x else x;

  /* Trace the supplied value after applying a function to it, and
  /**
    Trace the supplied value after applying a function to it, and
    return the original value.

     Type: traceValFn :: (a -> b) -> a -> a

     Example:
    # Inputs

    `f`

    : Function to apply

    `x`

    : Value to trace and return

    # Type

    ```
    traceValFn :: (a -> b) -> a -> a
    ```

    # Examples
    :::{.example}
    ## `lib.debug.traceValFn` usage example

    ```nix
    traceValFn (v: "mystring ${v}") "foo"
    trace: mystring foo
    => "foo"
    ```

    :::
  */
  traceValFn =
    # Function to apply
    f:
    # Value to trace and return
    x: trace (f x) x;

  /* Trace the supplied value and return it.
  /**
    Trace the supplied value and return it.

    # Inputs

    `x`

    : Value to trace and return

    # Type

     Type: traceVal :: a -> a
    ```
    traceVal :: a -> a
    ```

     Example:
    # Examples
    :::{.example}
    ## `lib.debug.traceVal` usage example

    ```nix
    traceVal 42
    # trace: 42
    => 42
    ```

    :::
  */
  traceVal = traceValFn id;

  /* `builtins.trace`, but the value is `builtins.deepSeq`ed first.
  /**
    `builtins.trace`, but the value is `builtins.deepSeq`ed first.


    # Inputs

    `x`

    : The value to trace

    `y`

    : The value to return

     Type: traceSeq :: a -> b -> b
    # Type

     Example:
    ```
    traceSeq :: a -> b -> b
    ```

    # Examples
    :::{.example}
    ## `lib.debug.traceSeq` usage example

    ```nix
    trace { a.b.c = 3; } null
    trace: { a = <CODE>; }
    => null
    traceSeq { a.b.c = 3; } null
    trace: { a = { b = { c = 3; }; }; }
    => null
    ```

    :::
  */
  traceSeq =
    # The value to trace
    x:
    # The value to return
    y: trace (builtins.deepSeq x x) y;

  /* Like `traceSeq`, but only evaluate down to depth n.
  /**
    Like `traceSeq`, but only evaluate down to depth n.
    This is very useful because lots of `traceSeq` usages
    lead to an infinite recursion.

     Example:

    # Inputs

    `depth`

    : 1\. Function argument

    `x`

    : 2\. Function argument

    `y`

    : 3\. Function argument

    # Type

    ```
    traceSeqN :: Int -> a -> b -> b
    ```

    # Examples
    :::{.example}
    ## `lib.debug.traceSeqN` usage example

    ```nix
    traceSeqN 2 { a.b.c = 3; } null
    trace: { a = { b = {…}; }; }
    => null
    ```

     Type: traceSeqN :: Int -> a -> b -> b
    :::
  */
  traceSeqN = depth: x: y:
    let snip = v: if      isList  v then noQuotes "[…]" v
@@ -118,41 +230,115 @@ rec {
    in trace (generators.toPretty { allowPrettyValues = true; }
               (modify depth snip x)) y;

  /* A combination of `traceVal` and `traceSeq` that applies a
  /**
    A combination of `traceVal` and `traceSeq` that applies a
    provided function to the value to be traced after `deepSeq`ing
    it.


    # Inputs

    `f`

    : Function to apply

    `v`

    : Value to trace
  */
  traceValSeqFn =
    # Function to apply
    f:
    # Value to trace
    v: traceValFn f (builtins.deepSeq v v);

  /* A combination of `traceVal` and `traceSeq`. */
  /**
    A combination of `traceVal` and `traceSeq`.

    # Inputs

    `v`

    : Value to trace

  */
  traceValSeq = traceValSeqFn id;

  /* A combination of `traceVal` and `traceSeqN` that applies a
  provided function to the value to be traced. */
  /**
    A combination of `traceVal` and `traceSeqN` that applies a
    provided function to the value to be traced.


    # Inputs

    `f`

    : Function to apply

    `depth`

    : 2\. Function argument

    `v`

    : Value to trace
  */
  traceValSeqNFn =
    # Function to apply
    f:
    depth:
    # Value to trace
    v: traceSeqN depth (f v) v;

  /* A combination of `traceVal` and `traceSeqN`. */
  /**
    A combination of `traceVal` and `traceSeqN`.

    # Inputs

    `depth`

    : 1\. Function argument

    `v`

    : Value to trace
  */
  traceValSeqN = traceValSeqNFn id;

  /* Trace the input and output of a function `f` named `name`,
  /**
    Trace the input and output of a function `f` named `name`,
    both down to `depth`.

    This is useful for adding around a function call,
    to see the before/after of values as they are transformed.

     Example:

    # Inputs

    `depth`

    : 1\. Function argument

    `name`

    : 2\. Function argument

    `f`

    : 3\. Function argument

    `v`

    : 4\. Function argument


    # Examples
    :::{.example}
    ## `lib.debug.traceFnSeqN` usage example

    ```nix
    traceFnSeqN 2 "id" (x: x) { a.b.c = 3; }
    trace: { fn = "id"; from = { a.b = {…}; }; to = { a.b = {…}; }; }
    => { a.b.c = 3; }
    ```

    :::
  */
  traceFnSeqN = depth: name: f: v:
    let res = f v;
@@ -168,7 +354,8 @@ rec {

  # -- TESTING --

  /* Evaluates a set of tests.
  /**
    Evaluates a set of tests.

    A test is an attribute set `{expr, expected}`,
    denoting an expression and its expected result.
@@ -188,8 +375,38 @@ rec {

    - If you want to run only a subset of the tests add the attribute `tests = ["testName"];`

    Example:

    # Inputs

    `tests`

    : Tests to run

    # Type

    ```
    runTests :: {
      tests = [ String ];
      ${testName} :: {
        expr :: a;
        expected :: a;
      };
    }
    ->
    [
      {
        name :: String;
        expected :: a;
        result :: a;
      }
    ]
    ```

    # Examples
    :::{.example}
    ## `lib.debug.runTests` usage example

    ```nix
    runTests {
      testAndOk = {
        expr = lib.and true false;
@@ -208,26 +425,11 @@ rec {
        result = false;
      }
    ]
    ```

    Type:
      runTests :: {
        tests = [ String ];
        ${testName} :: {
          expr :: a;
          expected :: a;
        };
      }
      ->
      [
        {
          name :: String;
          expected :: a;
          result :: a;
        }
      ]
    :::
  */
  runTests =
    # Tests to run
    tests: concatLists (attrValues (mapAttrs (name: test:
    let testsToRun = if tests ? tests then tests.tests else [];
    in if (substring 0 4 name == "test" ||  elem name testsToRun)
@@ -237,10 +439,26 @@ rec {
      then [ { inherit name; expected = test.expected; result = test.expr; } ]
      else [] ) tests));

  /* Create a test assuming that list elements are `true`.
  /**
    Create a test assuming that list elements are `true`.


    # Inputs

    `expr`

     Example:
    : 1\. Function argument


    # Examples
    :::{.example}
    ## `lib.debug.testAllTrue` usage example

    ```nix
    { testX = allTrue [ true ]; }
    ```

    :::
  */
  testAllTrue = expr: { inherit expr; expected = map (x: true) expr; };
}
+471 −280

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {

  nodes = {
    node1 = { pkgs, ... }: {
      networking.firewall.extraCommands = "iptables -A INPUT -p vrrp -j ACCEPT";
      services.keepalived.enable = true;
      services.keepalived.openFirewall = true;
      services.keepalived.vrrpInstances.test = {
        interface = "eth1";
        state = "MASTER";
@@ -16,8 +16,8 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
      environment.systemPackages = [ pkgs.tcpdump ];
    };
    node2 = { pkgs, ... }: {
      networking.firewall.extraCommands = "iptables -A INPUT -p vrrp -j ACCEPT";
      services.keepalived.enable = true;
      services.keepalived.openFirewall = true;
      services.keepalived.vrrpInstances.test = {
        interface = "eth1";
        state = "MASTER";
+753 −123

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -16,21 +16,21 @@

rustPlatform.buildRustPackage rec {
  pname = "asusctl";
  version = "6.0.6";
  version = "6.0.9";

  src = fetchFromGitLab {
    owner = "asus-linux";
    repo = "asusctl";
    rev = version;
    hash = "sha256-to2HJAqU3+xl6Wt90GH7RA7079v1QyP+AE0pL/9rd/M=";
    hash = "sha256-mml+nj+Z6267QtejTkWiR3SdNAdZCNz4M8r6LzvhALw=";
  };

  cargoLock = {
    lockFile = ./Cargo.lock;
    outputHashes = {
      "const-field-offset-0.1.5" = "sha256-53pT9ERsmF4lM9tVG09hgbM0zfbTp1qSM+NDyFQxe3c=";
      "const-field-offset-0.1.5" = "sha256-0MaNu6cUXislY+wDFuxZptXeJRkOuXGRJwZWm6AvcZ8=";
      "notify-rust-4.7.0" = "sha256-A7edUorty5GpGXCUQPszZuXtLdEmbmrDSU9JcoDaiaI=";
      "supergfxctl-5.2.2" = "sha256-hg1QJ7DLtn5oH6IqQu7BcWIsZKAsFy6jjsjF/2o1Cos=";
      "supergfxctl-5.2.3" = "sha256-wKcHoMukdUXZrdbE1xsylq7ySJpxny3+0dGUQ40BVH8=";
    };
  };

Loading