diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3d05e55 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1763835633, + "narHash": "sha256-HzxeGVID5MChuCPESuC0dlQL1/scDKu+MmzoVBJxulM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "050e09e091117c3d7328c7b2b7b577492c43c134", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..804268d --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + + outputs = { + self, + nixpkgs, + ... + }: let + systems = ["x86_64-linux" "aarch64-linux"]; + forEachSystem = nixpkgs.lib.genAttrs systems; + pkgsForEach = nixpkgs.legacyPackages; + in { + packages = forEachSystem (system: { + sin = pkgsForEach.${system}.callPackage ./nix/package.nix {}; + default = self.packages.${system}.sin; + }); + + devShells = forEachSystem (system: { + default = pkgsForEach.${system}.mkShell { + inputsFrom = [self.packages.${system}.default]; + }; + }); + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..debf559 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,41 @@ +{ + lib, + stdenv, + systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd, + systemd, +}: +stdenv.mkDerivation { + pname = "sin"; + version = "0.1.0"; + + src = let + fs = lib.fileset; + s = ../.; + in + fs.toSource { + root = s; + fileset = fs.unions [ + (s + /Makefile) + (s + /main.c) + ]; + }; + + strictDeps = true; + buildInputs = lib.optionals systemdSupport [systemd]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + install -Dm755 sin $out/bin/sin + + runHook postInstall + ''; + + meta = { + description = "Keep system idle inhibited while named processes run"; + license = lib.licenses.mit; + maintainers = [lib.maintainers.NotAShelf]; + platforms = lib.platforms.linux; + }; +}