summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
Diffstat (limited to 'templates')
-rw-r--r--templates/basic/default.nix13
-rw-r--r--templates/basic/flake.nix53
-rw-r--r--templates/full/flake.nix2
-rw-r--r--templates/full/nix/default.nix2
-rw-r--r--templates/full/nix/packages.nix12
-rw-r--r--templates/nixos/flake.nix40
-rw-r--r--templates/nixos/justfile53
7 files changed, 96 insertions, 79 deletions
diff --git a/templates/basic/default.nix b/templates/basic/default.nix
new file mode 100644
index 0000000..16b3594
--- /dev/null
+++ b/templates/basic/default.nix
@@ -0,0 +1,13 @@
+{
+ pkgs ? import nixpkgs {
+ inherit system;
+ config = { };
+ overlays = [ ];
+ },
+ lib ? pkgs.lib,
+ nixpkgs ? <nixpkgs>,
+ system ? builtins.currentSystem,
+}:
+{
+ inherit (pkgs) lib;
+}
diff --git a/templates/basic/flake.nix b/templates/basic/flake.nix
index 1840cb1..f1c84df 100644
--- a/templates/basic/flake.nix
+++ b/templates/basic/flake.nix
@@ -2,12 +2,13 @@
description = "";
inputs = {
- nixpkgs.url = "nixpkgs/nixos-unstable";
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
- { self, nixpkgs, ... }:
+ { self, nixpkgs }:
let
+ inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
@@ -15,31 +16,55 @@
"aarch64-darwin"
];
- forAllSystems = fn: nixpkgs.lib.genAttrs systems (sys: fn nixpkgs.legacyPackages.${sys});
- version = self.shortRev or self.dirtyShortRev or "unknown";
+ forAllSystems = fn: lib.genAttrs systems;
+ nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
in
{
+ checks = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgsFor.${system};
+ in
+ {
+ nixfmt = pkgs.runCommand "check-nixfmt" ''
+ cd ${self}
+
+ echo "Running nixfmt..."
+ ${lib.getExe self.formatter.${system}}--check .
+
+ touch $out
+ '';
+ }
+ );
+
devShells = forAllSystems (
- { pkgs, system, ... }:
+ system:
+ let
+ pkgs = nixpkgsFor.${system};
+ in
{
default = pkgs.mkShell {
- packages = with pkgs; [ bash ];
+ packages = [ pkgs.bash ];
inputsFrom = [ self.packages.${system}.hello ];
};
}
);
- formatter = forAllSystems (pkgs: pkgs.alejandra);
+ formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
packages = forAllSystems (
- { pkgs, system, ... }:
- {
- hello = pkgs.callPackage ./. { inherit version; };
- default = self.packages.${system}.hello;
- }
- );
+ system:
+ let
+ pkgs = import ./. {
+ inherit system nixpkgs lib;
+ pkgs = nixpkgsFor.${system};
+ };
- overlays.default = _: prev: { hello = prev.callPackage ./. { inherit version; }; };
+ isAvailable = lib.meta.availableOn { inherit system; };
+ pkgs' = lib.filterAttrs (_: isAvailable) pkgs;
+ in
+ pkgs // { default = pkgs'.hello; }
+ );
};
}
diff --git a/templates/full/flake.nix b/templates/full/flake.nix
index 9d33ecb..b35fa45 100644
--- a/templates/full/flake.nix
+++ b/templates/full/flake.nix
@@ -2,7 +2,7 @@
description = "";
inputs = {
- nixpkgs.url = "nixpkgs/nixpkgs-unstable";
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
diff --git a/templates/full/nix/default.nix b/templates/full/nix/default.nix
index 66bb711..87d9d60 100644
--- a/templates/full/nix/default.nix
+++ b/templates/full/nix/default.nix
@@ -7,6 +7,6 @@
perSystem =
{ pkgs, ... }:
{
- formatter = pkgs.alejandra;
+ formatter = pkgs.nixfmt-rfc-style;
};
}
diff --git a/templates/full/nix/packages.nix b/templates/full/nix/packages.nix
index e48cdde..8774a3b 100644
--- a/templates/full/nix/packages.nix
+++ b/templates/full/nix/packages.nix
@@ -1,17 +1,13 @@
{ self, ... }:
-let
- version = self.shortRev or self.dirtyShortRev or "unknown";
-in
{
- flake.overlays.default = _: prev: {
- hello = prev.callPackage ./derivation.nix { inherit version; };
- };
-
perSystem =
{ pkgs, self', ... }:
{
package = {
- hello = pkgs.callPackage ./derivation.nix { inherit version; };
+ hello = pkgs.callPackage ./derivation.nix {
+ version = self.shortRev or self.dirtyShortRev or "unknown";
+ };
+
default = self'.packages.hello;
};
};
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)