Skip to content

Commit 1e29613

Browse files
authored
feat(nix): add comprehensive Nix flake (flameshot-org#4403)
chore(nix): add flake.lock
1 parent 0f37bf0 commit 1e29613

File tree

7 files changed

+304
-12
lines changed

7 files changed

+304
-12
lines changed

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use_nix
1+
use flake

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ data/flatpak/.flatpak-builder
7575

7676
# Miscellaneous
7777
!docs/dev/Makefile
78+
79+
# Nix
80+
result
81+
result-*
82+
83+
# direnv
7884
.direnv

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,23 @@ pacman -S qt6-svg
470470
pacman -S openssl ca-certificates qt6-imageformats
471471
```
472472

473-
#### NixOS
473+
#### Nix
474474

475+
Development Shell:
475476
```shell
477+
# Without flakes:
476478
nix-shell
479+
480+
# With flakes:
481+
nix develop
482+
```
483+
484+
```shell
485+
# Build flameshot
486+
nix build
487+
488+
# Build and run flameshot
489+
nix run
477490
```
478491

479492
#### macOS

default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
nodeName = lock.nodes.root.inputs.flake-compat;
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.${nodeName}.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.${nodeName}.locked.narHash;
11+
}
12+
) { src = ./.; }).defaultNix

flake.lock

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
description = "Powerful yet simple to use screenshot software";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
systems.url = "github:nix-systems/default";
7+
flake-parts.url = "github:hercules-ci/flake-parts";
8+
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
9+
treefmt-nix.url = "github:numtide/treefmt-nix";
10+
};
11+
12+
outputs =
13+
inputs@{ flake-parts, systems, ... }:
14+
flake-parts.lib.mkFlake { inherit inputs; } {
15+
systems = import systems;
16+
imports = [
17+
inputs.treefmt-nix.flakeModule
18+
];
19+
20+
perSystem =
21+
{
22+
pkgs,
23+
lib,
24+
...
25+
}:
26+
let
27+
qtcolorwidgets = pkgs.fetchFromGitLab {
28+
owner = "mattbas";
29+
repo = "Qt-Color-Widgets";
30+
rev = "3.0.0";
31+
hash = "sha256-77G1NU7079pvqhQnSTmMdkd2g1R2hoJxn183WcsWq8c=";
32+
};
33+
34+
kdsingleapplication = pkgs.fetchFromGitHub {
35+
owner = "KDAB";
36+
repo = "KDSingleApplication";
37+
rev = "v1.2.0";
38+
hash = "sha256-rglt89Gw6OHXXVOEwf0TxezDzyHEvWepeGeup7fBlLs=";
39+
};
40+
41+
enableWlrSupport = true;
42+
43+
# Build time
44+
nativeBuildInputs =
45+
with pkgs;
46+
[
47+
cmake
48+
qt6.qttools
49+
qt6.wrapQtAppsHook
50+
makeBinaryWrapper
51+
]
52+
++ lib.optionals stdenv.hostPlatform.isDarwin [
53+
imagemagick
54+
libicns
55+
];
56+
57+
# Run time
58+
buildInputs = with pkgs; [
59+
qt6.qtbase
60+
qt6.qtsvg
61+
qt6.qtwayland
62+
kdePackages.kguiaddons
63+
];
64+
65+
flameshot = pkgs.stdenv.mkDerivation {
66+
pname = "flameshot";
67+
version = "dev";
68+
69+
src = ./.;
70+
71+
inherit nativeBuildInputs;
72+
inherit buildInputs;
73+
74+
preConfigure = ''
75+
mkdir -p build/_deps
76+
cp -r ${qtcolorwidgets} build/_deps/qtcolorwidgets-src
77+
cp -r ${kdsingleapplication} build/_deps/kdsingleapplication-src
78+
chmod -R +w build/_deps
79+
'';
80+
81+
cmakeFlags = [
82+
(lib.cmakeBool "DISABLE_UPDATE_CHECKER" true)
83+
(lib.cmakeBool "USE_WAYLAND_CLIPBOARD" true)
84+
(lib.cmakeBool "USE_WAYLAND_GRIM" enableWlrSupport)
85+
"-DFETCHCONTENT_FULLY_DISCONNECTED=ON"
86+
"-DFETCHCONTENT_SOURCE_DIR_QTCOLORWIDGETS=${qtcolorwidgets}"
87+
"-DFETCHCONTENT_SOURCE_DIR_KDSINGLEAPPLICATION=${kdsingleapplication}"
88+
];
89+
90+
dontWrapQtApps = true;
91+
92+
postFixup = ''
93+
wrapProgram $out/bin/flameshot \
94+
${lib.optionalString enableWlrSupport "--prefix PATH : ${lib.makeBinPath [ pkgs.grim ]}"} \
95+
''${qtWrapperArgs[@]}
96+
'';
97+
98+
meta = {
99+
description = "Powerful yet simple to use screenshot software";
100+
homepage = "https://github.com/flameshot-org/flameshot";
101+
license = pkgs.lib.licenses.gpl3Only;
102+
maintainers = [ "flameshot-org" ];
103+
platforms = pkgs.lib.platforms.unix ++ pkgs.lib.platforms.darwin;
104+
mainProgram = "flameshot";
105+
};
106+
};
107+
in
108+
{
109+
packages = {
110+
default = flameshot;
111+
inherit flameshot;
112+
};
113+
114+
devShells.default = pkgs.mkShell {
115+
name = "flameshot-dev";
116+
117+
buildInputs =
118+
with pkgs;
119+
[
120+
cmake
121+
gdb
122+
]
123+
++ buildInputs;
124+
};
125+
126+
treefmt = {
127+
programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
128+
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
129+
};
130+
};
131+
};
132+
}

shell.nix

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
{ pkgs ? import <nixpkgs> { } }:
2-
3-
pkgs.mkShell {
4-
nativeBuildInputs = with pkgs; [
5-
cmake
6-
kdePackages.qtsvg
7-
kdePackages.qttools
8-
];
9-
buildInputs = with pkgs; [ kdePackages.qtbase kdePackages.kguiaddons ];
10-
}
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
nodeName = lock.nodes.root.inputs.flake-compat;
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.${nodeName}.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.${nodeName}.locked.narHash;
11+
}
12+
) { src = ./.; }).shellNix

0 commit comments

Comments
 (0)