diff --git a/darwin-configuration.nix b/darwin-configuration.nix new file mode 100644 index 0000000..8f2bcdd --- /dev/null +++ b/darwin-configuration.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = [ + ./modules + ./hosts/work + ]; +} diff --git a/flake.lock b/flake.lock index a5289c9..5ad0509 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,27 @@ "type": "github" } }, + "darwin": { + "inputs": { + "nixpkgs": [ + "nixunstable" + ] + }, + "locked": { + "lastModified": 1662478528, + "narHash": "sha256-Myjd0HPL5lXri3NXOcJ6gP7IKod2eMweQBKM4uxgEGw=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "3b69bf3cc26ae19de847bfe54d6ab22d7381a90a", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -89,11 +110,11 @@ }, "nurpkgs": { "locked": { - "lastModified": 1662437281, - "narHash": "sha256-2OiUGv6m1lnwHFSbw/ebzLilSGykTtDaquBvZWHr+2Q=", + "lastModified": 1662716683, + "narHash": "sha256-NU+YC3jT99fp8CPhtm+mgM/c8PP6DwIRzIGkuCO3Vss=", "owner": "nix-community", "repo": "NUR", - "rev": "e77801698156c004515b61f3000190dd40348ab8", + "rev": "44284844e8329dfd07163965d0b9e2c3192911bc", "type": "github" }, "original": { @@ -105,6 +126,7 @@ "root": { "inputs": { "agenix": "agenix", + "darwin": "darwin", "home-manager": "home-manager", "nixpkgs": "nixpkgs_2", "nixunstable": "nixunstable", diff --git a/flake.nix b/flake.nix index a311e78..ad8851f 100644 --- a/flake.nix +++ b/flake.nix @@ -12,17 +12,29 @@ url = "github:nix-community/home-manager/release-22.05"; inputs.nixpkgs.follows = "nixpkgs"; }; + darwin = { + url = "github:lnl7/nix-darwin/master"; + inputs.nixpkgs.follows = "nixunstable"; + }; nurpkgs.url = "github:nix-community/NUR"; }; - outputs = {nixpkgs, nixunstable, agenix, home-manager, nurpkgs, self}@inputs: + outputs = {nixpkgs, nixunstable, agenix, home-manager, nurpkgs, self, ...}@inputs: let local_overlay = import ./overlays; + overlays = [ + local_overlay + nurpkgs.overlay + ]; + overlaid = system: import nixpkgs { + inherit overlays system; + }; mods = hostname: [ - { nixpkgs.overlays = [ nurpkgs.overlay local_overlay ]; } + { nixpkgs.overlays = overlays; } agenix.nixosModule - ./modules + ./modules-all + ./modules-linux ./hosts/${hostname} home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; @@ -39,6 +51,14 @@ modules = mods name; }; + darwinMods = hostname: [ + { nixpkgs.overlays = overlays; } + inputs.agenix.nixosModule + ./modules-all + ./modules-darwin + ./hosts/${hostname} + ]; + unstableMachine = system: name: inputs.nixunstable.lib.nixosSystem { system = system; modules = mods name; @@ -64,7 +84,16 @@ "iso" = machine "x86_64-linux" "iso"; }; + darwinConfigurations = { + "C02G48H8MD6R" = inputs.darwin.lib.darwinSystem { + system = "x86_64-darwin"; + specialArgs = inputs; + modules = darwinMods "work"; + }; + }; + defaultPackage."x86_64-linux" = inputs.self.nixosConfigurations.iso.config.system.build.isoImage; + defaultPackage."x86_64-darwin" = inputs.self.darwinConfigurations.C02G48H8MD6R.system; homeConfigurations = ( import ./home { @@ -72,7 +101,12 @@ } ); - overlay = local_overlay; - modules = import ./modules; + overlays = local_overlay; + modules = import [ + ./modules-all + ./modules-linux + ./modules-darwin + ]; + packages = import ./overlays/packages.nix { pkgs = nixpkgs; }; }; } diff --git a/home/default.nix b/home/default.nix index ec0ed68..e27b5af 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,25 +1,32 @@ { nixpkgs, nurpkgs, home-manager, username ? builtins.getEnv "USER", ... }: let - homeDirectory = if username == "root" then "/root" else "/home/${username}"; - configDir = "${homeDirectory}/.config"; - - pkgs = import nixpkgs { - config.allowUnfree = true; - config.xdg.configHome = configDir; - overlays = [ - nurpkgs.overlay - (import ../overlays) - ]; - }; - - nur = import nurpkgs { - inherit pkgs; - nur = pkgs; - }; + home = system: + if username == "root" then "/root" else + ( if ( nixpkgs.lib.hasSuffix "-darwin" system ) then "/Users/${username}" else "/home/${username}" ); mkhome = system: gui: - home-manager.lib.homeManagerConfiguration rec { + let + homeDirectory = home system; + + configDir = "${homeDirectory}/.config"; + + pkgs = import nixpkgs { + config.allowUnfree = true; + config.xdg.configHome = configDir; + overlays = [ + nurpkgs.overlay + (import ../overlays) + ]; + }; + + nur = import nurpkgs { + inherit pkgs; + nur = pkgs; + }; + + + in home-manager.lib.homeManagerConfiguration rec { inherit pkgs system username homeDirectory; stateVersion = "22.05"; configuration = import ./home.nix username { @@ -32,4 +39,5 @@ in { "aarch64-nogui" = mkhome "aarch64-linux" false; "x86_64-gui" = mkhome "x86_64-linux" true; "x86_64-nogui" = mkhome "x86_64-linux" false; + "x86_64-darwin" = mkhome "x86_64-darwin" true; } diff --git a/home/gui/chat.nix b/home/gui/chat.nix index ffc9f8b..a6ec78f 100644 --- a/home/gui/chat.nix +++ b/home/gui/chat.nix @@ -1,8 +1,9 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: { - home.packages = with pkgs; [ + home.packages = with pkgs; ( if ( lib.hasSuffix "-darwin" pkgs.system) then + [] else + [ element-desktop - nheko - ]; + ]); } diff --git a/home/gui/default.nix b/home/gui/default.nix index 8ce60ed..adf2f0e 100644 --- a/home/gui/default.nix +++ b/home/gui/default.nix @@ -8,11 +8,17 @@ ]; home.packages = with pkgs; [ - bitwarden - gnucash - handbrake - onlyoffice-bin synology-drive-client - vlc - ]; + ] ++ ( if pkgs.system == "x86_64-darwin" then + [ + libreoffice-bin + ] else + [ + bitwarden + gnucash + handbrake + onlyoffice-bin + vlc + ] + ); } diff --git a/home/gui/firefox.nix b/home/gui/firefox.nix index d1b97c7..e3974e0 100644 --- a/home/gui/firefox.nix +++ b/home/gui/firefox.nix @@ -1,9 +1,10 @@ { lib, pkgs, ... }: let - ffPkgs = wayland: if wayland - then [ pkgs.firefox-wayland ] - else [ pkgs.firefox ]; + # For now, we ignore this and don't install it + ffPkgs = if ( lib.hasSuffix "-darwin" pkgs.system ) + then pkgs.firefox-unwrapped + else pkgs.firefox-wayland.override { cfg.enableGnomeExtensions = true; }; vars = { MOZ_ENABLE_WAYLAND = "1"; @@ -12,12 +13,8 @@ let in with lib; { programs.firefox = { - enable = true; - package = pkgs.firefox-wayland.override { - cfg = { - enableGnomeExtensions = true; - }; - }; + enable = (if (lib.hasSuffix "-darwin" pkgs.system) then false else true); + package = ffPkgs; extensions = with pkgs.nur.repos.rycee.firefox-addons; [ bitwarden octotree diff --git a/home/gui/terminal.nix b/home/gui/terminal.nix index 7d90605..822b30e 100644 --- a/home/gui/terminal.nix +++ b/home/gui/terminal.nix @@ -1,7 +1,7 @@ -{ ... }: +{ lib, pkgs, ... }: { - programs.gnome-terminal = { + programs.gnome-terminal = lib.mkIf ( pkgs.system != "x86_64-darwin") { enable = true; showMenubar = true; themeVariant = "dark"; diff --git a/home/ssh.nix b/home/ssh.nix index 56d239a..fcc2d3f 100644 --- a/home/ssh.nix +++ b/home/ssh.nix @@ -5,6 +5,8 @@ enable = true; serverAliveInterval = 60; + includes = ["config.local"]; + matchBlocks = let nas = { user = "admin"; }; diff --git a/home/xonsh.nix b/home/xonsh.nix index aafa96a..9d9f9cd 100644 --- a/home/xonsh.nix +++ b/home/xonsh.nix @@ -44,10 +44,12 @@ tspub = "sudo tailscale up --exit-node=linode"; tshome = "sudo tailscale up --exit-node=2maccabees"; tsclear = "sudo tailscale up --exit-node=''"; - rebuild = "sudo nixos-rebuild switch"; }; configHeader = '' +if '__NIX_DARWIN_SET_ENVIRONMENT_DONE' not in ''${...} or not $__NIX_DARWIN_SET_ENVIRONMENT_DONE: + source-bash /etc/bashrc + # set -e == $RAISE_SUBPROC_ERROR = True # set -x == trace on; $XONSH_TRACE_SUBPROC = True # $? == _.rtn @@ -61,6 +63,14 @@ xontrib load direnv #$GOPATH = $HOME + '/.go' #$JAVA_HOME = '/etc/alternatives/java_sdk' configFooter = '' +def _rebuild(args): + import os + system = os.uname() + if system.sysname == 'Darwin': + darwin-rebuild --flake ~/.config/nix switch + else: + sudo nixos-rebuild switch + def _yaml2json(args, stdin=None, stdout=None): import sys, yaml, json from yaml import CLoader @@ -95,6 +105,7 @@ def _newdock(args): def _unknown_host(args): sed -i -e @(args[0])d ~/.ssh/known_hosts +aliases['rebuild'] = _rebuild aliases['yaml2json'] = _yaml2json aliases['py2env'] = _py2env aliases['py3env'] = _py3env diff --git a/hosts/work/default.nix b/hosts/work/default.nix new file mode 100644 index 0000000..a6e6219 --- /dev/null +++ b/hosts/work/default.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: + +{ + #greg.pypackages = with pkgs; [ + # datadog-api-client + # datadog + # dateutil + # ipython + # pyyaml + # responses + # ruamel-yaml + # typing-extensions + # virtualenv + #]; +} diff --git a/modules b/modules new file mode 120000 index 0000000..89a6caa --- /dev/null +++ b/modules @@ -0,0 +1 @@ +modules-all \ No newline at end of file diff --git a/modules-all/automatic/default.nix b/modules-all/automatic/default.nix new file mode 100644 index 0000000..8e990d3 --- /dev/null +++ b/modules-all/automatic/default.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = [ + ./nix.nix + ./programs.nix + ]; +} diff --git a/modules/automatic/nix.nix b/modules-all/automatic/nix.nix similarity index 77% rename from modules/automatic/nix.nix rename to modules-all/automatic/nix.nix index 3d71a48..f555dc6 100644 --- a/modules/automatic/nix.nix +++ b/modules-all/automatic/nix.nix @@ -15,10 +15,6 @@ max-free = ${toString (5 * 1024 * 1024 * 1024) } keep-outputs = true keep-derivations = true ''; - - # Use hardlinking instead of copying when possible - autoOptimiseStore = true; }; nixpkgs.config.allowUnfree = true; - system.stateVersion = "22.05"; } diff --git a/modules/automatic/programs.nix b/modules-all/automatic/programs.nix similarity index 76% rename from modules/automatic/programs.nix rename to modules-all/automatic/programs.nix index ebe8aeb..efca97f 100644 --- a/modules/automatic/programs.nix +++ b/modules-all/automatic/programs.nix @@ -2,7 +2,16 @@ let myPackages = pypackages: with pypackages; [ + pkgs.datadog-api-client pkgs.xonsh-direnv + datadog + dateutil + ipython + pyyaml + responses + ruamel-yaml + typing-extensions + virtualenv ]; myPython = pkgs.python3.withPackages myPackages; @@ -10,6 +19,8 @@ in { # Base packages that need to be in all my hosts environment.systemPackages = with pkgs; [ agenix.defaultPackage."${system}" + android-file-transfer + bitwarden-cli diffutils git gnupatch diff --git a/modules-all/default.nix b/modules-all/default.nix new file mode 100644 index 0000000..c7c9579 --- /dev/null +++ b/modules-all/default.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = [ + ./automatic + ./xprograms.nix + ]; +} diff --git a/modules-all/modules b/modules-all/modules new file mode 120000 index 0000000..dc428f0 --- /dev/null +++ b/modules-all/modules @@ -0,0 +1 @@ +modules \ No newline at end of file diff --git a/modules/xprograms.nix b/modules-all/xprograms.nix similarity index 100% rename from modules/xprograms.nix rename to modules-all/xprograms.nix diff --git a/modules-darwin/default.nix b/modules-darwin/default.nix new file mode 100644 index 0000000..81c4be2 --- /dev/null +++ b/modules-darwin/default.nix @@ -0,0 +1,10 @@ +{ ... }: + +{ + system.stateVersion = 4; + programs = { + zsh.enable = true; + bash.enable = true; + }; + services.nix-daemon.enable = true; +} diff --git a/modules-linux/automatic/default.nix b/modules-linux/automatic/default.nix new file mode 100644 index 0000000..f20fb29 --- /dev/null +++ b/modules-linux/automatic/default.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = [ + ./syncthing.nix + ./users.nix + ]; +} diff --git a/modules/automatic/syncthing.nix b/modules-linux/automatic/syncthing.nix similarity index 100% rename from modules/automatic/syncthing.nix rename to modules-linux/automatic/syncthing.nix diff --git a/modules/automatic/users.nix b/modules-linux/automatic/users.nix similarity index 98% rename from modules/automatic/users.nix rename to modules-linux/automatic/users.nix index e9f47a6..328baf4 100644 --- a/modules/automatic/users.nix +++ b/modules-linux/automatic/users.nix @@ -1,4 +1,6 @@ -{ config, pkgs, agenix, ... }: +# Only imported from the Linux modules + +{ pkgs, ... }: { # Enable the OpenSSH daemon for remote control diff --git a/modules/backup.nix b/modules-linux/backup.nix similarity index 100% rename from modules/backup.nix rename to modules-linux/backup.nix diff --git a/modules-linux/default.nix b/modules-linux/default.nix new file mode 100644 index 0000000..9b25e49 --- /dev/null +++ b/modules-linux/default.nix @@ -0,0 +1,22 @@ +{ ... }: + +{ + imports = [ + ./automatic + ./backup.nix + ./gnome.nix + ./home.nix + ./linode.nix + ./linux.nix + ./proxy.nix + ./rpi4.nix + ./tailscale.nix + ]; + + system.stateVersion = "22.05"; + + # I am a fan of network manager, myself + networking.networkmanager.enable = true; + + nix.settings.auto-optimise-store = true; +} diff --git a/modules/gnome.nix b/modules-linux/gnome.nix similarity index 100% rename from modules/gnome.nix rename to modules-linux/gnome.nix diff --git a/modules/home.nix b/modules-linux/home.nix similarity index 100% rename from modules/home.nix rename to modules-linux/home.nix diff --git a/modules/linode.nix b/modules-linux/linode.nix similarity index 100% rename from modules/linode.nix rename to modules-linux/linode.nix diff --git a/modules-linux/linux.nix b/modules-linux/linux.nix new file mode 100644 index 0000000..a5ad118 --- /dev/null +++ b/modules-linux/linux.nix @@ -0,0 +1,11 @@ +{ config, lib, ... }: + +let + cfg = config.greg.linux; + +in with lib; { + options.greg.linux = mkEnableOption "This system is Linux"; + + config = mkIf cfg { + }; +} diff --git a/modules/proxy.nix b/modules-linux/proxy.nix similarity index 100% rename from modules/proxy.nix rename to modules-linux/proxy.nix diff --git a/modules/rpi4.nix b/modules-linux/rpi4.nix similarity index 100% rename from modules/rpi4.nix rename to modules-linux/rpi4.nix diff --git a/modules/tailscale.nix b/modules-linux/tailscale.nix similarity index 100% rename from modules/tailscale.nix rename to modules-linux/tailscale.nix diff --git a/modules/automatic.nix b/modules/automatic.nix deleted file mode 100644 index b8f2f38..0000000 --- a/modules/automatic.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ ... }: - -{ - imports = [ - ./automatic/nix.nix - ./automatic/programs.nix - ./automatic/syncthing.nix - ./automatic/users.nix - ]; - # I am a fan of network manager, myself - networking.networkmanager.enable = true; -} diff --git a/modules/default.nix b/modules/default.nix deleted file mode 100644 index b766d39..0000000 --- a/modules/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ ... }: - -{ - imports = [ - ./automatic.nix - ./backup.nix - ./home.nix - ./gnome.nix - ./linode.nix - ./proxy.nix - ./rpi4.nix - ./tailscale.nix - ./xprograms.nix - ]; -} diff --git a/nix.conf b/nix.conf new file mode 100644 index 0000000..c7d7291 --- /dev/null +++ b/nix.conf @@ -0,0 +1 @@ +experimental-features = nix-command flakes diff --git a/overlays/datadog-api-client.nix b/overlays/datadog-api-client.nix new file mode 100644 index 0000000..df815d1 --- /dev/null +++ b/overlays/datadog-api-client.nix @@ -0,0 +1,38 @@ +{ lib, buildPythonPackage, fetchPypi, pkgs}: + +let + pydeps = pypkgs: with pypkgs; [ + certifi + dateutils + python-dateutil + typing-extensions + urllib3 + ]; + +in buildPythonPackage rec { + pname = "datadog-api-client"; + version = "2.3.0"; + + src = fetchPypi { + inherit pname version; + sha256 = "CIEQlw8S2lZk1n+ld/Ne7lBx4SKaJZUZfNbw9KvUcjk="; + }; + + meta = with lib; { + description = "Datadog API client support"; + homepage = "https://github.com/DataDog/datadog-api-client-python"; + license = licenses.asl20; + maintainers = []; + }; + + doCheck = false; + + buildInputs = with pkgs; [ + (python3.withPackages pydeps) + ]; + + nativeBuildInputs = with pkgs; [ + (python3.withPackages pydeps) + git + ]; +} diff --git a/overlays/default.nix b/overlays/default.nix index e228946..2296b82 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,15 +1,20 @@ self: super: { - xonsh-direnv = super.callPackage ./xonsh-direnv.nix { + datadog-api-client = super.callPackage ./datadog-api-client.nix { buildPythonPackage = self.python3.pkgs.buildPythonPackage; fetchPypi = self.python.pkgs.fetchPypi; }; + hms = super.callPackage ./hms.nix { + pkgs = self.pkgs; + }; + xonsh = super.xonsh.overridePythonAttrs (old: rec{ propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.xonsh-direnv ]; }); - hms = super.callPackage ./hms.nix { - pkgs = self.pkgs; + xonsh-direnv = super.callPackage ./xonsh-direnv.nix { + buildPythonPackage = self.python3.pkgs.buildPythonPackage; + fetchPypi = self.python.pkgs.fetchPypi; }; } diff --git a/overlays/hms.nix b/overlays/hms.nix index b3cefb1..4f47acc 100644 --- a/overlays/hms.nix +++ b/overlays/hms.nix @@ -3,17 +3,27 @@ pkgs.writeShellScriptBin "hms" '' set -eo pipefail # Build different targets with GUI or not -if [ -z "$DISPLAY" ]; then - target="nogui" + +arch="$(uname -m)" +if [ "$(uname -s)" == "Darwin" ]; then + # On macOS + src="$HOME/.config/nix/" + target="''${arch}-darwin" else - target="gui" + # On Linux/WSL2 systems + if [ -z "$DISPLAY" ]; then + target="''${arch}-nogui" + else + target="''${arch}-gui" + fi + src=/etc/nixos fi # Build and switch echo "Building $(uname -m)-$target" dest=$(mktemp -d) pushd "$dest" > /dev/null -nix build --impure /etc/nixos#homeConfigurations.$(uname -m)-$target.activationPackage +nix build --impure "$src#homeConfigurations.$target.activationPackage" ./result/activate popd > /dev/null rm -r "$dest" diff --git a/overlays/packages.nix b/overlays/packages.nix new file mode 100644 index 0000000..c094ce7 --- /dev/null +++ b/overlays/packages.nix @@ -0,0 +1,23 @@ +{ pkgs, ... }: + +let + callPackage = pkgs.lib.callPackageWith pkgs; + lib = pkgs.lib; + python = pkgs.packages.python3; +in { + datadog-api-client = callPackage ./datadog-api-client.nix { + inherit pkgs lib; + buildPythonPackage = python.pkgs.buildPythonPackage; + fetchPypi = pkgs.python.pkgs.fetchPypi; + }; + + hms = pkgs.callPackage ./hms.nix { + inherit pkgs; + }; + + xonsh-direnv = pkgs.callPackage ./xonsh-direnv.nix { + buildPythonPackage = pkgs.python3.pkgs.buildPythonPackage; + fetchPypi = pkgs.python.pkgs.fetchPypi; + }; + +} diff --git a/overlays/xonsh-direnv.nix b/overlays/xonsh-direnv.nix index 07d57a5..2d91acf 100644 --- a/overlays/xonsh-direnv.nix +++ b/overlays/xonsh-direnv.nix @@ -17,4 +17,8 @@ buildPythonPackage rec { }; doCheck = false; + + nativeBuildInputs = [ + pkgs.git + ]; } diff --git a/modules/ssh/id_ed25519 b/ssh/id_ed25519 similarity index 100% rename from modules/ssh/id_ed25519 rename to ssh/id_ed25519 diff --git a/modules/ssh/id_ed25519.pub b/ssh/id_ed25519.pub similarity index 100% rename from modules/ssh/id_ed25519.pub rename to ssh/id_ed25519.pub