From c75040b642185641264341d344ac3df6b2a0c8af Mon Sep 17 00:00:00 2001 From: Luke Channings <461449+LukeChannings@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:52:43 +0000 Subject: [PATCH] Add darwin-system template --- .github/workflows/template-darwin-system.yaml | 24 +++++++ templates/darwin-system/.gitignore | 6 ++ templates/darwin-system/configuration.nix | 35 ++++++++++ templates/darwin-system/devenv.nix | 64 +++++++++++++++++++ templates/darwin-system/flake.nix | 54 ++++++++++++++++ templates/default.nix | 5 ++ 6 files changed, 188 insertions(+) create mode 100644 .github/workflows/template-darwin-system.yaml create mode 100644 templates/darwin-system/.gitignore create mode 100644 templates/darwin-system/configuration.nix create mode 100644 templates/darwin-system/devenv.nix create mode 100644 templates/darwin-system/flake.nix diff --git a/.github/workflows/template-darwin-system.yaml b/.github/workflows/template-darwin-system.yaml new file mode 100644 index 0000000..bd1fb83 --- /dev/null +++ b/.github/workflows/template-darwin-system.yaml @@ -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 diff --git a/templates/darwin-system/.gitignore b/templates/darwin-system/.gitignore new file mode 100644 index 0000000..e1a3fd4 --- /dev/null +++ b/templates/darwin-system/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +.devenv +.direnv +.vscode +.env +result diff --git a/templates/darwin-system/configuration.nix b/templates/darwin-system/configuration.nix new file mode 100644 index 0000000..eb24a9e --- /dev/null +++ b/templates/darwin-system/configuration.nix @@ -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; + }; + }; + } + ) + ]; + }; +} diff --git a/templates/darwin-system/devenv.nix b/templates/darwin-system/devenv.nix new file mode 100644 index 0000000..78138d7 --- /dev/null +++ b/templates/darwin-system/devenv.nix @@ -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"; + }; + }; + }; + }; +} diff --git a/templates/darwin-system/flake.nix b/templates/darwin-system/flake.nix new file mode 100644 index 0000000..b758d1e --- /dev/null +++ b/templates/darwin-system/flake.nix @@ -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 + ''; + }; + }; + }; +} diff --git a/templates/default.nix b/templates/default.nix index c107983..cc8501f 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -5,5 +5,10 @@ description = "Create a barebones devenv"; path = ./devenv; }; + + darwin-system = { + description = "Create a nix-darwin system configuration"; + path = ./darwin-system; + }; }; }