diff options
| author | seth <[email protected]> | 2023-08-24 07:49:07 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2023-08-24 07:49:07 -0400 |
| commit | fab63c5065d06e577dab7faec41a8365b80c48e4 (patch) | |
| tree | 6ebe19664758903f0c6d2df619496c405de612cd | |
| parent | d266cbb1844959961e7aa12a9b979d8676d14e98 (diff) | |
templates/full: improve layout
| -rw-r--r-- | templates/full/flake.nix | 26 | ||||
| -rw-r--r-- | templates/full/nix/default.nix | 15 | ||||
| -rw-r--r-- | templates/full/nix/dev.nix | 28 | ||||
| -rw-r--r-- | templates/full/nix/flake/default.nix | 43 | ||||
| -rw-r--r-- | templates/full/nix/packages/default.nix | 23 | ||||
| -rw-r--r-- | templates/full/nix/packages/hello.nix | 29 | ||||
| -rw-r--r-- | templates/full/nix/pkgs/default.nix | 24 | ||||
| -rw-r--r-- | templates/full/nix/pkgs/hello.nix | 25 |
8 files changed, 108 insertions, 105 deletions
diff --git a/templates/full/flake.nix b/templates/full/flake.nix index c745441..3976e91 100644 --- a/templates/full/flake.nix +++ b/templates/full/flake.nix @@ -3,24 +3,34 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; - flake-compat = { + + compat = { url = "github:edolstra/flake-compat"; flake = false; }; - flake-parts = { + + parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; - pre-commit-hooks = { + + pre-commit = { url = "github:cachix/pre-commit-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs-stable.follows = "nixpkgs"; - inputs.flake-compat.follows = "flake-compat"; + inputs.flake-compat.follows = "compat"; }; }; - outputs = inputs: - inputs.flake-parts.lib.mkFlake - {inherit inputs;} - {imports = [./nix];}; + outputs = { + parts, + pre-commit, + ... + } @ inputs: + parts.lib.mkFlake {inherit inputs;} { + imports = [ + pre-commit.flakeModule + ./nix + ]; + }; } diff --git a/templates/full/nix/default.nix b/templates/full/nix/default.nix index 4b52983..2033702 100644 --- a/templates/full/nix/default.nix +++ b/templates/full/nix/default.nix @@ -1,6 +1,17 @@ _: { imports = [ - ./packages - ./flake + ./dev.nix + ./pkgs ]; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + perSystem = {pkgs, ...}: { + formatter = pkgs.alejandra; + }; } diff --git a/templates/full/nix/dev.nix b/templates/full/nix/dev.nix new file mode 100644 index 0000000..508e3d6 --- /dev/null +++ b/templates/full/nix/dev.nix @@ -0,0 +1,28 @@ +{self, ...}: { + perSystem = { + config, + pkgs, + ... + } @ args: { + pre-commit = { + settings.hooks = { + alejandra.enable = true; + deadnix.enable = true; + nil.enable = true; + statix.enable = true; + }; + }; + + devShells = { + default = pkgs.mkShell { + shellHook = config.pre-commit.installationScript; + packages = with pkgs; [ + self.formatter.${args.system} + deadnix + nil + statix + ]; + }; + }; + }; +} diff --git a/templates/full/nix/flake/default.nix b/templates/full/nix/flake/default.nix deleted file mode 100644 index 4402a16..0000000 --- a/templates/full/nix/flake/default.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ - inputs, - self, - ... -}: { - perSystem = { - pkgs, - system, - ... - }: { - checks = { - pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { - src = builtins.path { - name = "flake-src"; - path = ../../.; - }; - - hooks = { - alejandra.enable = true; - deadnix.enable = true; - nil.enable = true; - statix.enable = true; - }; - }; - }; - - devShells = let - inherit (pkgs) mkShell; - in { - default = mkShell { - inherit (self.checks.${system}.pre-commit-check) shellHook; - packages = with pkgs; [ - alejandra - deadnix - nil - statix - ]; - }; - }; - - formatter = pkgs.alejandra; - }; -} diff --git a/templates/full/nix/packages/default.nix b/templates/full/nix/packages/default.nix deleted file mode 100644 index 78e10db..0000000 --- a/templates/full/nix/packages/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{self, ...}: let - version = builtins.substring 0 8 self.lastModifiedDate; - - packageFn = pkgs: { - hello = pkgs.callPackage ./hello.nix {inherit version;}; - }; -in { - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - flake.overlays = final: _: packageFn final; - - perSystem = {pkgs, ...}: { - packages = let - p = packageFn pkgs; - in - p // {default = p.hello;}; - }; -} diff --git a/templates/full/nix/packages/hello.nix b/templates/full/nix/packages/hello.nix deleted file mode 100644 index 30cfc8d..0000000 --- a/templates/full/nix/packages/hello.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ - lib, - stdenv, - version, - ... -}: let - inherit (lib) licenses maintainers platforms; -in - stdenv.mkDerivation rec { - pname = "hello"; - inherit version; - - src = builtins.path { - name = "${pname}-src"; - path = ./.; - }; - - installPhase = '' - echo "hi" > $out - ''; - - meta = { - description = ""; - homepage = ""; - license = licenses.mit; - maintainers = [maintainers.getchoo]; - platforms = platforms.linux; - }; - } diff --git a/templates/full/nix/pkgs/default.nix b/templates/full/nix/pkgs/default.nix new file mode 100644 index 0000000..2bc2a93 --- /dev/null +++ b/templates/full/nix/pkgs/default.nix @@ -0,0 +1,24 @@ +{ + self, + inputs, + ... +}: let + version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; + + filterPkgs = + inputs.nixpkgs.lib.filterAttrs (_: v: + builtins.elem (v.meta.platforms or []) && !(v.meta.broken or false)); + + packageFn = pkgs: { + hello = pkgs.callpackage ./hello.nix {inherit self version;}; + }; +in { + flake.overlays = _: prev: (packageFn prev); + + perSystem = {pkgs, ...}: { + packages = let + p = filterPkgs (packageFn pkgs); + in + p // {default = p.hello;}; + }; +} diff --git a/templates/full/nix/pkgs/hello.nix b/templates/full/nix/pkgs/hello.nix new file mode 100644 index 0000000..1e2ec12 --- /dev/null +++ b/templates/full/nix/pkgs/hello.nix @@ -0,0 +1,25 @@ +{ + lib, + stdenv, + self, + version, + ... +}: +stdenv.mkDerivation { + pname = "hello"; + inherit version; + + src = lib.cleanSource self; + + installPhase = '' + echo "hi" > $out + ''; + + meta = with lib; { + description = ""; + homepage = ""; + license = licenses.mit; + maintainers = [maintainers.getchoo]; + platforms = platforms.linux; + }; +} |
