Skip to content

Commit

Permalink
flake: formatter: adopt alejandra
Browse files Browse the repository at this point in the history
Because formatters may wrap long lines with comments, I have replaced
`LOAD-BEARING COMMENT` on the package's `version` attribute with
`@VERSION@`.
This was done so that `sed` can still match the line, because it is
short enough to not wrap at 80 columns.
  • Loading branch information
spikespaz committed Sep 13, 2023
1 parent d9553bc commit f75461c
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
- name: Increment `flake.nix` version
run: |
sed -i \
-e "s/version = \"[^\"]*\"; # LOAD-BEARING COMMENT/version = \"${{ steps.new_cargo_metadata.outputs.version }}\"; # LOAD-BEARING COMMENT/" \
-e "s/version = \"[^\"]*\"; # @VERSION@/version = \"${{ steps.new_cargo_metadata.outputs.version }}\"; # @VERSION@/" \
flake.nix
# Commit the new changes
Expand Down
20 changes: 7 additions & 13 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
(
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 = ./.;}
)
(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
94 changes: 93 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 58 additions & 63 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,82 @@
url = "github:edolstra/flake-compat";
flake = false;
};
alejandra.url = "github:kamadorueda/alejandra";
};

outputs = {
self,
nixpkgs,
systems,
alejandra,
...
}:
let
inherit (nixpkgs) lib;
eachSystem = fn: lib.genAttrs (import systems) (system:
let
pkgs = import nixpkgs {
localSystem = system;
overlays = [self.overlays.default];
};
in
fn pkgs system
);
in {
packages = eachSystem (pkgs: system: {
nix-your-shell = pkgs.nix-your-shell;
default = self.packages.${system}.nix-your-shell;
});
}: let
inherit (nixpkgs) lib;
eachSystem = fn:
lib.genAttrs (import systems) (system: let
pkgs = import nixpkgs {
localSystem = system;
overlays = [self.overlays.default];
};
in
fn pkgs system);
in {
packages = eachSystem (pkgs: system: {
nix-your-shell = pkgs.nix-your-shell;
default = self.packages.${system}.nix-your-shell;
});

checks = eachSystem (_: system: self.packages.${system});
checks = eachSystem (_: system: self.packages.${system});

# for debugging
# inherit pkgs;
# for debugging
# inherit pkgs;

devShells = eachSystem (pkgs: system: {
default = pkgs.nix-your-shell.overrideAttrs (
old: {
# Make rust-analyzer work
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
devShells = eachSystem (pkgs: system: {
default = pkgs.nix-your-shell.overrideAttrs (old: {
# Make rust-analyzer work
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;

# Any dev tools you use in excess of the rust ones
nativeBuildInputs =
old.nativeBuildInputs;
}
);
});
# Any dev tools you use in excess of the rust ones
nativeBuildInputs = old.nativeBuildInputs;
});
});

overlays.default = (
final: prev: {
nix-your-shell = final.rustPlatform.buildRustPackage {
pname = "nix-your-shell";
version = "1.3.0"; # LOAD-BEARING COMMENT. See: `.github/workflows/version.yaml`
overlays.default = final: prev: {
nix-your-shell = final.rustPlatform.buildRustPackage {
pname = "nix-your-shell";
# The comment below is a target for `sed` to match. Do not remove.
# See `.github/workflows/version.yaml`.
version = "1.3.0"; # @VERSION@

cargoLock = {
lockFile = ./Cargo.lock;
};
cargoLock = {lockFile = ./Cargo.lock;};

src = ./.;
src = ./.;

# Tools on the builder machine needed to build; e.g. pkg-config
nativeBuildInputs = [
final.rustfmt
final.clippy
];
# Tools on the builder machine needed to build; e.g. pkg-config
nativeBuildInputs = [final.rustfmt final.clippy];

# Native libs
buildInputs = [];
# Native libs
buildInputs = [];

postCheck = ''
cargo fmt --check && echo "\`cargo fmt\` is OK"
cargo clippy -- --deny warnings && echo "\`cargo clippy\` is OK"
'';
postCheck = ''
cargo fmt --check && echo "\`cargo fmt\` is OK"
cargo clippy -- --deny warnings && echo "\`cargo clippy\` is OK"
'';

passthru.generate-config = shell: final.runCommand "nix-your-shell-config" { } ''
${final.nix-your-shell}/bin/nix-your-shell ${shell} >> $out
'';
passthru.generate-config = shell:
final.runCommand "nix-your-shell-config" {} ''
${final.nix-your-shell}/bin/nix-your-shell ${shell} >> $out
'';

meta = {
homepage = "https://github.com/MercuryTechnologies/nix-your-shell";
license = lib.licenses.mit;
platforms = import systems;
mainProgram = "nix-your-shell";
};
};
}
);
meta = {
homepage = "https://github.com/MercuryTechnologies/nix-your-shell";
license = lib.licenses.mit;
platforms = import systems;
mainProgram = "nix-your-shell";
};
};
};

formatter = eachSystem (_: system: alejandra.packages.${system}.default);
};
}
20 changes: 7 additions & 13 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
(
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 = ./.;}
)
(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

0 comments on commit f75461c

Please sign in to comment.