Skip to content

Commit

Permalink
Add darwin-system template
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeChannings committed Sep 17, 2024
1 parent 5c19287 commit c75040b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/template-darwin-system.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Template test: darwin-system"
on:
push:
paths:
- .github/workflows/template-darwin-system.yaml
- templates/darwin-system/*

jobs:
binary-cache:
permissions:
contents: write
runs-on: macos-latest
steps:
- uses: "actions/checkout@v4"
- uses: "DeterminateSystems/nix-installer-action@main"
- uses: cachix/cachix-action@v14
with:
name: luke-channings
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build packages
run: |
export NIXPKGS_ALLOW_UNFREE=1
nix flake new -t .#darwin-system darwin-system
nix run --flake ./darwin-system#activate
6 changes: 6 additions & 0 deletions templates/darwin-system/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.devenv
.direnv
.vscode
.env
result
35 changes: 35 additions & 0 deletions templates/darwin-system/configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ inputs, ... }:
let
inherit (builtins) attrValues;
inherit (inputs) dotfiles nix-darwin;
in
{
flake.darwinConfigurations.default = nix-darwin.lib.darwinSystem {
system = "aarch64-darwin";

inherit inputs;

modules = [
(dotfiles.lib.configureOsModules {
osModules = attrValues dotfiles.modules.darwin;
homeModules = attrValues dotfiles.modules.homeModules;
})
(
let
username = "luke";
in
{ ... }:
{
users = {
knownUsers = [ username ];

users.${username} = {
home = "/Users/${username}";
uid = 502;
};
};
}
)
];
};
}
64 changes: 64 additions & 0 deletions templates/darwin-system/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{ inputs, ... }:
{
imports = [
inputs.devenv.flakeModule
inputs.treefmt-nix.flakeModule
];

perSystem =
{
config,
pkgs,
lib,
system,
...
}:
{
treefmt = {
projectRoot = ./.;
projectRootFile = "flake.nix";

programs.nixfmt.enable = true;
programs.deadnix.enable = true;
programs.biome = {
enable = true;
settings.formatter.indentStyle = "space";
};
};

devenv.shells.default = {
devenv.root =
let
devenvRootFileContent = builtins.readFile inputs.devenv-root.outPath;
in
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;

imports = [ inputs.toolbox.modules.devenv.vscode-workspace ];

packages = with pkgs; [
nixVersions.latest
];

vscode-workspace = {
extensions = with inputs.vscode-extensions.extensions.${system}.vscode-marketplace; [
jnoortheen.nix-ide
ibecker.treefmt-vscode
];

settings = {
nix = {
enableLanguageServer = true;
serverPath = lib.getExe pkgs.nil;
};

treefmt = {
command = lib.getExe config.treefmt.package;
config = config.treefmt.build.configFile;
};

editor.defaultFormatter = "ibecker.treefmt-vscode";
};
};
};
};
}
54 changes: 54 additions & 0 deletions templates/darwin-system/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
description = "Configuration for Luke's CAIS MacBook Pro";

inputs = {
devenv-root = {
url = "file+file:///dev/null";
flake = false;
};
dotfiles.url = "github:lukechannings/dotfiles";
dotfiles.inputs.devenv-root.follows = "devenv-root";
};

outputs =
inputs@{ dotfiles, self, ... }:
let
inputs' = dotfiles.inputs // inputs;
in
inputs'.flake-parts.lib.mkFlake { inputs = inputs'; } {
imports = [
./devenv.nix
./configuration.nix
];

systems = [
"aarch64-darwin"
"x86_64-darwin"

"x86_64-linux"
"aarch64-linux"
];

perSystem =
{ system, ... }:
let
pkgs = inputs'.nixpkgs.legacyPackages.${system};
in
{
_module.args.pkgs = pkgs;

packages =
let
inherit (inputs.dotfiles.inputs.nix-darwin.packages.${system}) darwin-rebuild;
in
{
inherit darwin-rebuild;

activate = pkgs.writeScriptBin "activate" ''
#!${pkgs.bash}/bin/bash
${darwin-rebuild}/bin/darwin-rebuild switch --flake ${self}#default
'';
};
};
};
}
5 changes: 5 additions & 0 deletions templates/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
description = "Create a barebones devenv";
path = ./devenv;
};

darwin-system = {
description = "Create a nix-darwin system configuration";
path = ./darwin-system;
};
};
}

0 comments on commit c75040b

Please sign in to comment.