diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index bcda8a94..f03f7bcf 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -541,7 +541,11 @@ absorbExpr _ expr = pretty expr -- Render the RHS value of an assignment or function parameter default value absorbRHS :: Expression -> Doc absorbRHS expr = case expr of - -- Absorbable expression. Always start on the same line + -- Exception to the case below: Don't force-expand attrsets if they only contain a single inherit statement + (Term (Set _ _ binders _)) + | case unItems binders of [Item (Inherit{})] -> True; _ -> False -> + hardspace <> group (absorbExpr False expr) + -- Absorbable expression. Always start on the same line, and force-expand attrsets _ | isAbsorbableExpr expr -> hardspace <> group (absorbExpr True expr) -- Parenthesized expression. Same thing as the special case for parenthesized last argument in function calls. (Term (Parenthesized open expr' close)) -> hardspace <> absorbParen open expr' close diff --git a/test/diff/idioms_lib_4/out-pure.nix b/test/diff/idioms_lib_4/out-pure.nix index 8ff78dae..c1ed4245 100644 --- a/test/diff/idioms_lib_4/out-pure.nix +++ b/test/diff/idioms_lib_4/out-pure.nix @@ -521,33 +521,25 @@ rec { # the normalized name for macOS. macos = { execFormat = macho; - families = { - inherit darwin; - }; + families = { inherit darwin; }; name = "darwin"; }; ios = { execFormat = macho; - families = { - inherit darwin; - }; + families = { inherit darwin; }; }; # A tricky thing about FreeBSD is that there is no stable ABI across # versions. That means that putting in the version as part of the # config string is paramount. freebsd12 = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; name = "freebsd"; version = 12; }; freebsd13 = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; name = "freebsd"; version = 13; }; @@ -557,9 +549,7 @@ rec { }; netbsd = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; }; none = { execFormat = unknown; @@ -567,9 +557,7 @@ rec { }; openbsd = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; }; solaris = { execFormat = elf; diff --git a/test/diff/idioms_lib_4/out.nix b/test/diff/idioms_lib_4/out.nix index 8ff78dae..c1ed4245 100644 --- a/test/diff/idioms_lib_4/out.nix +++ b/test/diff/idioms_lib_4/out.nix @@ -521,33 +521,25 @@ rec { # the normalized name for macOS. macos = { execFormat = macho; - families = { - inherit darwin; - }; + families = { inherit darwin; }; name = "darwin"; }; ios = { execFormat = macho; - families = { - inherit darwin; - }; + families = { inherit darwin; }; }; # A tricky thing about FreeBSD is that there is no stable ABI across # versions. That means that putting in the version as part of the # config string is paramount. freebsd12 = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; name = "freebsd"; version = 12; }; freebsd13 = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; name = "freebsd"; version = 13; }; @@ -557,9 +549,7 @@ rec { }; netbsd = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; }; none = { execFormat = unknown; @@ -567,9 +557,7 @@ rec { }; openbsd = { execFormat = elf; - families = { - inherit bsd; - }; + families = { inherit bsd; }; }; solaris = { execFormat = elf; diff --git a/test/diff/idioms_nixos_1/out-pure.nix b/test/diff/idioms_nixos_1/out-pure.nix index f2bcf7ff..f8ec98ac 100644 --- a/test/diff/idioms_nixos_1/out-pure.nix +++ b/test/diff/idioms_nixos_1/out-pure.nix @@ -284,9 +284,7 @@ in }) (mkIf (!config.boot.isContainer) { - system.build = { - inherit kernel; - }; + system.build = { inherit kernel; }; system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; diff --git a/test/diff/idioms_nixos_1/out.nix b/test/diff/idioms_nixos_1/out.nix index f2bcf7ff..f8ec98ac 100644 --- a/test/diff/idioms_nixos_1/out.nix +++ b/test/diff/idioms_nixos_1/out.nix @@ -284,9 +284,7 @@ in }) (mkIf (!config.boot.isContainer) { - system.build = { - inherit kernel; - }; + system.build = { inherit kernel; }; system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;