on master help sign in
Initial commit
commitd6555bf153a0454f1fd93d98aeec2486ac21635e authoriko <mail@iko.soy> dateFri 3 Mar 2023, 13:49 (4 years ago)
6 files changed+281
.gitignore+1 example.apparmor+8 flake.lock+105 flake.nix+35 nix-click/flake.nix+131 nix-click/icon.svg+1
.gitignorenew file+1
@@ -0,0 +1 @@
1+result
example.apparmornew file+8
@@ -0,0 +1,8 @@
1+
2+{
3+ "template": "unconfined",
4+ "policy_groups": [
5+ ],
6+
7+ "policy_version": 20.04
8+}
flake.locknew file+105
@@ -0,0 +1,105 @@
1+{
2+ "nodes": {
3+ "flake-utils": {
4+ "locked": {
5+ "lastModified": 1676283394,
6+ "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
7+ "owner": "numtide",
8+ "repo": "flake-utils",
9+ "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
10+ "type": "github"
11+ },
12+ "original": {
13+ "owner": "numtide",
14+ "repo": "flake-utils",
15+ "type": "github"
16+ }
17+ },
18+ "flake-utils_2": {
19+ "locked": {
20+ "lastModified": 1676283394,
21+ "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
22+ "owner": "numtide",
23+ "repo": "flake-utils",
24+ "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
25+ "type": "github"
26+ },
27+ "original": {
28+ "owner": "numtide",
29+ "repo": "flake-utils",
30+ "type": "github"
31+ }
32+ },
33+ "nix-bundle": {
34+ "flake": false,
35+ "locked": {
36+ "lastModified": 1677673575,
37+ "narHash": "sha256-v6KkJT8dQkjsN9Dkx9P5zo+BYnjqQ1oJv3n6dW7fsaM=",
38+ "owner": "ilyakooo0",
39+ "repo": "nix-bundle",
40+ "rev": "db4b8ca5af5ccdb3a4ff8be4a2390fecc7c58134",
41+ "type": "github"
42+ },
43+ "original": {
44+ "owner": "ilyakooo0",
45+ "repo": "nix-bundle",
46+ "rev": "db4b8ca5af5ccdb3a4ff8be4a2390fecc7c58134",
47+ "type": "github"
48+ }
49+ },
50+ "nix-click": {
51+ "inputs": {
52+ "flake-utils": "flake-utils_2",
53+ "nix-bundle": "nix-bundle",
54+ "nixpkgs": "nixpkgs"
55+ },
56+ "locked": {
57+ "lastModified": 1,
58+ "narHash": "sha256-fveS7dUs8NQfRepjGdCTLVGuUE8iNCvZTiYz2IOUiYk=",
59+ "path": "/nix/store/djymmmmvcpqs5pqcs9wxravhwcsl3slp-source/nix-click",
60+ "type": "path"
61+ },
62+ "original": {
63+ "path": "/nix/store/djymmmmvcpqs5pqcs9wxravhwcsl3slp-source/nix-click",
64+ "type": "path"
65+ }
66+ },
67+ "nixpkgs": {
68+ "locked": {
69+ "lastModified": 1677673249,
70+ "narHash": "sha256-ckAqcoKIjfBBDZHSa3ez55PLopCyeShhZtf1UzIfO+o=",
71+ "owner": "NixOS",
72+ "repo": "nixpkgs",
73+ "rev": "fea42519a41102668eb215a6cb4a883a88b4b236",
74+ "type": "github"
75+ },
76+ "original": {
77+ "id": "nixpkgs",
78+ "type": "indirect"
79+ }
80+ },
81+ "nixpkgs_2": {
82+ "locked": {
83+ "lastModified": 1677560409,
84+ "narHash": "sha256-PIvUIsVNozPXe1FmNe9c6B8Febl3t9+51uBKMJ1Q8o0=",
85+ "owner": "NixOS",
86+ "repo": "nixpkgs",
87+ "rev": "9e56d6ec92c8fb4192f1392aa5c4101ad77f2070",
88+ "type": "github"
89+ },
90+ "original": {
91+ "id": "nixpkgs",
92+ "type": "indirect"
93+ }
94+ },
95+ "root": {
96+ "inputs": {
97+ "flake-utils": "flake-utils",
98+ "nix-click": "nix-click",
99+ "nixpkgs": "nixpkgs_2"
100+ }
101+ }
102+ },
103+ "root": "root",
104+ "version": 7
105+}
flake.nixnew file+35
@@ -0,0 +1,35 @@
1+{
2+ description = "Flake utils demo";
3+
4+ inputs = {
5+ flake-utils.url = "github:numtide/flake-utils";
6+ nix-click.url = "./nix-click";
7+ nix-click.inputs.nixpkgs.url =
8+ "github:NixOS/nixpkgs?rev=fea42519a41102668eb215a6cb4a883a88b4b236";
9+ };
10+
11+ outputs = { self, nixpkgs, flake-utils, nix-click }:
12+ flake-utils.lib.eachDefaultSystem (system: {
13+ packages = {
14+ default = nix-click.packages.${system}.buildAll {
15+ name = "yubioath";
16+ supportedPlatforms = {
17+ arm64 = true;
18+ amd64 = false;
19+ armhf = false;
20+ };
21+ } (p: {
22+ contents = [ ];
23+ exec = "${p.gnome.gnome-weather}/bin/epiphany";
24+ manifest = {
25+ name = "soy.iko.weather";
26+ version = "1.0.0";
27+ maintainer = "Ilia Kostiuchenko <mail@iko.soy>";
28+ title = "weather";
29+ framework = "ubuntu-sdk-20.04";
30+ };
31+ apparmor = ./example.apparmor;
32+ });
33+ };
34+ });
35+}
nix-click/flake.nixnew file+131
@@ -0,0 +1,131 @@
1+{
2+ description = "Flake utils demo";
3+
4+ inputs = {
5+ flake-utils.url = "github:numtide/flake-utils";
6+ nix-bundle = {
7+ url =
8+ "github:ilyakooo0/nix-bundle?rev=db4b8ca5af5ccdb3a4ff8be4a2390fecc7c58134";
9+ flake = false;
10+ };
11+ };
12+
13+ outputs = { self, nixpkgs, flake-utils, nix-bundle }:
14+ flake-utils.lib.eachDefaultSystem (system:
15+ let pkgs = import nixpkgs { inherit system; };
16+ in {
17+ packages = rec {
18+ buildAll = { name, supportedPlatforms ? {
19+ arm64 = true;
20+ amd64 = false;
21+ armhf = false;
22+ } }:
23+ f:
24+ let
25+ f_ = { arch, staticPkgs, targetSystem }:
26+ let args = f staticPkgs;
27+ in if args == null || !(supportedPlatforms ? ${arch})
28+ || supportedPlatforms.${arch} == null
29+ || !supportedPlatforms.${arch} then
30+ null
31+ else {
32+ name = "${arch}.click";
33+ path = build (args // {
34+ manifest = args.manifest // { architecture = arch; };
35+ inherit targetSystem;
36+ });
37+ };
38+ in pkgs.linkFarm name (builtins.filter (x: x != null) (builtins.map
39+ (args:
40+ let res = builtins.tryEval (f_ args);
41+ in if res.success then res.value else null) [{
42+ arch = "arm64";
43+ staticPkgs = (import nixpkgs { system = "aarch64-linux"; });
44+ targetSystem = "aarch64-linux";
45+ }
46+ {
47+ arch = "armhf";
48+ staticPkgs = (import nixpkgs { system = "armv7l-linux"; });
49+ targetSystem = "armv7l-linux";
50+ }
51+ {
52+ arch = "amd64";
53+ staticPkgs = (import nixpkgs { system = "x86_64-linux"; });
54+ targetSystem = "x86_64-linux";
55+ }
56+ ]));
57+ build = { targetSystem, exec, contents ? [ ], manifest ? null
58+ , apparmor, icon ? ./icon.svg }:
59+ let
60+ contentsList = if builtins.typeOf contents == "list" then
61+ contents
62+ else
63+ [ contents ];
64+ getObj = src: arg:
65+ if arg == null then
66+ # should be read from src
67+ builtins.fromJSON (builtins.readFile src)
68+ else
69+ # specified as an argument
70+ if builtins.typeOf arg == "path" then
71+ builtins.fromJSON (builtins.readFile manifest)
72+ else if builtins.typeOf arg == "set" then
73+ arg
74+ else
75+ builtins.throw "Could not read ${src}";
76+ desktopName = "${manifestObjectRaw.name}.desktop";
77+ apparomrName = "${manifestObjectRaw.name}.apparmor";
78+ desktopFile = pkgs.writeTextFile {
79+ name = desktopName;
80+ text = ''
81+ [Desktop Entry]
82+ Name=${manifestObject.title}
83+ Exec=nix-user-chroot -n ./nix -- ${exec}
84+ Icon=${builtins.baseNameOf icon}
85+ Terminal=false
86+ Type=Application
87+ X-Ubuntu-Touch=true
88+ '';
89+ };
90+ manifestObjectRaw = getObj "manifest.json" manifest;
91+ manifestObject = manifestObjectRaw // {
92+ hooks = {
93+ "${manifestObjectRaw.name}" = {
94+ apparmor = apparomrName;
95+ desktop = desktopName;
96+ };
97+ };
98+ };
99+ manifestFile = pkgs.writeTextFile {
100+ name = "manifest.json";
101+ text = builtins.toJSON manifestObject;
102+ };
103+ allDeps = pkgs.concatTextFile {
104+ name = "${manifest.name}-deps";
105+ files = builtins.map pkgs.writeReferencesToFile
106+ (contentsList ++ [ exec ]);
107+ };
108+ targetPkgs = import nixpkgs { system = targetSystem; };
109+ nix-user-chroot = (import nix-bundle {
110+ nixpkgs = targetPkgs.pkgsStatic;
111+ }).nix-user-chroot.override { postFixup = ""; };
112+ in pkgs.runCommand "${manifest.name}-${manifest.version}.click"
113+ { } ''
114+ cat ${allDeps} | uniq >deps
115+ mkdir build
116+ while read p; do
117+ echo "copying $p"
118+ cp -r --parents $p build
119+ done <deps
120+ cp ${nix-user-chroot}/bin/nix-user-chroot build/nix-user-chroot
121+ cp ${apparmor} build/${apparomrName}
122+ cp ${desktopFile} build/${desktopName}
123+ cp ${manifestFile} build/manifest.json
124+ cp ${icon} build/${builtins.baseNameOf icon}
125+ chmod -R 777 build
126+ ${pkgs.ubports-click}/bin/click build build
127+ cp *.click $out
128+ '';
129+ };
130+ });
131+}
nix-click/icon.svgnew file+1
@@ -0,0 +1 @@
1+<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" fill="none" style="-webkit-print-color-adjust:exact"><defs><clipPath id="a" class="frame-clip-def frame-clip"><rect width="512" height="512" rx="0" ry="0" style="fill:#fff;fill-opacity:1"/></clipPath></defs><g clip-path="url(#a)"><g class="fills"><rect width="512" height="512" class="frame-background" rx="0" ry="0" style="fill:#fff;fill-opacity:1"/></g></g></svg>