From 2faf9059b8de5288d82b37afb4f6a63f7113f199 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 11 Jul 2024 11:51:23 +0700 Subject: [PATCH] refactor: Split nix config --- .config/nix/darwin/configuration.nix | 60 ++++++++++++++++++++ .config/nix/darwin/default.nix | 42 ++++++++++++++ .config/nix/flake.nix | 76 +++----------------------- .config/nvim/lua/null/plugins/init.lua | 10 ++++ 4 files changed, 121 insertions(+), 67 deletions(-) create mode 100644 .config/nix/darwin/configuration.nix create mode 100644 .config/nix/darwin/default.nix diff --git a/.config/nix/darwin/configuration.nix b/.config/nix/darwin/configuration.nix new file mode 100644 index 0000000..a0b2998 --- /dev/null +++ b/.config/nix/darwin/configuration.nix @@ -0,0 +1,60 @@ +{ pkgs, vars, ... }: + +let + python = pkgs.python310Full.override { + # FIXME: Build failed, maybe override postInstall instead? + #enableFramework = true; + }; +in +{ + # List packages installed in system profile. To search by name, run: + # $ nix-env -qaP | grep wget + environment.systemPackages = [ + pkgs.zsh + pkgs.git + pkgs.vim + pkgs.neovim + pkgs.pass + pkgs.passExtensions.pass-otp + pkgs.pinentry_mac + pkgs.gnupg + pkgs.htop-vim + python + # FIXME: Build failed, dnspython pytest keep returning FAILED caused by timeout. Maybe find a way to bypass check for them + # (pkgs.poetry.override { python3 = python; }) + pkgs.python310Packages.pip + pkgs.python310Packages.tkinter + pkgs.fastfetch + pkgs.eza + pkgs.lf + pkgs.wimlib + pkgs.google-cloud-sdk + pkgs.nmap + pkgs.cargo + pkgs.android-tools + # pkgs.browserpass + pkgs.coreutils-full + ]; + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + # nix.package = pkgs.nix; + + # Necessary for using flakes on this system. + nix.settings.experimental-features = "nix-command flakes"; + + # Create /etc/zshrc that loads the nix-darwin environment. + programs.zsh.enable = true; # default shell on catalina + # programs.fish.enable = true; + + # Set Git commit hash for darwin-version. + system.configurationRevision = vars.rev or null; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; + + # The platform the configuration will be used on. + nixpkgs.hostPlatform = vars.arch; +} +# vim:set ts=2 sw=2 et: diff --git a/.config/nix/darwin/default.nix b/.config/nix/darwin/default.nix new file mode 100644 index 0000000..925b0e7 --- /dev/null +++ b/.config/nix/darwin/default.nix @@ -0,0 +1,42 @@ +{ inputs, nixpkgs, nix-darwin, vars, ... }: + +let + systemConfig = system: { + system = system; + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + }; +in +{ + # Host list + # Build with darwin flake: `darwin-rebuild build --flake .#` + # e.g. `darwin-rebuild build --flake .#"ThiccBook-Pro"` + # Switch to current build: `darwin-rebuild switch --flake .#` + + # Lenovo ThinkPad L460; Intel Core i5-6300U + "ThiccBook-Pro" = + let + vars.arch = "x86_64-darwin"; + inherit (systemConfig vars.arch) system pkgs; + in + nix-darwin.lib.darwinSystem { + inherit system; + specialArgs = { inherit inputs pkgs vars; }; + modules = [ ./configuration.nix ]; + }; + + # Imaginary M1, just for reference + MacBookProM1 = + let + vars.arch = "aarch64-darwin"; + inherit (systemConfig vars.arch) system pkgs; + in + nix-darwin.lib.darwinSystem { + inherit system; + specialArgs = { inherit inputs pkgs vars; }; + modules = [ ./configuration.nix ]; + }; +} +# vim:set ts=2 sw=2 et: diff --git a/.config/nix/flake.nix b/.config/nix/flake.nix index 4ba86fe..4d1a1a0 100644 --- a/.config/nix/flake.nix +++ b/.config/nix/flake.nix @@ -1,5 +1,5 @@ { - description = "Example Darwin system flake"; + description = "null2264's Nix Setup"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin"; @@ -9,75 +9,17 @@ outputs = inputs@{ self, nix-darwin, nixpkgs }: let - configuration = { pkgs, ... }: let - python = pkgs.python310Full.override { - # FIXME: Build failed, maybe override postInstall instead? - #enableFramework = true; - }; - in - { - # List packages installed in system profile. To search by name, run: - # $ nix-env -qaP | grep wget - environment.systemPackages = [ - pkgs.zsh - pkgs.git - pkgs.vim - pkgs.neovim - pkgs.pass - pkgs.passExtensions.pass-otp - pkgs.pinentry_mac - pkgs.gnupg - pkgs.htop-vim - python - # FIXME: Build failed, dnspython pytest keep returning FAILED caused by timeout. Maybe find a way to bypass check for them - # (pkgs.poetry.override { python3 = python; }) - pkgs.python310Packages.pip - pkgs.python310Packages.tkinter - pkgs.fastfetch - pkgs.eza - pkgs.lf - pkgs.wimlib - pkgs.google-cloud-sdk - pkgs.nmap - pkgs.cargo - pkgs.android-tools - # pkgs.browserpass - pkgs.coreutils-full - ]; - - # Auto upgrade nix package and the daemon service. - services.nix-daemon.enable = true; - # nix.package = pkgs.nix; - - # Necessary for using flakes on this system. - nix.settings.experimental-features = "nix-command flakes"; - - # Create /etc/zshrc that loads the nix-darwin environment. - programs.zsh.enable = true; # default shell on catalina - # programs.fish.enable = true; - - # Set Git commit hash for darwin-version. - system.configurationRevision = self.rev or self.dirtyRev or null; - - # Used for backwards compatibility, please read the changelog before changing. - # $ darwin-rebuild changelog - system.stateVersion = 4; - - # The platform the configuration will be used on. - nixpkgs.hostPlatform = "x86_64-darwin"; + vars = { + rev = self.rev or self.dirtyRev or null; }; in { - # TODO: Split configurations - - # Build darwin flake using: - # $ darwin-rebuild build --flake .#ThiccBook-Pro - darwinConfigurations."ThiccBook-Pro" = nix-darwin.lib.darwinSystem { - modules = [ configuration ]; - }; - - # Expose the package set, including overlays, for convenience. - darwinPackages = self.darwinConfigurations."ThiccBook-Pro".pkgs; + darwinConfigurations = ( + import ./darwin { + inherit (nixpkgs) lib; + inherit inputs nixpkgs nix-darwin vars; + } + ); }; } # vim:set ts=2 sw=2 et: diff --git a/.config/nvim/lua/null/plugins/init.lua b/.config/nvim/lua/null/plugins/init.lua index b813a30..d4eda63 100644 --- a/.config/nvim/lua/null/plugins/init.lua +++ b/.config/nvim/lua/null/plugins/init.lua @@ -55,6 +55,16 @@ return { keys = { { "gc", mode = { "n", "v", "i" } }, }, + init = function () + vim.api.nvim_create_autocmd("FileType", { + pattern = { "nix" }, + callback = function() + vim.opt_local.commentstring = "# %s" + end, + group = generalSettingsGroup, + }) + + end, }, { "dstein64/vim-startuptime",