diff --git a/Makefile b/Makefile index d0fc5db..4f0c5d0 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,3 @@ -HOSTNAME := $(shell hostname -s) - -all: - if [[ "`uname`" == 'Darwin' ]]; then \ - echo macOS; \ - make macos-system; \ - else \ - echo NixOS; \ - make nixos-system; \ - fi - -nixos-system: - nixos-rebuild --use-remote-sudo switch -j auto - -macos-system: - sudo ls # cache sudo - $$(nix build --extra-experimental-features "flakes nix-command" .#darwinConfigurations.$(HOSTNAME).system --no-link --json | nix --extra-experimental-features "flakes nix-command" run ${WITHEXP} nixpkgs#jq -- -r '.[].outputs.out')/sw/bin/darwin-rebuild switch --flake . - # Update the primary inputs # # Typically run as: `make update all` followed by a git commit. diff --git a/README.md b/README.md index f4402fa..46d3de3 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ This repository contains the Nix / NixOS configuration for all of my systems. St To build, ```sh -# First, edit nixosConfigurations or darwinConfigurations in flake.nix to add -# your system's hostname. And then change `userName` to your username. -make +# First, edit nixosConfigurations in flake.nix to add your system's hostname. +# And then change `userName` to your username. +nix run ``` ## Install notes @@ -18,14 +18,14 @@ make - Windows (via WSL): https://github.com/nix-community/NixOS-WSL - Clone this repo at `/etc/nixos` - Edit `flake.nix` and add your Linux's hostname in the `nixosConfigurations` set, as well as update `userName`. - - Run `make`. That's it. Re-open your shell. + - Run `nix run`. That's it. Re-open your shell. - macOS: - Install Nix normally (multi-user) - Install [nix-darwin](https://github.com/LnL7/nix-darwin) - This will create a `~/.nixpkgs/darwin-configuration.nix`, but we do not need that. - Clone this repo anywhere - Edit `flake.nix` and add your Mac's [hostname](https://support.apple.com/en-ca/guide/mac-help/mchlp2322/mac) in the `darwinConfigurations` set, as well update `userName`. - - Run `make`.[^cleanup] That's it. Re-open your shell. + - Run `nix run`.[^cleanup] That's it. Re-open your shell. [^cleanup]: You might have to `rm -rf /etc/nix/nix.conf`, so our flake.nix can do its thing. diff --git a/flake.nix b/flake.nix index b26110e..ba27e6b 100644 --- a/flake.nix +++ b/flake.nix @@ -163,14 +163,8 @@ }; in { - # These are indexed, by convention, using hostnames. - # For example, if `sky.local` is the hostname of your Mac, then use - # `sky` here. - air = defaultMacosSystem; - sky = defaultMacosSystem; + default = defaultMacosSystem; }; - - } // inputs.flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" ] (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -184,6 +178,32 @@ ]; }; formatter = pkgs.nixpkgs-fmt; + apps.default = + let + bashCmdApp = name: cmd: { + type = "app"; + program = + let + pkgs = inputs.nixpkgs.legacyPackages.aarch64-darwin; + in + (pkgs.writeShellApplication { + inherit name; + text = '' + set -x + ${cmd} + ''; + }) + "/bin/${name}"; + }; + in + if system == "aarch64-darwin" then + bashCmdApp "darwin" '' + ${self.darwinConfigurations.default.system}/sw/bin/darwin-rebuild \ + switch --flake ${self}#default + '' + else + bashCmdApp "linux" '' + nixos-rebuild --use-remote-sudo switch -j auto + ''; } );