diff --git a/flake.lock b/flake.lock index e7a4af3..778ae31 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,26 @@ { "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1622060422, + "narHash": "sha256-hPVlvrAyf6zL7tTx0lpK+tMxEfZeMiIZ/A2xaJ41WOY=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "007d700e644ac588ad6668e6439950a5b6e2ff64", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, "deploy-rs": { "inputs": { "flake-compat": "flake-compat", @@ -203,6 +224,7 @@ }, "root": { "inputs": { + "darwin": "darwin", "deploy-rs": "deploy-rs", "flake-utils-plus": "flake-utils-plus", "home-manager": "home-manager", diff --git a/flake.nix b/flake.nix index 41c0102..2548d18 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,10 @@ description = "soxin: opiniated configs for everyone"; inputs = { + darwin = { + url = "github:lnl7/nix-darwin/master"; + inputs.nixpkgs.follows = "nixpkgs"; + }; deploy-rs.url = "github:serokell/deploy-rs"; flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.3.1"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; diff --git a/lib/home-manager-configuration.nix b/lib/home-manager-configuration.nix index d174fbe..be234ae 100644 --- a/lib/home-manager-configuration.nix +++ b/lib/home-manager-configuration.nix @@ -39,21 +39,21 @@ let in home-manager.lib.homeManagerConfiguration (recursiveUpdate - { - extraSpecialArgs = { - inherit inputs soxin soxincfg; - - mode = "home-manager"; - } - # include the home-manager special arguments. - // hmSpecialArgs; - - extraModules = - # include the home-manager modules - hmModules - # include Soxin module - ++ (singleton soxin.nixosModules.soxin) - # include SoxinCFG module - ++ (singleton soxincfg.nixosModules.soxincfg); +{ + extraSpecialArgs = { + inherit inputs soxin soxincfg; + + mode = "home-manager"; } + # include the home-manager special arguments. + // hmSpecialArgs; + + extraModules = + # include the home-manager modules + hmModules + # include Soxin module + ++ (singleton soxin.nixosModules.soxin) + # include SoxinCFG module + ++ (singleton soxincfg.nixosModules.soxincfg); +} otherArguments) diff --git a/lib/mk-flake.nix b/lib/mk-flake.nix index 75f94e5..ecc7e94 100644 --- a/lib/mk-flake.nix +++ b/lib/mk-flake.nix @@ -1,4 +1,5 @@ -{ deploy-rs +{ darwin +, deploy-rs , home-manager , flake-utils-plus , nixpkgs @@ -34,6 +35,9 @@ # NixOS specific modules. , extraNixosModules ? [ ] + # nix-darwin specific modules. +, extraNixDarwinModules ? [ ] + # The global extra arguments are included in both NixOS and home-manager. , globalSpecialArgs ? { } @@ -43,6 +47,9 @@ # NixOS specific extra arguments. , nixosSpecialArgs ? { } + # nix-darwin specific extra arguments. +, nixDarwinSpecialArgs ? { } + # Shared overlays between channels, gets applied to all `channels..input` , sharedOverlays ? [ ] @@ -95,9 +102,11 @@ let "extraGlobalModules" "extraHomeManagerModules" "extraNixosModules" + "extraNixDarwinModules" "globalSpecialArgs" "hmSpecialArgs" "nixosSpecialArgs" + "nixDarwinSpecialArgs" "outputsBuilder" "sharedOverlays" ]; @@ -105,25 +114,105 @@ let # generate each host by injecting special arguments and the given host # without certain soxin-only attributes. hosts' = - mapAttrs - (hostname: host: (recursiveUpdate - { - specialArgs = { - inherit soxin soxincfg home-manager; - - # the mode allows us to tell at what level we are within the modules. - mode = "NixOS"; - } - # include the global special arguments. - // globalSpecialArgs - # include the NixOS special arguments. - // nixosSpecialArgs; - } - - # pass along the hosts minus the deploy key that's specific to soxin. - (removeAttrs host [ "deploy" ]) - )) - hosts; + let + darwinHosts = + let + darwinOnlyHosts = filterAttrs (n: host: host.mode == "nix-darwin") hosts; + + # Build host with darwinSystem. + builder = args: darwin.lib.darwinSystem args; + + # Setup the output + output = "darwinConfigurations"; + in + mapAttrs + (_: host: + # setup the default attributes, users can override it by passing them through their host definition. + { inherit builder output; } + // + (recursiveUpdate + # pass along the hosts minus few keys that are implementation detail to soxin. + (removeAttrs host [ "deploy" "mode" "modules" ]) + + { + modules = [ ] + # include modules for the host + ++ (host.modules or [ ]) + # include the NixOS modules + ++ extraNixDarwinModules + # include home-manager modules + ++ (singleton home-manager.darwinModules.home-manager) + ; + specialArgs = + { + inherit + home-manager + soxin + soxincfg + ; + + inherit (host) + mode + ; + } + # include the specialArgs that were passed in. + // (host.specialArgs or { }) + # include the global special arguments. + // globalSpecialArgs + # include the NixDarwin special arguments. + // nixDarwinSpecialArgs + ; + } + )) + darwinOnlyHosts; + + nixosHosts = + let + nixosOnlyHosts = filterAttrs (n: host: host.mode == "NixOS") hosts; + in + mapAttrs + (_: host: (recursiveUpdate + # pass along the hosts minus few keys that are implementation detail to soxin. + (removeAttrs host [ "deploy" "mode" ]) + + { + modules = [ ] + # include modules for the host + ++ (host.modules or [ ]) + # include the NixOS modules + ++ extraNixosModules + # include sops + ++ (optionals withSops (singleton sops-nix.nixosModules.sops)) + # include home-manager modules + ++ (singleton home-manager.nixosModules.home-manager) + ; + + specialArgs = + { + inherit + home-manager + soxin + soxincfg + ; + + inherit (host) + mode + ; + } + # include the specialArgs that were passed in. + // (host.specialArgs or { }) + # include the global special arguments. + // globalSpecialArgs + # include the NixOS special arguments. + // nixosSpecialArgs + ; + } + )) + nixosOnlyHosts; + + # TODO: add support for home-manager modes + in + darwinHosts // nixosHosts; # Generate the deployment nodes. deploy.nodes = @@ -131,7 +220,7 @@ let # filter out hosts without a deploy attribute. deploy-hosts = filterAttrs (n: v: (v.deploy or { }) != { }) hosts; in - mapAttrs (hostname: host: host.deploy) deploy-hosts; + mapAttrs (_: host: host.deploy) deploy-hosts; soxinSystemFlake = { # inherit the required fields as-is @@ -236,22 +325,17 @@ let modules = # include the modules that are passed in (hostDefaults.modules or [ ]) - # include sops - ++ (optionals withSops (singleton sops-nix.nixosModules.sops)) # include the global modules ++ extraGlobalModules - # include the NixOS modules - ++ extraNixosModules # include Soxin modules ++ (singleton soxin.nixosModule) - # include home-manager modules - ++ (singleton home-manager.nixosModules.home-manager) # configure fup to expose NIX_PATH and Nix registry from inputs. ++ (singleton { nix = { inherit generateNixPathFromInputs generateRegistryFromInputs linkInputs; }; }) # configure home-manager ++ (singleton { - # tell home-manager to use the global (as in NixOS system-level) pkgs and - # install all user packages through the users.users..packages. + # tell home-manager to use the global (as in NixOS/Nix-Darwin + # system-level) pkgs and install all user packages through the + # users.users..packages. home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; @@ -264,7 +348,8 @@ let # include the global special arguments. // globalSpecialArgs # include the home-manager special arguments. - // hmSpecialArgs; + // hmSpecialArgs + ; home-manager.sharedModules = # include the global modules @@ -272,7 +357,8 @@ let # include the home-manager modules ++ extraHomeManagerModules # include Soxin module - ++ (singleton soxin.nixosModule); + ++ (singleton soxin.nixosModule) + ; }); }; } @@ -292,7 +378,7 @@ flake-utils-plus.lib.mkFlake (recursiveUpdate soxinSystemFlake otherArguments) # TODO: Let flake-utils-plus.lib.mkFlake handle the home-managers by using the host's builder function // { homeConfigurations = (mapAttrs - (hostname: host: soxin.lib.homeManagerConfiguration (host // { + (_: host: soxin.lib.homeManagerConfiguration (host // { inherit inputs; hmModules = # include the global modules diff --git a/modules/programs/keybase/default.nix b/modules/programs/keybase/default.nix index b50a84a..5c5bd65 100644 --- a/modules/programs/keybase/default.nix +++ b/modules/programs/keybase/default.nix @@ -1,8 +1,19 @@ { mode, config, pkgs, lib, ... }: -with lib; let cfg = config.soxin.programs.keybase; + + inherit (lib) + mkEnableOption + mkIf + mkMerge + optionalAttrs + recursiveUpdate + ; + + inherit (pkgs.hostPlatform) + isLinux + ; in { options = { @@ -11,14 +22,14 @@ in enableFs = recursiveUpdate (mkEnableOption "Keybase filesystem") - { default = true; }; + { default = isLinux; }; }; }; config = mkIf cfg.enable (mkMerge [ - { + (optionalAttrs (mode == "NixOS" || mode == "home-manager") { services.keybase.enable = true; services.kbfs.enable = cfg.enableFs; - } + }) ]); } diff --git a/modules/programs/tmux/default.nix b/modules/programs/tmux/default.nix index ffdfc8b..2514d40 100644 --- a/modules/programs/tmux/default.nix +++ b/modules/programs/tmux/default.nix @@ -86,7 +86,7 @@ in secureSocket = mkOption { type = types.bool; - default = true; + default = pkgs.stdenv.isLinux; description = '' Store tmux socket under /run, which is more secure than /tmp, but as a downside it doesn't @@ -99,7 +99,9 @@ in config = mkIf cfg.enable (mkMerge [ # add all plugins installed by themes - { soxin.programs.tmux.plugins = cfg.theme.plugins; } + (optionalAttrs (mode == "NixOS" || mode == "home-manager") { + soxin.programs.tmux.plugins = cfg.theme.plugins; + }) (optionalAttrs (mode == "NixOS") (mkMerge [ { programs.tmux = { inherit (cfg) enable extraConfig secureSocket; }; } diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index abbafae..e02265f 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -14,12 +14,19 @@ in includeTheme = true; # TODO: copied from home-manager, fix this! extraOptions = { - # TODO: Consider taking one from NixOS because of the strategy feature! + # TODO: Consider taking this one from NixOS because of the strategy feature! enableAutosuggestions = mkOption { default = true; type = types.bool; description = "Enable zsh autosuggestions"; }; + + enableCompletion = mkOption { + default = true; + type = types.bool; + description = "Enable zsh auto-completion"; + }; + plugins = mkOption { # type = types.listOf soxin.lib.modules.zsh.pluginModule; @@ -55,28 +62,19 @@ in }; config = mkIf cfg.enable (mkMerge [ - # add all plugins installed by themes - { soxin.programs.zsh.plugins = cfg.theme.plugins; } - - { programs.zsh = { inherit (cfg) enable; }; } + (optionalAttrs (mode == "NixOS" || mode == "home-manager") { + programs.zsh = { inherit (cfg) enable; }; - # Forward configurations to home-manager. - (optionalAttrs (mode == "home-manager") { - programs.zsh = { inherit (cfg) enableAutosuggestions plugins; }; - }) - - # Forward configurations to NixOS. - (optionalAttrs (mode == "NixOS") { - programs.zsh.autosuggestions.enable = cfg.enableAutosuggestions; + # add all plugins installed by themes + soxin.programs.zsh.plugins = cfg.theme.plugins; }) - # Forward plugins to NixOS. - # Copy the plugin management from home-manager - # TODO: Send it upstream to NixOS. - (optionalAttrs (mode == "NixOS") (mkIf (cfg.plugins != [ ]) { + # Copy the plugin management from home-manager to send plugins to NixOS and nix-darwin + # TODO: Send it upstream to NixOS and nix-darwin. + (optionalAttrs (mode == "NixOS" || mode == "nix-darwin") (mkIf (cfg.plugins != [ ]) { # Many plugins require compinit to be called # but allow the user to opt out. - programs.zsh.enableCompletion = mkDefault true; + soxin.programs.zsh.enableCompletion = mkDefault true; environment.etc = foldl' (a: b: a // b) { } @@ -91,6 +89,19 @@ in cfg.plugins); })) + (optionalAttrs (mode == "NixOS") { + programs.zsh = { inherit (cfg) enableCompletion; }; + programs.zsh.autosuggestions.enable = cfg.enableAutosuggestions; + }) + + (optionalAttrs (mode == "nix-darwin") { + programs.zsh = { inherit (cfg) enable enableCompletion; }; + }) + + (optionalAttrs (mode == "home-manager") { + programs.zsh = { inherit (cfg) enableAutosuggestions plugins; }; + }) + # install all completions libraries for system packages (optionalAttrs (mode == "NixOS") (mkIf config.programs.zsh.enableCompletion { environment.pathsToLink = [ "/share/zsh" ]; diff --git a/modules/settings/keyboard.nix b/modules/settings/keyboard.nix index f60268c..614805c 100644 --- a/modules/settings/keyboard.nix +++ b/modules/settings/keyboard.nix @@ -76,5 +76,11 @@ in variant = concatMapStringsSep "," (l: l.x11.variant) cfg.layouts; }; }) + + (optionalAttrs (mode == "nix-darwin") { + # TODO: Write this up. + # Some resources: + # - https://github.com/kalbasit/shabka/blob/b6161e62e08eb323eb59fd94d4e12335507a6238/modules/darwin/general/keyboard.nix#L29-L38 + }) ]; } diff --git a/template/flake.nix b/template/flake.nix index 8304525..9f51c6a 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -3,15 +3,30 @@ inputs = { deploy-rs.url = "github:serokell/deploy-rs"; - flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.3.1"; - home-manager.url = "github:nix-community/home-manager/release-21.11"; + flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus"; + nixos-hardware.url = "github:NixOS/nixos-hardware"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; - nixpkgs.url = "github:NixOS/nixpkgs/release-21.11"; + nixpkgs.url = "github:NixOS/nixpkgs/release-23.05"; nur.url = "github:nix-community/NUR"; + home-manager = { + url = "github:nix-community/home-manager/release-23.05"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + + darwin = { + url = "github:LnL7/nix-darwin"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + soxin = { - url = "github:SoxinOS/soxin"; + url = "path:../"; inputs = { + darwin.follows = "darwin"; deploy-rs.follows = "deploy-rs"; flake-utils-plus.follows = "flake-utils-plus"; home-manager.follows = "home-manager"; @@ -22,7 +37,7 @@ }; }; - outputs = inputs@{ flake-utils-plus, nixpkgs, self, soxin, ... }: + outputs = inputs@{ flake-utils-plus, nixos-hardware, nixpkgs, self, soxin, ... }: let # Enable deploy-rs support withDeploy = true; @@ -54,6 +69,7 @@ channelsConfig = { # allowBroken = true; allowUnfree = true; + # allowUnsupportedSystem = true; }; nixosModules = (import ./modules) // { @@ -87,5 +103,8 @@ # include all overlays overlay = import ./overlays; + + # set the nixos specialArgs + nixosSpecialArgs = { inherit nixos-hardware; }; }; } diff --git a/template/hosts/darwins/default.nix b/template/hosts/darwins/default.nix index 1671f4e..d08aab3 100644 --- a/template/hosts/darwins/default.nix +++ b/template/hosts/darwins/default.nix @@ -1,3 +1,40 @@ -inputs@{ self, deploy-rs, nixpkgs, ... }: +inputs@{ self, deploy-rs, lib ? nixpkgs.lib, nixpkgs, ... }: -{ } +let + inherit (lib) + mapAttrs + recursiveUpdate + ; + + # the default channel to follow. + channelName = "nixpkgs"; + + # the operating mode of Soxin + mode = "nix-darwin"; +in +mapAttrs + (n: v: recursiveUpdate + { + inherit + mode + ; + } + v) +{ + ### + # x86_64-darwin + ### + + minimal-darwin-system = + let + system = "x86_64-darwin"; + in + { + inherit + channelName + system + ; + + modules = [ ./minimal-darwin-system/configuration.nix ]; + }; +} diff --git a/template/hosts/darwins/minimal-darwin-system/configuration.nix b/template/hosts/darwins/minimal-darwin-system/configuration.nix new file mode 100644 index 0000000..2a9ab1c --- /dev/null +++ b/template/hosts/darwins/minimal-darwin-system/configuration.nix @@ -0,0 +1,17 @@ +{ config, lib, soxincfg, ... }: + +let + inherit (lib) singleton; +in +{ + imports = [ + # import the workstation profile that configures a workstation. + soxincfg.nixosModules.profiles.workstation.darwin.local + ]; + + # the user nick is created by the core profiles which is automatically added + # to the configuration of all supported systems. + home-manager.users.nick = { ... }: { + imports = singleton ./home.nix; + }; +} diff --git a/template/hosts/darwins/minimal-darwin-system/home.nix b/template/hosts/darwins/minimal-darwin-system/home.nix new file mode 100644 index 0000000..32e1203 --- /dev/null +++ b/template/hosts/darwins/minimal-darwin-system/home.nix @@ -0,0 +1,14 @@ +{ lib, soxincfg, pkgs, ... }: + +let + inherit (lib) singleton; +in +{ + imports = [ soxincfg.nixosModules.profiles.workstation.darwin.local ]; + + home.packages = with soxincfg.packages."${pkgs.system}"; singleton helloSh; + + programs.zsh.enable = true; + + home.stateVersion = "23.05"; +} diff --git a/template/hosts/default.nix b/template/hosts/default.nix index b6d0144..040f7cd 100644 --- a/template/hosts/default.nix +++ b/template/hosts/default.nix @@ -1,4 +1,4 @@ inputs@{ ... }: -(import ./nixoses inputs) // -(import ./darwins inputs) +(import ./nixoses inputs) + // (import ./darwins inputs) diff --git a/template/hosts/nixoses/default.nix b/template/hosts/nixoses/default.nix index 7c981a6..065c3bb 100644 --- a/template/hosts/nixoses/default.nix +++ b/template/hosts/nixoses/default.nix @@ -1,6 +1,30 @@ -inputs@{ self, deploy-rs, ... }: +inputs@{ self, deploy-rs, lib ? nixpkgs.lib, nixpkgs, ... }: +let + inherit (lib) + mapAttrs + recursiveUpdate + ; + + # the default channel to follow. + channelName = "nixpkgs"; + + # the operating mode of Soxin + mode = "NixOS"; +in +mapAttrs + (n: v: recursiveUpdate + { + inherit + mode + ; + } + v) { + ### + # x86_64-linux + ### + minimal-nixos-system = let system = "x86_64-linux"; @@ -9,7 +33,7 @@ inputs@{ self, deploy-rs, ... }: # System architecture. inherit system; # of the channel to be used. Defaults to `nixpkgs` - channelName = "nixpkgs"; + inherit channelName; # Extra arguments to be passed to the modules. extraArgs = { }; # Host specific configuration. diff --git a/template/hosts/nixoses/minimal-nixos-system/configuration.nix b/template/hosts/nixoses/minimal-nixos-system/configuration.nix index bd77ad4..d1cff4f 100644 --- a/template/hosts/nixoses/minimal-nixos-system/configuration.nix +++ b/template/hosts/nixoses/minimal-nixos-system/configuration.nix @@ -9,13 +9,16 @@ in ./hardware-configuration.nix # import the workstation profile that configures a workstation. - soxincfg.nixosModules.profiles.workstation + soxincfg.nixosModules.profiles.workstation.nixos.local ]; + programs.zsh.enable = true; # the user nick is created by the core profiles which is automatically added # to the configuration of all supported systems. home-manager.users.nick = { ... }: { imports = singleton ./home.nix; }; + + system.stateVersion = "23.05"; } diff --git a/template/hosts/nixoses/minimal-nixos-system/home.nix b/template/hosts/nixoses/minimal-nixos-system/home.nix index 3cfd501..a92f8b5 100644 --- a/template/hosts/nixoses/minimal-nixos-system/home.nix +++ b/template/hosts/nixoses/minimal-nixos-system/home.nix @@ -4,9 +4,11 @@ let inherit (lib) singleton; in { - imports = [ soxincfg.nixosModules.profiles.workstation ]; + imports = [ soxincfg.nixosModules.profiles.workstation.nixos.local ]; home.packages = with soxincfg.packages."${pkgs.system}"; singleton helloSh; programs.zsh.enable = true; + + home.stateVersion = "23.05"; } diff --git a/template/profiles/workstation/darwin/default.nix b/template/profiles/workstation/darwin/default.nix new file mode 100644 index 0000000..099964e --- /dev/null +++ b/template/profiles/workstation/darwin/default.nix @@ -0,0 +1,3 @@ +{ + local = import ./local; +} diff --git a/template/profiles/workstation/darwin/local/default.nix b/template/profiles/workstation/darwin/local/default.nix new file mode 100644 index 0000000..7108179 --- /dev/null +++ b/template/profiles/workstation/darwin/local/default.nix @@ -0,0 +1,10 @@ +{ lib, ... }: + +let + inherit (lib) mkMerge; +in +{ + config = mkMerge [ + { soxin.programs.zsh.enable = true; } + ]; +} diff --git a/template/profiles/workstation/default.nix b/template/profiles/workstation/default.nix index 765c9f7..a91d764 100644 --- a/template/profiles/workstation/default.nix +++ b/template/profiles/workstation/default.nix @@ -1,10 +1,4 @@ -{ lib, ... }: - -let - inherit (lib) mkMerge; -in { - config = mkMerge [ - { soxin.hardware.bluetooth.enable = true; } - ]; + darwin = import ./darwin; + nixos = import ./nixos; } diff --git a/template/profiles/workstation/nixos/default.nix b/template/profiles/workstation/nixos/default.nix new file mode 100644 index 0000000..b82905b --- /dev/null +++ b/template/profiles/workstation/nixos/default.nix @@ -0,0 +1,4 @@ +{ + local = import ./local; + # remote = import ./remote; +} diff --git a/template/profiles/workstation/nixos/local/default.nix b/template/profiles/workstation/nixos/local/default.nix new file mode 100644 index 0000000..7108179 --- /dev/null +++ b/template/profiles/workstation/nixos/local/default.nix @@ -0,0 +1,10 @@ +{ lib, ... }: + +let + inherit (lib) mkMerge; +in +{ + config = mkMerge [ + { soxin.programs.zsh.enable = true; } + ]; +}