Skip to content

Commit

Permalink
feat: welcome darwin configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnossiom committed Aug 2, 2024
1 parent eac1af6 commit 3b8b884
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ _default:
switch:
sudo nixos-rebuild switch --show-trace

switch-darwin:
darwin-rebuild switch --flake ~/.config/nix-darwin

build:
nixos-rebuild build --show-trace

Expand Down
21 changes: 21 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
home-manager.url = "github:nix-community/home-manager/release-24.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";

nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";

agenix.url = "github:ryantm/agenix";
agenix.inputs.nixpkgs.follows = "nixpkgs";
agenix.inputs.home-manager.follows = "home-manager";
Expand Down Expand Up @@ -87,6 +90,7 @@
# (user "milomoisson" { description = "Milo Moisson"; profile = "minimal"; keys = keys.users; })
# ];
};

# I bundle my Home Manager config via the NixOS modules which create system generations and give free rollbacks.
# However, in non-NixOS contexts, you can still use Home Manager to manage dotfiles using this template.
homeConfigurations = {
Expand All @@ -96,5 +100,15 @@
# modules = [ ./home-manager/profiles/desktop.nix ];
# };
};

# $ darwin-rebuild build --flake .#MacBook-Pro-de-Milo
darwinConfigurations = with flake-lib.darwin; {
"apple-wiro-laptop" = createSystem pkgs."aarch64-darwin" [
(system "apple-wiro-laptop" "macintosh")
(user "milomoisson" { description = "Milo Moisson"; profile = "desktop"; keys = keys.users; })
];
};

# darwinPackages = ...;
};
}
20 changes: 16 additions & 4 deletions lib/flake/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ in
rec {
forAllSystems = genAttrs [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];

# Makes
# - flake accessible through `self`
# - local flake library accessible through `llib`
# - unstable nixpkgs set accessible through `upkgs`
# - `self`: flake
# - `llib`: local flake library
# - `upkgs`: unstable nixpkgs set
# - `isDarwin`: indicates if system is darwin
specialModuleArgs = pkgs: {
inherit self;
llib = import ../. pkgs;
upkgs = import nixpkgs-unstable { inherit (pkgs) system config; };
isDarwin = pkgs.stdenv.isDarwin;
};

createSystem = pkgs: modules: nixosSystem {
Expand All @@ -39,4 +40,15 @@ rec {
};
user = import ./user.nix;
managedDiskLayout = import ./managedDiskLayout.nix;

# Darwin related
darwin = {
createSystem = pkgs: modules: darwinSystem {
inherit pkgs modules;
specialArgs = specialModuleArgs pkgs;
};

inherit system;
user = import ./user.nix;
};
}
19 changes: 19 additions & 0 deletions nixos/hardware/apple-wiro-laptop.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ self
, config
, lib
, ...
}:

{
imports = [ ];

config = {
system.configurationRevision = self.rev or self.dirtyRev;

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;

nixpkgs.hostPlatform = "aarch64-darwin";
};
}
13 changes: 11 additions & 2 deletions nixos/modules/nix.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ self
, lib
, pkgs
, config
, isDarwin
, ...
}:

Expand All @@ -27,8 +29,13 @@ in

gc = {
automatic = true;
dates = "weekly";
};
}
# Same option to say that GC is ran weekly at 3h15
// (if isDarwin then {
interval = { Weekday = 7; Hour = 3; Minute = 15; };
} else {
dates = "Sun *-*-* 03:15:00";
});

settings = {
experimental-features = [ "nix-command" "flakes" ];
Expand All @@ -45,11 +52,13 @@ in
"https://nix-community.cachix.org"
"https://mrnossiom.cachix.org"
"https://radicle.cachix.org"
"https://helix.cachix.org"
];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"mrnossiom.cachix.org-1:WKo+xfDFaT6pRP4YiIFsEXvyBzI/Pm9uGhURgF1wlQg="
"radicle.cachix.org-1:x7jrVNzziAP6GAAJF2wvgJBndqRhmh2EylgWr93ofx0="
"helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="
];
};
};
Expand Down
27 changes: 27 additions & 0 deletions nixos/profiles/macintosh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ self
, lib
, config
, pkgs
, upkgs
, ...
}:

with lib;

let
inherit (self.outputs) nixosModules;
in
{
# Hardware is imported in the flake to be machine specific
imports = map (modPath: ../modules/${modPath}) [
# "agenix.nix"
# "logiops.nix"
"nix.nix"
];

security.pam.enableSudoTouchIdAuth = true;

services.nix-daemon.enable = true;

programs.zsh.enable = true;
}

0 comments on commit 3b8b884

Please sign in to comment.