From 8d2806d5bc9692bf502e72e274ba71eeabefb9ae Mon Sep 17 00:00:00 2001 From: Alina Sireneva Date: Sun, 3 Mar 2024 06:32:03 +0300 Subject: [PATCH] initial darwin --- flake.lock | 21 ++++++++++++ flake.nix | 30 ++++++++++++---- hosts/koi/configuration.nix | 2 +- hosts/teidesu-osx/configuration.nix | 42 +++++++++++++++++++++++ switch | 10 +++++- users/teidesu/common.nix | 17 +++++++++ users/teidesu/darwin.nix | 19 ++++++++++ users/teidesu/{default.nix => server.nix} | 16 ++------- users/teidesu/zsh.nix | 23 +++++++++++-- 9 files changed, 155 insertions(+), 25 deletions(-) create mode 100644 hosts/teidesu-osx/configuration.nix create mode 100644 users/teidesu/common.nix create mode 100644 users/teidesu/darwin.nix rename users/teidesu/{default.nix => server.nix} (52%) diff --git a/flake.lock b/flake.lock index 470aedc..e433c4a 100644 --- a/flake.lock +++ b/flake.lock @@ -143,6 +143,26 @@ "type": "github" } }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709348262, + "narHash": "sha256-eYTA1uZtYGFKrDOKiAz1wlE6aIC9WSdBNF8bSS818zM=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "8a15cb36fffa0b5fbe31ef16ede0a479bef4b365", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1704194953, @@ -179,6 +199,7 @@ "bootspec-secureboot": "bootspec-secureboot", "home-manager": "home-manager_2", "nil": "nil", + "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs", "vscode-server": "vscode-server" } diff --git a/flake.nix b/flake.nix index de35a8a..def5e8d 100755 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,9 @@ url = "github:nix-community/home-manager/master"; inputs.nixpkgs.follows = "nixpkgs"; }; + + nix-darwin.url = "github:LnL7/nix-darwin"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = @@ -45,26 +48,39 @@ , agenix , bootspec-secureboot , home-manager + , nix-darwin , ... }: let - makeNixosSystem = obj: nixpkgs.lib.nixosSystem (obj // { - specialArgs = (obj.specialArgs or { }) // { - inherit inputs; - abs = path: ./. + ("/" + path); - }; - }); + specialArgs = { + inherit inputs; + abs = path: ./. + ("/" + path); + }; in { nixosConfigurations = { - koi = makeNixosSystem { + koi = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ agenix.nixosModules.default bootspec-secureboot.nixosModules.bootspec-secureboot home-manager.nixosModules.home-manager + { home-manager.extraSpecialArgs = specialArgs; } ./hosts/koi/configuration.nix ]; + inherit specialArgs; + }; + }; + + darwinConfigurations = { + teidesu-osx = nix-darwin.lib.darwinSystem { + modules = [ + agenix.darwinModules.default + home-manager.darwinModules.home-manager + { home-manager.extraSpecialArgs = specialArgs; } + ./hosts/teidesu-osx/configuration.nix + ]; + inherit specialArgs; }; }; }; diff --git a/hosts/koi/configuration.nix b/hosts/koi/configuration.nix index 9f5429d..5191bbb 100755 --- a/hosts/koi/configuration.nix +++ b/hosts/koi/configuration.nix @@ -7,7 +7,7 @@ { imports = [ (abs "hosts/nixos-common.nix") - (abs "users/teidesu/default.nix") + (abs "users/teidesu/server.nix") ./hardware-configuration.nix ./partials/fde.nix diff --git a/hosts/teidesu-osx/configuration.nix b/hosts/teidesu-osx/configuration.nix new file mode 100644 index 0000000..72bb847 --- /dev/null +++ b/hosts/teidesu-osx/configuration.nix @@ -0,0 +1,42 @@ +{ pkgs +, abs +, inputs +, ... +}: + +{ + nix = { + settings.experimental-features = [ "nix-command" "flakes" ]; + settings.trusted-users = [ "@admin" ]; + + useDaemon = true; + }; + nixpkgs.hostPlatform = "aarch64-darwin"; + services.nix-daemon.enable = true; + + age.identityPaths = [ + "/Users/teidesu/.ssh/agenix_key" + ]; + + security.pam.enableSudoTouchIdAuth = true; + + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + + programs.zsh.enable = true; + + users.users.teidesu = { + home = "/Users/teidesu"; + }; + + home-manager.users.teidesu = { pkgs, ... }: { + imports = [ + (abs "users/teidesu/darwin.nix") + + ./arc-setup.nix + ]; + }; + + system.stateVersion = 4; +} + diff --git a/switch b/switch index 3acec4a..2ae2302 100755 --- a/switch +++ b/switch @@ -23,4 +23,12 @@ if [ "$1" == "boot" ]; then shift fi -sudo nixos-rebuild $cmd --flake . $args $@ \ No newline at end of file +if [ "$(uname)" == "Darwin" ]; then + if command -v darwin-rebuild &> /dev/null; then + darwin-rebuild switch --flake . $args $@ + else + nix --extra-experimental-features nix-command --extra-experimental-features flakes run nix-darwin -- switch --flake . $args $@ + fi +else + sudo nixos-rebuild $cmd --flake . $args $@ +fi \ No newline at end of file diff --git a/users/teidesu/common.nix b/users/teidesu/common.nix new file mode 100644 index 0000000..bffefd7 --- /dev/null +++ b/users/teidesu/common.nix @@ -0,0 +1,17 @@ +{ pkgs, inputs, ... }: { + imports = [ + ./zsh.nix + ]; + + home.stateVersion = "23.11"; + + home.packages = with pkgs; [ + tree + nixpkgs-fmt + htop + jq + micro + inputs.nil.packages.${system}.default + inputs.agenix.packages.${system}.default + ]; +} \ No newline at end of file diff --git a/users/teidesu/darwin.nix b/users/teidesu/darwin.nix new file mode 100644 index 0000000..c016237 --- /dev/null +++ b/users/teidesu/darwin.nix @@ -0,0 +1,19 @@ +{ abs, pkgs, lib, inputs, ... }: + +{ + imports = [ + ./common.nix + ]; + + home.packages = with pkgs; [ + scc + ripgrep + fnm + aria2 + ffmpeg + hyfetch + wget + watch + curl + ]; +} diff --git a/users/teidesu/default.nix b/users/teidesu/server.nix similarity index 52% rename from users/teidesu/default.nix rename to users/teidesu/server.nix index 69ed1f6..bb68d24 100644 --- a/users/teidesu/default.nix +++ b/users/teidesu/server.nix @@ -1,4 +1,4 @@ -{ abs, pkgs, inputs, ... }: +{ abs, pkgs, lib, inputs, ... }: { users.users.teidesu = { @@ -13,20 +13,10 @@ home-manager.users.teidesu = { pkgs, ... }: { imports = [ + ./common.nix inputs.vscode-server.homeModules.default - ./zsh.nix ]; - services.vscode-server.enable = true; - home.stateVersion = "23.11"; - - home.packages = with pkgs; [ - tree - nixpkgs-fmt - htop - jq - inputs.nil.packages.${system}.default - inputs.agenix.packages.${system}.default - ]; + services.vscode-server.enable = true; }; } diff --git a/users/teidesu/zsh.nix b/users/teidesu/zsh.nix index ac7beea..3781e16 100644 --- a/users/teidesu/zsh.nix +++ b/users/teidesu/zsh.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: { programs.zsh = { @@ -17,13 +17,30 @@ shellAliases = { "rm" = "rm -f"; - "systemctl" = "sudo systemctl"; "entervenv" = "source venv/bin/activate"; + } // lib.optionalAttrs (pkgs.stdenv.isLinux) { + "systemctl" = "sudo systemctl"; }; initExtra = '' unsetopt correct_all - export CURRENT_BG="$(( `hostname | cksum | cut -f 1 -d ' '` % 255 ))" + + CURRENT_BG="$(( `hostname | cksum | cut -f 1 -d ' '` % 255 ))" + CASE_SENSITIVE="false" + HYPHEN_INSENSITIVE="true" + ENABLE_CORRECTION="true" + COMPLETION_WAITING_DOTS="true" + ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=5" + + if command -v micro &> /dev/null; then + export EDITOR="micro" + elif command -v nano &> /dev/null; then + export EDITOR="nano" + fi + + if command -v fnm &> /dev/null; then + eval "$(fnm env)" + fi ''; }; }