From 8c087c0eb3a0d4891ff83fc005792bbc20448136 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 30 Aug 2023 23:45:37 +0800 Subject: [PATCH] refactor: split system into modules --- flake.lock | 36 ++++++------ flake.nix | 9 ++- modules/homebrew.nix | 31 ++++++++++ modules/nix.nix | 35 +++++++++++ modules/packages.nix | 75 ++++++++++++++++++++++++ programs/go.nix | 8 +-- system.nix | 135 +++++-------------------------------------- users.nix | 17 ------ 8 files changed, 182 insertions(+), 164 deletions(-) create mode 100644 modules/homebrew.nix create mode 100644 modules/nix.nix create mode 100644 modules/packages.nix delete mode 100644 users.nix diff --git a/flake.lock b/flake.lock index 1f47836..fdd7cfe 100644 --- a/flake.lock +++ b/flake.lock @@ -71,11 +71,11 @@ ] }, "locked": { - "lastModified": 1692750383, - "narHash": "sha256-n5P5HOXuu23UB1h9PuayldnRRVQuXJLpoO+xqtMO3ws=", + "lastModified": 1693163878, + "narHash": "sha256-HXuyMUVaRSoIA602jfFuYGXt6AMZ+WUxuvLq8iJmYTA=", "owner": "ipetkov", "repo": "crane", - "rev": "ef5d11e3c2e5b3924eb0309dba2e1fea2d9062ae", + "rev": "43db881168bc65b568d36ceb614a0fc8b276191b", "type": "github" }, "original": { @@ -86,11 +86,11 @@ }, "darwin-custom-icons": { "locked": { - "lastModified": 1693056564, - "narHash": "sha256-hFZVorJ0jdTDqM0DKArtOyMIxVX14oNpqG+58j3WLKg=", + "lastModified": 1693410124, + "narHash": "sha256-DXjBumqDVHoTgB4JOZeDWMhYpgHmk9qoSziYFLclfL0=", "owner": "ryanccn", "repo": "nix-darwin-custom-icons", - "rev": "7001db539da6247a18e9021c2d387f72db005466", + "rev": "9095bdc551000d789ea0e829c98ec3d5c7a9e9d9", "type": "github" }, "original": { @@ -106,11 +106,11 @@ ] }, "locked": { - "lastModified": 1692089279, - "narHash": "sha256-4OcROiMbf+YF41n+KPx3cqiHs2KoY7pdDGyCvJow1p8=", + "lastModified": 1693198521, + "narHash": "sha256-xhH3T6j9JvT1UDLM1QJmtwrjJpA4MoZx2hPxJLrin7w=", "owner": "ryanccn", "repo": "discord-applemusic-rich-presence", - "rev": "f257c32c794ef6b09cddcaaa7be27a1f74d9683d", + "rev": "42d98b6d99a32ca5075b10c61e3446af97af7c8f", "type": "github" }, "original": { @@ -160,11 +160,11 @@ ] }, "locked": { - "lastModified": 1692763155, - "narHash": "sha256-qMrGKZ8c/q/mHO3ZdrcBPwiVVXPLLgXjY98Ejqb5kAA=", + "lastModified": 1693399033, + "narHash": "sha256-yXhiMo8MnE86sGtPIHAKaLHhmhe8v9tqGGotlUgKJvY=", "owner": "nix-community", "repo": "home-manager", - "rev": "6a20e40acaebf067da682661aa67da8b36812606", + "rev": "f5c15668f9842dd4d5430787d6aa8a28a07f7c10", "type": "github" }, "original": { @@ -195,11 +195,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1692934111, - "narHash": "sha256-9EEE59v/esKNMR5zKbLRV9NoRPYvERw5jHQOnfr47bk=", + "lastModified": 1693355128, + "narHash": "sha256-+ZoAny3ZxLcfMaUoLVgL9Ywb/57wP+EtsdNGuXUJrwg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1e44a037bbf4fcaba041436e65e87be88f3f495b", + "rev": "a63a64b593dcf2fe05f7c5d666eb395950f36bc9", "type": "github" }, "original": { @@ -262,11 +262,11 @@ ] }, "locked": { - "lastModified": 1693015707, - "narHash": "sha256-SFr93DYn502sVT9nB5U8/cKg1INyEk/jCeq8tHioz7Y=", + "lastModified": 1693361441, + "narHash": "sha256-TRFdMQj9wSKMduNqe/1xF8TzcPWEdcn/hKWcVcZ5fO8=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "e90223633068a44f0fb62374e0fa360ccc987292", + "rev": "1fb2aa49635e9f30b6fa211ab7c454f7175e1ba3", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index a4c4cac..31c9834 100644 --- a/flake.nix +++ b/flake.nix @@ -58,7 +58,9 @@ inputs.flake-compat.follows = "flake-compat"; }; - darwin-custom-icons.url = "github:ryanccn/nix-darwin-custom-icons"; + darwin-custom-icons = { + url = "github:ryanccn/nix-darwin-custom-icons"; + }; flake-utils = { url = "github:numtide/flake-utils"; @@ -83,12 +85,9 @@ home-manager.darwinModules.home-manager darwin-custom-icons.darwinModules.default ./system.nix - ./users.nix ]; - specialArgs = { - inherit inputs; - }; + specialArgs = {inherit inputs;}; }; }; } diff --git a/modules/homebrew.nix b/modules/homebrew.nix new file mode 100644 index 0000000..d3b76df --- /dev/null +++ b/modules/homebrew.nix @@ -0,0 +1,31 @@ +_: { + environment.variables = { + HOMEBREW_NO_ANALYTICS = "1"; + HOMEBREW_NO_INSECURE_REDIRECT = "1"; + HOMEBREW_NO_EMOJI = "1"; + }; + + homebrew = { + enable = true; + caskArgs.require_sha = true; + onActivation = { + autoUpdate = true; + cleanup = "uninstall"; + upgrade = true; + }; + + casks = let + noQuarantine = name: { + inherit name; + args = {no_quarantine = true;}; + }; + in [ + "blackhole-16ch" + (noQuarantine "eloston-chromium") + "sf-symbols" + "1password/tap/1password-cli" + ]; + + taps = ["1password/tap"]; + }; +} diff --git a/modules/nix.nix b/modules/nix.nix new file mode 100644 index 0000000..00f53fd --- /dev/null +++ b/modules/nix.nix @@ -0,0 +1,35 @@ +{ + pkgs, + inputs, + ... +}: { + services.nix-daemon.enable = true; + nix.package = pkgs.nix; + + nix.settings = { + experimental-features = "nix-command flakes"; + build-users-group = "nixbld"; + trusted-users = ["ryanccn"]; + auto-optimise-store = true; + extra-platforms = ["x86_64-darwin" "aarch64-darwin"]; + + extra-substituters = [ + "https://nix-community.cachix.org" + ]; + extra-trusted-public-keys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + }; + + nixpkgs = { + overlays = [ + inputs.attic.overlays.default + inputs.discord-applemusic-rich-presence.overlays.default + inputs.nyoom.overlays.default + (import ../overlays/ryan-mono-bin.nix) + ]; + + config.allowUnfree = true; + hostPlatform = "aarch64-darwin"; + }; +} diff --git a/modules/packages.nix b/modules/packages.nix new file mode 100644 index 0000000..b5ccc00 --- /dev/null +++ b/modules/packages.nix @@ -0,0 +1,75 @@ +{pkgs, ...}: { + environment.systemPackages = with pkgs; [ + nil + statix + alejandra + nixpkgs-fmt + + nix-melt + attic-client + cachix + direnv + + rustc + cargo + sccache + + fnm + deno + bun + + (python311.withPackages (ps: with ps; [pip])) + yt-dlp + xkcdpass + pipreqs + + libffi + openssl + + rust-analyzer + nodePackages.typescript-language-server + rustfmt + clippy + dprint + + age + bat + btop + cloudflared + doggo + doppler + du-dust + fd + ffmpeg + flyctl + fzf + gh + gen-license + gum + hyperfine + jq + just + mkcert + nerdfix + pscale + railway + ripgrep + silicon + tealdeer + tokei + vhs + vivid + watchexec + xh + zoxide + + typst + + packwiz + catppuccin-catwalk + + nyoom + spicetify-cli + exiftool + ]; +} diff --git a/programs/go.nix b/programs/go.nix index a4c83e0..cb51745 100644 --- a/programs/go.nix +++ b/programs/go.nix @@ -4,8 +4,8 @@ _: { goPath = ".go"; }; - home.file."Library/Application Support/go/env".text = '' - GOTOOLCHAIN=path - GOPROXY=direct - ''; + home.sessionVariables = { + GOTOOLCHAIN = "path"; + GOPROXY = "direct"; + }; } diff --git a/system.nix b/system.nix index 4655394..b55d94b 100644 --- a/system.nix +++ b/system.nix @@ -3,109 +3,12 @@ inputs, ... }: { - environment.systemPackages = with pkgs; [ - nil - alejandra - nixpkgs-fmt - attic-client - statix - cachix - direnv - - rustc - cargo - - sccache - deno - fnm - bun - - (python311.withPackages (ps: - with ps; [ - pip - yt-dlp - xkcdpass - ])) - libffi - openssl - - rust-analyzer - nodePackages.typescript-language-server - rustfmt - clippy - dprint - - age - bat - btop - cloudflared - doggo - doppler - du-dust - fd - ffmpeg - flyctl - fzf - gh - gen-license - gum - hyperfine - jq - just - mkcert - nerdfix - pscale - railway - ripgrep - silicon - tealdeer - tokei - vhs - vivid - watchexec - xh - zoxide - - typst - - packwiz - catppuccin-catwalk - - nyoom - spicetify-cli - exiftool + imports = [ + ./modules/nix.nix + ./modules/packages.nix + ./modules/homebrew.nix ]; - services.nix-daemon.enable = true; - nix.package = pkgs.nix; - - nix.settings = { - experimental-features = "nix-command flakes"; - build-users-group = "nixbld"; - trusted-users = ["ryanccn"]; - auto-optimise-store = true; - extra-platforms = ["x86_64-darwin" "aarch64-darwin"]; - - extra-substituters = [ - "https://nix-community.cachix.org" - ]; - extra-trusted-public-keys = [ - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - ]; - }; - - nixpkgs = { - overlays = [ - inputs.attic.overlays.default - inputs.discord-applemusic-rich-presence.overlays.default - inputs.nyoom.overlays.default - (import ./overlays/ryan-mono-bin.nix) - ]; - - config.allowUnfree = true; - hostPlatform = "aarch64-darwin"; - }; - system.activationScripts.extraActivation = { text = '' set -eo pipefail @@ -128,28 +31,20 @@ programs.fish.enable = true; programs.zsh.enable = true; - homebrew = { - enable = true; - caskArgs.require_sha = true; - onActivation = { - autoUpdate = true; - cleanup = "uninstall"; - upgrade = true; + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + + extraSpecialArgs = { + ctpModule = inputs.catppuccin.homeManagerModules.catppuccin; + discord-applemusic-rich-presence = inputs.discord-applemusic-rich-presence.homeManagerModules.default; }; - casks = let - noQuarantine = name: { - inherit name; - args = {no_quarantine = true;}; - }; - in [ - "blackhole-16ch" - (noQuarantine "eloston-chromium") - "sf-symbols" - "1password/tap/1password-cli" - ]; + users.ryanccn = import ./home.nix; + }; - taps = ["1password/tap"]; + users.users.ryanccn = { + home = "/Users/ryanccn"; }; system.stateVersion = 4; diff --git a/users.nix b/users.nix deleted file mode 100644 index 9bda7be..0000000 --- a/users.nix +++ /dev/null @@ -1,17 +0,0 @@ -{inputs, ...}: { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - - extraSpecialArgs = { - ctpModule = inputs.catppuccin.homeManagerModules.catppuccin; - discord-applemusic-rich-presence = inputs.discord-applemusic-rich-presence.homeManagerModules.default; - }; - - users.ryanccn = import ./home.nix; - }; - - users.users.ryanccn = { - home = "/Users/ryanccn"; - }; -}