From 47f202fcd382aa2950c5739d015bc6eac870b30e Mon Sep 17 00:00:00 2001 From: Johan Date: Sat, 20 May 2023 09:16:27 +0200 Subject: [PATCH] Add support for Darwin (aarch64) (#37) * Add support for Darwin (aarch64) * Fix home directory for MacOS * Edit gitconfig path * Add podman See related issue for needed workarounds on Mac: https://github.com/NixOS/nixpkgs/issues/169118 * Add mac to wireguard config --- Makefile | 27 ++++++++++++++++++++++----- README.md | 15 ++++++++++++--- dotfiles/git/gitconfig | 2 ++ flake.lock | 21 +++++++++++++++++++++ flake.nix | 30 ++++++++++++++++++++++-------- home/cli.nix | 13 ++++++++----- home/dev.nix | 10 ++++------ home/firefox.nix | 6 +++++- hosts/airm2/default.nix | 10 ++++++++++ hosts/airm2/home.nix | 25 +++++++++++++++++++++++++ sys/wireguard.nix | 8 ++++++++ 11 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 hosts/airm2/default.nix create mode 100644 hosts/airm2/home.nix diff --git a/Makefile b/Makefile index 3805f35..ca1a033 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,31 @@ -.PHONY: rb-switch +UNAME := $(shell uname) + rb-switch: +ifeq ($(UNAME), Darwin) + echo "Switching configuration on $(UNAME)" + darwin-rebuild switch --flake . +else + echo "Switching configuration on $(UNAME)" sudo nixos-rebuild switch --use-remote-sudo --flake . - +endif rb-test: +ifeq ($(UNAME), Linux) sudo nixos-rebuild test --use-remote-sudo --flake . +else + echo "Unsupported system $(UNAME)" +endif rb-boot: +ifeq ($(UNAME), Linux) sudo nixos-rebuild boot --use-remote-sudo --flake . +else + echo "Unsupported system $(UNAME)" +endif -.PHONY: install install: - ln -T -fs $(PWD)/dotfiles/git/gitconfig ~/.gitconfig - ln -T -fs $(PWD)/dotfiles/autostart/activitywatch.desktop ~/.config/autostart/activitywatch.desktop + ln -fs $(PWD)/dotfiles/git/gitconfig ~/.gitconfig + +mac-update-zshrc: + echo 'if test -e /etc/static/zshrc; then . /etc/static/zshrc; fi' | sudo tee -a /etc/zshrc + +.PHONY: rb-switch rb-test rb-boot install mac-update-zshrc diff --git a/README.md b/README.md index 34818ef..00653a3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# OS dotfiles for NixOS +# OS dotfiles for Nix(OS) -This repository configures all of my digital devices that run ✨ NixOS ✨ ! +This repository configures all of my digital devices that run ✨ Nix(OS) ✨ ! ## Help @@ -21,12 +21,17 @@ looking elsewhere first: A machine, such as a server or laptop, is called a *host*. -Host configurations live in the [hosts](./hosts) directory. The configuration of a host is comprised of three parts: +Host configurations live in the [hosts](./hosts) directory. + +If a host is using NixOS, the configuration of a host is comprised of three +parts: 1. a hardware configuration 2. a system configuration 3. a home configuration +If a host is using MacOS, the configuration is comprised only of a home configuration. + All of these files are imported by [./flake.nix](./flake.nix). ### System services, apps, ... @@ -45,3 +50,7 @@ Software and configuration files in user-land live in [home](./home) and is conf 4. Done! Note that the hostname of the new device must match the name of the host in [./flake.nix](./flake.nix). + +### MacOS specifics + +For MacOS devices, some caveats apply. To set up my repository for compatibility with MacOS, I followed this excellent blog post: https://xyno.space/post/nix-darwin-introduction. diff --git a/dotfiles/git/gitconfig b/dotfiles/git/gitconfig index 2a1f5a0..b3d087c 100644 --- a/dotfiles/git/gitconfig +++ b/dotfiles/git/gitconfig @@ -1,5 +1,7 @@ [include] path = ~/os/dotfiles/git/gituser-default +[include] + path = ~/code/os/dotfiles/git/gituser-default [includeIf "gitdir:~/code/meraki/**"] path = ~/os/dotfiles/git/gituser-meraki [includeIf "gitdir:~/code/modcam/**"] diff --git a/flake.lock b/flake.lock index dabbecc..9f4bf4a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1684343812, + "narHash": "sha256-ZTEjiC8PDKeP8JRchuwcFXUNlMcyQ4U+DpyVZ3pB6Q4=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "dfbdabbb3e797334172094d4f6c0ffca8c791281", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": "nixpkgs", @@ -54,6 +74,7 @@ }, "root": { "inputs": { + "darwin": "darwin", "home-manager": "home-manager", "nixpkgs": "nixpkgs_2", "unstable": "unstable" diff --git a/flake.nix b/flake.nix index 31b4c0c..01593ca 100644 --- a/flake.nix +++ b/flake.nix @@ -3,17 +3,13 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; unstable.url = "github:nixos/nixpkgs/nixos-unstable"; home-manager.url = "github:nix-community/home-manager/release-22.11"; + darwin.url = "github:lnl7/nix-darwin"; + darwin.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, unstable, home-manager, ... }: + outputs = { self, nixpkgs, unstable, home-manager, darwin, ... }: { - nixosConfigurations = { - keeper = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./hosts/keeper - home-manager.nixosModules.home-manager - { + nixosConfigurations = { keeper = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ ./hosts/keeper home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.users.johanan = { ... }: { @@ -84,6 +80,24 @@ ]; }; }; + + darwinConfigurations = { + airm2 = darwin.lib.darwinSystem { + system = "aarch64-darwin"; + modules = [ + ./hosts/airm2 + home-manager.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.johanan = { ... }: { + _module.args.unstable = unstable; + imports = [ ./hosts/airm2/home.nix ]; + }; + } + ]; + }; + }; }; } diff --git a/home/cli.nix b/home/cli.nix index 0c6bfdc..61e7648 100644 --- a/home/cli.nix +++ b/home/cli.nix @@ -6,6 +6,12 @@ let cfg = config.skogsbrus.cli; inherit (lib) mkOption mkEnableOption types; + linuxPackages = with pkgs; [ + iputils # Not supported on Darwin (22-05-19) + traceroute # Not supported on Darwin (22-05-19) + usbutils # Not supported on Darwin (22-05-19) + iw # Not supported on Darwin (22-05-19) + ]; in { config = { @@ -16,11 +22,8 @@ in curl dig iperf - iw mtr openssl - iputils - traceroute wget # build tools @@ -45,9 +48,9 @@ in tmux # misc - usbutils zsh - ]; + ] ++ (if stdenv.isLinux then linuxPackages else []); + programs.fzf = { enable = true; diff --git a/home/dev.nix b/home/dev.nix index ac97924..15e8841 100644 --- a/home/dev.nix +++ b/home/dev.nix @@ -35,10 +35,10 @@ in config = mkIf cfg.enable { home.packages = with pkgs; [ jetbrains-mono - docker + podman + qemu postgresql - zeal - ] + ] ++ (if stdenv.isLinux then [ zeal ] else [ ]) ++ cfg.extraPackages ++ (if cfg.enableAll || cfg.cuda then [ pkgs.cudatoolkit_11 ] else [ ]) ++ (if cfg.enableAll || cfg.k8s then [ @@ -58,12 +58,10 @@ in ] else [ ]) ++ (if cfg.enableAll || cfg.cxx then [ pkgs.cmake - pkgs.coz pkgs.gcc pkgs.gdb pkgs.gnumake - pkgs.valgrind - ] else [ ]) + ] else [ ] ++ (if stdenv.isLinux then [ pkgs.coz pkgs.valgrind ] else [ ])) ++ (if cfg.enableAll || cfg.corporate then [ pkgs.go-jira ] else [ ]); diff --git a/home/firefox.nix b/home/firefox.nix index 66f071f..0a705e3 100644 --- a/home/firefox.nix +++ b/home/firefox.nix @@ -3,12 +3,16 @@ , pkgs , ... }: +let + cfg = config.skogsbrus.firefox; + inherit (lib) mkIf; +in { options.skogsbrus.firefox = { enable = lib.mkEnableOption "firefox"; }; - config = { + config = mkIf cfg.enable { programs.firefox = { enable = true; profiles.johanan = { diff --git a/hosts/airm2/default.nix b/hosts/airm2/default.nix new file mode 100644 index 0000000..679c7d3 --- /dev/null +++ b/hosts/airm2/default.nix @@ -0,0 +1,10 @@ +{ pkgs, ... }: +{ + users.users.johanan = { + name = "johanan"; + home = "/Users/johanan"; + }; + + services.nix-daemon.enable = true; + programs.zsh.enable = true; +} diff --git a/hosts/airm2/home.nix b/hosts/airm2/home.nix new file mode 100644 index 0000000..b6776e6 --- /dev/null +++ b/hosts/airm2/home.nix @@ -0,0 +1,25 @@ +{ config +, lib +, pkgs +, modulesPath +, ... +}: +{ + imports = [ + ../../home + ]; + + skogsbrus = { + dev = { + enable = true; + aws = true; + cxx = true; + k8s = true; + terraform = true; + }; + lspServers = { + enable = true; + enableAll = true; + }; + }; +} diff --git a/sys/wireguard.nix b/sys/wireguard.nix index 6b184f3..f76afce 100644 --- a/sys/wireguard.nix +++ b/sys/wireguard.nix @@ -81,6 +81,14 @@ in "${cfg.subnet}.4/32" ]; } + { + # airm2 + publicKey = "h4QkyuAWO7Iq3ZlHOSIjmvFGTuqCLhZSr94HDNl4xyw="; + presharedKeyFile = "/home/johanan/os/secrets/wireguard-psk-airm2.key"; + allowedIPs = [ + "${cfg.subnet}.5/32" + ]; + } ] else [ ]) ++ (if !cfg.server then [{ # Router