diff options
author | a-kenji <aks.kenji@protonmail.com> | 2022-03-10 16:27:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-10 16:27:39 +0100 |
commit | bd849574bec51f03187522c6773e284e0f9a3d51 (patch) | |
tree | 1f5423b2c052f9ad60890a408c72b549d70a4c09 | |
parent | a25fd88dbb2e35f823c9dea34bdbc82149f6bd70 (diff) |
add(nix): treefmt / alejandra (#1201)
* add(nix): treefmt / alejandra
* fmt the nix tree
* add fmt check for nix to ci
* switch `nixpkgs-fmt` -> `alejandra`
-rw-r--r-- | .github/workflows/nix.yml | 42 | ||||
-rw-r--r-- | default.nix | 17 | ||||
-rw-r--r-- | flake.nix | 2 | ||||
-rw-r--r-- | nix/crate2nix.nix | 53 | ||||
-rw-r--r-- | nix/default.nix | 286 | ||||
-rw-r--r-- | nix/devShell.nix | 8 | ||||
-rw-r--r-- | shell.nix | 17 | ||||
-rw-r--r-- | treefmt.toml | 3 |
8 files changed, 231 insertions, 197 deletions
diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 44b6f826a..24b3f2845 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -9,26 +9,28 @@ on: - main jobs: - #check: - #runs-on: ubuntu-latest - #name: "flake check" - #environment: cachix - #timeout-minutes: 5 - #steps: - #- uses: actions/checkout@v3 - #with: - ## Nix Flakes doesn't work on shallow clones - #fetch-depth: 0 - #- uses: cachix/install-nix-action@v16 - #with: - #extra_nix_config: | - #experimental-features = nix-command flakes - #fetch-depth: 0 - #- uses: cachix/cachix-action@v10 - #with: - #name: zellij - ## If you chose API tokens for write access OR if you have a private cache - #authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + check: + runs-on: ubuntu-latest + name: "flake check" + environment: cachix + timeout-minutes: 5 + steps: + - uses: actions/checkout@v3 + with: + # Nix Flakes doesn't work on shallow clones + fetch-depth: 0 + - uses: cachix/install-nix-action@v16 + with: + extra_nix_config: | + experimental-features = nix-command flakes + fetch-depth: 0 + - uses: cachix/cachix-action@v10 + with: + name: zellij + # If you chose API tokens for write access OR if you have a private cache + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix develop .#fmtShell --command treefmt --fail-on-change + ## nix flake check still fails on IFD #- run: nix flake check --print-build-logs --show-trace build: diff --git a/default.nix b/default.nix index 873ece493..78bc3a1f6 100644 --- a/default.nix +++ b/default.nix @@ -1,13 +1,14 @@ (import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in +( + 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 +) +{ + src = ./.; +}) +.defaultNix @@ -14,5 +14,5 @@ crate2nix.flake = false; }; - outputs = { ... } @ args: import ./nix args; + outputs = {...} @ args: import ./nix args; } diff --git a/nix/crate2nix.nix b/nix/crate2nix.nix index 435627d4a..fc2ce4eb5 100644 --- a/nix/crate2nix.nix +++ b/nix/crate2nix.nix @@ -1,34 +1,35 @@ -{ pkgs -, crate2nix -, name -, src -, postInstall -, nativeBuildInputs -, desktopItems -, meta -}: - -let - inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) - generatedCargoNix; +{ + pkgs, + crate2nix, + name, + src, + postInstall, + nativeBuildInputs, + desktopItems, + meta, +}: let + inherit + (import "${crate2nix}/tools.nix" {inherit pkgs;}) + generatedCargoNix + ; project = import - (generatedCargoNix { - inherit name src; - }) - { - inherit pkgs; - buildRustCrateForPkgs = pkgs: - pkgs.buildRustCrate.override { - defaultCrateOverrides = pkgs.defaultCrateOverrides // { + (generatedCargoNix { + inherit name src; + }) + { + inherit pkgs; + buildRustCrateForPkgs = pkgs: + pkgs.buildRustCrate.override { + defaultCrateOverrides = + pkgs.defaultCrateOverrides + // { # Crate dependency overrides go here zellij = attrs: { inherit postInstall desktopItems meta name nativeBuildInputs; - }; }; - }; - }; - + }; + }; in -project.workspaceMembers.zellij.build + project.workspaceMembers.zellij.build diff --git a/nix/default.nix b/nix/default.nix index f7c59d484..18f56f841 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,9 +1,10 @@ -{ self -, nixpkgs -, rust-overlay -, flake-utils -, flake-compat -, crate2nix +{ + self, + nixpkgs, + rust-overlay, + flake-utils, + flake-compat, + crate2nix, }: flake-utils.lib.eachSystem [ "aarch64-linux" @@ -12,128 +13,153 @@ flake-utils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] - (system: - let - overlays = [ (import rust-overlay) ]; - - pkgs = import nixpkgs { inherit system overlays; }; - - crate2nixPkgs = import nixpkgs { inherit system; - overlays = [ - (self: _: { - rustc = rustToolchainToml; - cargo = rustToolchainToml; - }) - - ];}; - - name = "zellij"; - pname = name; - root = toString ../.; - - ignoreSource = [ ".git" "target" "example" ]; - - src = pkgs.nix-gitignore.gitignoreSource ignoreSource root; - - rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain; - cargoLock = { - lockFile = (builtins.path { path = ../Cargo.lock; name = "Cargo.lock"; }); - }; - cargo = rustToolchainToml; - rustc = rustToolchainToml; - - buildInputs = [ - rustToolchainToml - - # in order to run tests - pkgs.openssl - ]; - - nativeBuildInputs = [ - # generates manpages - pkgs.mandown - - pkgs.installShellFiles - pkgs.copyDesktopItems - - # for openssl/openssl-sys - pkgs.pkg-config - ]; - - devInputs = [ - pkgs.cargo-make - pkgs.rust-analyzer - pkgs.nixpkgs-fmt - - # optimizes wasm binaries - pkgs.binaryen - - # used for snapshotting the e2e tests - pkgs.cargo-insta - ]; - - postInstall = '' - mandown ./docs/MANPAGE.md > ./zellij.1 - installManPage ./zellij.1 - - # explicit behavior - $out/bin/zellij setup --generate-completion bash > ./completions.bash - installShellCompletion --bash --name ${pname}.bash ./completions.bash - $out/bin/zellij setup --generate-completion fish > ./completions.fish - installShellCompletion --fish --name ${pname}.fish ./completions.fish - $out/bin/zellij setup --generate-completion zsh > ./completions.zsh - installShellCompletion --zsh --name _${pname} ./completions.zsh - - install -Dm644 ./assets/logo.png $out/share/icons/hicolor/scalable/apps/zellij.png - - copyDesktopItems - ''; - - desktopItems = [ - (pkgs.makeDesktopItem { - type = "Application"; - inherit name; - desktopName = "zellij"; - terminal = true; - genericName = "Terminal multiplexer"; - comment = "Manage your terminal applications"; - exec = "zellij"; - icon = "zellij"; - categories = [ "ConsoleOnly;System" ]; - }) - ]; - meta = with pkgs.lib; { - homepage = "https://github.com/zellij-org/zellij/"; - description = "A terminal workspace with batteries included"; - license = [ licenses.mit ]; - }; - in - rec { - - # crate2nix - better incremental builds, but uses ifd - packages.zellij = crate2nixPkgs.callPackage ./crate2nix.nix { - inherit crate2nix name src desktopItems postInstall - meta nativeBuildInputs; - }; - - # native nixpkgs support - keep supported - packages.zellij-native = - (pkgs.makeRustPlatform { inherit cargo rustc; }).buildRustPackage { - inherit src name cargoLock - buildInputs nativeBuildInputs - postInstall desktopItems meta; - }; - - defaultPackage = packages.zellij; - - # nix run - apps.zellij = flake-utils.lib.mkApp { drv = packages.zellij; }; - defaultApp = apps.zellij; - - - devShell = pkgs.callPackage ./devShell.nix { - inherit buildInputs; - nativeBuildInputs = nativeBuildInputs ++ devInputs; - }; - +(system: let + overlays = [(import rust-overlay)]; + + pkgs = import nixpkgs {inherit system overlays;}; + + crate2nixPkgs = import nixpkgs { + inherit system; + overlays = [ + (self: _: { + rustc = rustToolchainToml; + cargo = rustToolchainToml; + }) + ]; + }; + + name = "zellij"; + pname = name; + root = toString ../.; + + ignoreSource = [".git" "target" "example"]; + + src = pkgs.nix-gitignore.gitignoreSource ignoreSource root; + + rustToolchainToml = pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain; + cargoLock = { + lockFile = (builtins.path { + path = ../Cargo.lock; + name = "Cargo.lock"; + }); + }; + cargo = rustToolchainToml; + rustc = rustToolchainToml; + + buildInputs = [ + rustToolchainToml + + # in order to run tests + pkgs.openssl + ]; + + nativeBuildInputs = [ + # generates manpages + pkgs.mandown + + pkgs.installShellFiles + pkgs.copyDesktopItems + + # for openssl/openssl-sys + pkgs.pkg-config + ]; + + devInputs = [ + pkgs.cargo-make + pkgs.rust-analyzer + + # optimizes wasm binaries + pkgs.binaryen + + # used for snapshotting the e2e tests + pkgs.cargo-insta + ]; + + fmtInputs = [ + pkgs.alejandra + pkgs.treefmt + ]; + + postInstall = '' + mandown ./docs/MANPAGE.md > ./zellij.1 + installManPage ./zellij.1 + + # explicit behavior + $out/bin/zellij setup --generate-completion bash > ./completions.bash + installShellCompletion --bash --name ${pname}.bash ./completions.bash + $out/bin/zellij setup --generate-completion fish > ./completions.fish + installShellCompletion --fish --name ${pname}.fish ./completions.fish + $out/bin/zellij setup --generate-completion zsh > ./completions.zsh + installShellCompletion --zsh --name _${pname} ./completions.zsh + + install -Dm644 ./assets/logo.png $out/share/icons/hicolor/scalable/apps/zellij.png + + copyDesktopItems + ''; + + desktopItems = [ + (pkgs.makeDesktopItem { + type = "Application"; + inherit name; + desktopName = "zellij"; + terminal = true; + genericName = "Terminal multiplexer"; + comment = "Manage your terminal applications"; + exec = "zellij"; + icon = "zellij"; + categories = ["ConsoleOnly;System"]; }) + ]; + meta = with pkgs.lib; { + homepage = "https://github.com/zellij-org/zellij/"; + description = "A terminal workspace with batteries included"; + license = [licenses.mit]; + }; +in rec { + # crate2nix - better incremental builds, but uses ifd + packages.zellij = crate2nixPkgs.callPackage ./crate2nix.nix { + inherit + name + src + nativeBuildInputs + crate2nix + desktopItems + postInstall + meta + ; + }; + + # native nixpkgs support - keep supported + packages.zellij-native = + (pkgs.makeRustPlatform {inherit cargo rustc;}).buildRustPackage { + inherit + src + name + cargoLock + buildInputs + nativeBuildInputs + postInstall + desktopItems + meta + ; + }; + + defaultPackage = packages.zellij; + + # nix run + apps.zellij = flake-utils.lib.mkApp {drv = packages.zellij;}; + defaultApp = apps.zellij; + + devShells = { + zellij = pkgs.callPackage ./devShell.nix { + inherit buildInputs; + nativeBuildInputs = nativeBuildInputs ++ devInputs ++ fmtInputs; + }; + fmtShell = pkgs.mkShell { + name = "fmt-shell"; + nativeBuildInputs = fmtInputs; + }; + }; + + devShell = devShells.zellij; +}) diff --git a/nix/devShell.nix b/nix/devShell.nix index 86850e709..261234f65 100644 --- a/nix/devShell.nix +++ b/nix/devShell.nix @@ -1,8 +1,8 @@ -{ mkShell -, buildInputs -, nativeBuildInputs +{ + mkShell, + buildInputs, + nativeBuildInputs, }: - mkShell { name = "zj-dev-env"; inherit buildInputs nativeBuildInputs; @@ -1,13 +1,14 @@ (import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in +( + 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 = ./.; - }).shellNix +) +{ + src = ./.; +}) +.shellNix diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 000000000..fe5d1f37e --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,3 @@ +[formatter.nix] +command = "alejandra" +includes = ["*.nix"] |