1
0
Fork 0

Much better mode concept

This commit is contained in:
Malte Brandy 2020-05-16 13:20:32 +02:00
parent ac7d7112c2
commit 1b60e26e47
No known key found for this signature in database
GPG key ID: 226A2D41EF5378C9
4 changed files with 144 additions and 134 deletions

130
home.nix
View file

@ -1,126 +1,8 @@
let
inherit (import <nixpkgs> { }) lib;
home-manager = import <home-manager/home-manager/home-manager.nix>;
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))

View file

@ -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
'';

117
home/modes.nix Normal file
View file

@ -0,0 +1,117 @@
let
inherit (import <nixpkgs> { }) 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
];
};
}

16
home/target.nix Normal file
View file

@ -0,0 +1,16 @@
let
inherit (import <nixpkgs> { }) lib pkgs;
modes = import ./modes.nix;
home-manager = import <home-manager/home-manager/home-manager.nix>;
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