Skip to content

Commit

Permalink
treewide: format more files
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier committed May 21, 2022
1 parent 32bde94 commit 8d75e43
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 66 deletions.
3 changes: 0 additions & 3 deletions format
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ esac
# The excludes are for files touched by open pull requests and we want
# to avoid merge conflicts.
find . -name '*.nix' \
! -path ./home-manager/home-manager.nix \
! -path ./modules/default.nix \
! -path ./modules/files.nix \
! -path ./modules/home-environment.nix \
! -path ./modules/launchd/launchd.nix \
! -path ./modules/lib/default.nix \
! -path ./modules/lib/file-type.nix \
! -path ./modules/manual.nix \
! -path ./modules/misc/news.nix \
! -path ./modules/programs/bash.nix \
! -path ./modules/programs/ssh.nix \
Expand Down
93 changes: 39 additions & 54 deletions home-manager/home-manager.nix
Original file line number Diff line number Diff line change
@@ -1,78 +1,64 @@
{ pkgs ? import <nixpkgs> {}
, confPath
, confAttr ? null
, check ? true
, newsReadIdsFile ? null
}:
{ pkgs ? import <nixpkgs> { }, confPath, confAttr ? null, check ? true
, newsReadIdsFile ? null }:

let
inherit (pkgs.lib)
concatMapStringsSep fileContents filter length optionalString removeSuffix
replaceStrings splitString;

env = import ../modules {
configuration =
if confAttr == "" || confAttr == null
then confPath
else (import confPath).${confAttr};
configuration = if confAttr == "" || confAttr == null then
confPath
else
(import confPath).${confAttr};
pkgs = pkgs;
check = check;
};

newsReadIds =
if newsReadIdsFile == null
then {}
else
let
ids = splitString "\n" (fileContents newsReadIdsFile);
in
builtins.listToAttrs (map (id: { name = id; value = null; }) ids);
newsReadIds = if newsReadIdsFile == null then
{ }
else
let ids = splitString "\n" (fileContents newsReadIdsFile);
in builtins.listToAttrs (map (id: {
name = id;
value = null;
}) ids);

newsIsRead = entry: builtins.hasAttr entry.id newsReadIds;

newsFiltered =
let
pred = entry: entry.condition && ! newsIsRead entry;
in
filter pred env.newsEntries;
newsFiltered = let pred = entry: entry.condition && !newsIsRead entry;
in filter pred env.newsEntries;

newsNumUnread = length newsFiltered;

newsFileUnread = pkgs.writeText "news-unread.txt" (
concatMapStringsSep "\n\n" (entry:
newsFileUnread = pkgs.writeText "news-unread.txt" (concatMapStringsSep "\n\n"
(entry:
let
time = replaceStrings ["T"] [" "] (removeSuffix "+00:00" entry.time);
in
''
* ${time}
time =
replaceStrings [ "T" ] [ " " ] (removeSuffix "+00:00" entry.time);
in ''
* ${time}
${replaceStrings ["\n"] ["\n "] entry.message}
''
) newsFiltered
);
${replaceStrings [ "\n" ] [ "\n " ] entry.message}
'') newsFiltered);

newsFileAll = pkgs.writeText "news-all.txt" (
concatMapStringsSep "\n\n" (entry:
newsFileAll = pkgs.writeText "news-all.txt" (concatMapStringsSep "\n\n"
(entry:
let
flag = if newsIsRead entry then "read" else "unread";
time = replaceStrings ["T"] [" "] (removeSuffix "+00:00" entry.time);
in
''
* ${time} [${flag}]
time =
replaceStrings [ "T" ] [ " " ] (removeSuffix "+00:00" entry.time);
in ''
* ${time} [${flag}]
${replaceStrings ["\n"] ["\n "] entry.message}
''
) env.newsEntries
);
${replaceStrings [ "\n" ] [ "\n " ] entry.message}
'') env.newsEntries);

# File where each line corresponds to an unread news entry
# identifier. If non-empty then the file ends in "\n".
newsUnreadIdsFile = pkgs.writeText "news-unread-ids" (
let
text = concatMapStringsSep "\n" (entry: entry.id) newsFiltered;
in
text + optionalString (text != "") "\n"
);
newsUnreadIdsFile = pkgs.writeText "news-unread-ids"
(let text = concatMapStringsSep "\n" (entry: entry.id) newsFiltered;
in text + optionalString (text != "") "\n");

newsInfo = pkgs.writeText "news-info.sh" ''
local newsNumUnread=${toString newsNumUnread}
Expand All @@ -82,8 +68,7 @@ let
local newsUnreadIdsFile="${newsUnreadIdsFile}"
'';

in
{
inherit (env) activationPackage;
inherit newsInfo;
}
in {
inherit (env) activationPackage;
inherit newsInfo;
}
14 changes: 9 additions & 5 deletions modules/launchd/launchd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ with lib;

StartCalendarInterval = mkOption {
default = null;
example = { Hour = 2; Minute = 30; };
example = {
Hour = 2;
Minute = 30;
};
description = ''
This optional key causes the job to be started every calendar interval as specified. Missing arguments
are considered to be wildcard. The semantics are much like <literal>crontab(5)</literal>. Unlike cron which skips job
Expand Down Expand Up @@ -652,7 +655,8 @@ with lib;
};

ProcessType = mkOption {
type = types.nullOr (types.enum [ "Background" "Standard" "Adaptive" "Interactive" ]);
type = types.nullOr
(types.enum [ "Background" "Standard" "Adaptive" "Interactive" ]);
default = null;
example = "Background";
description = ''
Expand Down Expand Up @@ -840,7 +844,8 @@ with lib;
};

Bonjour = mkOption {
type = types.nullOr (types.either types.bool (types.listOf types.str));
type =
types.nullOr (types.either types.bool (types.listOf types.str));
default = null;
description = ''
This optional key can be used to request that the service be registered with the
Expand All @@ -864,6 +869,5 @@ with lib;
};
};

config = {
};
config = { };
}
4 changes: 1 addition & 3 deletions modules/manual.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ let

docs = import ../docs { inherit lib pkgs; };

in

{
in {
options = {
manual.html.enable = mkOption {
type = types.bool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
${
pkgs.writeText "expected" ''
xwayland disable
''
''
}
'';
}

0 comments on commit 8d75e43

Please sign in to comment.