Skip to content

Commit

Permalink
Remove overuse of with expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
pdalpra committed Aug 18, 2024
1 parent a705159 commit dd26fd3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 50 deletions.
4 changes: 1 addition & 3 deletions home/home.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{ lib, ... }:

with lib;

let
importAll = imports: foldl' concat [ ] (map import imports);
importAll = imports: lib.foldl' lib.concat [ ] (map import imports);
in
{
imports = importAll [
Expand Down
19 changes: 8 additions & 11 deletions home/modules/cli/starship.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{ pkgs, lib, myLib, ... }:

with builtins;
with lib;
with myLib;

let
isRust = path: hasSuffix ".rs" path && path != "mod.rs";
toogleModules = enabled: modules: mergeAll (map (mod: { "${mod}" = { disabled = !enabled; }; }) modules);
isRust = path: lib.hasSuffix ".rs" path && path != "mod.rs";
toogleModules = enabled: modules: myLib.mergeAll (map (mod: { "${mod}" = { disabled = !enabled; }; }) modules);
starshipPackage = pkgs.unstable.starship;
promptOrder = [
"nix_shell"
Expand All @@ -26,7 +23,7 @@ let
"line_break"
"character"
];
promptFormat = concatStrings (map (s: "\$${s}") promptOrder);
promptFormat = lib.concatStrings (map (s: "\$${s}") promptOrder);
modulesSources = "${starshipPackage.src}/src/modules";
enabledModules = toogleModules true promptOrder; # <== ensure all modules used in the prompt are enabled

Expand All @@ -35,10 +32,10 @@ let
# - List all Rust sources files
# - Get the file name, without the extension (<- name of the module)
# - Exclude the enabled modules
disabledModules = pipe modulesSources [
(filterFiles isRust)
(map (removeSuffix ".rs"))
(subtractLists promptOrder)
disabledModules = lib.pipe modulesSources [
(myLib.filterFiles isRust)
(map (lib.removeSuffix ".rs"))
(lib.subtractLists promptOrder)
(toogleModules false)
];
starshipConfig = {
Expand Down Expand Up @@ -85,7 +82,7 @@ in
enableZshIntegration = true;
catppuccin.enable = true;
package = starshipPackage;
settings = mergeAll [
settings = myLib.mergeAll [
enabledModules
disabledModules
starshipConfig
Expand Down
9 changes: 3 additions & 6 deletions home/modules/wm/xmonad.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{ pkgs, config, lib, myLib, ... }:

with lib;
with myLib;

let
libPath = ./xmonad-config/lib;
libFiles = pipe libPath [
listFiles
libFiles = lib.pipe libPath [
myLib.listFiles
(map (file: { "${file}" = libPath + "/${file}"; }))
mergeAll
myLib.mergeAll
];
in
{
Expand Down
12 changes: 5 additions & 7 deletions lib/dev-shell.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{ pkgs, lintingPkgs, agenixBin }:

with pkgs;

let
agenixFile = writeShellScriptBin "agenix-file" "cat $2 | ${agenixBin}/bin/agenix --editor='-' -e $1";
nixTools = [
agenixFile = pkgs.writeShellScriptBin "agenix-file" "cat $2 | ${agenixBin}/bin/agenix --editor='-' -e $1";
nixTools = with pkgs; [
cachix
git-secret
nixpkgs-fmt
unstable.nixd
agenixBin
agenixFile
];
haskellTools = with haskellPackages; [
haskellTools = with pkgs.haskellPackages; [
cabal-install
fourmolu
haskell-language-server
hlint
];
xmonadDependencies = [
xmonadDependencies = with pkgs; [
xorg.libX11
xorg.libXrandr
xorg.libXScrnSaver
Expand All @@ -28,7 +26,7 @@ let
zlib.dev
];
in
mkShell {
pkgs.mkShell {
name = "nix-config-dev";

buildInputs =
Expand Down
4 changes: 1 addition & 3 deletions modules/common/profile.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{ config, lib, ... }:

with lib;

{
options.profile = with types; mkOption {
options.profile = with lib; with types; mkOption {
description = "Usage profile for this machine. Must be set.";
default = null;
type = nullOr (enum [
Expand Down
9 changes: 3 additions & 6 deletions modules/nixos/illuminanced.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{ config, lib, myLib, pkgs, ... }:

with lib;
with myLib;

let
pidFile = "/var/run/illuminanced.pid";
cfg = config.services.illuminanced;
Expand All @@ -19,7 +16,7 @@ let
hash = "sha256-PQHGKz/2UxCf8FosuxmL7DL9Z+H9nzXHdyn+73gWw1I=";
};
};
levels = mergeAll (lists.imap0
levels = myLib.mergeAll (lib.lists.imap0
(i: v: {
"illuminance_${toString i}" = v.illuminance;
"light_${toString i}" = v.light;
Expand Down Expand Up @@ -56,7 +53,7 @@ in
# TODO: document module options
# - kalman
# - devices.events
options.services.illuminanced = with types; {
options.services.illuminanced = with lib; with types; {
enable = mkEnableOption "Enable illuminanced";
package = mkOption {
type = package;
Expand Down Expand Up @@ -160,7 +157,7 @@ in
};
};

config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
systemd.services.illuminanced = {
enable = true;
wantedBy = [ "multi-user.target" ];
Expand Down
21 changes: 9 additions & 12 deletions modules/nixos/impermanence.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{ config, lib, myLib, ... }:

with lib;
with myLib;

let
cfg = config.system.impermanence;
concat = s1: s2: s1 + s2;
Expand All @@ -25,7 +22,7 @@ let
} // options;
in
{
options.system.impermanence = with types; {
options.system.impermanence = with lib; with types; {
enable = mkEnableOption "Enable impermanence";
pause = mkEnableOption "Keep disk layout, but do not wipe on boot";

Expand Down Expand Up @@ -110,9 +107,9 @@ in
};
};

config = mkMerge [
config = lib.mkMerge [
# Generic support: setting paths, enable fuse, etc...
(mkIf cfg.enable {
(lib.mkIf cfg.enable {

##########
# SYSTEM #
Expand All @@ -125,23 +122,23 @@ in

environment.persistence.${cfg.paths.homes} = {
hideMounts = true;
users = pipe cfg.users [
attrValues
users = lib.pipe cfg.users [
lib.attrValues
(map perUser)
mergeAll
myLib.mergeAll
];
};
})
# ZFS based setup:
# - blank snapshot after creation
# - auto restore blank snapshot at boot
# - Create datasets for system, homes and the nix store
(mkIf (cfg.enable && cfg.zfs.enable) {
(lib.mkIf (cfg.enable && cfg.zfs.enable) {
boot = {
loader.grub.zfsSupport = true;
supportedFilesystems = [ "zfs" ];
initrd.postDeviceCommands = mkAfter (
mkIfElse (!cfg.pause)
initrd.postDeviceCommands = lib.mkAfter (
myLib.mkIfElse (!cfg.pause)
"zfs rollback -r ${blankSnapshot cfg.zfs.pool} && echo 'Blank snapshot restored'"
""
);
Expand Down
3 changes: 1 addition & 2 deletions system/users.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{ pkgs, config, myLib, agenix, catppuccin, ... }:

with myLib;
let
networkManager = mkIfElse
networkManager = myLib.mkIfElse
config.networking.networkmanager.enable
[ "networkmanager" ]
[ ];
Expand Down

0 comments on commit dd26fd3

Please sign in to comment.