diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..cb982f0 --- /dev/null +++ b/.envrc @@ -0,0 +1,9 @@ +watch_file flake.nix +watch_file flake.lock + +DEVENV_ROOT_FILE="$(mktemp)" +printf %s "$PWD" > "$DEVENV_ROOT_FILE" +if ! use flake . --override-input devenv-root "file+file://$DEVENV_ROOT_FILE" +then + echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..55281ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.direnv/ +.devenv/ + +.pre-commit-config.yaml diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..4525ffe --- /dev/null +++ b/devenv.nix @@ -0,0 +1,8 @@ +{ + pre-commit.hooks = { + alejandra.enable = true; + deadnix.enable = true; + statix.enable = true; + flake-checker.enable = true; + }; +} diff --git a/flake.lock b/flake.lock index bcd769c..6ade029 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,23 @@ { "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1734424634, @@ -16,8 +34,21 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + } + }, "root": { "inputs": { + "flake-parts": "flake-parts", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 301611e..51bab88 100644 --- a/flake.nix +++ b/flake.nix @@ -1,21 +1,51 @@ { description = "A wrapper for Helix that provides language support"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - - outputs = {nixpkgs, ...}: let - supportedSystems = nixpkgs.lib.systems.flakeExposed; - forAllSupportedSystems = f: - nixpkgs.lib.genAttrs supportedSystems ( - system: - f (import nixpkgs { - inherit system; - config.allowUnfree = true; - }) - ); - in { - packages = forAllSupportedSystems (pkgs: { - default = pkgs.callPackage ./package.nix {}; - }); + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + devenv-root = { + url = "file+file:///dev/null"; + flake = false; + }; + devenv.url = "github:cachix/devenv"; }; + + outputs = { + self, + nixpkgs, + flake-parts, + devenv, + devenv-root, + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + devenv.flakeModule + ]; + + systems = nixpkgs.lib.systems.flakeExposed; + + flake = { + lib = nixpkgs.lib.extend (import ./lib.nix); + + nixosConfigurations = self.lib.genNixosConfigurations {inherit inputs;}; + }; + + perSystem = {pkgs, ...}: { + devenv.shells.default = { + devenv.root = let + devenvRootFileContent = builtins.readFile devenv-root.outPath; + in + pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent; + + name = "hxwrap"; + + imports = [ + ./devenv.nix + ]; + }; + + packages.default = pkgs.callPackage ./package.nix {}; + }; + }; }