From 1b60e26e4777df2aa3f0ea64f60fc60d7295295f Mon Sep 17 00:00:00 2001 From: Malte Brandy Date: Sat, 16 May 2020 13:20:32 +0200 Subject: [PATCH] Much better mode concept --- home.nix | 130 +++--------------------------------------------- home/laptop.nix | 15 ++---- home/modes.nix | 117 +++++++++++++++++++++++++++++++++++++++++++ home/target.nix | 16 ++++++ 4 files changed, 144 insertions(+), 134 deletions(-) create mode 100644 home/modes.nix create mode 100644 home/target.nix diff --git a/home.nix b/home.nix index ce247de5..6041da68 100644 --- a/home.nix +++ b/home.nix @@ -1,126 +1,8 @@ let inherit (import { }) lib; - home-manager = import ; - buildHomeManager = attr: - (home-manager { - confPath = ~/git/config/home.nix; - confAttr = attr; - }).activationPackage; - makeConfig = hostName: imports: - { ... }: { - imports = imports ++ [ ./home ]; - m-0.hostName = hostName; - }; - apollo = let - setStartpage = startpage: - { ... }: { - programs.firefox.profiles."fz2sm95u.default".settings = { - "browser.startup.homepage" = startpage; - }; - }; - makeBlock = list: - { pkgs, lib, ... }: { - systemd.user = { - services.blockserver = { - Unit = { Description = "Serve a blocklist"; }; - Service = { - ExecStart = "${pkgs.python3}/bin/python -m http.server 8842 -d ${ - pkgs.writeTextDir "blocklist" - (lib.concatStringsSep "\r\n" list) - }"; - Restart = "always"; - }; - Install = { WantedBy = [ "default.target" ]; }; - }; - }; - }; - tinkerPages = [ - "reddit.com" - "github.com" - "*.ccc.de" - "haskell.org" - "*.haskell.org" - "*.nixos.org" - "nixos.org" - "matrix.org" - "riot.im" - "youtube.de" - "youtube.com" - ]; - leisurePages = [ - "zeit.de" - "heise.de" - "spiegel.de" - "xkcd.com" - "smbc-comics.com" - "tagesschau.de" - "welt.de" - "ndr.de" - "ard.de" - "zdf.de" - "twitter.com" - "chaos.social" - ]; - apolloConfig = imports: - makeConfig "apollo" (imports ++ [ - home/battery.nix - home/mpd.nix - home/mpclient.nix - home/on-my-machine.nix - home/desktop - home/firefox.nix - home/git-sign.nix - home/laptop.nix - ]); - in { - communication = apolloConfig [ - home/mail.nix - home/update_tasks.nix - home/chat.nix - (setStartpage "https://cloud.maralorn.de/apps/calendar") - (makeBlock [ ]) - ]; - orga = apolloConfig [ - home/accounting.nix - home/mail.nix - home/pythia.nix - home/update_tasks.nix - (setStartpage "https://cloud.maralorn.de/apps/calendar") - (makeBlock (tinkerPages ++ leisurePages)) - ]; - research = apolloConfig [ - home/research.nix - (makeBlock (tinkerPages ++ leisurePages)) - (setStartpage "http://localhost:8042") - ]; - - tinkering = apolloConfig [ - home/mail.nix - home/update-script.nix - home/tinkering.nix - home/chat.nix - (makeBlock leisurePages) - (setStartpage "https://stats.maralorn.de/d/health-status") - ]; - leisure = apolloConfig [ - home/games.nix - home/chat.nix - (makeBlock [ ]) - (setStartpage "https://stats.maralorn.de/d/health-status") - ]; - }; - -in { - hera = makeConfig "hera" [ - ./home - home/on-my-machine.nix - hosts/hera/weechat - hosts/hera/secret - home/kassandra.nix - home/headless-mpd.nix - home/mail.nix - ]; -} // lib.listToAttrs (lib.mapAttrsToList (name: config: { - name = "apollo-${name}"; - value = config; -}) apollo) + modes = import home/modes.nix; +in lib.listToAttrs (lib.flatten (lib.mapAttrsToList (host: configs: + lib.mapAttrsToList (mode: config: { + name = "${host}-${mode}"; + value = config; + }) configs) modes)) diff --git a/home/laptop.nix b/home/laptop.nix index d54871e8..464d4108 100644 --- a/home/laptop.nix +++ b/home/laptop.nix @@ -2,9 +2,7 @@ let inherit (import ../lib) unfreePkgs; inherit (import ../pkgs) my-ssh-add; - modes = map (lib.removePrefix "apollo-") - (builtins.filter (lib.hasPrefix "apollo-") - (pkgs.lib.attrNames (import ../home.nix))); + modes = pkgs.lib.attrNames (import ./modes.nix).apollo; autostart-script = pkgs.writeShellScriptBin "home-manager-autostart" '' ${my-ssh-add}/bin/my-ssh-add ${pkgs.xorg.xrdb}/bin/xrdb ${builtins.toFile "Xresources" "Xft.dpi: 96"} @@ -27,15 +25,13 @@ in { sudo -A nix optimise-store ''; activateMode = pkgs.writeShellScriptBin "activate-mode" '' - ~/.modes/result-home-manager-apollo-$(cat ~/tmp/mode)/activate + ~/.modes/$(cat ~/tmp/mode)/activate + random-wallpaper ''; updateModes = pkgs.writeShellScriptBin "update-modes" '' set -e - update-home -A apollo-$(cat ~/tmp/mode) - mkdir -p ~/.modes - cd ~/.modes - ${lib.concatStringsSep "\n" - (map (mode: "test-home-config ~/git/config apollo-${mode}") modes)} + nix build -f ~/git/config/home/target.nix apollo -o ~/.modes + activate-mode ''; selectMode = pkgs.writeShellScriptBin "select-mode" '' ${pkgs.dialog}/bin/dialog --menu "Select Mode" 20 80 5 ${ @@ -43,7 +39,6 @@ in { } 2> ~/tmp/mode clear echo "Switching to mode $(cat ~/tmp/mode)..." - ln -sfT ~/.wallpapers/$(cat ~/tmp/mode) ~/volatile/wallpapers activate-mode > /dev/null ''; diff --git a/home/modes.nix b/home/modes.nix new file mode 100644 index 00000000..23542441 --- /dev/null +++ b/home/modes.nix @@ -0,0 +1,117 @@ +let + inherit (import { }) lib; + makeConfig = hostName: imports: + { ... }: { + imports = imports ++ [ ./default.nix ]; + m-0.hostName = hostName; + }; +in { + apollo = let + setStartpage = startpage: + { ... }: { + programs.firefox.profiles."fz2sm95u.default".settings = { + "browser.startup.homepage" = startpage; + }; + }; + makeBlock = list: + { pkgs, lib, ... }: { + systemd.user = { + services.blockserver = { + Unit = { Description = "Serve a blocklist"; }; + Service = { + ExecStart = "${pkgs.python3}/bin/python -m http.server 8842 -d ${ + pkgs.writeTextDir "blocklist" + (lib.concatStringsSep "\r\n" list) + }"; + Restart = "always"; + }; + Install = { WantedBy = [ "default.target" ]; }; + }; + }; + }; + tinkerPages = [ + "reddit.com" + "github.com" + "*.ccc.de" + "haskell.org" + "*.haskell.org" + "*.nixos.org" + "nixos.org" + "matrix.org" + "riot.im" + "youtube.de" + "youtube.com" + ]; + leisurePages = [ + "zeit.de" + "heise.de" + "spiegel.de" + "xkcd.com" + "smbc-comics.com" + "tagesschau.de" + "welt.de" + "ndr.de" + "ard.de" + "zdf.de" + "twitter.com" + "chaos.social" + ]; + apolloConfig = imports: + makeConfig "apollo" (imports ++ [ + ./battery.nix + ./mpd.nix + ./mpclient.nix + ./on-my-machine.nix + ./desktop + ./firefox.nix + ./git-sign.nix + ./laptop.nix + ]); + in { + communication = apolloConfig [ + ./mail.nix + ./update_tasks.nix + ./chat.nix + (setStartpage "https://cloud.maralorn.de/apps/calendar") + (makeBlock [ ]) + ]; + orga = apolloConfig [ + ./accounting.nix + ./mail.nix + ./pythia.nix + ./update_tasks.nix + (setStartpage "https://cloud.maralorn.de/apps/calendar") + (makeBlock (tinkerPages ++ leisurePages)) + ]; + research = apolloConfig [ + ./research.nix + (makeBlock (tinkerPages ++ leisurePages)) + (setStartpage "http://localhost:8042") + ]; + + tinkering = apolloConfig [ + ./mail.nix + ./update-script.nix + ./tinkering.nix + ./chat.nix + (makeBlock leisurePages) + (setStartpage "https://stats.maralorn.de/d/health-status") + ]; + leisure = apolloConfig [ + ./games.nix + ./chat.nix + (makeBlock [ ]) + (setStartpage "https://stats.maralorn.de/d/health-status") + ]; + }; + hera = { + default = makeConfig "hera" [ + ./on-my-machine.nix + ./hosts/hera/weechat + ./hosts/hera/secret + ./kassandra.nix + ./headless-mpd.nix + ./mail.nix + ]; + }; +} diff --git a/home/target.nix b/home/target.nix new file mode 100644 index 00000000..d85961b0 --- /dev/null +++ b/home/target.nix @@ -0,0 +1,16 @@ +let + inherit (import { }) lib pkgs; + modes = import ./modes.nix; + home-manager = import ; + buildHomeManager = attr: + (home-manager { + confPath = ~/git/config/home.nix; + confAttr = attr; + }).activationPackage; +in lib.mapAttrs (host: configs: + pkgs.runCommand "${host}-modes" { } '' + mkdir $out + ${lib.concatStringsSep "\n" (lib.mapAttrsToList + (mode: config: "ln -s ${buildHomeManager "${host}-${mode}"} $out/${mode}") + configs)} + '') modes