Skip to content

Commit f61a370

Browse files
ratsclubkmaasrud
authored andcommitted
refactor: improve nix infrastructure
1 parent e963629 commit f61a370

File tree

7 files changed

+143
-209
lines changed

7 files changed

+143
-209
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Nix
1+
name: Nix build
22

33
on:
44
push:
@@ -12,13 +12,11 @@ jobs:
1212

1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v1
15+
uses: actions/checkout@v4
1616

1717
- name: Install Nix
18-
uses: cachix/install-nix-action@v15
19-
with:
20-
extra_nix_config: |
21-
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
22-
18+
uses: DeterminateSystems/nix-installer-action@main
19+
- name: Install Nix magic cache
20+
uses: DeterminateSystems/magic-nix-cache-action@main
2321
- name: Build
2422
run: nix build

Diff for: .github/workflows/nix-flake-update.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Update flake.lock
2+
on:
3+
workflow_dispatch: # allows manual triggering
4+
schedule:
5+
- cron: '0 0 * * 1' # runs weekly on Monday at 00:00
6+
7+
jobs:
8+
lockfile:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
- name: Install Nix
14+
uses: DeterminateSystems/nix-installer-action@main
15+
- name: Install Nix magic cache
16+
uses: DeterminateSystems/magic-nix-cache-action@main
17+
- name: Update flake.lock
18+
uses: DeterminateSystems/update-flake-lock@main
19+
with:
20+
pr-title: "chore: update flake.lock" # Title of PR to be created
21+
pr-labels: | # Labels to be set on the PR
22+
dependencies
23+
automated

Diff for: .github/workflows/website-publish.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout 🛎️
15-
uses: actions/checkout@v2.3.1
15+
uses: actions/checkout@v4
1616

1717
- name: Install Nix
18-
uses: cachix/install-nix-action@v15
19-
with:
20-
extra_nix_config: |
21-
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
18+
uses: DeterminateSystems/nix-installer-action@main
19+
- name: Install Nix magic cache
20+
uses: DeterminateSystems/magic-nix-cache-action@main
2221

2322
- name: Build
2423
run: nix build .#website

Diff for: flake.lock

+7-108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+68-51
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,82 @@
22
description = "Plain text Zettelkasten based on mdBook";
33

44
inputs = {
5-
utils.url = "github:numtide/flake-utils";
6-
rust.url = "github:oxalica/rust-overlay";
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
76
};
87

9-
outputs = {
10-
self,
11-
nixpkgs,
12-
utils,
13-
rust,
14-
}: let
15-
pname = "mdzk";
16-
version =
17-
(builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
18-
in
19-
{
20-
overlays.default = nixpkgs.lib.composeManyExtensions [
21-
rust.overlays.default
22-
(final: _: {
23-
customRustToolchain =
24-
final.rust-bin.selectLatestNightlyWith
25-
(toolchain:
26-
toolchain.default.override {
27-
extensions = ["rust-std" "rust-src"];
28-
});
8+
outputs =
9+
{ self
10+
, nixpkgs
11+
}:
12+
let
13+
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
2914

30-
mdzk = import ./nix/package.nix {
31-
inherit pname version;
32-
pkgs = final;
33-
};
34-
})
35-
];
36-
}
37-
// utils.lib.eachDefaultSystem (system: let
38-
pkgs = import nixpkgs {
15+
nixpkgsFor = forAllSystems (system: import nixpkgs {
3916
inherit system;
40-
overlays = [self.overlays.default];
17+
overlays = [ self.overlays.default ];
18+
});
19+
20+
pname = "mdzk";
21+
version =
22+
(builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
23+
in
24+
{
25+
overlays.default = final: prev: {
26+
mdzk = prev.callPackage ./nix/package.nix { inherit prev pname version; };
4127
};
4228

43-
inherit (pkgs) mdzk;
44-
in rec {
45-
# `nix build .#mdzk`
46-
packages.${pname} = mdzk;
29+
apps = forAllSystems (system:
30+
let
31+
pkgs = nixpkgsFor."${system}";
32+
app = {
33+
type = "app";
34+
program = "${pkgs.mdzk}/bin/mdzk";
35+
};
36+
in
37+
{
38+
# `nix run`
39+
default = app;
40+
41+
# `nix run .#mdzk`
42+
mdzk = app;
43+
});
4744

48-
# `nix build .#website`
49-
packages.website = pkgs.callPackage ./nix/website.nix {inherit pkgs;};
45+
packages = forAllSystems (system:
46+
let
47+
pkgs = nixpkgsFor."${system}";
48+
in
49+
{
50+
# `nix build`
51+
default = pkgs.mdzk;
5052

51-
# `nix build`
52-
packages.default = packages.${pname};
53+
# `nix build .#mdzk`
54+
"${pname}" = pkgs.mdzk;
5355

54-
# `nix run`
55-
apps.${pname} = utils.lib.mkApp {drv = packages.${pname};};
56-
apps.default = apps.${pname};
56+
# `nix build .#website`
57+
website = pkgs.callPackage ./nix/website.nix { };
58+
});
5759

58-
# `nix develop`
59-
devShells.default = pkgs.mkShell {
60-
nativeBuildInputs = with pkgs; [
61-
# rust
62-
customRustToolchain
63-
];
64-
};
65-
});
60+
formatter = forAllSystems (system:
61+
let
62+
pkgs = nixpkgsFor."${system}";
63+
in
64+
# `nix fmt`
65+
pkgs.nixpkgs-fmt);
66+
67+
devShells = forAllSystems (system:
68+
let
69+
pkgs = nixpkgsFor."${system}";
70+
71+
inherit (pkgs)
72+
mkShell
73+
cargo
74+
rustc
75+
rust-analyzer;
76+
in
77+
{
78+
default = mkShell {
79+
buildInputs = [ cargo rust-analyzer rustc ];
80+
};
81+
});
82+
};
6683
}

Diff for: nix/package.nix

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
{
2-
pkgs,
3-
pname,
4-
version,
5-
...
6-
}: let
7-
rustPlatform = pkgs.makeRustPlatform {
8-
rustc = pkgs.customRustToolchain;
9-
cargo = pkgs.customRustToolchain;
10-
};
1+
{ pkgs
2+
, pname
3+
, version
4+
, ...
5+
}:
6+
let
7+
inherit (pkgs)
8+
rustPlatform;
119
in
12-
rustPlatform.buildRustPackage {
13-
inherit pname version;
10+
rustPlatform.buildRustPackage {
11+
inherit pname version;
1412

15-
src = pkgs.lib.cleanSource ../.;
13+
src = pkgs.lib.cleanSource ../.;
1614

17-
buildInputs =
18-
pkgs.lib.optionals pkgs.stdenv.isDarwin
19-
[pkgs.darwin.apple_sdk.frameworks.CoreServices];
15+
buildInputs =
16+
pkgs.lib.optionals pkgs.stdenv.isDarwin
17+
[ pkgs.darwin.apple_sdk.frameworks.CoreServices ];
2018

21-
makeFlags = ["PREFIX=$(out)"];
19+
makeFlags = [ "PREFIX=$(out)" ];
2220

23-
postBuild = ''
24-
pandoc --standalone --to man public/man.md -o public/mdzk.1
25-
'';
21+
postBuild = ''
22+
pandoc --standalone --to man public/man.md -o public/mdzk.1
23+
'';
2624

27-
preInstall = ''
28-
install -d $out/share/man/man1/
29-
install -pm 0644 public/mdzk.1 $out/share/man/man1/
30-
'';
25+
preInstall = ''
26+
install -d $out/share/man/man1/
27+
install -pm 0644 public/mdzk.1 $out/share/man/man1/
28+
'';
3129

32-
nativeBuildInputs = with pkgs; [pandoc];
30+
nativeBuildInputs = with pkgs; [ pandoc ];
3331

34-
cargoSha256 = "sha256-2exNoGAj2ndVRu90tCv+CEn3nPSBtcjHzJcPkZKBndA=";
35-
}
32+
cargoHash = "sha256-2exNoGAj2ndVRu90tCv+CEn3nPSBtcjHzJcPkZKBndA=";
33+
}

0 commit comments

Comments
 (0)