From da40952f2cabc58ac8a4de66ce0cea4088d46116 Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Sat, 5 Jun 2021 14:25:38 +0200 Subject: [PATCH 1/2] programs: keybase: check if we are on NixOS or home-manager Signed-off-by: Marc 'risson' Schmitt --- modules/programs/keybase/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/programs/keybase/default.nix b/modules/programs/keybase/default.nix index b50a84a..9abf0fc 100644 --- a/modules/programs/keybase/default.nix +++ b/modules/programs/keybase/default.nix @@ -16,9 +16,9 @@ in }; config = mkIf cfg.enable (mkMerge [ - { + (optionalAttrs (mode == "NixOS" || mode == "home-manager") { services.keybase.enable = true; services.kbfs.enable = cfg.enableFs; - } + }) ]); } From 944a9d7d5a08ff75963e9071704be2563f0efa1e Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Sat, 5 Jun 2021 14:25:55 +0200 Subject: [PATCH 2/2] flake, lib: add darwin support Signed-off-by: Marc 'risson' Schmitt --- flake.lock | 21 ++++++++++ flake.nix | 9 ++++- lib/darwin-system.nix | 93 +++++++++++++++++++++++++++++++++++++++++++ lib/default.nix | 3 +- 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 lib/darwin-system.nix diff --git a/flake.lock b/flake.lock index 30de46b..72c3644 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "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", + "repo": "nix-darwin", + "type": "github" + } + }, "futils": { "locked": { "lastModified": 1620759905, @@ -52,6 +72,7 @@ }, "root": { "inputs": { + "darwin": "darwin", "futils": "futils", "home-manager": "home-manager", "nixpkgs": "nixpkgs" diff --git a/flake.nix b/flake.nix index fadf1c8..5ec4b1d 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,10 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; + darwin = { + url = "github:LnL7/nix-darwin"; + inputs.nixpkgs.follows = "nixpkgs"; + }; home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; @@ -10,7 +14,7 @@ futils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, home-manager, futils } @ inputs: + outputs = { self, nixpkgs, darwin, home-manager, futils } @ inputs: let inherit (nixpkgs) lib; inherit (lib) recursiveUpdate; @@ -42,6 +46,9 @@ nixosModules = (import ./modules) // { soxin = import ./modules/soxin.nix; }; nixosModule = self.nixosModules.soxin; + /* For now they are the same. */ + darwinModules = self.nixosModules; + darwinModule = self.darwinModules.soxin; defaultTemplate = { path = ./template; diff --git a/lib/darwin-system.nix b/lib/darwin-system.nix new file mode 100644 index 0000000..c7778e4 --- /dev/null +++ b/lib/darwin-system.nix @@ -0,0 +1,93 @@ +{ self, lib, darwin, home-manager }: + +with lib; + +{ + # The global modules are included in both Darwin and home-manager. + globalModules ? [ ] + + # Darwin specific modules. +, darwinModules ? [ ] + + # Home-manager specific modules. +, hmModules ? [ ] + + # The global extra arguments are included in both Darwin and home-manager. +, globalSpecialArgs ? { } + + # Darwin specific extra arguments. +, darwinSpecialArgs ? { } + + # Home-manager specific extra arguments. +, hmSpecialArgs ? { } + +, ... +} @ args: +let + args' = removeAttrs args [ + "globalModules" + "darwinModules" + "hmModules" + + "globalSpecialArgs" + "darwinSpecialArgs" + "hmSpecialArgs" + ]; +in +darwin.lib.darwinSystem (recursiveUpdate args' { + specialArgs = { + # send home-manager down to the Darwin modules + inherit home-manager; + + # the mode allows us to tell at what level we are within the modules. + mode = "Darwin"; + + # send soxin down to NixOS. + soxin = self; + } + # include the global special arguments. + // globalSpecialArgs + # include the NixOS special arguments. + // darwinSpecialArgs; + + modules = + # include the global modules + globalModules + # include the Darwin modules + ++ darwinModules + # include Soxin modules + ++ (singleton self.darwinModule) + # include home-manager modules + ++ (singleton home-manager.darwinModules.home-manager) + # configure Nix registry so users can find soxin + ++ singleton { nix.registry.soxin.flake = self; } + # configure home-manager + ++ (singleton { + # tell home-manager to use the global (as in Darwin system-level) pkgs + # and install all user packages through the users.users..packages. + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + + home-manager.extraSpecialArgs = { + # send home-manager down to the home-manager modules + inherit home-manager; + + # the mode allows us to tell at what level we are within the modules. + mode = "home-manager"; + # send soxin down to home-manager. + soxin = self; + } + # include the global special arguments. + // globalSpecialArgs + # include the home-manager special arguments. + // hmSpecialArgs; + + home-manager.sharedModules = + # include the global modules + globalModules + # include the home-manager modules + ++ hmModules + # include Soxin module + ++ (singleton self.nixosModule); + }); +}) diff --git a/lib/default.nix b/lib/default.nix index 102651c..560ed42 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,6 +1,7 @@ -{ lib, self, home-manager, ... }: +{ lib, self, darwin, home-manager, ... }: rec { + darwinSystem = import ./darwin-system.nix { inherit self lib darwin home-manager; }; homeManagerConfiguration = import ./home-manager-configuration.nix { inherit self lib home-manager; }; mkSoxinModule = import ./mk-soxin-module.nix { inherit lib modules; }; modules = import ./modules { inherit lib; };