diff --git a/flake.nix b/flake.nix index 0428621..b8c2d44 100644 --- a/flake.nix +++ b/flake.nix @@ -64,7 +64,7 @@ flake = false; }; - mtxclient ={ + mtxclient = { url = "github:nheko-reborn/mtxclient"; flake = false; }; @@ -90,17 +90,24 @@ findModules = dir: builtins.concatLists (builtins.attrValues (builtins.mapAttrs (name: type: - if type == "regular" then - [{ - name = builtins.elemAt (builtins.match "(.*)\\.nix" name) 0; - value = dir + "/${name}"; - }] - else if (builtins.readDir (dir + "/${name}")) + if type == "regular" then [{ + name = builtins.elemAt (builtins.match "(.*)\\.nix" name) 0; + value = dir + "/${name}"; + }] else if (builtins.readDir (dir + "/${name}")) ? "default.nix" then [{ inherit name; value = dir + "/${name}"; }] else findModules (dir + "/${name}")) (builtins.readDir dir))); + pkgsFor = system: + import inputs.nixpkgs { + overlays = [ (import inputs.emacs-overlay) self.overlay ]; + localSystem = { inherit system; }; + config = { + allowUnfree = true; + android_sdk.accept_license = true; + }; + }; in { nixosModules = builtins.listToAttrs (findModules ./modules); @@ -111,20 +118,30 @@ nixosConfigurations = with nixpkgs.lib; let hosts = builtins.attrNames (builtins.readDir ./machines); + mkHost = name: - nixosSystem { + let system = builtins.readFile (./machines + "/${name}/system"); - modules = - [ (import (./machines + "/${name}")) { device = name; } ]; + pkgs = pkgsFor system; + in nixosSystem { + inherit system; + modules = [ + (import (./machines + "/${name}")) + { nixpkgs.pkgs = pkgs; } + { device = name; } + ]; specialArgs = { inherit inputs; }; }; in genAttrs hosts mkHost; - legacyPackages.x86_64-linux = - (builtins.head (builtins.attrValues self.nixosConfigurations)).pkgs; + legacyPackages.x86_64-linux = pkgsFor "x86_64-linux"; defaultApp = deploy-rs.defaultApp; + overlay = import ./overlay.nix inputs; + + lib = import ./lib.nix nixpkgs.lib; + devShell.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux; mkShell { buildInputs = [ @@ -137,15 +154,18 @@ deploy = { user = "root"; nodes = (builtins.mapAttrs (name: machine: - let activateable = name == "T420-Laptop" || name == "RasPi-Server"; in { - hostname = machine.config.networking.hostName; - profiles.system = { - user = if activateable then "root" else "balsoft"; - path = with deploy-rs.lib.${machine.pkgs.system}.activate; if activateable - then nixos machine - else noop machine.config.system.build.toplevel; - }; - }) self.nixosConfigurations); + let activateable = name == "T420-Laptop" || name == "RasPi-Server"; + in { + hostname = machine.config.networking.hostName; + profiles.system = { + user = if activateable then "root" else "balsoft"; + path = with deploy-rs.lib.${machine.pkgs.system}.activate; + if activateable then + nixos machine + else + noop machine.config.system.build.toplevel; + }; + }) self.nixosConfigurations); }; }; } diff --git a/lib.nix b/lib.nix new file mode 100644 index 0000000..d19b6f1 --- /dev/null +++ b/lib.nix @@ -0,0 +1,61 @@ +lib: rec { + mkKeyValue = key: value: + let + mvalue = if builtins.isBool value then + (if value then "true" else "false") + else if builtins.isString value then + value + else + builtins.toString value; + in "${key}=${mvalue}"; + attrsToList = with builtins; + x: + (map (key: { + name = key; + value = getAttr key x; + }) (attrNames x)); + + genIni = lib.generators.toINI { inherit mkKeyValue; }; + genIniOrdered = lst: + (builtins.concatStringsSep "\n" (map ({ name ? "widget", ... }@attrs: + builtins.concatStringsSep "\n" ([ "[${name}]" ] + ++ (map ({ name, value }: mkKeyValue name value) + (attrsToList (builtins.removeAttrs attrs [ "name" ]))))) lst)) + "\n"; + splitHex = hexStr: + map (x: builtins.elemAt x 0) + (builtins.filter (a: a != "" && a != [ ]) (builtins.split "(.{2})" hexStr)); + hex2decDigits = rec { + "0" = 0; + "1" = 1; + "2" = 2; + "3" = 3; + "4" = 4; + "5" = 5; + "6" = 6; + "7" = 7; + "8" = 8; + "9" = 9; + "a" = 10; + "b" = 11; + "c" = 12; + "d" = 13; + "e" = 14; + "f" = 15; + A = a; + B = b; + C = c; + D = d; + E = e; + F = f; + }; + + doubleDigitHexToDec = hex: + 16 * hex2decDigits."${builtins.substring 0 1 hex}" + + hex2decDigits."${builtins.substring 1 2 hex}"; + thmDec = builtins.mapAttrs (name: color: colorHex2Dec color); + thmHash = builtins.mapAttrs (name: color: "#${color}"); + colorHex2Dec = color: + builtins.concatStringsSep "," + (map (x: toString (doubleDigitHexToDec x)) (splitHex color)); + +} diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..51ebec9 --- /dev/null +++ b/overlay.nix @@ -0,0 +1,104 @@ +inputs: final: prev: +let + old = + import inputs.nixpkgs-old ({ localSystem = { inherit (final) system; }; }); + inherit (final) system lib; +in rec { + + my-lib = import ./lib.nix lib; + + nur = (import inputs.NUR { + pkgs = old; + nurpkgs = final; + }).repos; + + mopidy-ytmusic = with final; + python3Packages.buildPythonApplication rec { + pname = "mopidy-ytmusic"; + version = "3.2"; + + src = inputs.mopidy-ytmusic; + + propagatedBuildInputs = [ + mopidy + (python3Packages.ytmusicapi.overrideAttrs (oa: rec { + name = "python3.9-ytmusicapi-${version}"; + version = "0.19.1"; + src = fetchFromGitHub { + owner = "sigma67"; + repo = "ytmusicapi"; + rev = "fd9f57750de103202106f02be1696bd440f2c05b"; + sha256 = "/NMy2cGe0K/14OZd+/dXKA6Ez1ivrtrZ6Lwl0P8dioA="; + fetchSubmodules = true; + }; + })) + (python3Packages.pytube.overrideAttrs (oa: rec { + name = "python3.9-pytube-${version}"; + version = "11.0.1"; + src = fetchFromGitHub { + owner = "pytube"; + repo = "pytube"; + rev = "f06e0710dcf5089e582487fee94f7bb0afbf7ba9"; + sha256 = "sha256-yQCgrnoPOSdTnTPEsVkgLYpPLiHq7kXRUO72TxD152k="; + fetchSubmodules = true; + }; + })) + ]; + + doCheck = false; + }; + + inherit (nur.balsoft.pkgs) termNote nix-patch; + + lambda-launcher = inputs.lambda-launcher.defaultPackage.${system}; + + simple-osd = inputs.simple-osd-daemons.packages.${system}; + + nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd; + + pass-secret-service = + prev.pass-secret-service.overrideAttrs (_: { installCheckPhase = null; }); + + nix-direnv = inputs.nix-direnv.defaultPackage.${system}; + + coeurl = final.stdenv.mkDerivation { + name = "coeurl"; + src = inputs.coeurl; + buildInputs = [ final.curl.all final.libevent final.spdlog ]; + nativeBuildInputs = [ final.meson final.ninja final.pkg-config final.cmake ]; + }; + + mtxclient = prev.mtxclient.overrideAttrs (oa: { + src = inputs.mtxclient; + cmakeFlags = oa.cmakeFlags ++ [ "-DCMAKE_CXX_FLAGS=-DSPDLOG_FMT_EXTERNAL" ]; + buildInputs = oa.buildInputs + ++ [ final.libevent final.curl.all final.coeurl final.spdlog.dev ]; + patches = [ ]; + }); + + nheko = (prev.nheko.overrideAttrs (oa: { + src = inputs.nheko; + postPatch = '' + substituteInPlace CMakeLists.txt --replace "# Fixup bundled keychain include dirs" "find_package(Boost COMPONENTS iostreams system thread REQUIRED)" + ''; + buildInputs = oa.buildInputs ++ [ + final.xorg.libXdmcp + final.pcre + final.libunwind + final.elfutils + final.coeurl + final.curl + final.libevent + final.asciidoc + ]; + cmakeFlags = oa.cmakeFlags ++ [ "-DBUILD_SHARED_LIBS=OFF" ]; + })).override { mtxclient = final.mtxclient; }; + + nix = inputs.nix.defaultPackage.${system}.overrideAttrs + (oa: { patches = [ ./profiles/nix/nix.patch ] ++ oa.patches or [ ]; }); + + mako = prev.mako.overrideAttrs (_: { + postInstall = + "sed 's/Exec=.*//' -i $out/share/dbus-1/services/fr.emersion.mako.service"; + }); +} diff --git a/profiles/applications/alacritty.nix b/profiles/applications/alacritty.nix index 9774620..af03113 100644 --- a/profiles/applications/alacritty.nix +++ b/profiles/applications/alacritty.nix @@ -22,7 +22,7 @@ cursor.style = "Beam"; - colors = with pkgs.my-lib.thmHash; { + colors = with pkgs.my-lib.thmHash config.themes.colors; { primary = { background = base00; foreground = base05; diff --git a/profiles/applications/emacs/default.nix b/profiles/applications/emacs/default.nix index 0dd0c89..711361c 100644 --- a/profiles/applications/emacs/default.nix +++ b/profiles/applications/emacs/default.nix @@ -95,6 +95,6 @@ in { xdg.configFile."emacs/init.el".source = pkgs.substituteAll ({ src = ./init.el; font = with config.themes.fonts; "${mono.family} ${toString mono.size}"; - } // pkgs.my-lib.thmHash); + } // pkgs.my-lib.thmHash config.themes.colors); }; } diff --git a/profiles/applications/firefox.nix b/profiles/applications/firefox.nix index d6a64ac..73b9803 100644 --- a/profiles/applications/firefox.nix +++ b/profiles/applications/firefox.nix @@ -1,6 +1,6 @@ { config, pkgs, lib, ... }: let - thm = pkgs.my-lib.thmHash; + thm = pkgs.my-lib.thmHash config.themes.colors; fonts = config.themes.fonts; in { environment.sessionVariables = { diff --git a/profiles/applications/geary.nix b/profiles/applications/geary.nix index 6ebd2c2..0fe3a1c 100644 --- a/profiles/applications/geary.nix +++ b/profiles/applications/geary.nix @@ -62,15 +62,18 @@ in { desktop = "org.gnome.Geary"; }; - home-manager.users.balsoft = { + home-manager.users.balsoft = let + fonts = config.themes.fonts; + thm = pkgs.my-lib.thmHash config.themes.colors; + in { xdg.configFile."geary/user-style.css".text = '' *, html, body, body.plain div, body.plain a, body.plain p, body.plain span { - background: ${pkgs.my-lib.thmHash.base00} !important; - color: ${pkgs.my-lib.thmHash.base05} !important; - font-family: '${config.themes.fonts.mono.family}', monospace !important; + background: ${thm.base00} !important; + color: ${thm.base05} !important; + font-family: '${fonts.mono.family}', monospace !important; } *, html, body { - font-size: ${toString config.themes.fonts.mono.size}pt; + font-size: ${toString fonts.mono.size}pt; } ''; home.activation.geary = '' diff --git a/profiles/applications/packages.nix b/profiles/applications/packages.nix index 46216c7..31b47a7 100644 --- a/profiles/applications/packages.nix +++ b/profiles/applications/packages.nix @@ -4,7 +4,6 @@ # Internet wget curl - unrar neochat exa @@ -23,7 +22,6 @@ pavucontrol # Tools zip - unrar plasma-systemmonitor wl-clipboard grim diff --git a/profiles/overlay.nix b/profiles/overlay.nix deleted file mode 100644 index 33f6b35..0000000 --- a/profiles/overlay.nix +++ /dev/null @@ -1,173 +0,0 @@ -{ pkgs, config, lib, inputs, ... }: -let - filterGit = - builtins.filterSource (type: name: name != ".git" || type != "directory"); - inherit (pkgs) system; - old = import inputs.nixpkgs-old ({ - config = config.nixpkgs.config; - localSystem = { inherit system; }; - }); - mkKeyValue = key: value: - let - mvalue = if builtins.isBool value then - (if value then "true" else "false") - else if builtins.isString value then - value - else - builtins.toString value; - in ''${key}=${mvalue}''; - attrsToList = with builtins; - x: - (map (key: { - name = key; - value = getAttr key x; - }) (attrNames x)); -in { - nixpkgs.overlays = [ - (import inputs.emacs-overlay) - (self: super: rec { - - my-lib = rec { - genIni = lib.generators.toINI { inherit mkKeyValue; }; - genIniOrdered = lst: - (builtins.concatStringsSep "\n" (map ({ name ? "widget", ... }@attrs: - builtins.concatStringsSep "\n" ([ "[${name}]" ] - ++ (map ({ name, value }: mkKeyValue name value) - (attrsToList (builtins.removeAttrs attrs [ "name" ]))))) lst)) - + "\n"; - thm = config.themes.colors; - splitHex = hexStr: - map (x: builtins.elemAt x 0) (builtins.filter (a: a != "" && a != [ ]) - (builtins.split "(.{2})" hexStr)); - hex2decDigits = rec { - "0" = 0; - "1" = 1; - "2" = 2; - "3" = 3; - "4" = 4; - "5" = 5; - "6" = 6; - "7" = 7; - "8" = 8; - "9" = 9; - "a" = 10; - "b" = 11; - "c" = 12; - "d" = 13; - "e" = 14; - "f" = 15; - A = a; - B = b; - C = c; - D = d; - E = e; - F = f; - }; - - doubleDigitHexToDec = hex: - 16 * hex2decDigits."${builtins.substring 0 1 hex}" - + hex2decDigits."${builtins.substring 1 2 hex}"; - thmDec = builtins.mapAttrs (name: color: colorHex2Dec color) thm; - thmHash = builtins.mapAttrs (name: color: "#${color}") thm; - colorHex2Dec = color: - builtins.concatStringsSep "," - (map (x: toString (doubleDigitHexToDec x)) (splitHex color)); - - }; - - nur = (import inputs.NUR { - pkgs = old; - nurpkgs = pkgs; - }).repos; - - mopidy-ytmusic = with pkgs; - python3Packages.buildPythonApplication rec { - pname = "mopidy-ytmusic"; - version = "3.2"; - - src = inputs.mopidy-ytmusic; - - propagatedBuildInputs = [ - mopidy - (python3Packages.ytmusicapi.overrideAttrs (oa: rec { - name = "python3.9-ytmusicapi-${version}"; - version = "0.19.1"; - src = fetchFromGitHub { - owner = "sigma67"; - repo = "ytmusicapi"; - rev = "fd9f57750de103202106f02be1696bd440f2c05b"; - sha256 = "/NMy2cGe0K/14OZd+/dXKA6Ez1ivrtrZ6Lwl0P8dioA="; - fetchSubmodules = true; - }; - })) - (python3Packages.pytube.overrideAttrs (oa: rec { - name = "python3.9-pytube-${version}"; - version = "11.0.1"; - src = fetchFromGitHub { - owner = "pytube"; - repo = "pytube"; - rev = "f06e0710dcf5089e582487fee94f7bb0afbf7ba9"; - sha256 = "sha256-yQCgrnoPOSdTnTPEsVkgLYpPLiHq7kXRUO72TxD152k="; - fetchSubmodules = true; - }; - })) - ]; - - doCheck = false; - }; - - inherit (nur.balsoft.pkgs) termNote nix-patch; - - lambda-launcher = inputs.lambda-launcher.defaultPackage.${system}; - - simple-osd = inputs.simple-osd-daemons.packages.${system}; - - nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd; - - pass-secret-service = super.pass-secret-service.overrideAttrs (_: { installCheckPhase = null; }); - - nix-direnv = inputs.nix-direnv.defaultPackage.${system}; - - coeurl = self.stdenv.mkDerivation { - name = "coeurl"; - src = inputs.coeurl; - buildInputs = [ self.curl.all self.libevent self.spdlog ]; - nativeBuildInputs = [ self.meson self.ninja self.pkg-config self.cmake ]; - }; - - mtxclient = super.mtxclient.overrideAttrs (oa: { - src = inputs.mtxclient; - cmakeFlags = oa.cmakeFlags ++ [ "-DCMAKE_CXX_FLAGS=-DSPDLOG_FMT_EXTERNAL" ]; - buildInputs = oa.buildInputs ++ [ self.libevent self.curl.all self.coeurl self.spdlog.dev ]; - patches = []; - }); - - nheko = (super.nheko.overrideAttrs (oa: { - src = inputs.nheko; - postPatch = '' - substituteInPlace CMakeLists.txt --replace "# Fixup bundled keychain include dirs" "find_package(Boost COMPONENTS iostreams system thread REQUIRED)" - ''; - buildInputs = oa.buildInputs ++ [ - self.xorg.libXdmcp - self.pcre - self.libunwind - self.elfutils - self.coeurl - self.curl - self.libevent - self.asciidoc - ]; - cmakeFlags = oa.cmakeFlags ++ [ "-DBUILD_SHARED_LIBS=OFF" ]; - })).override { mtxclient = self.mtxclient; }; - - nix = inputs.nix.defaultPackage.${pkgs.system}.overrideAttrs (oa: { - patches = [ ./nix/nix.patch ] ++ oa.patches or [ ]; - }); - - }) - ]; - nixpkgs.config = { - allowUnfree = true; - android_sdk.accept_license = true; - }; -} diff --git a/profiles/workspace/i3blocks/default.nix b/profiles/workspace/i3blocks/default.nix index 224bdcb..f903d50 100644 --- a/profiles/workspace/i3blocks/default.nix +++ b/profiles/workspace/i3blocks/default.nix @@ -19,7 +19,7 @@ in { trayOutput = "primary"; command = "true"; colors = let - thm = pkgs.my-lib.thmHash; + thm = pkgs.my-lib.thmHash config.themes.colors; default = { background = thm.base00; border = thm.base00; diff --git a/profiles/workspace/kde/qt.nix b/profiles/workspace/kde/qt.nix index 9ca8ad3..94be0f5 100644 --- a/profiles/workspace/kde/qt.nix +++ b/profiles/workspace/kde/qt.nix @@ -21,7 +21,7 @@ with pkgs.my-lib; { home-manager.users.balsoft = let fonts = config.themes.fonts; in { - xdg.configFile."kdeglobals".text = with thmDec; lib.generators.toGitINI { + xdg.configFile."kdeglobals".text = with (thmDec config.themes.colors); lib.generators.toGitINI { "Colors:Button" = { BackgroundAlternate = base01; BackgroundNormal = base01; diff --git a/profiles/workspace/mako.nix b/profiles/workspace/mako.nix index af63b9e..72de834 100644 --- a/profiles/workspace/mako.nix +++ b/profiles/workspace/mako.nix @@ -9,7 +9,7 @@ WantedBy = [ "sway-session.target" ]; }; }; - programs.mako = with pkgs.my-lib.thmHash; { + programs.mako = with (pkgs.my-lib.thmHash config.themes.colors); { enable = true; layer = "overlay"; font = with config.themes.fonts; "${main.family} ${toString main.size}"; diff --git a/profiles/workspace/misc.nix b/profiles/workspace/misc.nix index d58a31e..6e3bb2e 100644 --- a/profiles/workspace/misc.nix +++ b/profiles/workspace/misc.nix @@ -18,6 +18,8 @@ home.stateVersion = "20.09"; }; + home-manager.useGlobalPkgs = true; + persist.cache.directories = [ "/home/balsoft/.cache" "/home/balsoft/.local/share/cargo" "/var/cache" ]; persist.state.directories = [ "/var/lib/nixos" "/var/lib/systemd" ]; diff --git a/profiles/workspace/sway/default.nix b/profiles/workspace/sway/default.nix index d881c56..01303da 100755 --- a/profiles/workspace/sway/default.nix +++ b/profiles/workspace/sway/default.nix @@ -1,6 +1,6 @@ { pkgs, lib, config, ... }: let - thm = pkgs.my-lib.thmHash; + thm = pkgs.my-lib.thmHash config.themes.colors; apps = config.defaultApplications; lock_fork = pkgs.writeShellScript "lock_fork" "sudo /run/current-system/sw/bin/lock &"; diff --git a/roles/base.nix b/roles/base.nix index d7f0beb..003c116 100644 --- a/roles/base.nix +++ b/roles/base.nix @@ -21,7 +21,6 @@ misc network nix - overlay security ssh zsh