From 19b64bed1e31489de83f0c7d1b0ec1e77e3f7c49 Mon Sep 17 00:00:00 2001 From: seth Date: Wed, 16 Oct 2024 21:18:46 -0400 Subject: templates: cleanup --- flake.nix | 5 ++- templates/basic/default.nix | 13 -------- templates/basic/flake.nix | 70 --------------------------------------- templates/full/default.nix | 9 ----- templates/full/flake.nix | 30 ----------------- templates/full/nix/default.nix | 12 ------- templates/full/nix/derivation.nix | 1 - templates/full/nix/packages.nix | 14 -------- templates/full/nix/shell.nix | 13 -------- templates/nixos/flake.nix | 6 ++-- templates/nixos/justfile | 7 ++-- templates/standard/default.nix | 12 +++++++ templates/standard/flake.nix | 69 ++++++++++++++++++++++++++++++++++++++ 13 files changed, 92 insertions(+), 169 deletions(-) delete mode 100644 templates/basic/default.nix delete mode 100644 templates/basic/flake.nix delete mode 100644 templates/full/default.nix delete mode 100644 templates/full/flake.nix delete mode 100644 templates/full/nix/default.nix delete mode 100644 templates/full/nix/derivation.nix delete mode 100644 templates/full/nix/packages.nix delete mode 100644 templates/full/nix/shell.nix create mode 100644 templates/standard/default.nix create mode 100644 templates/standard/flake.nix diff --git a/flake.nix b/flake.nix index 41d61a1..8d078c3 100644 --- a/flake.nix +++ b/flake.nix @@ -63,9 +63,8 @@ }; in lib.mapAttrs toTemplate { - basic = "Minimal boilerplate for my Flakes"; - full = "Big template for complex Flakes (using flake-parts)"; - nixos = "minimal boilerplate for a Flake-based NixOS configuration"; + standard = "Minimal boilerplate for my Flakes"; + nixos = "Minimal boilerplate for a Flake-based NixOS configuration"; }; }; } diff --git a/templates/basic/default.nix b/templates/basic/default.nix deleted file mode 100644 index 16b3594..0000000 --- a/templates/basic/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - pkgs ? import nixpkgs { - inherit system; - config = { }; - overlays = [ ]; - }, - lib ? pkgs.lib, - nixpkgs ? , - system ? builtins.currentSystem, -}: -{ - inherit (pkgs) lib; -} diff --git a/templates/basic/flake.nix b/templates/basic/flake.nix deleted file mode 100644 index 86efae0..0000000 --- a/templates/basic/flake.nix +++ /dev/null @@ -1,70 +0,0 @@ -{ - description = ""; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - }; - - outputs = - { self, nixpkgs }: - let - inherit (nixpkgs) lib; - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - forAllSystems = 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 ( - system: - let - pkgs = nixpkgsFor.${system}; - in - { - default = pkgs.mkShell { - packages = [ pkgs.bash ]; - - inputsFrom = [ self.packages.${system}.hello ]; - }; - } - ); - - formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); - - packages = forAllSystems ( - system: - let - pkgs = import ./. { - inherit system nixpkgs lib; - pkgs = nixpkgsFor.${system}; - }; - - isAvailable = lib.meta.availableOn { inherit system; }; - pkgs' = lib.filterAttrs (_: isAvailable) pkgs; - in - pkgs // { default = pkgs'.hello; } - ); - }; -} diff --git a/templates/full/default.nix b/templates/full/default.nix deleted file mode 100644 index 6466507..0000000 --- a/templates/full/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -(import ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } -) { src = ./.; }).defaultNix diff --git a/templates/full/flake.nix b/templates/full/flake.nix deleted file mode 100644 index b35fa45..0000000 --- a/templates/full/flake.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - description = ""; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; - - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - }; - - outputs = - inputs: - inputs.flake-parts.lib.mkFlake { inherit inputs; } { - imports = [ ./nix ]; - - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - }; -} diff --git a/templates/full/nix/default.nix b/templates/full/nix/default.nix deleted file mode 100644 index 87d9d60..0000000 --- a/templates/full/nix/default.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ - imports = [ - ./shell.nix - ./packages.nix - ]; - - perSystem = - { pkgs, ... }: - { - formatter = pkgs.nixfmt-rfc-style; - }; -} diff --git a/templates/full/nix/derivation.nix b/templates/full/nix/derivation.nix deleted file mode 100644 index ac18240..0000000 --- a/templates/full/nix/derivation.nix +++ /dev/null @@ -1 +0,0 @@ -{ hello }: hello diff --git a/templates/full/nix/packages.nix b/templates/full/nix/packages.nix deleted file mode 100644 index 8774a3b..0000000 --- a/templates/full/nix/packages.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ self, ... }: -{ - perSystem = - { pkgs, self', ... }: - { - package = { - hello = pkgs.callPackage ./derivation.nix { - version = self.shortRev or self.dirtyShortRev or "unknown"; - }; - - default = self'.packages.hello; - }; - }; -} diff --git a/templates/full/nix/shell.nix b/templates/full/nix/shell.nix deleted file mode 100644 index 680c875..0000000 --- a/templates/full/nix/shell.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - perSystem = - { pkgs, self', ... }: - { - devShells = { - default = pkgs.mkShell { - packages = [ self'.formatter ]; - - inputsFrom = [ self'.packages.hello ]; - }; - }; - }; -} diff --git a/templates/nixos/flake.nix b/templates/nixos/flake.nix index 2f4f57f..f78331c 100644 --- a/templates/nixos/flake.nix +++ b/templates/nixos/flake.nix @@ -1,5 +1,5 @@ { - description = "my cool flake"; + description = "My cool Nix Flake"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -14,6 +14,7 @@ { self, nixpkgs, ... }@inputs: let inherit (nixpkgs) lib; + systems = [ "x86_64-linux" "aarch64-linux" @@ -22,7 +23,7 @@ ]; forAllSystems = lib.genAttrs systems; - nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); + nixpkgsFor = nixpkgs.legacyPackages; in { nixosConfigurations.myComputer = nixpkgs.lib.nixosSystem { @@ -43,6 +44,7 @@ packages = [ pkgs.fzf pkgs.just + # Lets you run `nixfmt` to format all of your files self.formatter.${system} ]; diff --git a/templates/nixos/justfile b/templates/nixos/justfile index a6f8655..5b524fb 100644 --- a/templates/nixos/justfile +++ b/templates/nixos/justfile @@ -1,5 +1,5 @@ -alias b := boot -alias s := switch +alias bo := boot +alias bu := build alias sw := switch alias t := test @@ -15,6 +15,9 @@ rebuild subcmd *args="": # Switch to your new configuration when you reboot boot *args="": (rebuild "boot" args) +# Build your new configuration +build *args="": (rebuild "build" args) + # Immediately switch to your new configuration switch *args="": (rebuild "switch" args) diff --git a/templates/standard/default.nix b/templates/standard/default.nix new file mode 100644 index 0000000..b782208 --- /dev/null +++ b/templates/standard/default.nix @@ -0,0 +1,12 @@ +{ + pkgs ? import nixpkgs { + inherit system; + config = { }; + overlays = [ ]; + }, + nixpkgs ? , + system ? builtins.currentSystem, +}: +{ + inherit (pkgs) hello; +} diff --git a/templates/standard/flake.nix b/templates/standard/flake.nix new file mode 100644 index 0000000..9c80e4b --- /dev/null +++ b/templates/standard/flake.nix @@ -0,0 +1,69 @@ +{ + description = ""; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = + { self, nixpkgs }: + let + inherit (nixpkgs) lib; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forAllSystems = lib.genAttrs systems; + nixpkgsFor = nixpkgs.legacyPackages; + in + { + checks = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + + mkCheck = + name: deps: script: + pkgs.runCommand name { nativeBuildInputs = deps; } script; + in + { + nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] '' + nixfmt --check ${self} + + touch $out + ''; + } + ); + + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShell { + packages = [ pkgs.bash ]; + + inputsFrom = [ self.packages.${system}.hello ]; + }; + } + ); + + formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); + + packages = forAllSystems ( + system: + let + pkgs = import ./default.nix { + pkgs = nixpkgsFor.${system}; + }; + + isAvailable = lib.meta.availableOn { inherit system; }; + pkgs' = lib.filterAttrs (_: isAvailable) pkgs; + in + pkgs // { default = pkgs'.hello or pkgs.emptyFile; } + ); + }; +} -- cgit v1.2.3