From ee831b6c4838f150cd6c9e422caba5b844382b26 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Mon, 18 Nov 2024 21:31:43 -0600 Subject: [PATCH] Fix flake.nix and use its hooks Fixes #24 --- .gitignore | 1 + flake.lock | 102 ++++++++++++++++++++++++++++++-------------------- flake.nix | 108 +++++++++++++++++++---------------------------------- 3 files changed, 101 insertions(+), 110 deletions(-) diff --git a/.gitignore b/.gitignore index 1e1b574..8fac0c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.pre-commit-config.yaml output_* output/* *.box diff --git a/flake.lock b/flake.lock index b3ca643..7641126 100644 --- a/flake.lock +++ b/flake.lock @@ -1,21 +1,18 @@ { "nodes": { - "devshell": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - }, + "flake-compat": { + "flake": false, "locked": { - "lastModified": 1717408969, - "narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=", - "owner": "numtide", - "repo": "devshell", - "rev": "1ebbe68d57457c8cae98145410b164b5477761f4", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { - "owner": "numtide", - "repo": "devshell", + "owner": "edolstra", + "repo": "flake-compat", "type": "github" } }, @@ -37,31 +34,55 @@ "type": "github" } }, - "flake-utils": { + "gitignore": { "inputs": { - "systems": "systems" + "nixpkgs": [ + "hooks", + "nixpkgs" + ] }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1731363552, + "narHash": "sha256-vFta1uHnD29VUY4HJOO/D6p6rxyObnf+InnSMT4jlMU=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "cd1af27aa85026ac759d5d3fccf650abe7e1bbf0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1704161960, - "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "63143ac2c9186be6d9da6035fa22620018c85932", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", "type": "github" }, "original": { @@ -83,6 +104,22 @@ "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1730741070, + "narHash": "sha256-edm8WG19kWozJ/GqyYx2VjW99EdhjKwbY3ZwdlPAAlo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d063c1dd113c91ab27959ba540c0d9753409edf3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1720750130, @@ -116,26 +153,11 @@ }, "root": { "inputs": { - "devshell": "devshell", "flake-parts": "flake-parts", + "hooks": "hooks", "nixpkgs": "nixpkgs_2", "process-compose": "process-compose" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 0d34da1..3c106b7 100644 --- a/flake.nix +++ b/flake.nix @@ -3,9 +3,9 @@ description = "Greg's homepage"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - devshell.url = "github:numtide/devshell"; flake-parts.url = "github:hercules-ci/flake-parts"; process-compose.url = "github:Platonic-Systems/process-compose-flake"; + hooks.url = "github:cachix/git-hooks.nix"; }; outputs = @@ -41,11 +41,6 @@ packer build -only=${d.provider}.${d.arch} -var-file=${distroFile d}''; in flake-parts.lib.mkFlake { inherit inputs; } { - imports = [ - inputs.devshell.flakeModule - inputs.flake-root.flakeModule - inputs.treefmt-nix.flakeModule - ]; flake = { # Universal things }; @@ -65,56 +60,29 @@ inherit system; config.allowUnfree = true; }; - # https://numtide.github.io/devshell/intro.html - devshells.default = { + + devShells.default = pkgs.mkShell { + buildInputs = self'.checks.pre-commit.enabledPackages; + shellHook = self'.checks.pre-commit.shellHook; + + packages = + (with pkgs; [ + vagrant + ]) + ++ (with self'.packages; [ + cache + generate + shellcheck + validate + ]) + ++ (builtins.map (d: self'.packages."build${name d}") withProviders); # These commands will be shown in the motd that users read # upon entering the shell - commands = - [ - { - package = self'.packages.cache; - category = "utils"; - help = "Downloads ISO files and adds them to the S3 bucket"; - } - { - package = self'.packages.generate; - category = "utils"; - help = "Generate dynamic HCL files"; - } - { - package = self'.packages.shellcheck; - category = "utils"; - help = "Run shellchecks"; - } - { - package = self'.packages.validate; - category = "utils"; - help = "Validate all the files"; - } - { - package = pkgs.vagrant; - category = "utils"; - help = "Vagrant to help with testing"; - } - ] - ++ (builtins.map (d: { - package = self'.packages."build${name d}"; - category = "builds"; - }) withProviders); - env = [ - { - name = "EFI_DIR"; - value = "${pkgs.OVMF.fd}/FV/"; - } - { - name = "PACKER_CONFIG_DIR"; - value = "./packer_config"; - } - { - name = "STORAGE_URL"; - value = "http://s3.thehellings.lan:9000"; - } - ]; + env = { + EFI_DIR = "${pkgs.OVMF.fd}/FV/"; + PACKER_CONFIG_DIR = "./packer_config"; + STORAGE_URL = "http://s3.thehellings.lan:9000"; + }; }; # This is not special, this is just flakes @@ -162,8 +130,8 @@ // { name = "ci${name d}"; text = '' - set -x - ${cmd d} -except=upload sources/ + set -x + ${cmd d} -except=upload sources/ ''; } ); @@ -174,8 +142,8 @@ // { name = "upload${name d}"; text = '' - set -x - ${cmd d} sources/ + set -x + ${cmd d} sources/ ''; } ); @@ -235,12 +203,12 @@ pup ]; text = '' - shopt -s globstar - for vars in distros/**/*.pkrvars.hcl.sh; do - bash "./''${vars}" - done - set -x - echo "BUILD=$(date "+%Y.%m.%d.%H")" >> build.env + shopt -s globstar + for vars in distros/**/*.pkrvars.hcl.sh; do + bash "./''${vars}" + done + set -x + echo "BUILD=$(date "+%Y.%m.%d.%H")" >> build.env ''; }; shellcheck = pkgs.writeShellApplication { @@ -249,12 +217,12 @@ shellcheck ]; text = '' - scripts=() - shopt -s globstar - for f in **/*.sh; do - scripts+=("$f") - done - shellcheck -e SC2239 "''${scripts[@]}" + scripts=() + shopt -s globstar + for f in **/*.sh; do + scripts+=("$f") + done + shellcheck -e SC2239 "''${scripts[@]}" ''; }; };