diff --git a/src/Nixfmt/Predoc.hs b/src/Nixfmt/Predoc.hs
index 0f5a3380..4ddd106a 100644
--- a/src/Nixfmt/Predoc.hs
+++ b/src/Nixfmt/Predoc.hs
@@ -37,16 +37,18 @@ module Nixfmt.Predoc
) where
import Data.List (intersperse)
+import qualified Data.List.NonEmpty as NonEmpty
+import Data.List.NonEmpty (NonEmpty(..), singleton, (<|))
import Data.Function ((&))
import Data.Functor ((<&>), ($>))
import Data.Functor.Identity (runIdentity)
-import Data.Bifunctor (second)
+import Data.Bifunctor (first, second)
import Data.Maybe (fromMaybe)
import Data.Text as Text (Text, concat, length, replicate, strip)
import GHC.Stack (HasCallStack)
-- import Debug.Trace (traceShow, traceShowId)
import Control.Applicative ((<|>), asum, empty)
-import Control.Monad.Trans.State.Strict (State, StateT, StateT(..), mapStateT, state, runState, evalState, get, put)
+import Control.Monad.Trans.State.Strict (State, StateT, StateT(..), mapStateT, state, runState, evalState, get, put, modify)
-- | Sequential Spacings are reduced to a single Spacing by taking the maximum.
-- This means that e.g. a Space followed by an Emptyline results in just an
@@ -109,7 +111,7 @@ data TextAnn = RegularT | Comment | TrailingComment | Trailing
-- | Single document element. Documents are modeled as lists of these elements
-- in order to make concatenation simple.
data DocE =
- -- indent level, offset, kind, text
+ -- nesting depth, offset, kind, text
Text Int Int TextAnn Text
| Spacing Spacing
| Group GroupAnn Doc
@@ -172,28 +174,26 @@ group x = pure . (Group RegularG) $
group' :: Pretty a => GroupAnn -> a -> Doc
group' ann = pure . (Group ann) . pretty
--- | @nest doc@ declarse @doc@ to have a higher indentation level
+-- | @nest doc@ declarse @doc@ to have a higher nesting depth
-- than before. Not all nestings actually result in indentation changes,
-- this will be calculated automatically later on. As a rule of thumb:
--- Multiple indentation levels on one line will be compacted and only result in a single
--- bump for the next line. This prevents excessive indentation.
+-- Multiple nesting levels on one line will be compacted and only result in a single
+-- indentation bump for the next line. This prevents excessive indentation.
nest :: Pretty a => a -> Doc
-nest x = go $ pretty x
+nest x = map go $ pretty x
where
- go (Text i o ann t : rest) = (Text (i + 2) o ann t) : go rest
- go (Group ann inner : rest) = (Group ann (go inner)) : go rest
- go (spacing : rest) = spacing : go rest
- go [] = []
+ go (Text i o ann t) = Text (i + 1) o ann t
+ go (Group ann inner) = Group ann (map go inner)
+ go spacing = spacing
-- This is similar to nest, however it circumvents the "smart" rules that usually apply.
-- This should only be useful to manage the indentation within indented strings.
offset :: Pretty a => Int -> a -> Doc
-offset level x = go $ pretty x
+offset level x = map go $ pretty x
where
- go (Text i o ann t : rest) = (Text i (o + level) ann t) : go rest
- go (Group ann inner : rest) = (Group ann (go inner)) : go rest
- go (spacing : rest) = spacing : go rest
- go [] = []
+ go (Text i o ann t) = Text i (o + level) ann t
+ go (Group ann inner) = Group ann (map go inner)
+ go spacing = spacing
-- | Line break or nothing (soft)
softline' :: Doc
@@ -470,38 +470,38 @@ indent n = Text.replicate n " "
-- All state is (cc, indents)
-- cc: current column (within the current line, *not including indentation*)
-- indents:
--- A stack of tuples (realIndent, virtualIndent)
+-- A stack of tuples (currentIndent, nestingLevel)
-- This is guaranteed to never be empty, as we start with [(0, 0)] and never go below that.
-type St = (Int, [(Int, Int)])
+type St = (Int, NonEmpty (Int, Int))
-- tw Target Width
layoutGreedy :: Int -> Doc -> Text
-layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, [(0, 0)])
+layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, singleton (0, 0))
where
+ -- Simple helpers around `put` with a tuple state
+ putL = modify . first . const
+ putR = modify . second . const
+
-- Print a given text. If this is the first token on a line, it will
-- do the appropriate calculations for indentation and print that in addition to the text.
putText :: Int -> Int -> Text -> State St [Text]
- putText textVI textOffset t = get >>=
- \case
- -- Needs indent, but no more than last line
- (0, indents@((ci, vi):_)) | textVI == vi ->
- go' indents (ci + textOffset)
- -- Needs more indent than last line. We only go up by one level every time
- (0, indents@((ci, vi):_)) | textVI > vi ->
- go' ((ci + 2, textVI):indents) (ci + 2 + textOffset)
+ putText textNL textOffset t = get >>=
+ \(cc, indents@((ci, nl) :| indents')) ->
+ case textNL `compare` nl of
+ -- Push the textNL onto the stack, but only increase the actual indentation (`ci`)
+ -- if this is the first one of a line. All subsequent nestings within the line effectively get "swallowed"
+ GT -> putR ((if cc == 0 then ci + 2 else ci, textNL) <| indents) >> go'
-- Need to go down one or more levels
-- Just pop from the stack and recurse until the indent matches again
- (0, ((_, vi) : indents@((ci, vi'):_))) | textVI < vi ->
- if textVI < vi' then
- put (0, indents) >> putText textVI textOffset t
- else
- go' indents (ci + textOffset)
- -- Does not need indent (not at start of line)
- (cc, indents) ->
- put (cc + textWidth t, indents) $> [t]
+ LT -> putR (NonEmpty.fromList indents') >> putText textNL textOffset t
+ EQ -> go'
where
- -- Start a new line
- go' indents i = put (textWidth t, indents) $> [indent i, t]
+ -- Put the text and advance the `cc` cursor. Add the appropriate amount of indentation if this is
+ -- the first token on a line
+ go' = do
+ (cc, (ci, _) :| _) <- get
+ putL (cc + textWidth t)
+ pure $ if cc == 0 then [indent (ci + textOffset), t] else [t]
-- Simply put text without caring about line-start indentation
putText' :: [Text] -> State St [Text]
@@ -540,9 +540,9 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, [
-- [ # comment
-- 1
-- ]
- Text _ _ TrailingComment t | cc == 2 && (fst $ nextIndent xs) > lineVI -> putText' [" ", t]
- where lineVI = snd $ head indents
- Text vi off _ t -> putText vi off t
+ Text _ _ TrailingComment t | cc == 2 && (fst $ nextIndent xs) > lineNL -> putText' [" ", t]
+ where lineNL = snd $ NonEmpty.head indents
+ Text nl off _ t -> putText nl off t
-- This code treats whitespace as "expanded"
-- A new line resets the column counter and sets the target indentation as current indentation
@@ -618,19 +618,19 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, [
Spacing _ -> tail grp
Group ann ((Spacing _) : inner) -> (Group ann inner) : tail grp
_ -> grp
- (vi, off) = nextIndent grp'
+ (nl, off) = nextIndent grp'
- indentWillIncrease = if fst (nextIndent rest) > lineVI then 2 else 0
+ indentWillIncrease = if fst (nextIndent rest) > lineNL then 2 else 0
where
- lastLineVI = snd $ head ci
- lineVI = lastLineVI + (if vi > lastLineVI then 2 else 0)
+ lastLineNL = snd $ NonEmpty.head ci
+ lineNL = lastLineNL + (if nl > lastLineNL then 2 else 0)
in
fits indentWillIncrease (tw - firstLineWidth rest) grp'
- <&> \t -> runState (putText vi off t) (cc, ci)
+ <&> \t -> runState (putText nl off t) (cc, ci)
else
let
- indentWillIncrease = if fst (nextIndent rest) > lineVI then 2 else 0
- where lineVI = snd $ head ci
+ indentWillIncrease = if fst (nextIndent rest) > lineNL then 2 else 0
+ where lineNL = snd $ NonEmpty.head ci
in
fits (indentWillIncrease - cc) (tw - cc - firstLineWidth rest) grp
<&> \t -> ([t], (cc + textWidth t, ci))
diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs
index 5e018a11..65b5ec1e 100644
--- a/src/Nixfmt/Pretty.hs
+++ b/src/Nixfmt/Pretty.hs
@@ -50,7 +50,7 @@ instance Pretty Trivium where
| otherwise
= comment "/*" <> hardspace
-- Add an offset to manually indent the comment by one
- <> (nest $ offset 1 $ hcat $ map prettyCommentLine c)
+ <> (offset 3 $ hcat $ map prettyCommentLine c)
<> comment "*/" <> hardline
where
prettyCommentLine :: Text -> Doc
@@ -117,7 +117,7 @@ instance Pretty Binder where
-- `foo = bar`
pretty (Assignment selectors assign expr semicolon)
= group $ hcat selectors
- <> nest (hardspace <> pretty assign <> absorbRHS expr) <> pretty semicolon
+ <> nest (hardspace <> pretty assign <> nest (absorbRHS expr)) <> pretty semicolon
-- Pretty a set
-- while we already pretty eagerly expand sets with more than one element,
@@ -198,7 +198,7 @@ instance Pretty ParamAttr where
pretty (ParamAttr name (Just (qmark, def)) maybeComma)
= group $
pretty name <> hardspace
- <> nest (pretty qmark <> absorbRHS def)
+ <> nest (pretty qmark <> nest (absorbRHS def))
<> pretty maybeComma
-- `...`
diff --git a/test/diff/apply/out.nix b/test/diff/apply/out.nix
index c5189553..8d187057 100644
--- a/test/diff/apply/out.nix
+++ b/test/diff/apply/out.nix
@@ -356,5 +356,5 @@
(function (
something
# ...
- ) { })
+ ) { })
]
diff --git a/test/diff/idioms_lib_4/out.nix b/test/diff/idioms_lib_4/out.nix
index 75f1467d..3cbd159a 100644
--- a/test/diff/idioms_lib_4/out.nix
+++ b/test/diff/idioms_lib_4/out.nix
@@ -829,7 +829,7 @@ rec {
};
}
.${toString (length l)}
- or (throw "system string has invalid number of hyphen-separated components");
+ or (throw "system string has invalid number of hyphen-separated components");
# This should revert the job done by config.guess from the gcc compiler.
mkSystemFromSkeleton =
diff --git a/test/diff/key_value/out.nix b/test/diff/key_value/out.nix
index 033cbdc3..92004523 100644
--- a/test/diff/key_value/out.nix
+++ b/test/diff/key_value/out.nix
@@ -32,13 +32,13 @@ rec {
};
h = {
a # b
- = # c
- 1;
+ = # c
+ 1;
};
i = {
a # b
- = # c
- 1 # d
+ = # c
+ 1 # d
;
};
j = a: { b = 1; };
@@ -61,8 +61,8 @@ rec {
a
# b
=
- # c
- 1
+ # c
+ 1
# d
;
diff --git a/test/diff/monsters_1/out.nix b/test/diff/monsters_1/out.nix
index 7d8c596b..18183d4e 100644
--- a/test/diff/monsters_1/out.nix
+++ b/test/diff/monsters_1/out.nix
@@ -58,198 +58,198 @@ stdenv.mkDerivation
pname
# foo
=
- # foo
- "contrast";
+ # foo
+ "contrast";
# foo
version
# foo
=
- # foo
- "0.0.5";
+ # foo
+ "0.0.5";
# foo
src
# foo
=
- # foo
- fetchFromGitLab
# foo
- {
- # foo
- domain
- # foo
- =
- # foo
- "gitlab.gnome.org";
- # foo
- group
- # foo
- =
- # foo
- "World";
- # foo
- owner
- # foo
- =
- # foo
- "design";
- # foo
- repo
- # foo
- =
- # foo
- "contrast";
- # foo
- rev
- # foo
- =
- # foo
- version;
- # foo
- sha256
- # foo
- =
- # foo
- "cypSbqLwSmauOoWOuppWpF3hvrxiqmkLspxAWzvlUC0=";
- # foo
- };
+ fetchFromGitLab
+ # foo
+ {
+ # foo
+ domain
+ # foo
+ =
+ # foo
+ "gitlab.gnome.org";
+ # foo
+ group
+ # foo
+ =
+ # foo
+ "World";
+ # foo
+ owner
+ # foo
+ =
+ # foo
+ "design";
+ # foo
+ repo
+ # foo
+ =
+ # foo
+ "contrast";
+ # foo
+ rev
+ # foo
+ =
+ # foo
+ version;
+ # foo
+ sha256
+ # foo
+ =
+ # foo
+ "cypSbqLwSmauOoWOuppWpF3hvrxiqmkLspxAWzvlUC0=";
+ # foo
+ };
# foo
cargoDeps
# foo
=
- # foo
- rustPlatform.fetchCargoTarball
# foo
- {
- # foo
- inherit
- # foo
- src
- ;
+ rustPlatform.fetchCargoTarball
# foo
- name
+ {
# foo
- =
+ inherit
+ # foo
+ src
+ ;
# foo
- "${pname}-${version}";
- # foo
- hash
+ name
+ # foo
+ =
+ # foo
+ "${pname}-${version}";
# foo
- =
+ hash
+ # foo
+ =
+ # foo
+ "sha256-W4FyqwJpimf0isQRCq9TegpTQPQfsumx40AFQCFG5VQ=";
# foo
- "sha256-W4FyqwJpimf0isQRCq9TegpTQPQfsumx40AFQCFG5VQ=";
- # foo
- };
+ };
# foo
nativeBuildInputs
# foo
=
- # foo
- [
- # foo
- desktop-file-utils
- # foo
- gettext
- # foo
- meson
- # foo
- ninja
- # foo
- pkg-config
- # foo
- python3
- # foo
- rustPlatform.rust.cargo
- # foo
- rustPlatform.cargoSetupHook
- # foo
- rustPlatform.rust.rustc
# foo
- wrapGAppsHook4
- # foo
- glib
- # foo
- # for glib-compile-resources
+ [
+ # foo
+ desktop-file-utils
+ # foo
+ gettext
+ # foo
+ meson
+ # foo
+ ninja
+ # foo
+ pkg-config
+ # foo
+ python3
+ # foo
+ rustPlatform.rust.cargo
+ # foo
+ rustPlatform.cargoSetupHook
+ # foo
+ rustPlatform.rust.rustc
+ # foo
+ wrapGAppsHook4
+ # foo
+ glib
+ # foo
+ # for glib-compile-resources
- # foo
- ];
+ # foo
+ ];
# foo
buildInputs
# foo
=
- # foo
- [
- # foo
- cairo
- # foo
- glib
- # foo
- gtk4
# foo
- libadwaita
- # foo
- pango
- # foo
- ];
+ [
+ # foo
+ cairo
+ # foo
+ glib
+ # foo
+ gtk4
+ # foo
+ libadwaita
+ # foo
+ pango
+ # foo
+ ];
# foo
postPatch
# foo
=
- # foo
- ''
- patchShebangs build-aux/meson_post_install.py
- # https://gitlab.gnome.org/World/design/contrast/-/merge_requests/23
- substituteInPlace build-aux/meson_post_install.py \
- --replace "gtk-update-icon-cache" "gtk4-update-icon-cache"
- '';
+ # foo
+ ''
+ patchShebangs build-aux/meson_post_install.py
+ # https://gitlab.gnome.org/World/design/contrast/-/merge_requests/23
+ substituteInPlace build-aux/meson_post_install.py \
+ --replace "gtk-update-icon-cache" "gtk4-update-icon-cache"
+ '';
# foo
meta
# foo
=
- # foo
- with
- # foo
- lib;
- # foo
- {
# foo
- description
+ with
# foo
- =
- # foo
- "Checks whether the contrast between two colors meet the WCAG requirements";
- # foo
- homepage
- # foo
- =
- # foo
- "https://gitlab.gnome.org/World/design/contrast";
+ lib;
# foo
- license
- # foo
- =
+ {
# foo
- licenses.gpl3Plus;
- # foo
- maintainers
+ description
+ # foo
+ =
+ # foo
+ "Checks whether the contrast between two colors meet the WCAG requirements";
# foo
- =
+ homepage
+ # foo
+ =
+ # foo
+ "https://gitlab.gnome.org/World/design/contrast";
# foo
- with
+ license
# foo
- maintainers;
+ =
+ # foo
+ licenses.gpl3Plus;
# foo
- [
+ maintainers
# foo
- jtojnar
+ =
+ # foo
+ with
+ # foo
+ maintainers;
+ # foo
+ [
+ # foo
+ jtojnar
+ # foo
+ ];
+ # foo
+ platforms
# foo
- ];
- # foo
- platforms
- # foo
- =
+ =
+ # foo
+ platforms.unix;
# foo
- platforms.unix;
- # foo
- };
+ };
# foo
}
diff --git a/test/diff/monsters_4/out.nix b/test/diff/monsters_4/out.nix
index c24bf122..ac311ac3 100644
--- a/test/diff/monsters_4/out.nix
+++ b/test/diff/monsters_4/out.nix
@@ -37,110 +37,110 @@ stdenv.mkDerivation # Foo
{
# Foo
pname # Foo
- = # Foo
- "contrast"; # Foo
+ = # Foo
+ "contrast"; # Foo
version # Foo
- = # Foo
- "0.0.5"; # Foo
+ = # Foo
+ "0.0.5"; # Foo
src # Foo
- = # Foo
- # Foo
- fetchFromGitLab {
+ = # Foo
# Foo
- domain # Foo
- = # Foo
- "gitlab.gnome.org"; # Foo
- group # Foo
- = # Foo
- "World"; # Foo
- owner # Foo
- = # Foo
- "design"; # Foo
- repo # Foo
- = # Foo
- "contrast"; # Foo
- rev # Foo
- = # Foo
- version; # Foo
- sha256 # Foo
- = # Foo
- "cypSbqLwSmauOoWOuppWpF3hvrxiqmkLspxAWzvlUC0="; # Foo
- }; # Foo
- cargoDeps # Foo
- = # Foo
- rustPlatform.fetchCargoTarball # Foo
- {
+ fetchFromGitLab {
# Foo
- inherit # Foo
- src
- ; # Foo
- name # Foo
- = # Foo
- "${pname}-${version}"; # Foo
- hash # Foo
- = # Foo
- "sha256-W4FyqwJpimf0isQRCq9TegpTQPQfsumx40AFQCFG5VQ="; # Foo
+ domain # Foo
+ = # Foo
+ "gitlab.gnome.org"; # Foo
+ group # Foo
+ = # Foo
+ "World"; # Foo
+ owner # Foo
+ = # Foo
+ "design"; # Foo
+ repo # Foo
+ = # Foo
+ "contrast"; # Foo
+ rev # Foo
+ = # Foo
+ version; # Foo
+ sha256 # Foo
+ = # Foo
+ "cypSbqLwSmauOoWOuppWpF3hvrxiqmkLspxAWzvlUC0="; # Foo
}; # Foo
+ cargoDeps # Foo
+ = # Foo
+ rustPlatform.fetchCargoTarball # Foo
+ {
+ # Foo
+ inherit # Foo
+ src
+ ; # Foo
+ name # Foo
+ = # Foo
+ "${pname}-${version}"; # Foo
+ hash # Foo
+ = # Foo
+ "sha256-W4FyqwJpimf0isQRCq9TegpTQPQfsumx40AFQCFG5VQ="; # Foo
+ }; # Foo
nativeBuildInputs # Foo
- = # Foo
- [
- # Foo
- desktop-file-utils # Foo
- gettext # Foo
- meson # Foo
- ninja # Foo
- pkg-config # Foo
- python3 # Foo
- rustPlatform.rust.cargo # Foo
- rustPlatform.cargoSetupHook # Foo
- rustPlatform.rust.rustc # Foo
- wrapGAppsHook4 # Foo
- glib # Foo for glib-compile-resources
- # Foo
- ]; # Foo
+ = # Foo
+ [
+ # Foo
+ desktop-file-utils # Foo
+ gettext # Foo
+ meson # Foo
+ ninja # Foo
+ pkg-config # Foo
+ python3 # Foo
+ rustPlatform.rust.cargo # Foo
+ rustPlatform.cargoSetupHook # Foo
+ rustPlatform.rust.rustc # Foo
+ wrapGAppsHook4 # Foo
+ glib # Foo for glib-compile-resources
+ # Foo
+ ]; # Foo
buildInputs # Foo
- = # Foo
- [
- # Foo
- cairo # Foo
- glib # Foo
- gtk4 # Foo
- libadwaita # Foo
- pango # Foo
- ]; # Foo
+ = # Foo
+ [
+ # Foo
+ cairo # Foo
+ glib # Foo
+ gtk4 # Foo
+ libadwaita # Foo
+ pango # Foo
+ ]; # Foo
postPatch # Foo
- = # Foo
- ''
- patchShebangs build-aux/meson_post_install.py
- # https://gitlab.gnome.org/World/design/contrast/-/merge_requests/23
- substituteInPlace build-aux/meson_post_install.py \
- --replace "gtk-update-icon-cache" "gtk4-update-icon-cache"
- ''; # Foo
+ = # Foo
+ ''
+ patchShebangs build-aux/meson_post_install.py
+ # https://gitlab.gnome.org/World/design/contrast/-/merge_requests/23
+ substituteInPlace build-aux/meson_post_install.py \
+ --replace "gtk-update-icon-cache" "gtk4-update-icon-cache"
+ ''; # Foo
meta # Foo
- = # Foo
- with # Foo
- lib; # Foo
- {
- # Foo
- description # Foo
- = # Foo
- "Checks whether the contrast between two colors meet the WCAG requirements"; # Foo
- homepage # Foo
- = # Foo
- "https://gitlab.gnome.org/World/design/contrast"; # Foo
- license # Foo
- = # Foo
- licenses.gpl3Plus; # Foo
- maintainers # Foo
- = # Foo
- with # Foo
- maintainers; # Foo
- [
- # Foo
- jtojnar # Foo
- ]; # Foo
- platforms # Foo
- = # Foo
- platforms.unix; # Foo
- }; # Foo
+ = # Foo
+ with # Foo
+ lib; # Foo
+ {
+ # Foo
+ description # Foo
+ = # Foo
+ "Checks whether the contrast between two colors meet the WCAG requirements"; # Foo
+ homepage # Foo
+ = # Foo
+ "https://gitlab.gnome.org/World/design/contrast"; # Foo
+ license # Foo
+ = # Foo
+ licenses.gpl3Plus; # Foo
+ maintainers # Foo
+ = # Foo
+ with # Foo
+ maintainers; # Foo
+ [
+ # Foo
+ jtojnar # Foo
+ ]; # Foo
+ platforms # Foo
+ = # Foo
+ platforms.unix; # Foo
+ }; # Foo
}
diff --git a/test/diff/monsters_5/out.nix b/test/diff/monsters_5/out.nix
index 288584f9..ad6ecb84 100644
--- a/test/diff/monsters_5/out.nix
+++ b/test/diff/monsters_5/out.nix
@@ -43,13 +43,13 @@ let
=
- pkgs.writeText
+ pkgs.writeText
- "nixos.conf"
+ "nixos.conf"
- ''
- ${concatStringsSep "\n" config.boot.kernelModules}
- '';
+ ''
+ ${concatStringsSep "\n" config.boot.kernelModules}
+ '';
in
{
@@ -60,207 +60,207 @@ in
=
- {
+ {
- boot.kernel.features
+ boot.kernel.features
- =
+ =
- mkOption
+ mkOption
- {
+ {
- default
+ default
- =
+ =
- { };
+ { };
- example
+ example
- =
+ =
- literalExpression
+ literalExpression
- "{debug= true;}";
+ "{debug= true;}";
- internal
+ internal
- =
+ =
- true;
+ true;
- description
+ description
- =
+ =
- ''
- This option allows to enable or disable certain kernel features.
- It's not API, because it's about kernel feature sets, that
- make sense for specific use cases. Mostly along with programs,
- which would have separate nixos options.
- `grep features pkgs/os-specific/linux/kernel/common-config.nix`
- '';
- };
+ ''
+ This option allows to enable or disable certain kernel features.
+ It's not API, because it's about kernel feature sets, that
+ make sense for specific use cases. Mostly along with programs,
+ which would have separate nixos options.
+ `grep features pkgs/os-specific/linux/kernel/common-config.nix`
+ '';
+ };
- boot.kernelPackages
+ boot.kernelPackages
- =
+ =
- mkOption
+ mkOption
- {
+ {
- default
+ default
- =
+ =
- pkgs.linuxPackages;
+ pkgs.linuxPackages;
- type
+ type
- =
+ =
- types.unspecified
+ types.unspecified
- //
+ //
- {
+ {
- merge
+ merge
- =
+ =
- mergeEqualOption;
- };
+ mergeEqualOption;
+ };
- apply
+ apply
- =
+ =
- kernelPackages:
+ kernelPackages:
- kernelPackages.extend
+ kernelPackages.extend
- (
- self:
+ (
+ self:
- super:
+ super:
- {
+ {
- kernel
+ kernel
- =
+ =
- super.kernel.override
+ super.kernel.override
- (
- originalArgs:
+ (
+ originalArgs:
- {
+ {
- inherit
+ inherit
- randstructSeed
- ;
+ randstructSeed
+ ;
- kernelPatches
+ kernelPatches
- =
+ =
- (originalArgs.kernelPatches
+ (originalArgs.kernelPatches
- or
+ or
- [ ]
- )
+ [ ]
+ )
- ++
+ ++
- kernelPatches;
+ kernelPatches;
- features
+ features
- =
+ =
- lib.recursiveUpdate
+ lib.recursiveUpdate
- super.kernel.features
+ super.kernel.features
- 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
+ defaultText
- =
+ =
- literalExpression
+ literalExpression
- "pkgs.linuxPackages";
+ "pkgs.linuxPackages";
- example
+ example
- =
+ =
- literalExpression
+ literalExpression
- "pkgs.linuxKernel.packages.linux_5_10";
+ "pkgs.linuxKernel.packages.linux_5_10";
- description
+ description
- =
+ =
- ''
- This option allows you to override the Linux kernel used by
- NixOS. Since things like external kernel module packages are
- tied to the kernel you're using, it also overrides those.
- This option is a function that takes Nixpkgs as an argument
- (as a convenience), and returns an attribute set containing at
- the very least an attribute kernel.
- Additional attributes may be needed depending on your
- configuration. For instance, if you use the NVIDIA X driver,
- then it also needs to contain an attribute
- nvidia_x11.
- '';
- };
+ ''
+ This option allows you to override the Linux kernel used by
+ NixOS. Since things like external kernel module packages are
+ tied to the kernel you're using, it also overrides those.
+ This option is a function that takes Nixpkgs as an argument
+ (as a convenience), and returns an attribute set containing at
+ the very least an attribute kernel.
+ Additional attributes may be needed depending on your
+ configuration. For instance, if you use the NVIDIA X driver,
+ then it also needs to contain an attribute
+ nvidia_x11.
+ '';
+ };
- boot.kernelPatches
+ boot.kernelPatches
- =
+ =
- mkOption
+ mkOption
- {
+ {
- type
+ type
- =
+ =
- types.listOf
+ types.listOf
- types.attrs;
+ types.attrs;
- default
+ default
- =
+ =
- [ ];
+ [ ];
- example
+ example
- =
+ =
- literalExpression
+ literalExpression
- "[ pkgs.kernelPatches.ubuntu_fan_4_4 ]";
- description = "A list of additional patches to apply to the kernel.";
- };
- };
+ "[ pkgs.kernelPatches.ubuntu_fan_4_4 ]";
+ description = "A list of additional patches to apply to the kernel.";
+ };
+ };
}
diff --git a/test/diff/pattern/out.nix b/test/diff/pattern/out.nix
index 77ae6a7f..cdac106f 100644
--- a/test/diff/pattern/out.nix
+++ b/test/diff/pattern/out.nix
@@ -644,12 +644,12 @@
# a
{
b # a
- ? # a
- null # c
+ ? # a
+ null # c
, # d
e # a
- ? # a
- null # f
+ ? # a
+ null # f
, # g
... # h
}:
@@ -664,9 +664,9 @@
# a
#
?
- # a
- #
- null,
+ # a
+ #
+ null,
# c
#
# d
@@ -675,9 +675,9 @@
# a
#
?
- # a
- #
- null,
+ # a
+ #
+ null,
# f
#
# g