diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 8ec7a8df..3a3d7b52 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -83,9 +83,21 @@ instance Pretty Binder where -- `foo = bar` pretty (Assignment selectors assign expr semicolon) - = base $ group (hcat selectors <> hardspace - <> nest 2 (pretty assign <> softline <> pretty expr)) - <> pretty semicolon + = base $ group $ hcat selectors <> hardspace + <> nest 2 (pretty assign <> absorbInner expr) + where + -- Function declaration / If statement / Let binding + -- If it is multi-line, force it into a new line with indentation, semicolon on separate line + absorbInner expr@(Abstraction _ _ _) = line <> pretty expr <> line' <> pretty semicolon + absorbInner expr@(If _ _ _ _ _ _) = line <> pretty expr <> line' <> pretty semicolon + absorbInner expr@(Let _ _ _ _) = line <> pretty expr <> line' <> pretty semicolon + -- Absorbable term (list/attrset) + -- force-absorb the term and then the semicolon + absorbInner expr@(Term t) | isAbsorbable t = hardspace <> group expr <> softline' <> pretty semicolon + -- `foo = bar`, otherwise + -- Try to absorb and keep the semicolon attached, spread otherwise + absorbInner expr = softline <> group (pretty expr <> softline' <> pretty semicolon) + -- | Pretty print a term without wrapping it in a group. prettyTerm :: Term -> Doc diff --git a/test/diff/apply/out.nix b/test/diff/apply/out.nix index 9b00a175..87619c4b 100644 --- a/test/diff/apply/out.nix +++ b/test/diff/apply/out.nix @@ -57,10 +57,12 @@ } # https://github.com/kamadorueda/alejandra/issues/372#issuecomment-1435083516 { - outputs = { + outputs = + { utils, }: # For each supported platform, - utils.lib.eachDefaultSystem (system: { }); + utils.lib.eachDefaultSystem (system: { }) + ; } ] diff --git a/test/diff/attr_set/out.nix b/test/diff/attr_set/out.nix index b95620b0..8cb17e75 100644 --- a/test/diff/attr_set/out.nix +++ b/test/diff/attr_set/out.nix @@ -71,11 +71,11 @@ c = 1; - # d + # d e = 1; - # f + # f } ] diff --git a/test/diff/comment/out.nix b/test/diff/comment/out.nix index 01c854ba..1f5f795f 100644 --- a/test/diff/comment/out.nix +++ b/test/diff/comment/out.nix @@ -52,12 +52,12 @@ a = 1; # 3 b = 1; c = 1; # 4 - #5 + #5 - #6 + #6 d = 1; - #7 + #7 } (let # 1 @@ -65,12 +65,12 @@ a = 1; # 3 b = 1; c = 1; # 4 - #5 + #5 - #6 + #6 d = 1; - #7 + #7 in d ) diff --git a/test/diff/idioms_lib_1/out.nix b/test/diff/idioms_lib_1/out.nix index 8f28264f..50646a88 100644 --- a/test/diff/idioms_lib_1/out.nix +++ b/test/diff/idioms_lib_1/out.nix @@ -9,5 +9,6 @@ if pred then trace msg x else - x; + x + ; } diff --git a/test/diff/idioms_lib_2/out.nix b/test/diff/idioms_lib_2/out.nix index 205d1897..7b42e87a 100644 --- a/test/diff/idioms_lib_2/out.nix +++ b/test/diff/idioms_lib_2/out.nix @@ -14,155 +14,173 @@ rec { id = # The value to return x: - x; + x + ; - /* The constant function + /* The constant function - Ignores the second argument. If called with only one argument, - constructs a function that always returns a static value. + Ignores the second argument. If called with only one argument, + constructs a function that always returns a static value. - Type: const :: a -> b -> a - Example: - let f = const 5; in f 10 - => 5 - */ + Type: const :: a -> b -> a + Example: + let f = const 5; in f 10 + => 5 + */ const = # Value to return x: # Value to ignore y: - x; + x + ; - /* Pipes a value through a list of functions, left to right. + /* Pipes a value through a list of functions, left to right. - Type: pipe :: a -> [] -> - Example: - pipe 2 [ - (x: x + 2) # 2 + 2 = 4 - (x: x * 2) # 4 * 2 = 8 - ] - => 8 + Type: pipe :: a -> [] -> + Example: + pipe 2 [ + (x: x + 2) # 2 + 2 = 4 + (x: x * 2) # 4 * 2 = 8 + ] + => 8 - # ideal to do text transformations - pipe [ "a/b" "a/c" ] [ + # ideal to do text transformations + pipe [ "a/b" "a/c" ] [ - # create the cp command - (map (file: ''cp "${src}/${file}" $out\n'')) + # create the cp command + (map (file: ''cp "${src}/${file}" $out\n'')) - # concatenate all commands into one string - lib.concatStrings + # concatenate all commands into one string + lib.concatStrings - # make that string into a nix derivation - (pkgs.runCommand "copy-to-out" {}) + # make that string into a nix derivation + (pkgs.runCommand "copy-to-out" {}) - ] - => + ] + => - The output type of each function has to be the input type - of the next function, and the last function returns the - final value. - */ - pipe = val: functions: + The output type of each function has to be the input type + of the next function, and the last function returns the + final value. + */ + pipe = + val: functions: let reverseApply = x: f: f x; in builtins.foldl' reverseApply val functions - ; + ; - # note please don’t add a function like `compose = flip pipe`. - # This would confuse users, because the order of the functions - # in the list is not clear. With pipe, it’s obvious that it - # goes first-to-last. With `compose`, not so much. + # note please don’t add a function like `compose = flip pipe`. + # This would confuse users, because the order of the functions + # in the list is not clear. With pipe, it’s obvious that it + # goes first-to-last. With `compose`, not so much. - ## Named versions corresponding to some builtin operators. + ## Named versions corresponding to some builtin operators. - /* Concatenate two lists + /* Concatenate two lists - Type: concat :: [a] -> [a] -> [a] + Type: concat :: [a] -> [a] -> [a] - Example: - concat [ 1 2 ] [ 3 4 ] - => [ 1 2 3 4 ] - */ - concat = x: y: x ++ y; + Example: + concat [ 1 2 ] [ 3 4 ] + => [ 1 2 3 4 ] + */ + concat = + x: y: + x ++ y + ; - # boolean “or” - or = x: y: x || y; + # boolean “or” + or = + x: y: + x || y + ; - # boolean “and” - and = x: y: x && y; + # boolean “and” + and = + x: y: + x && y + ; - # bitwise “and” + # bitwise “and” bitAnd = builtins.bitAnd or (import ./zip-int-bits.nix (a: b: if a == 1 && b == 1 then 1 else 0)); - # bitwise “or” + # bitwise “or” bitOr = builtins.bitOr or (import ./zip-int-bits.nix (a: b: if a == 1 || b == 1 then 1 else 0)); - # bitwise “xor” + # bitwise “xor” bitXor = builtins.bitXor or (import ./zip-int-bits.nix (a: b: if a != b then 1 else 0)); - # bitwise “not” + # bitwise “not” bitNot = builtins.sub (-1); - /* Convert a boolean to a string. + /* Convert a boolean to a string. - This function uses the strings "true" and "false" to represent - boolean values. Calling `toString` on a bool instead returns "1" - and "" (sic!). + This function uses the strings "true" and "false" to represent + boolean values. Calling `toString` on a bool instead returns "1" + and "" (sic!). - Type: boolToString :: bool -> string - */ - boolToString = b: + Type: boolToString :: bool -> string + */ + boolToString = + b: if b then "true" else - "false"; + "false" + ; - /* Merge two attribute sets shallowly, right side trumps left + /* Merge two attribute sets shallowly, right side trumps left - mergeAttrs :: attrs -> attrs -> attrs + mergeAttrs :: attrs -> attrs -> attrs - Example: - mergeAttrs { a = 1; b = 2; } { b = 3; c = 4; } - => { a = 1; b = 3; c = 4; } - */ + Example: + mergeAttrs { a = 1; b = 2; } { b = 3; c = 4; } + => { a = 1; b = 3; c = 4; } + */ mergeAttrs = # Left attribute set x: # Right attribute set (higher precedence for equal keys) y: - x // y; + x // y + ; - /* Flip the order of the arguments of a binary function. + /* Flip the order of the arguments of a binary function. - Type: flip :: (a -> b -> c) -> (b -> a -> c) + Type: flip :: (a -> b -> c) -> (b -> a -> c) - Example: - flip concat [1] [2] - => [ 2 1 ] - */ - flip = f: a: b: f b a; + Example: + flip concat [1] [2] + => [ 2 1 ] + */ + flip = + f: a: b: + f b a + ; - /* Apply function if the supplied argument is non-null. + /* Apply function if the supplied argument is non-null. - Example: - mapNullable (x: x+1) null - => null - mapNullable (x: x+1) 22 - => 23 - */ + Example: + mapNullable (x: x+1) null + => null + mapNullable (x: x+1) 22 + => 23 + */ mapNullable = # Function to call f: @@ -171,9 +189,10 @@ rec { if a == null then a else - f a; + f a + ; - # Pull in some builtins not included elsewhere. + # Pull in some builtins not included elsewhere. inherit (builtins) pathExists readFile @@ -193,29 +212,31 @@ rec { # Returns the current full nixpkgs version number. version = release + versionSuffix; - # Returns the current nixpkgs release number as string. + # Returns the current nixpkgs release number as string. release = lib.strings.fileContents ../.version; - /* Returns the current nixpkgs release code name. + /* Returns the current nixpkgs release code name. - On each release the first letter is bumped and a new animal is chosen - starting with that new letter. - */ + On each release the first letter is bumped and a new animal is chosen + starting with that new letter. + */ codeName = "Quokka"; - # Returns the current nixpkgs version suffix as string. - versionSuffix = let - suffixFile = ../.version-suffix; - in if pathExists suffixFile then - lib.strings.fileContents suffixFile - else - "pre-git"; + # Returns the current nixpkgs version suffix as string. + versionSuffix = + let + suffixFile = ../.version-suffix; + in if pathExists suffixFile then + lib.strings.fileContents suffixFile + else + "pre-git" + ; - /* Attempts to return the the current revision of nixpkgs and - returns the supplied default value otherwise. + /* Attempts to return the the current revision of nixpkgs and + returns the supplied default value otherwise. - Type: revisionWithDefault :: string -> string - */ + Type: revisionWithDefault :: string -> string + */ revisionWithDefault = # Default value to return if revision can not be determined default: @@ -227,78 +248,88 @@ rec { else if lib.pathExists revisionFile then lib.fileContents revisionFile else - default; + default + ; nixpkgsVersion = builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!" version; - /* Determine whether the function is being called from inside a Nix - shell. + /* Determine whether the function is being called from inside a Nix + shell. - Type: inNixShell :: bool - */ + Type: inNixShell :: bool + */ inNixShell = builtins.getEnv "IN_NIX_SHELL" != ""; - ## Integer operations + ## Integer operations - # Return minimum of two numbers. - min = x: y: + # Return minimum of two numbers. + min = + x: y: if x < y then x else - y; + y + ; - # Return maximum of two numbers. - max = x: y: + # Return maximum of two numbers. + max = + x: y: if x > y then x else - y; - - /* Integer modulus + y + ; - Example: - mod 11 10 - => 1 - mod 1 10 - => 1 - */ - mod = base: int: base - (int * (builtins.div base int)); + /* Integer modulus + + Example: + mod 11 10 + => 1 + mod 1 10 + => 1 + */ + mod = + base: int: + base - (int * (builtins.div base int)) + ; - ## Comparisons + ## Comparisons - /* C-style comparisons + /* C-style comparisons - a < b, compare a b => -1 - a == b, compare a b => 0 - a > b, compare a b => 1 - */ - compare = a: b: + a < b, compare a b => -1 + a == b, compare a b => 0 + a > b, compare a b => 1 + */ + compare = + a: b: if a < b then -1 else if a > b then 1 else - 0; + 0 + ; - /* Split type into two subtypes by predicate `p`, take all elements - of the first subtype to be less than all the elements of the - second subtype, compare elements of a single subtype with `yes` - and `no` respectively. + /* Split type into two subtypes by predicate `p`, take all elements + of the first subtype to be less than all the elements of the + second subtype, compare elements of a single subtype with `yes` + and `no` respectively. - Type: (a -> bool) -> (a -> a -> int) -> (a -> a -> int) -> (a -> a -> int) + Type: (a -> bool) -> (a -> a -> int) -> (a -> a -> int) -> (a -> a -> int) - Example: - let cmp = splitByAndCompare (hasPrefix "foo") compare compare; in + Example: + let cmp = splitByAndCompare (hasPrefix "foo") compare compare; in - cmp "a" "z" => -1 - cmp "fooa" "fooz" => -1 + cmp "a" "z" => -1 + cmp "fooa" "fooz" => -1 - cmp "f" "a" => 1 - cmp "fooa" "a" => -1 - # while - compare "fooa" "a" => 1 - */ + cmp "f" "a" => 1 + cmp "fooa" "a" => -1 + # while + compare "fooa" "a" => 1 + */ splitByAndCompare = # Predicate p: @@ -318,102 +349,116 @@ rec { else if p b then 1 else - no a b; + no a b + ; - /* Reads a JSON file. + /* Reads a JSON file. - Type :: path -> any - */ - importJSON = path: builtins.fromJSON (builtins.readFile path); + Type :: path -> any + */ + importJSON = + path: + builtins.fromJSON (builtins.readFile path) + ; - /* Reads a TOML file. + /* Reads a TOML file. - Type :: path -> any - */ - importTOML = path: builtins.fromTOML (builtins.readFile path); - - ## Warnings - - # See https://github.com/NixOS/nix/issues/749. Eventually we'd like these - # to expand to Nix builtins that carry metadata so that Nix can filter out - # the INFO messages without parsing the message string. - # - # Usage: - # { - # foo = lib.warn "foo is deprecated" oldFoo; - # bar = lib.warnIf (bar == "") "Empty bar is deprecated" bar; - # } - # - # TODO: figure out a clever way to integrate location information from - # something like __unsafeGetAttrPos. - - /* Print a warning before returning the second argument. This function behaves - like `builtins.trace`, but requires a string message and formats it as a - warning, including the `warning: ` prefix. - - To get a call stack trace and abort evaluation, set the environment variable - `NIX_ABORT_ON_WARN=true` and set the Nix options `--option pure-eval false --show-trace` - - Type: string -> a -> a - */ - warn = if - lib.elem (builtins.getEnv "NIX_ABORT_ON_WARN") [ - "1" - "true" - "yes" - ] - then - msg: - builtins.trace "warning: ${msg}" (abort - "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.") - else - msg: builtins.trace "warning: ${msg}"; - - /* Like warn, but only warn when the first argument is `true`. - - Type: bool -> string -> a -> a - */ - warnIf = cond: msg: + Type :: path -> any + */ + importTOML = + path: + builtins.fromTOML (builtins.readFile path) + ; + + ## Warnings + + # See https://github.com/NixOS/nix/issues/749. Eventually we'd like these + # to expand to Nix builtins that carry metadata so that Nix can filter out + # the INFO messages without parsing the message string. + # + # Usage: + # { + # foo = lib.warn "foo is deprecated" oldFoo; + # bar = lib.warnIf (bar == "") "Empty bar is deprecated" bar; + # } + # + # TODO: figure out a clever way to integrate location information from + # something like __unsafeGetAttrPos. + + /* Print a warning before returning the second argument. This function behaves + like `builtins.trace`, but requires a string message and formats it as a + warning, including the `warning: ` prefix. + + To get a call stack trace and abort evaluation, set the environment variable + `NIX_ABORT_ON_WARN=true` and set the Nix options `--option pure-eval false --show-trace` + + Type: string -> a -> a + */ + warn = + if + lib.elem (builtins.getEnv "NIX_ABORT_ON_WARN") [ + "1" + "true" + "yes" + ] + then + msg: + builtins.trace "warning: ${msg}" (abort + "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.") + else + msg: builtins.trace "warning: ${msg}" + ; + + /* Like warn, but only warn when the first argument is `true`. + + Type: bool -> string -> a -> a + */ + warnIf = + cond: msg: if cond then warn msg else - id; + id + ; - /* Like the `assert b; e` expression, but with a custom error message and - without the semicolon. + /* Like the `assert b; e` expression, but with a custom error message and + without the semicolon. - If true, return the identity function, `r: r`. + If true, return the identity function, `r: r`. - If false, throw the error message. + If false, throw the error message. - Calls can be juxtaposed using function application, as `(r: r) a = a`, so - `(r: r) (r: r) a = a`, and so forth. + Calls can be juxtaposed using function application, as `(r: r) a = a`, so + `(r: r) (r: r) a = a`, and so forth. - Type: bool -> string -> a -> a + Type: bool -> string -> a -> a - Example: + Example: - throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list." - lib.foldr (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.") (r: r) overlays - pkgs - */ - throwIfNot = cond: msg: + throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list." + lib.foldr (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.") (r: r) overlays + pkgs + */ + throwIfNot = + cond: msg: if cond then x: x else - throw msg; + throw msg + ; - /* Check if the elements in a list are valid values from a enum, returning the identity function, or throwing an error message otherwise. + /* Check if the elements in a list are valid values from a enum, returning the identity function, or throwing an error message otherwise. - Example: - let colorVariants = ["bright" "dark" "black"] - in checkListOfEnum "color variants" [ "standard" "light" "dark" ] colorVariants; - => - error: color variants: bright, black unexpected; valid ones: standard, light, dark + Example: + let colorVariants = ["bright" "dark" "black"] + in checkListOfEnum "color variants" [ "standard" "light" "dark" ] colorVariants; + => + error: color variants: bright, black unexpected; valid ones: standard, light, dark - Type: String -> List ComparableVal -> List ComparableVal -> a -> a - */ - checkListOfEnum = msg: valid: given: + Type: String -> List ComparableVal -> List ComparableVal -> a -> a + */ + checkListOfEnum = + msg: valid: given: let unexpected = lib.subtractLists valid given; in @@ -422,60 +467,70 @@ rec { } unexpected; valid ones: ${ builtins.concatStringsSep ", " (builtins.map builtins.toString valid) }" - ; + ; info = msg: builtins.trace "INFO: ${msg}"; - showWarnings = warnings: res: lib.foldr (w: x: warn w x) res warnings; + showWarnings = + warnings: res: + lib.foldr (w: x: warn w x) res warnings + ; - ## Function annotations + ## Function annotations - /* Add metadata about expected function arguments to a function. - The metadata should match the format given by - builtins.functionArgs, i.e. a set from expected argument to a bool - representing whether that argument has a default or not. - setFunctionArgs : (a → b) → Map String Bool → (a → b) + /* Add metadata about expected function arguments to a function. + The metadata should match the format given by + builtins.functionArgs, i.e. a set from expected argument to a bool + representing whether that argument has a default or not. + setFunctionArgs : (a → b) → Map String Bool → (a → b) - This function is necessary because you can't dynamically create a - function of the { a, b ? foo, ... }: format, but some facilities - like callPackage expect to be able to query expected arguments. - */ + This function is necessary because you can't dynamically create a + function of the { a, b ? foo, ... }: format, but some facilities + like callPackage expect to be able to query expected arguments. + */ setFunctionArgs = f: args: { # TODO: Should we add call-time "type" checking like built in? __functor = self: f; __functionArgs = args; - }; + } + ; - /* Extract the expected function arguments from a function. - This works both with nix-native { a, b ? foo, ... }: style - functions and functions with args set with 'setFunctionArgs'. It - has the same return type and semantics as builtins.functionArgs. - setFunctionArgs : (a → b) → Map String Bool. - */ - functionArgs = f: + /* Extract the expected function arguments from a function. + This works both with nix-native { a, b ? foo, ... }: style + functions and functions with args set with 'setFunctionArgs'. It + has the same return type and semantics as builtins.functionArgs. + setFunctionArgs : (a → b) → Map String Bool. + */ + functionArgs = + f: if f ? __functor then f.__functionArgs or (lib.functionArgs (f.__functor f)) else - builtins.functionArgs f; + builtins.functionArgs f + ; - /* Check whether something is a function or something - annotated with function args. - */ - isFunction = f: - builtins.isFunction f || (f ? __functor && isFunction (f.__functor f)); + /* Check whether something is a function or something + annotated with function args. + */ + isFunction = + f: + builtins.isFunction f || (f ? __functor && isFunction (f.__functor f)) + ; - /* Convert the given positive integer to a string of its hexadecimal - representation. For example: + /* Convert the given positive integer to a string of its hexadecimal + representation. For example: - toHexString 0 => "0" + toHexString 0 => "0" - toHexString 16 => "10" + toHexString 16 => "10" - toHexString 250 => "FA" - */ - toHexString = i: + toHexString 250 => "FA" + */ + toHexString = + i: let - toHexDigit = d: + toHexDigit = + d: if d < 10 then toString d else @@ -486,23 +541,26 @@ rec { "13" = "D"; "14" = "E"; "15" = "F"; - }.${toString d}; + }.${toString d} + ; in lib.concatMapStrings toHexDigit (toBaseDigits 16 i) - ; + ; - /* `toBaseDigits base i` converts the positive integer i to a list of its - digits in the given base. For example: + /* `toBaseDigits base i` converts the positive integer i to a list of its + digits in the given base. For example: - toBaseDigits 10 123 => [ 1 2 3 ] + toBaseDigits 10 123 => [ 1 2 3 ] - toBaseDigits 2 6 => [ 1 1 0 ] + toBaseDigits 2 6 => [ 1 1 0 ] - toBaseDigits 16 250 => [ 15 10 ] - */ - toBaseDigits = base: i: + toBaseDigits 16 250 => [ 15 10 ] + */ + toBaseDigits = + base: i: let - go = i: + go = + i: if i < base then [ i ] else @@ -511,8 +569,8 @@ rec { q = (i - r) / base; in [ r ] ++ go q - ; + ; in assert (base >= 2); assert (i >= 0); lib.reverseList (go i) - ; + ; } diff --git a/test/diff/idioms_lib_3/out.nix b/test/diff/idioms_lib_3/out.nix index cb4a2184..e7844203 100644 --- a/test/diff/idioms_lib_3/out.nix +++ b/test/diff/idioms_lib_3/out.nix @@ -29,13 +29,16 @@ in rec { # Convert a value to a sensible default string representation. # The builtin `toString` function has some strange defaults, # suitable for bash scripts but not much else. - mkValueStringDefault = { }: + mkValueStringDefault = + { }: v: with builtins; let - err = t: v: + err = + t: v: abort ("generators.mkValueStringDefault: " - + "${t} not supported: ${toPretty { } v}"); + + "${t} not supported: ${toPretty { } v}") + ; in if isInt v then toString v # convert derivations to store paths @@ -67,67 +70,74 @@ in rec { else if isFloat v then libStr.floatToString v else - err "this value is" (toString v); + err "this value is" (toString v) + ; - # Generate a line of key k and value v, separated by - # character sep. If sep appears in k, it is escaped. - # Helper for synaxes with different separators. - # - # mkValueString specifies how values should be formatted. - # - # mkKeyValueDefault {} ":" "f:oo" "bar" - # > "f\:oo:bar" - mkKeyValueDefault = { + # Generate a line of key k and value v, separated by + # character sep. If sep appears in k, it is escaped. + # Helper for synaxes with different separators. + # + # mkValueString specifies how values should be formatted. + # + # mkKeyValueDefault {} ":" "f:oo" "bar" + # > "f\:oo:bar" + mkKeyValueDefault = + { mkValueString ? mkValueStringDefault { } }: sep: k: v: - "${libStr.escape [ sep ] k}${sep}${mkValueString v}"; + "${libStr.escape [ sep ] k}${sep}${mkValueString v}" + ; - ## -- FILE FORMAT GENERATORS -- + ## -- FILE FORMAT GENERATORS -- - # Generate a key-value-style config file from an attrset. - # - # mkKeyValue is the same as in toINI. - toKeyValue = { + # Generate a key-value-style config file from an attrset. + # + # mkKeyValue is the same as in toINI. + toKeyValue = + { mkKeyValue ? mkKeyValueDefault { } "=", listsAsDuplicateKeys ? false }: let mkLine = k: v: mkKeyValue k v + "\n"; - mkLines = if listsAsDuplicateKeys then - k: v: - map (mkLine k) (if lib.isList v then - v + mkLines = + if listsAsDuplicateKeys then + k: v: + map (mkLine k) (if lib.isList v then + v + else + [ v ]) else - [ v ]) - else - k: v: [ (mkLine k v) ]; + k: v: [ (mkLine k v) ] + ; in attrs: libStr.concatStrings (lib.concatLists (libAttr.mapAttrsToList mkLines attrs)) - ; + ; - # Generate an INI-style config file from an - # attrset of sections to an attrset of key-value pairs. - # - # generators.toINI {} { - # foo = { hi = "${pkgs.hello}"; ciao = "bar"; }; - # baz = { "also, integers" = 42; }; - # } - # - #> [baz] - #> also, integers=42 - #> - #> [foo] - #> ciao=bar - #> hi=/nix/store/y93qql1p5ggfnaqjjqhxcw0vqw95rlz0-hello-2.10 - # - # The mk* configuration attributes can generically change - # the way sections and key-value strings are generated. - # - # For more examples see the test cases in ./tests/misc.nix. - toINI = { + # Generate an INI-style config file from an + # attrset of sections to an attrset of key-value pairs. + # + # generators.toINI {} { + # foo = { hi = "${pkgs.hello}"; ciao = "bar"; }; + # baz = { "also, integers" = 42; }; + # } + # + #> [baz] + #> also, integers=42 + #> + #> [foo] + #> ciao=bar + #> hi=/nix/store/y93qql1p5ggfnaqjjqhxcw0vqw95rlz0-hello-2.10 + # + # The mk* configuration attributes can generically change + # the way sections and key-value strings are generated. + # + # For more examples see the test cases in ./tests/misc.nix. + toINI = + { # apply transformations (e.g. escapes) to section names mkSectionName ? (name: libStr.escape [ @@ -142,48 +152,53 @@ in rec { attrsOfAttrs: let # map function to string for each key val - mapAttrsToStringsSep = sep: mapFn: attrs: - libStr.concatStringsSep sep (libAttr.mapAttrsToList mapFn attrs); - mkSection = sectName: sectValues: + mapAttrsToStringsSep = + sep: mapFn: attrs: + libStr.concatStringsSep sep (libAttr.mapAttrsToList mapFn attrs) + ; + mkSection = + sectName: sectValues: '' [${mkSectionName sectName}] - '' + toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } sectValues; - # map input to ini sections + '' + toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } sectValues + ; + # map input to ini sections in mapAttrsToStringsSep "\n" mkSection attrsOfAttrs - ; + ; - # Generate an INI-style config file from an attrset - # specifying the global section (no header), and an - # attrset of sections to an attrset of key-value pairs. - # - # generators.toINIWithGlobalSection {} { - # globalSection = { - # someGlobalKey = "hi"; - # }; - # sections = { - # foo = { hi = "${pkgs.hello}"; ciao = "bar"; }; - # baz = { "also, integers" = 42; }; - # } - # - #> someGlobalKey=hi - #> - #> [baz] - #> also, integers=42 - #> - #> [foo] - #> ciao=bar - #> hi=/nix/store/y93qql1p5ggfnaqjjqhxcw0vqw95rlz0-hello-2.10 - # - # The mk* configuration attributes can generically change - # the way sections and key-value strings are generated. - # - # For more examples see the test cases in ./tests/misc.nix. - # - # If you don’t need a global section, you can also use - # `generators.toINI` directly, which only takes - # the part in `sections`. - toINIWithGlobalSection = { + # Generate an INI-style config file from an attrset + # specifying the global section (no header), and an + # attrset of sections to an attrset of key-value pairs. + # + # generators.toINIWithGlobalSection {} { + # globalSection = { + # someGlobalKey = "hi"; + # }; + # sections = { + # foo = { hi = "${pkgs.hello}"; ciao = "bar"; }; + # baz = { "also, integers" = 42; }; + # } + # + #> someGlobalKey=hi + #> + #> [baz] + #> also, integers=42 + #> + #> [foo] + #> ciao=bar + #> hi=/nix/store/y93qql1p5ggfnaqjjqhxcw0vqw95rlz0-hello-2.10 + # + # The mk* configuration attributes can generically change + # the way sections and key-value strings are generated. + # + # For more examples see the test cases in ./tests/misc.nix. + # + # If you don’t need a global section, you can also use + # `generators.toINI` directly, which only takes + # the part in `sections`. + toINIWithGlobalSection = + { # apply transformations (e.g. escapes) to section names mkSectionName ? (name: libStr.escape [ @@ -205,29 +220,32 @@ in rec { (toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } globalSection) + "\n") + (toINI { inherit mkSectionName mkKeyValue listsAsDuplicateKeys; } - sections); + sections) + ; - # Generate a git-config file from an attrset. - # - # It has two major differences from the regular INI format: - # - # 1. values are indented with tabs - # 2. sections can have sub-sections - # - # generators.toGitINI { - # url."ssh://git@github.com/".insteadOf = "https://github.com"; - # user.name = "edolstra"; - # } - # - #> [url "ssh://git@github.com/"] - #> insteadOf = https://github.com/ - #> - #> [user] - #> name = edolstra - toGitINI = attrs: + # Generate a git-config file from an attrset. + # + # It has two major differences from the regular INI format: + # + # 1. values are indented with tabs + # 2. sections can have sub-sections + # + # generators.toGitINI { + # url."ssh://git@github.com/".insteadOf = "https://github.com"; + # user.name = "edolstra"; + # } + # + #> [url "ssh://git@github.com/"] + #> insteadOf = https://github.com/ + #> + #> [user] + #> name = edolstra + toGitINI = + attrs: with builtins; let - mkSectionName = name: + mkSectionName = + name: let containsQuote = libStr.hasInfix ''"'' name; sections = libStr.splitString "." name; @@ -237,50 +255,60 @@ in rec { in if containsQuote || subsections == [ ] then name else - ''${section} "${subsection}"''; + ''${section} "${subsection}"'' + ; - # generation for multiple ini values - mkKeyValue = k: v: + # generation for multiple ini values + mkKeyValue = + k: v: let mkKeyValue = mkKeyValueDefault { } " = " k; in concatStringsSep "\n" (map (kv: " " + mkKeyValue kv) (lib.toList v)) - ; + ; - # converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI - gitFlattenAttrs = let - recurse = path: value: - if isAttrs value && !lib.isDerivation value then - lib.mapAttrsToList (name: value: recurse ([ name ] ++ path) value) - value - else if length path > 1 then - { - ${concatStringsSep "." (lib.reverseList (tail path))}.${ - head path - } = value; - } - else - { ${head path} = value; }; - in - attrs: lib.foldl lib.recursiveUpdate { } (lib.flatten (recurse [ ] attrs)) - ; + # converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI + gitFlattenAttrs = + let + recurse = + path: value: + if isAttrs value && !lib.isDerivation value then + lib.mapAttrsToList (name: value: recurse ([ name ] ++ path) value) + value + else if length path > 1 then + { + ${concatStringsSep "." (lib.reverseList (tail path))}.${ + head path + } = value; + } + else + { ${head path} = value; } + ; + in + attrs: + lib.foldl lib.recursiveUpdate { } (lib.flatten (recurse [ ] attrs)) + ; toINI_ = toINI { inherit mkKeyValue mkSectionName; }; in toINI_ (gitFlattenAttrs attrs) - ; + ; - # Generates JSON from an arbitrary (non-function) value. - # For more information see the documentation of the builtin. - toJSON = { }: builtins.toJSON; + # Generates JSON from an arbitrary (non-function) value. + # For more information see the documentation of the builtin. + toJSON = + { }: + builtins.toJSON + ; - # YAML has been a strict superset of JSON since 1.2, so we - # use toJSON. Before it only had a few differences referring - # to implicit typing rules, so it should work with older - # parsers as well. + # YAML has been a strict superset of JSON since 1.2, so we + # use toJSON. Before it only had a few differences referring + # to implicit typing rules, so it should work with older + # parsers as well. toYAML = toJSON; - withRecursion = { + withRecursion = + { # If this option is not null, the given value will stop evaluating at a certain depth depthLimit # If this option is true, an error will be thrown, if a certain given depth is exceeded @@ -295,12 +323,15 @@ in rec { "__toString" "__pretty" ]; - stepIntoAttr = evalNext: name: + stepIntoAttr = + evalNext: name: if builtins.elem name specialAttrs then id else - evalNext; - transform = depth: + evalNext + ; + transform = + depth: if depthLimit != null && depth > depthLimit then if throwOnDepthLimit then throw "Exceeded maximum eval-depth limit of ${ @@ -309,7 +340,8 @@ in rec { else const "" else - id; + id + ; mapAny = with builtins; depth: v: let @@ -322,14 +354,15 @@ in rec { transform (depth + 1) v; in mapAny 0 - ; + ; - # Pretty print a value, akin to `builtins.trace`. - # Should probably be a builtin as well. - # The pretty-printed string should be suitable for rendering default values - # in the NixOS manual. In particular, it should be as close to a valid Nix expression - # as possible. - toPretty = { + # Pretty print a value, akin to `builtins.trace`. + # Should probably be a builtin as well. + # The pretty-printed string should be suitable for rendering default values + # in the NixOS manual. In particular, it should be as close to a valid Nix expression + # as possible. + toPretty = + { /* If this option is true, attrsets like { __pretty = fn; val = …; } will use fn to convert val to a pretty printed representation. (This means fn is type Val -> String.) @@ -341,22 +374,27 @@ in rec { indent ? "" }: let - go = indent: v: + go = + indent: v: with builtins; let isPath = v: typeOf v == "path"; - introSpace = if multiline then - '' + introSpace = + if multiline then + '' - ${indent} '' - else - " "; - outroSpace = if multiline then - '' + ${indent} '' + else + " " + ; + outroSpace = + if multiline then + '' - ${indent}'' - else - " "; + ${indent}'' + else + " " + ; in if isInt v then toString v # toString loses precision on floats, so we use toJSON instead. This isn't perfect @@ -381,19 +419,20 @@ in rec { ]; singlelineResult = ''"'' + concatStringsSep "\\n" (map escapeSingleline lines) + ''"''; - multilineResult = let - escapedLines = map escapeMultiline lines; - # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" - # indentation level. Otherwise, '' is appended to the last line. - lastLine = lib.last escapedLines; - in - "''" + introSpace - + concatStringsSep introSpace (lib.init escapedLines) - + (if lastLine == "" then - outroSpace - else - introSpace + lastLine) + "''" - ; + multilineResult = + let + escapedLines = map escapeMultiline lines; + # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" + # indentation level. Otherwise, '' is appended to the last line. + lastLine = lib.last escapedLines; + in + "''" + introSpace + + concatStringsSep introSpace (lib.init escapedLines) + + (if lastLine == "" then + outroSpace + else + introSpace + lastLine) + "''" + ; in if multiline && length lines > 1 then multilineResult else @@ -445,17 +484,20 @@ in rec { (go (indent + " ") value) };") v) + outroSpace + "}" else - abort "generators.toPretty: should never happen (v = ${v})"; + abort "generators.toPretty: should never happen (v = ${v})" + ; in go indent - ; + ; - # PLIST handling - toPlist = { }: + # PLIST handling + toPlist = + { }: v: let isFloat = builtins.isFloat or (x: false); - expr = ind: x: + expr = + ind: x: with builtins; if x == null then "" @@ -472,15 +514,18 @@ in rec { else if isFloat x then float ind x else - abort "generators.toPlist: should never happen (v = ${v})"; + abort "generators.toPlist: should never happen (v = ${v})" + ; literal = ind: x: ind + x; - bool = ind: x: + bool = + ind: x: literal ind (if x then "" else - ""); + "") + ; int = ind: x: literal ind "${toString x}"; str = ind: x: literal ind "${x}"; key = ind: x: literal ind "${x}"; @@ -490,43 +535,50 @@ in rec { item = ind: libStr.concatMapStringsSep "\n" (indent ind); - list = ind: x: + list = + ind: x: libStr.concatStringsSep "\n" [ (literal ind "") (item ind x) (literal ind "") - ]; + ] + ; - attrs = ind: x: + attrs = + ind: x: libStr.concatStringsSep "\n" [ (literal ind "") (attr ind x) (literal ind "") - ]; + ] + ; - attr = let - attrFilter = name: value: name != "_module" && value != null; - in - ind: x: - libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList - (name: value: - lib.optionals (attrFilter name value) [ - (key " ${ind}" name) - (expr " ${ind}" value) - ]) x)) - ; + attr = + let + attrFilter = name: value: name != "_module" && value != null; + in + ind: x: + libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList + (name: value: + lib.optionals (attrFilter name value) [ + (key " ${ind}" name) + (expr " ${ind}" value) + ]) x)) + ; in '' ${expr "" v} - '' ; + '' + ; - # Translate a simple Nix expression to Dhall notation. - # Note that integers are translated to Integer and never - # the Natural type. - toDhall = { }@args: + # Translate a simple Nix expression to Dhall notation. + # Note that integers are translated to Integer and never + # the Natural type. + toDhall = + { }@args: v: with builtins; let @@ -555,5 +607,6 @@ in rec { else if v == null then abort "generators.toDhall: cannot convert a null to Dhall" else - builtins.toJSON v; + builtins.toJSON v + ; } diff --git a/test/diff/idioms_nixos_1/out.nix b/test/diff/idioms_nixos_1/out.nix index aec88cdc..f64b3013 100644 --- a/test/diff/idioms_nixos_1/out.nix +++ b/test/diff/idioms_nixos_1/out.nix @@ -39,17 +39,19 @@ in { boot.kernelPackages = mkOption { default = pkgs.linuxPackages; type = types.unspecified // { merge = mergeEqualOption; }; - apply = kernelPackages: + apply = + kernelPackages: kernelPackages.extend (self: super: { kernel = super.kernel.override (originalArgs: { inherit randstructSeed; - kernelPatches = (originalArgs.kernelPatches or [ ]) - ++ kernelPatches; + kernelPatches = + (originalArgs.kernelPatches or [ ]) ++ kernelPatches; features = lib.recursiveUpdate super.kernel.features features; }); - }); - # We don't want to evaluate all of linuxPackages for the manual - # - some of it might not even evaluate correctly. + }) + ; + # We don't want to evaluate all of linuxPackages for the manual + # - some of it might not even evaluate correctly. defaultText = literalExpression "pkgs.linuxPackages"; example = literalExpression "pkgs.linuxKernel.packages.linux_5_10"; description = '' @@ -185,7 +187,7 @@ in { built outside of the kernel. Combine these into a single tree of symlinks because modprobe only supports one directory. ''; - # Convert the list of path to only one path. + # Convert the list of path to only one path. apply = pkgs.aggregateModules; }; @@ -209,7 +211,7 @@ in { }; - ###### implementation + ###### implementation config = mkMerge [ (mkIf config.boot.initrd.enable { @@ -276,8 +278,8 @@ in { system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; - # Implement consoleLogLevel both in early boot and using sysctl - # (so you don't need to reboot to have changes take effect). + # Implement consoleLogLevel both in early boot and using sysctl + # (so you don't need to reboot to have changes take effect). boot.kernelParams = [ "loglevel=${toString config.boot.consoleLogLevel}" ] ++ optionals config.boot.vesa [ "vga=0x317" @@ -292,11 +294,11 @@ in { "atkbd" ]; - # The Linux kernel >= 2.6.27 provides firmware. + # The Linux kernel >= 2.6.27 provides firmware. hardware.firmware = [ kernel ]; - # Create /etc/modules-load.d/nixos.conf, which is read by - # systemd-modules-load.service to load required kernel modules. + # Create /etc/modules-load.d/nixos.conf, which is read by + # systemd-modules-load.service to load required kernel modules. environment.etc = { "modules-load.d/nixos.conf".source = kernelModulesConf; }; @@ -313,41 +315,51 @@ in { }; lib.kernelConfig = { - isYes = option: { - assertion = config: config.isYes option; - message = "CONFIG_${option} is not yes!"; - configLine = "CONFIG_${option}=y"; - }; - - isNo = option: { - assertion = config: config.isNo option; - message = "CONFIG_${option} is not no!"; - configLine = "CONFIG_${option}=n"; - }; - - isModule = option: { - assertion = config: config.isModule option; - message = "CONFIG_${option} is not built as a module!"; - configLine = "CONFIG_${option}=m"; - }; - - ### Usually you will just want to use these two - # True if yes or module - isEnabled = option: { - assertion = config: config.isEnabled option; - message = "CONFIG_${option} is not enabled!"; - configLine = "CONFIG_${option}=y"; - }; - - # True if no or omitted - isDisabled = option: { - assertion = config: config.isDisabled option; - message = "CONFIG_${option} is not disabled!"; - configLine = "CONFIG_${option}=n"; - }; + isYes = + option: { + assertion = config: config.isYes option; + message = "CONFIG_${option} is not yes!"; + configLine = "CONFIG_${option}=y"; + } + ; + + isNo = + option: { + assertion = config: config.isNo option; + message = "CONFIG_${option} is not no!"; + configLine = "CONFIG_${option}=n"; + } + ; + + isModule = + option: { + assertion = config: config.isModule option; + message = "CONFIG_${option} is not built as a module!"; + configLine = "CONFIG_${option}=m"; + } + ; + + ### Usually you will just want to use these two + # True if yes or module + isEnabled = + option: { + assertion = config: config.isEnabled option; + message = "CONFIG_${option} is not enabled!"; + configLine = "CONFIG_${option}=y"; + } + ; + + # True if no or omitted + isDisabled = + option: { + assertion = config: config.isDisabled option; + message = "CONFIG_${option} is not disabled!"; + configLine = "CONFIG_${option}=n"; + } + ; }; - # The config options that all modules can depend upon + # The config options that all modules can depend upon system.requiredKernelConfig = with config.lib.kernelConfig; [ # !!! Should this really be needed? @@ -355,18 +367,19 @@ in { (isYes "BINFMT_ELF") ] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT")); - # nixpkgs kernels are assumed to have all required features - assertions = if config.boot.kernelPackages.kernel ? features then - [ ] - else - let - cfg = config.boot.kernelPackages.kernel.config; - in - map (attrs: { - assertion = attrs.assertion cfg; - inherit (attrs) message; - }) config.system.requiredKernelConfig - ; + # nixpkgs kernels are assumed to have all required features + assertions = + if config.boot.kernelPackages.kernel ? features then + [ ] + else + let + cfg = config.boot.kernelPackages.kernel.config; + in + map (attrs: { + assertion = attrs.assertion cfg; + inherit (attrs) message; + }) config.system.requiredKernelConfig + ; }) diff --git a/test/diff/idioms_pkgs_3/out.nix b/test/diff/idioms_pkgs_3/out.nix index aec88cdc..f64b3013 100644 --- a/test/diff/idioms_pkgs_3/out.nix +++ b/test/diff/idioms_pkgs_3/out.nix @@ -39,17 +39,19 @@ in { boot.kernelPackages = mkOption { default = pkgs.linuxPackages; type = types.unspecified // { merge = mergeEqualOption; }; - apply = kernelPackages: + apply = + kernelPackages: kernelPackages.extend (self: super: { kernel = super.kernel.override (originalArgs: { inherit randstructSeed; - kernelPatches = (originalArgs.kernelPatches or [ ]) - ++ kernelPatches; + kernelPatches = + (originalArgs.kernelPatches or [ ]) ++ kernelPatches; features = lib.recursiveUpdate super.kernel.features features; }); - }); - # We don't want to evaluate all of linuxPackages for the manual - # - some of it might not even evaluate correctly. + }) + ; + # We don't want to evaluate all of linuxPackages for the manual + # - some of it might not even evaluate correctly. defaultText = literalExpression "pkgs.linuxPackages"; example = literalExpression "pkgs.linuxKernel.packages.linux_5_10"; description = '' @@ -185,7 +187,7 @@ in { built outside of the kernel. Combine these into a single tree of symlinks because modprobe only supports one directory. ''; - # Convert the list of path to only one path. + # Convert the list of path to only one path. apply = pkgs.aggregateModules; }; @@ -209,7 +211,7 @@ in { }; - ###### implementation + ###### implementation config = mkMerge [ (mkIf config.boot.initrd.enable { @@ -276,8 +278,8 @@ in { system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; - # Implement consoleLogLevel both in early boot and using sysctl - # (so you don't need to reboot to have changes take effect). + # Implement consoleLogLevel both in early boot and using sysctl + # (so you don't need to reboot to have changes take effect). boot.kernelParams = [ "loglevel=${toString config.boot.consoleLogLevel}" ] ++ optionals config.boot.vesa [ "vga=0x317" @@ -292,11 +294,11 @@ in { "atkbd" ]; - # The Linux kernel >= 2.6.27 provides firmware. + # The Linux kernel >= 2.6.27 provides firmware. hardware.firmware = [ kernel ]; - # Create /etc/modules-load.d/nixos.conf, which is read by - # systemd-modules-load.service to load required kernel modules. + # Create /etc/modules-load.d/nixos.conf, which is read by + # systemd-modules-load.service to load required kernel modules. environment.etc = { "modules-load.d/nixos.conf".source = kernelModulesConf; }; @@ -313,41 +315,51 @@ in { }; lib.kernelConfig = { - isYes = option: { - assertion = config: config.isYes option; - message = "CONFIG_${option} is not yes!"; - configLine = "CONFIG_${option}=y"; - }; - - isNo = option: { - assertion = config: config.isNo option; - message = "CONFIG_${option} is not no!"; - configLine = "CONFIG_${option}=n"; - }; - - isModule = option: { - assertion = config: config.isModule option; - message = "CONFIG_${option} is not built as a module!"; - configLine = "CONFIG_${option}=m"; - }; - - ### Usually you will just want to use these two - # True if yes or module - isEnabled = option: { - assertion = config: config.isEnabled option; - message = "CONFIG_${option} is not enabled!"; - configLine = "CONFIG_${option}=y"; - }; - - # True if no or omitted - isDisabled = option: { - assertion = config: config.isDisabled option; - message = "CONFIG_${option} is not disabled!"; - configLine = "CONFIG_${option}=n"; - }; + isYes = + option: { + assertion = config: config.isYes option; + message = "CONFIG_${option} is not yes!"; + configLine = "CONFIG_${option}=y"; + } + ; + + isNo = + option: { + assertion = config: config.isNo option; + message = "CONFIG_${option} is not no!"; + configLine = "CONFIG_${option}=n"; + } + ; + + isModule = + option: { + assertion = config: config.isModule option; + message = "CONFIG_${option} is not built as a module!"; + configLine = "CONFIG_${option}=m"; + } + ; + + ### Usually you will just want to use these two + # True if yes or module + isEnabled = + option: { + assertion = config: config.isEnabled option; + message = "CONFIG_${option} is not enabled!"; + configLine = "CONFIG_${option}=y"; + } + ; + + # True if no or omitted + isDisabled = + option: { + assertion = config: config.isDisabled option; + message = "CONFIG_${option} is not disabled!"; + configLine = "CONFIG_${option}=n"; + } + ; }; - # The config options that all modules can depend upon + # The config options that all modules can depend upon system.requiredKernelConfig = with config.lib.kernelConfig; [ # !!! Should this really be needed? @@ -355,18 +367,19 @@ in { (isYes "BINFMT_ELF") ] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT")); - # nixpkgs kernels are assumed to have all required features - assertions = if config.boot.kernelPackages.kernel ? features then - [ ] - else - let - cfg = config.boot.kernelPackages.kernel.config; - in - map (attrs: { - assertion = attrs.assertion cfg; - inherit (attrs) message; - }) config.system.requiredKernelConfig - ; + # nixpkgs kernels are assumed to have all required features + assertions = + if config.boot.kernelPackages.kernel ? features then + [ ] + else + let + cfg = config.boot.kernelPackages.kernel.config; + in + map (attrs: { + assertion = attrs.assertion cfg; + inherit (attrs) message; + }) config.system.requiredKernelConfig + ; }) diff --git a/test/diff/key_value/out.nix b/test/diff/key_value/out.nix index b99a70e7..2ce030b5 100644 --- a/test/diff/key_value/out.nix +++ b/test/diff/key_value/out.nix @@ -7,7 +7,7 @@ rec { b = { a = 1 # d - ; + ; }; c = { @@ -17,7 +17,7 @@ rec { d = { a = # c 1 # d - ; + ; }; e = { a # b @@ -26,7 +26,7 @@ rec { f = { a # b = 1 # d - ; + ; }; h = { a # b @@ -37,28 +37,36 @@ rec { a # b = # c 1 # d - ; + ; }; j = a: { b = 1; }; - k = a: { - b = 1; - c = 2; - }; - l = a: # b + k = + a: { + b = 1; + c = 2; + } + ; + l = + a: # b { b = 1; - }; - m = a: # b + } + ; + m = + a: # b { b = 1; c = 2; - }; + } + ; n = pkgs: { }; - o = { + o = + { pkgs, ... }: - { }; + { } + ; a # b @@ -66,7 +74,7 @@ rec { # c 1 # d - ; + ; p = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { } a; diff --git a/test/diff/let_in/out.nix b/test/diff/let_in/out.nix index 8fc183fd..c5f94f3b 100644 --- a/test/diff/let_in/out.nix +++ b/test/diff/let_in/out.nix @@ -1,63 +1,74 @@ let - a = let - b = 2; - c = 3; - in - d - ; - a = let - c = 1; - in - f - ; + a = + let + b = 2; + c = 3; + in + d + ; + a = + let + c = 1; + in + f + ; - a = let - c = 1; - # e - in - f - ; - a = let - c = 1; # d - in - f - ; + a = + let + c = 1; + # e + in + f + ; + a = + let + c = 1; # d + in + f + ; - a = let - c = 1; # d - # e - in - f - ; - a = let # b - c = 1; - in - f - ; - a = let # b - c = 1; - # e - in - f - ; - a = let # b - c = 1; # d - in - f - ; - a = let # b - c = 1; # d - # e - in - f - ; + a = + let + c = 1; # d + # e + in + f + ; + a = + let # b + c = 1; + in + f + ; + a = + let # b + c = 1; + # e + in + f + ; + a = + let # b + c = 1; # d + in + f + ; + a = + let # b + c = 1; # d + # e + in + f + ; - a = let - in [ - 1 - 2 - ] ; + a = + let + in [ + 1 + 2 + ] + ; in a diff --git a/test/diff/monsters_1/out.nix b/test/diff/monsters_1/out.nix index f1b408a9..e6895770 100644 --- a/test/diff/monsters_1/out.nix +++ b/test/diff/monsters_1/out.nix @@ -76,13 +76,13 @@ rec = # foo "contrast"; - # foo + # foo version # foo = # foo "0.0.5"; - # foo + # foo src # foo = @@ -96,39 +96,39 @@ rec = # foo "gitlab.gnome.org"; - # foo + # foo group # foo = # foo "World"; - # foo + # foo owner # foo = # foo "design"; - # foo + # foo repo # foo = # foo "contrast"; - # foo + # foo rev # foo = # foo version; - # foo + # foo sha256 # foo = # foo "cypSbqLwSmauOoWOuppWpF3hvrxiqmkLspxAWzvlUC0="; - # foo + # foo }; - # foo + # foo cargoDeps # foo = @@ -147,15 +147,15 @@ rec = # foo "${pname}-${version}"; - # foo + # foo hash # foo = # foo "sha256-W4FyqwJpimf0isQRCq9TegpTQPQfsumx40AFQCFG5VQ="; - # foo + # foo }; - # foo + # foo nativeBuildInputs # foo = @@ -188,7 +188,7 @@ rec # foo ]; - # foo + # foo buildInputs # foo = @@ -206,7 +206,7 @@ rec pango # foo ]; - # foo + # foo postPatch # foo = @@ -217,7 +217,7 @@ rec substituteInPlace build-aux/meson_post_install.py \ --replace "gtk-update-icon-cache" "gtk4-update-icon-cache" ''; - # foo + # foo meta # foo = @@ -232,20 +232,21 @@ rec # foo = # foo - "Checks whether the contrast between two colors meet the WCAG requirements"; - # foo + "Checks whether the contrast between two colors meet the WCAG requirements" + ; + # foo homepage # foo = # foo "https://gitlab.gnome.org/World/design/contrast"; - # foo + # foo license # foo = # foo licenses.gpl3Plus; - # foo + # foo maintainers # foo = @@ -259,13 +260,13 @@ rec jtojnar # foo ]; - # foo + # foo platforms # foo = # foo platforms.unix; - # foo + # foo }; - # foo + # foo } diff --git a/test/diff/monsters_3/out.nix b/test/diff/monsters_3/out.nix index 0f66f531..fac5cee4 100644 --- a/test/diff/monsters_3/out.nix +++ b/test/diff/monsters_3/out.nix @@ -60,7 +60,8 @@ stdenv.mkDerivation rec { ''; meta = with lib; { description = - "Checks whether the contrast between two colors meet the WCAG requirements"; + "Checks whether the contrast between two colors meet the WCAG requirements" + ; homepage = "https://gitlab.gnome.org/World/design/contrast"; license = licenses.gpl3Plus; maintainers = with maintainers; [ jtojnar ]; diff --git a/test/diff/monsters_4/out.nix b/test/diff/monsters_4/out.nix index 10c74252..90d57edc 100644 --- a/test/diff/monsters_4/out.nix +++ b/test/diff/monsters_4/out.nix @@ -118,7 +118,8 @@ rec # Foo { # Foo description # Foo = # Foo - "Checks whether the contrast between two colors meet the WCAG requirements"; # Foo + "Checks whether the contrast between two colors meet the WCAG requirements" + ; # Foo homepage # Foo = # Foo "https://gitlab.gnome.org/World/design/contrast"; # Foo diff --git a/test/diff/monsters_5/out.nix b/test/diff/monsters_5/out.nix index f580e883..10b8a24b 100644 --- a/test/diff/monsters_5/out.nix +++ b/test/diff/monsters_5/out.nix @@ -190,10 +190,11 @@ in { }); - }); + }) + ; - # We don't want to evaluate all of linuxPackages for the manual - # - some of it might not even evaluate correctly. + # We don't want to evaluate all of linuxPackages for the manual + # - some of it might not even evaluate correctly. defaultText diff --git a/test/diff/with/out.nix b/test/diff/with/out.nix index 8eb76a24..0f658ee4 100644 --- a/test/diff/with/out.nix +++ b/test/diff/with/out.nix @@ -26,8 +26,9 @@ 1; } { - a = with b; 1; - # comment + a = with b; + 1; + # comment } (with a; with b; with c; { a = 1; }) (with a;