From 6444b67a4ec60d2127561a55be8cb92424d29bdc Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 16 Oct 2024 14:43:06 +0700 Subject: [PATCH] refactor(nix): Seperate home manager stuff from nix-darwin --- .config/nix/flake.nix | 8 +++- .config/nix/{systems => lib}/mkCommon.nix | 1 + .config/nix/lib/mkSystem.nix | 27 +++++++++++ .config/nix/systems/darwin/configuration.nix | 29 ------------ .config/nix/systems/darwin/default.nix | 48 +++----------------- .config/nix/systems/nix/configuration.nix | 29 ------------ .config/nix/systems/nix/default.nix | 39 ++-------------- .config/nix/users/default.nix | 30 ++++++++++++ .config/nix/users/ziro.nix | 33 ++++++++++++++ 9 files changed, 110 insertions(+), 134 deletions(-) rename .config/nix/{systems => lib}/mkCommon.nix (70%) create mode 100644 .config/nix/lib/mkSystem.nix create mode 100644 .config/nix/users/default.nix create mode 100644 .config/nix/users/ziro.nix diff --git a/.config/nix/flake.nix b/.config/nix/flake.nix index 17cb6c2..042dd0b 100644 --- a/.config/nix/flake.nix +++ b/.config/nix/flake.nix @@ -4,7 +4,6 @@ outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager, system-manager }: let vars = { - user = "ziro"; # TODO: Make it possible to setup multi-user rev = self.rev or self.dirtyRev or null; }; in @@ -23,6 +22,13 @@ inherit inputs nixpkgs system-manager home-manager vars; } ); + + homeConfigurations = ( + import ./users { + inherit (nixpkgs) lib; + inherit inputs nixpkgs home-manager vars; + } + ); }; inputs = { diff --git a/.config/nix/systems/mkCommon.nix b/.config/nix/lib/mkCommon.nix similarity index 70% rename from .config/nix/systems/mkCommon.nix rename to .config/nix/lib/mkCommon.nix index 57912e9..39682ab 100644 --- a/.config/nix/systems/mkCommon.nix +++ b/.config/nix/lib/mkCommon.nix @@ -3,5 +3,6 @@ { packages = [ pkgs.zsh + pkgs.home-manager ]; } diff --git a/.config/nix/lib/mkSystem.nix b/.config/nix/lib/mkSystem.nix new file mode 100644 index 0000000..9849ada --- /dev/null +++ b/.config/nix/lib/mkSystem.nix @@ -0,0 +1,27 @@ +system: nixpkgs: # e.g. x86_64-linux + +let + disablePyChecks = pkg: pkg.overridePythonAttrs (old: { + doCheck = false; + doInstallCheck = false; + dontCheck = true; + }); +in { + system = system; + pkgs = import nixpkgs { + inherit system; + overlays = [(final: prev: { + pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [(pyfinal: pyprev: { + dnspython = (disablePyChecks pyprev.dnspython).overridePythonAttrs (old: { + disabledTests = [ + # This test is unreliable when my internet is throttled by Indonesian ISP, timeout everywhere... lovely... + "test_resolver" + ] ++ old.disabledTests; + }); + pillow = disablePyChecks pyprev.pillow; + cherrypy = disablePyChecks pyprev.cherrypy; + })]; + })]; + config.allowUnfree = true; + }; +} diff --git a/.config/nix/systems/darwin/configuration.nix b/.config/nix/systems/darwin/configuration.nix index 036aa8a..2f0846e 100644 --- a/.config/nix/systems/darwin/configuration.nix +++ b/.config/nix/systems/darwin/configuration.nix @@ -97,33 +97,4 @@ done ''; }; - - users.users.ziro = { - name = vars.user; - home = "/Users/${vars.user}"; - }; - home-manager.users.ziro = { - home.stateVersion = "22.05"; - - programs = { - browserpass = { - enable = true; - browsers = [ "brave" "chrome" ]; # Arc and Chrome share the same `Application Support` dir, not sure why tbh. - }; - }; - - # Swap CapsLock with Esc for better vi-mode experience. - launchd.agents.CapsEscSwap = { - enable = true; - config = { - ProgramArguments = [ - "/usr/bin/hidutil" - "property" - "--set" - "{\"UserKeyMapping\":[{\"HIDKeyboardModifierMappingSrc\":0x700000039,\"HIDKeyboardModifierMappingDst\":0x700000029},{\"HIDKeyboardModifierMappingSrc\":0x700000029,\"HIDKeyboardModifierMappingDst\":0x700000039}]}" - ]; - RunAtLoad = true; - }; - }; - }; } diff --git a/.config/nix/systems/darwin/default.nix b/.config/nix/systems/darwin/default.nix index 594ec39..a8c56ab 100644 --- a/.config/nix/systems/darwin/default.nix +++ b/.config/nix/systems/darwin/default.nix @@ -1,32 +1,8 @@ -{ inputs, nixpkgs, nix-darwin, home-manager, vars, ... }: +{ inputs, nixpkgs, nix-darwin, vars, ... }: let - mkCommon = import ../mkCommon.nix; - - disablePyChecks = pkg: pkg.overridePythonAttrs (old: { - doCheck = false; - doInstallCheck = false; - dontCheck = true; - }); - systemConfig = system: { - system = system; - pkgs = import nixpkgs { - inherit system; - overlays = [(final: prev: { - pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [(pyfinal: pyprev: { - dnspython = (disablePyChecks pyprev.dnspython).overridePythonAttrs (old: { - disabledTests = [ - # This test is unreliable when my internet is throttled by Indonesian ISP, timeout everywhere... lovely... - "test_resolver" - ] ++ old.disabledTests; - }); - pillow = disablePyChecks pyprev.pillow; - cherrypy = disablePyChecks pyprev.cherrypy; - })]; - })]; - config.allowUnfree = true; - }; - }; + mkCommon = import ../../lib/mkCommon.nix; + mkSystem = import ../../lib/mkSystem.nix; in { # Host list @@ -37,38 +13,28 @@ in # Lenovo ThinkPad L460; Intel Core i5-6300U "ThiccBook-Pro" = let - inherit (systemConfig "x86_64-darwin") system pkgs; + inherit (mkSystem "x86_64-darwin" nixpkgs) system pkgs; common = (mkCommon pkgs); in nix-darwin.lib.darwinSystem { inherit system; - specialArgs = { inherit inputs pkgs home-manager vars common; }; + specialArgs = { inherit inputs pkgs vars common; }; modules = [ ./configuration.nix - home-manager.darwinModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - } ]; }; # Imaginary M1, just for reference MacBookProM1 = let - inherit (systemConfig "aarch64-darwin") system pkgs; + inherit (mkSystem "aarch64-darwin" nixpkgs) system pkgs; common = (mkCommon pkgs); in nix-darwin.lib.darwinSystem { inherit system; - specialArgs = { inherit inputs pkgs home-manager vars common; }; + specialArgs = { inherit inputs pkgs vars common; }; modules = [ ./configuration.nix - home-manager.darwinModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - } ]; }; } diff --git a/.config/nix/systems/nix/configuration.nix b/.config/nix/systems/nix/configuration.nix index 400bb79..c002bb1 100644 --- a/.config/nix/systems/nix/configuration.nix +++ b/.config/nix/systems/nix/configuration.nix @@ -56,33 +56,4 @@ system = { stateVersion = 4; }; - - # users.users.ziro = { - # name = vars.user; - # home = "/Users/${vars.user}"; - # }; - # home-manager.users.ziro = { - # home.stateVersion = "22.05"; - - # programs = { - # browserpass = { - # enable = true; - # browsers = [ "brave" "chrome" ]; # Arc and Chrome share the same `Application Support` dir, not sure why tbh. - # }; - # }; - - # # Swap CapsLock with Esc for better vi-mode experience. - # launchd.agents.CapsEscSwap = { - # enable = true; - # config = { - # ProgramArguments = [ - # "/usr/bin/hidutil" - # "property" - # "--set" - # "{\"UserKeyMapping\":[{\"HIDKeyboardModifierMappingSrc\":0x700000039,\"HIDKeyboardModifierMappingDst\":0x700000029},{\"HIDKeyboardModifierMappingSrc\":0x700000029,\"HIDKeyboardModifierMappingDst\":0x700000039}]}" - # ]; - # RunAtLoad = true; - # }; - # }; - # }; } diff --git a/.config/nix/systems/nix/default.nix b/.config/nix/systems/nix/default.nix index 671fa1b..3154158 100644 --- a/.config/nix/systems/nix/default.nix +++ b/.config/nix/systems/nix/default.nix @@ -1,49 +1,20 @@ -{ inputs, nixpkgs, system-manager, home-manager, vars, ... }: +{ inputs, nixpkgs, system-manager, vars, ... }: let - mkCommon = import ../mkCommon.nix; - - disablePyChecks = pkg: pkg.overridePythonAttrs (old: { - doCheck = false; - doInstallCheck = false; - dontCheck = true; - }); - systemConfig = system: { - system = system; - pkgs = import nixpkgs { - inherit system; - overlays = [(final: prev: { - pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [(pyfinal: pyprev: { - dnspython = (disablePyChecks pyprev.dnspython).overridePythonAttrs (old: { - disabledTests = [ - # This test is unreliable when my internet is throttled by Indonesian ISP, timeout everywhere... lovely... - "test_resolver" - ] ++ old.disabledTests; - }); - pillow = disablePyChecks pyprev.pillow; - cherrypy = disablePyChecks pyprev.cherrypy; - })]; - })]; - config.allowUnfree = true; - }; - }; + mkCommon = import ../../lib/mkCommon.nix; + mkSystem = import ../../lib/mkSystem.nix; in { "potato" = let - inherit (systemConfig "x86_64-linux") system pkgs; + inherit (mkSystem "x86_64-linux" nixpkgs) system pkgs; common = (mkCommon pkgs); in system-manager.lib.makeSystemConfig { inherit system; - specialArgs = { inherit inputs pkgs home-manager vars common; }; + specialArgs = { inherit inputs pkgs vars common; }; modules = [ ./configuration.nix - # home-manager.darwinModules.home-manager - # { - # home-manager.useGlobalPkgs = true; - # home-manager.useUserPackages = true; - # } ]; }; } diff --git a/.config/nix/users/default.nix b/.config/nix/users/default.nix new file mode 100644 index 0000000..801581f --- /dev/null +++ b/.config/nix/users/default.nix @@ -0,0 +1,30 @@ +{ inputs, nixpkgs, home-manager, vars, ... }: + +let + mkSystem = import ../lib/mkSystem.nix; +in +{ + # Host list + # Build with: `home-manager build --flake .#@` + # e.g. `home-manager build --flake .#"ziro@ThiccBook-Pro"` + # Switch to current build: `home-manager switch --flake .#@` + # + # If you're feeling lucky `home-manager build --flake .` or + # `home-manager switch --flake .` should be enough, since home-manager will + # search the correct @ on its own. + # + # You may need to run `scutil --set HostName ` if home-manager can't + # find your @. + + "ziro@ThiccBook-Pro" = + let + inherit (mkSystem "x86_64-darwin" nixpkgs) system pkgs; + in + home-manager.lib.homeManagerConfiguration { + inherit pkgs; + extraSpecialArgs = { inherit inputs pkgs home-manager vars; }; + modules = [ + ./ziro.nix + ]; + }; +} diff --git a/.config/nix/users/ziro.nix b/.config/nix/users/ziro.nix new file mode 100644 index 0000000..f53c970 --- /dev/null +++ b/.config/nix/users/ziro.nix @@ -0,0 +1,33 @@ +{ pkgs, config, vars, ... }: + +let + dirPrefix = if pkgs.stdenv.isDarwin then "/Users/" else "/home/"; +in { + home = { + username = "ziro"; + homeDirectory = dirPrefix + "ziro"; + }; + + programs = { + browserpass = { + enable = true; + browsers = [ "brave" "chrome" ]; # Arc and Chrome share the same `Application Support` dir, not sure why tbh. + }; + }; + + # Swap CapsLock with Esc for better vi-mode experience. + launchd.agents.CapsEscSwap = { + enable = true; + config = { + ProgramArguments = [ + "/usr/bin/hidutil" + "property" + "--set" + "{\"UserKeyMapping\":[{\"HIDKeyboardModifierMappingSrc\":0x700000039,\"HIDKeyboardModifierMappingDst\":0x700000029},{\"HIDKeyboardModifierMappingSrc\":0x700000029,\"HIDKeyboardModifierMappingDst\":0x700000039}]}" + ]; + RunAtLoad = true; + }; + }; + + home.stateVersion = "24.05"; +}