From 4adf8fea0a1080620f034c60f709e1ad04369a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 7 Apr 2021 09:37:57 +0200 Subject: [PATCH] feat: use pkgs.formats for everything --- configs/alacritty.nix | 73 +++++++++++++------------ configs/default.nix | 1 - configs/i3.nix | 2 +- configs/matterbridge.nix | 81 ++++++++++++++-------------- configs/mpd-fm.nix | 2 +- configs/packages/haskell/default.nix | 5 +- configs/urlwatch.nix | 4 +- modules/mpd-fm.nix | 2 +- overlays/toml.nix | 7 --- 9 files changed, 83 insertions(+), 94 deletions(-) delete mode 100644 overlays/toml.nix diff --git a/configs/alacritty.nix b/configs/alacritty.nix index 94fac24..cb303e3 100644 --- a/configs/alacritty.nix +++ b/configs/alacritty.nix @@ -1,46 +1,45 @@ { pkgs, lib, config, ... }: -let - inherit (import ) colours; - colourNames = - [ "black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" ]; - colourPairs = lib.getAttrs colourNames colours; - alacrittyConfig = { - background_opacity = 0.9; - colors = { - primary = { inherit (colours) background foreground; }; - normal = lib.mapAttrs (_: colour: colour.dark) colourPairs; - bright = lib.mapAttrs (_: colour: colour.bright) colourPairs; - }; - font = { - normal.family = "Monospace"; - size = 6; - }; - key_bindings = [ - { - key = "Add"; - mods = "Control"; - action = "IncreaseFontSize"; - } - { - key = "Minus"; - mods = "Control"; - action = "DecreaseFontSize"; - } - { - key = "Key0"; - mods = "Control"; - action = "ResetFontSize"; - } - ]; - }; -in { +{ environment.variables.TERMINAL = "alacritty"; environment.systemPackages = [ pkgs.alacritty ]; - home-manager.users.me.xdg.configFile = { - "alacritty/alacritty.yml".text = builtins.toJSON alacrittyConfig; + home-manager.users.me.xdg.configFile = + let + inherit (import ) colours; + colourNames = [ "black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" ]; + colourPairs = lib.getAttrs colourNames colours; + in { + "alacritty/alacritty.yml".source = (pkgs.formats.yaml {}).generate "alacritty.yml" { + background_opacity = 0.9; + colors = { + primary = { inherit (colours) background foreground; }; + normal = lib.mapAttrs (_: colour: colour.dark) colourPairs; + bright = lib.mapAttrs (_: colour: colour.bright) colourPairs; + }; + font = { + normal.family = "Monospace"; + size = 6; + }; + key_bindings = [ + { + key = "Add"; + mods = "Control"; + action = "IncreaseFontSize"; + } + { + key = "Minus"; + mods = "Control"; + action = "DecreaseFontSize"; + } + { + key = "Key0"; + mods = "Control"; + action = "ResetFontSize"; + } + ]; + }; }; } diff --git a/configs/default.nix b/configs/default.nix index d18343a..f026efe 100644 --- a/configs/default.nix +++ b/configs/default.nix @@ -36,7 +36,6 @@ in { (self: super: { scripts = import { pkgs = super; lib = super.lib; }; }) - (import ) (import ) (import ) (import ) diff --git a/configs/i3.nix b/configs/i3.nix index c524770..41b79e6 100644 --- a/configs/i3.nix +++ b/configs/i3.nix @@ -143,7 +143,7 @@ in { }; }; statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs ${ - pkgs.writeTOML (import { + (pkgs.formats.toml {}).generate "i3status-rust.toml" (import { inherit (config.niveum) batteryName wirelessInterface; inherit colours; inherit pkgs; diff --git a/configs/matterbridge.nix b/configs/matterbridge.nix index 52ad0cd..9c0d43e 100644 --- a/configs/matterbridge.nix +++ b/configs/matterbridge.nix @@ -1,47 +1,6 @@ { pkgs, lib, ... }: -let - bridgeBotToken = lib.strings.fileContents ; - config = { - general = { - RemoteNickFormat = "[{NICK}] "; - Charset = "utf-8"; - }; - telegram.kmein.Token = bridgeBotToken; - irc.freenode = { - Server = "irc.freenode.net:6667"; - Nick = "ponte"; - StripMarkdown = true; - }; - mumble.lassulus = { - Server = "lassul.us:64738"; - Nick = "krebs_bridge"; - SkipTLSVerify = true; - }; - gateway = [ - { - name = "krebs-bridge"; - enable = true; - inout = [ - { - account = "irc.freenode"; - channel = "#krebs"; - } - { - account = "telegram.kmein"; - channel = "-330372458"; - } - { - account = "mumble.lassulus"; - channel = 6; # "nixos" - } - ]; - } - ]; - }; -in { nixpkgs.overlays = [ - (import ) (self: super: { matterbridge = (import (super.fetchFromGitHub { owner = "NixOS"; @@ -54,6 +13,44 @@ in services.matterbridge = { enable = true; - configPath = toString (pkgs.writeTOML config); + configPath = + let bridgeBotToken = lib.strings.fileContents ; + in toString ((pkgs.formats.toml {}).generate "config.toml" { + general = { + RemoteNickFormat = "[{NICK}] "; + Charset = "utf-8"; + }; + telegram.kmein.Token = bridgeBotToken; + irc.freenode = { + Server = "irc.freenode.net:6667"; + Nick = "ponte"; + StripMarkdown = true; + }; + mumble.lassulus = { + Server = "lassul.us:64738"; + Nick = "krebs_bridge"; + SkipTLSVerify = true; + }; + gateway = [ + { + name = "krebs-bridge"; + enable = true; + inout = [ + { + account = "irc.freenode"; + channel = "#krebs"; + } + { + account = "telegram.kmein"; + channel = "-330372458"; + } + { + account = "mumble.lassulus"; + channel = 6; # "nixos" + } + ]; + } + ]; + }); }; } diff --git a/configs/mpd-fm.nix b/configs/mpd-fm.nix index e778d3e..6b84ac2 100644 --- a/configs/mpd-fm.nix +++ b/configs/mpd-fm.nix @@ -47,7 +47,7 @@ in systemd.services.mpd-fm-stations = let stations = lib.lists.imap0 (id: {desc ? "", logo ? "https://picsum.photos/seed/${builtins.hashString "md5" stream}/300", stream, station}: { inherit id desc logo stream station; }) streams; - stationsJson = pkgs.writeText "stations.json" (builtins.toJSON stations); + stationsJson = (pkgs.formats.json {}).generate "stations.json" stations; in { wantedBy = [ "mpd-fm.service" ]; startAt = "hourly"; diff --git a/configs/packages/haskell/default.nix b/configs/packages/haskell/default.nix index b0c337b..972c987 100644 --- a/configs/packages/haskell/default.nix +++ b/configs/packages/haskell/default.nix @@ -10,8 +10,9 @@ ''; # :def unpl \x -> return $ ":!${pkgs.haskellPackages.pointful}/bin/pointful \"" ++ x ++ "\"" # :def pl \x -> return $ ":!${pkgs.haskellPackages.pointfree}/bin/pointfree -v \"" ++ x ++ "\"" - ".stack/config.yaml".text = let inherit (import ) kieran; - in builtins.toJSON { + ".stack/config.yaml".source = + let inherit (import ) kieran; + in (pkgs.formats.yaml {}).generate "config.yaml" { templates.params = { author-name = kieran.name; author-email = kieran.email; diff --git a/configs/urlwatch.nix b/configs/urlwatch.nix index 34b1bed..e5412be 100644 --- a/configs/urlwatch.nix +++ b/configs/urlwatch.nix @@ -66,7 +66,7 @@ let } ]; - configFile = pkgs.writeText "urlwatch.yaml" (builtins.toJSON { + configFile = (pkgs.formats.yaml {}).generate "urlwatch.yaml" { display = { error = true; new = true; @@ -100,7 +100,7 @@ let # chat_id = [ "18980945" ]; # }; }; - }); + }; urlwatch = pkgs.urlwatch.overrideAttrs (attrs: { patches = [ ]; }); diff --git a/modules/mpd-fm.nix b/modules/mpd-fm.nix index e95c2ba..e2589f4 100644 --- a/modules/mpd-fm.nix +++ b/modules/mpd-fm.nix @@ -44,7 +44,7 @@ in { stationsFile = mkOption { type = types.path; - default = pkgs.writeText "stations.json" (builtins.toJSON cfg.stations); + default = (pkgs.formats.json {}).generate "stations.json" cfg.stations; }; package = mkOption { diff --git a/overlays/toml.nix b/overlays/toml.nix deleted file mode 100644 index 6f98b3c..0000000 --- a/overlays/toml.nix +++ /dev/null @@ -1,7 +0,0 @@ -(self: super: { - writeTOML = object: super.runCommand "writeTOML" {} '' - echo '${builtins.toJSON object}' | ${super.remarshal}/bin/json2toml > $out - ''; - toTOML = object: builtins.readFile (self.writeTOML object); - writeJSON = path: object: super.writeText path (builtins.toJSON object); -})