diff options
Diffstat (limited to 'templates/nixos')
| -rw-r--r-- | templates/nixos/flake.nix | 40 | ||||
| -rw-r--r-- | templates/nixos/justfile | 53 |
2 files changed, 38 insertions, 55 deletions
diff --git a/templates/nixos/flake.nix b/templates/nixos/flake.nix index 1ae27dc..2f4f57f 100644 --- a/templates/nixos/flake.nix +++ b/templates/nixos/flake.nix @@ -2,7 +2,8 @@ description = "my cool flake"; inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; @@ -10,8 +11,9 @@ }; outputs = - { nixpkgs, ... }@inputs: + { self, nixpkgs, ... }@inputs: let + inherit (nixpkgs) lib; systems = [ "x86_64-linux" "aarch64-linux" @@ -19,26 +21,36 @@ "aarch64-darwin" ]; - forAllSystems = fn: nixpkgs.lib.genAttrs systems (sys: fn nixpkgs.legacyPackages.${sys}); + forAllSystems = lib.genAttrs systems; + nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); in { nixosConfigurations.myComputer = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ ./configuration.nix ]; + modules = [ ./configuration.nix ]; # You should already have this specialArgs = { + # Gives your configuration.nix access to the inputs from above inherit inputs; }; }; - devShells = forAllSystems (pkgs: { - default = pkgs.mkShellNoCC { - packages = with pkgs; [ - just - fzf - ]; - }; - }); + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShellNoCC { + packages = [ + pkgs.fzf + pkgs.just + # Lets you run `nixfmt` to format all of your files + self.formatter.${system} + ]; + }; + } + ); - formatter = forAllSystems (pkgs: pkgs.alejandra); + # You can also use `nix fmt` + formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); }; } diff --git a/templates/nixos/justfile b/templates/nixos/justfile index 7c44f0d..a6f8655 100644 --- a/templates/nixos/justfile +++ b/templates/nixos/justfile @@ -1,51 +1,22 @@ -alias b := build -alias c := check -alias dr := dry-run +alias b := boot +alias s := switch alias sw := switch alias t := test -alias u := update -alias ui := update-input -rebuildArgs := "--verbose" rebuild := if os() == "macos" { "darwin-rebuild" } else { "nixos-rebuild" } default: - @just --choose + @just --choose -[private] -rebuild subcmd *extraArgs="": - {{ rebuild }} {{ subcmd }} {{ rebuildArgs }} --flake . {{ extraArgs }} +# Wrapper for `nixos-rebuild`. See `man nixos-rebuild` +rebuild subcmd *args="": + {{ rebuild }} {{ subcmd }} --flake . {{ args }} -boot *extraArgs="": (rebuild "boot" extraArgs) +# Switch to your new configuration when you reboot +boot *args="": (rebuild "boot" args) -build *extraArgs="": (rebuild "build" extraArgs) +# Immediately switch to your new configuration +switch *args="": (rebuild "switch" args) -dry-run *extraArgs="": (rebuild "dry-run" extraArgs) - -switch *extraArgs="": (rebuild "switch" extraArgs) - -test *extraArgs="": (rebuild "test" extraArgs) - -check *args="": - nix flake check \ - --print-build-logs \ - --show-trace \ - --accept-flake-config \ - {{ args }} - -eval system *args="": - nix eval \ - --raw \ - '.#nixosConfigurations.{{ system }}.config.system.build.toplevel' \ - {{ args }} - -update: - nix flake update \ - --commit-lock-file \ - --commit-lockfile-summary "flake: update all inputs" - -update-input input: - nix flake lock \ - --update-input {{ input }} \ - --commit-lock-file \ - --commit-lockfile-summary "flake: update {{ input }}" +# Temporarily switch to your new configuration +test *args="": (rebuild "test" args) |
